Cudf support. (#4745)
* Initial support for cudf integration. * Add two C APIs for consuming data and metainfo. * Add CopyFrom for SimpleCSRSource as a generic function to consume the data. * Add FromDeviceColumnar for consuming device data. * Add new MetaInfo::SetInfo for consuming label, weight etc.
This commit is contained in:
committed by
Rory Mitchell
parent
ab357dd41c
commit
9700776597
92
tests/cpp/common/test_bitfield.cc
Normal file
92
tests/cpp/common/test_bitfield.cc
Normal file
@@ -0,0 +1,92 @@
|
||||
/*!
|
||||
* Copyright 2019 XGBoost contributors
|
||||
*/
|
||||
#include <gtest/gtest.h>
|
||||
#include "../../../src/common/bitfield.h"
|
||||
|
||||
namespace xgboost {
|
||||
|
||||
TEST(BitField, Check) {
|
||||
{
|
||||
std::vector<LBitField64::value_type> storage(4, 0);
|
||||
storage[2] = 2;
|
||||
auto bits = LBitField64({storage.data(),
|
||||
static_cast<typename common::Span<LBitField64::value_type>::index_type>(
|
||||
storage.size())});
|
||||
size_t true_bit = 190;
|
||||
for (size_t i = true_bit + 1; i < bits.Size(); ++i) {
|
||||
ASSERT_FALSE(bits.Check(i));
|
||||
}
|
||||
ASSERT_TRUE(bits.Check(true_bit));
|
||||
for (size_t i = 0; i < true_bit; ++i) {
|
||||
ASSERT_FALSE(bits.Check(i));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
std::vector<RBitField8::value_type> storage(4, 0);
|
||||
storage[2] = 1 << 3;
|
||||
auto bits = RBitField8({storage.data(),
|
||||
static_cast<typename common::Span<RBitField8::value_type>::index_type>(
|
||||
storage.size())});
|
||||
size_t true_bit = 19;
|
||||
for (size_t i = 0; i < true_bit; ++i) {
|
||||
ASSERT_FALSE(bits.Check(i));
|
||||
}
|
||||
ASSERT_TRUE(bits.Check(true_bit));
|
||||
for (size_t i = true_bit + 1; i < bits.Size(); ++i) {
|
||||
ASSERT_FALSE(bits.Check(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename BitFieldT, typename VT = typename BitFieldT::value_type>
|
||||
void TestBitFieldSet(typename BitFieldT::value_type res, size_t index, size_t true_bit) {
|
||||
using IndexT = typename common::Span<VT>::index_type;
|
||||
std::vector<VT> storage(4, 0);
|
||||
auto bits = BitFieldT({storage.data(), static_cast<IndexT>(storage.size())});
|
||||
|
||||
bits.Set(true_bit);
|
||||
|
||||
for (size_t i = 0; i < true_bit; ++i) {
|
||||
ASSERT_FALSE(bits.Check(i));
|
||||
}
|
||||
|
||||
ASSERT_TRUE(bits.Check(true_bit));
|
||||
|
||||
for (size_t i = true_bit + 1; i < storage.size() * BitFieldT::kValueSize; ++i) {
|
||||
ASSERT_FALSE(bits.Check(i));
|
||||
}
|
||||
ASSERT_EQ(storage[index], res);
|
||||
}
|
||||
|
||||
TEST(BitField, Set) {
|
||||
{
|
||||
TestBitFieldSet<LBitField64>(2, 2, 190);
|
||||
}
|
||||
{
|
||||
TestBitFieldSet<RBitField8>(1 << 3, 2, 19);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename BitFieldT, typename VT = typename BitFieldT::value_type>
|
||||
void TestBitFieldClear(size_t clear_bit) {
|
||||
using IndexT = typename common::Span<VT>::index_type;
|
||||
std::vector<VT> storage(4, 0);
|
||||
auto bits = BitFieldT({storage.data(), static_cast<IndexT>(storage.size())});
|
||||
|
||||
bits.Set(clear_bit);
|
||||
bits.Clear(clear_bit);
|
||||
|
||||
ASSERT_FALSE(bits.Check(clear_bit));
|
||||
}
|
||||
|
||||
TEST(BitField, Clear) {
|
||||
{
|
||||
TestBitFieldClear<LBitField64>(190);
|
||||
}
|
||||
{
|
||||
TestBitFieldClear<RBitField8>(19);
|
||||
}
|
||||
}
|
||||
} // namespace xgboost
|
||||
@@ -5,56 +5,55 @@
|
||||
#include <thrust/copy.h>
|
||||
#include <thrust/device_vector.h>
|
||||
#include <vector>
|
||||
#include "../../../src/common/bitfield.cuh"
|
||||
#include "../../../src/common/bitfield.h"
|
||||
#include "../../../src/common/device_helpers.cuh"
|
||||
|
||||
namespace xgboost {
|
||||
|
||||
__global__ void TestSetKernel(BitField bits) {
|
||||
__global__ void TestSetKernel(LBitField64 bits) {
|
||||
auto tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
if (tid < bits.Size()) {
|
||||
bits.Set(tid);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(BitField, Set) {
|
||||
dh::device_vector<BitField::value_type> storage;
|
||||
TEST(BitField, GPU_Set) {
|
||||
dh::device_vector<LBitField64::value_type> storage;
|
||||
uint32_t constexpr kBits = 128;
|
||||
storage.resize(128);
|
||||
auto bits = BitField(dh::ToSpan(storage));
|
||||
auto bits = LBitField64(dh::ToSpan(storage));
|
||||
TestSetKernel<<<1, kBits>>>(bits);
|
||||
|
||||
std::vector<BitField::value_type> h_storage(storage.size());
|
||||
std::vector<LBitField64::value_type> h_storage(storage.size());
|
||||
thrust::copy(storage.begin(), storage.end(), h_storage.begin());
|
||||
|
||||
BitField outputs {
|
||||
common::Span<BitField::value_type>{h_storage.data(),
|
||||
LBitField64 outputs {
|
||||
common::Span<LBitField64::value_type>{h_storage.data(),
|
||||
h_storage.data() + h_storage.size()}};
|
||||
for (size_t i = 0; i < kBits; ++i) {
|
||||
ASSERT_TRUE(outputs.Check(i));
|
||||
}
|
||||
}
|
||||
|
||||
__global__ void TestOrKernel(BitField lhs, BitField rhs) {
|
||||
__global__ void TestOrKernel(LBitField64 lhs, LBitField64 rhs) {
|
||||
lhs |= rhs;
|
||||
}
|
||||
|
||||
TEST(BitField, And) {
|
||||
TEST(BitField, GPU_And) {
|
||||
uint32_t constexpr kBits = 128;
|
||||
dh::device_vector<BitField::value_type> lhs_storage(kBits);
|
||||
dh::device_vector<BitField::value_type> rhs_storage(kBits);
|
||||
auto lhs = BitField(dh::ToSpan(lhs_storage));
|
||||
auto rhs = BitField(dh::ToSpan(rhs_storage));
|
||||
dh::device_vector<LBitField64::value_type> lhs_storage(kBits);
|
||||
dh::device_vector<LBitField64::value_type> rhs_storage(kBits);
|
||||
auto lhs = LBitField64(dh::ToSpan(lhs_storage));
|
||||
auto rhs = LBitField64(dh::ToSpan(rhs_storage));
|
||||
thrust::fill(lhs_storage.begin(), lhs_storage.end(), 0UL);
|
||||
thrust::fill(rhs_storage.begin(), rhs_storage.end(), ~static_cast<BitField::value_type>(0UL));
|
||||
thrust::fill(rhs_storage.begin(), rhs_storage.end(), ~static_cast<LBitField64::value_type>(0UL));
|
||||
TestOrKernel<<<1, kBits>>>(lhs, rhs);
|
||||
|
||||
std::vector<BitField::value_type> h_storage(lhs_storage.size());
|
||||
std::vector<LBitField64::value_type> h_storage(lhs_storage.size());
|
||||
thrust::copy(lhs_storage.begin(), lhs_storage.end(), h_storage.begin());
|
||||
BitField outputs {{h_storage.data(), h_storage.data() + h_storage.size()}};
|
||||
LBitField64 outputs {{h_storage.data(), h_storage.data() + h_storage.size()}};
|
||||
for (size_t i = 0; i < kBits; ++i) {
|
||||
ASSERT_TRUE(outputs.Check(i));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace xgboost
|
||||
Reference in New Issue
Block a user