Use the new DeviceOrd in the linalg module. (#9527)
This commit is contained in:
@@ -22,7 +22,7 @@ TEST(ArrayInterface, Initialize) {
|
||||
|
||||
HostDeviceVector<size_t> u64_storage(storage.Size());
|
||||
std::string u64_arr_str{ArrayInterfaceStr(linalg::TensorView<size_t const, 2>{
|
||||
u64_storage.ConstHostSpan(), {kRows, kCols}, Context::kCpuId})};
|
||||
u64_storage.ConstHostSpan(), {kRows, kCols}, DeviceOrd::CPU()})};
|
||||
std::copy(storage.ConstHostVector().cbegin(), storage.ConstHostVector().cend(),
|
||||
u64_storage.HostSpan().begin());
|
||||
auto u64_arr = ArrayInterface<2>{u64_arr_str};
|
||||
|
||||
@@ -129,8 +129,8 @@ TEST(MetaInfo, SaveLoadBinary) {
|
||||
EXPECT_EQ(inforead.group_ptr_, info.group_ptr_);
|
||||
EXPECT_EQ(inforead.weights_.HostVector(), info.weights_.HostVector());
|
||||
|
||||
auto orig_margin = info.base_margin_.View(xgboost::Context::kCpuId);
|
||||
auto read_margin = inforead.base_margin_.View(xgboost::Context::kCpuId);
|
||||
auto orig_margin = info.base_margin_.View(xgboost::DeviceOrd::CPU());
|
||||
auto read_margin = inforead.base_margin_.View(xgboost::DeviceOrd::CPU());
|
||||
EXPECT_TRUE(std::equal(orig_margin.Values().cbegin(), orig_margin.Values().cend(),
|
||||
read_margin.Values().cbegin()));
|
||||
|
||||
@@ -267,8 +267,8 @@ TEST(MetaInfo, Validate) {
|
||||
xgboost::HostDeviceVector<xgboost::bst_group_t> d_groups{groups};
|
||||
d_groups.SetDevice(0);
|
||||
d_groups.DevicePointer(); // pull to device
|
||||
std::string arr_interface_str{ArrayInterfaceStr(
|
||||
xgboost::linalg::MakeVec(d_groups.ConstDevicePointer(), d_groups.Size(), 0))};
|
||||
std::string arr_interface_str{ArrayInterfaceStr(xgboost::linalg::MakeVec(
|
||||
d_groups.ConstDevicePointer(), d_groups.Size(), xgboost::DeviceOrd::CUDA(0)))};
|
||||
EXPECT_THROW(info.SetInfo(ctx, "group", xgboost::StringView{arr_interface_str}), dmlc::Error);
|
||||
#endif // defined(XGBOOST_USE_CUDA)
|
||||
}
|
||||
@@ -307,5 +307,5 @@ TEST(MetaInfo, HostExtend) {
|
||||
}
|
||||
|
||||
namespace xgboost {
|
||||
TEST(MetaInfo, CPUStridedData) { TestMetaInfoStridedData(Context::kCpuId); }
|
||||
TEST(MetaInfo, CPUStridedData) { TestMetaInfoStridedData(DeviceOrd::CPU()); }
|
||||
} // namespace xgboost
|
||||
|
||||
@@ -65,7 +65,7 @@ TEST(MetaInfo, FromInterface) {
|
||||
}
|
||||
|
||||
info.SetInfo(ctx, "base_margin", str.c_str());
|
||||
auto const h_base_margin = info.base_margin_.View(Context::kCpuId);
|
||||
auto const h_base_margin = info.base_margin_.View(DeviceOrd::CPU());
|
||||
ASSERT_EQ(h_base_margin.Size(), d_data.size());
|
||||
for (size_t i = 0; i < d_data.size(); ++i) {
|
||||
ASSERT_EQ(h_base_margin(i), d_data[i]);
|
||||
@@ -83,7 +83,7 @@ TEST(MetaInfo, FromInterface) {
|
||||
}
|
||||
|
||||
TEST(MetaInfo, GPUStridedData) {
|
||||
TestMetaInfoStridedData(0);
|
||||
TestMetaInfoStridedData(DeviceOrd::CUDA(0));
|
||||
}
|
||||
|
||||
TEST(MetaInfo, Group) {
|
||||
|
||||
@@ -14,10 +14,10 @@
|
||||
#include "../../../src/data/array_interface.h"
|
||||
|
||||
namespace xgboost {
|
||||
inline void TestMetaInfoStridedData(int32_t device) {
|
||||
inline void TestMetaInfoStridedData(DeviceOrd device) {
|
||||
MetaInfo info;
|
||||
Context ctx;
|
||||
ctx.UpdateAllowUnknown(Args{{"gpu_id", std::to_string(device)}});
|
||||
ctx.UpdateAllowUnknown(Args{{"device", device.Name()}});
|
||||
{
|
||||
// labels
|
||||
linalg::Tensor<float, 3> labels;
|
||||
@@ -28,9 +28,9 @@ inline void TestMetaInfoStridedData(int32_t device) {
|
||||
ASSERT_EQ(t_labels.Shape().size(), 2);
|
||||
|
||||
info.SetInfo(ctx, "label", StringView{ArrayInterfaceStr(t_labels)});
|
||||
auto const& h_result = info.labels.View(-1);
|
||||
auto const& h_result = info.labels.View(DeviceOrd::CPU());
|
||||
ASSERT_EQ(h_result.Shape().size(), 2);
|
||||
auto in_labels = labels.View(-1);
|
||||
auto in_labels = labels.View(DeviceOrd::CPU());
|
||||
linalg::ElementWiseKernelHost(h_result, omp_get_max_threads(), [&](size_t i, float& v_0) {
|
||||
auto tup = linalg::UnravelIndex(i, h_result.Shape());
|
||||
auto i0 = std::get<0>(tup);
|
||||
@@ -62,9 +62,9 @@ inline void TestMetaInfoStridedData(int32_t device) {
|
||||
ASSERT_EQ(t_margin.Shape().size(), 2);
|
||||
|
||||
info.SetInfo(ctx, "base_margin", StringView{ArrayInterfaceStr(t_margin)});
|
||||
auto const& h_result = info.base_margin_.View(-1);
|
||||
auto const& h_result = info.base_margin_.View(DeviceOrd::CPU());
|
||||
ASSERT_EQ(h_result.Shape().size(), 2);
|
||||
auto in_margin = base_margin.View(-1);
|
||||
auto in_margin = base_margin.View(DeviceOrd::CPU());
|
||||
linalg::ElementWiseKernelHost(h_result, omp_get_max_threads(), [&](size_t i, float v_0) {
|
||||
auto tup = linalg::UnravelIndex(i, h_result.Shape());
|
||||
auto i0 = std::get<0>(tup);
|
||||
|
||||
@@ -298,8 +298,8 @@ TEST(SimpleDMatrix, Slice) {
|
||||
ASSERT_EQ(p_m->Info().weights_.HostVector().at(ridx),
|
||||
out->Info().weights_.HostVector().at(i));
|
||||
|
||||
auto out_margin = out->Info().base_margin_.View(Context::kCpuId);
|
||||
auto in_margin = margin.View(Context::kCpuId);
|
||||
auto out_margin = out->Info().base_margin_.View(DeviceOrd::CPU());
|
||||
auto in_margin = margin.View(DeviceOrd::CPU());
|
||||
for (size_t j = 0; j < kClasses; ++j) {
|
||||
ASSERT_EQ(out_margin(i, j), in_margin(ridx, j));
|
||||
}
|
||||
@@ -372,8 +372,8 @@ TEST(SimpleDMatrix, SliceCol) {
|
||||
out->Info().labels_upper_bound_.HostVector().at(i));
|
||||
ASSERT_EQ(p_m->Info().weights_.HostVector().at(i), out->Info().weights_.HostVector().at(i));
|
||||
|
||||
auto out_margin = out->Info().base_margin_.View(Context::kCpuId);
|
||||
auto in_margin = margin.View(Context::kCpuId);
|
||||
auto out_margin = out->Info().base_margin_.View(DeviceOrd::CPU());
|
||||
auto in_margin = margin.View(DeviceOrd::CPU());
|
||||
for (size_t j = 0; j < kClasses; ++j) {
|
||||
ASSERT_EQ(out_margin(i, j), in_margin(i, j));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user