merge latest change from upstream
This commit is contained in:
@@ -60,8 +60,7 @@ TEST_F(FederatedCollTest, Allgather) {
|
||||
|
||||
std::vector<std::int32_t> buffer(n_workers, 0);
|
||||
buffer[comm->Rank()] = comm->Rank();
|
||||
auto rc = coll.Allgather(*comm, common::EraseType(common::Span{buffer.data(), buffer.size()}),
|
||||
sizeof(int));
|
||||
auto rc = coll.Allgather(*comm, common::EraseType(common::Span{buffer.data(), buffer.size()}));
|
||||
ASSERT_TRUE(rc.OK());
|
||||
for (auto i = 0; i < n_workers; i++) {
|
||||
ASSERT_EQ(buffer[i], i);
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <xgboost/collective/result.h> // for Result
|
||||
|
||||
#include "../../../../src/collective/allreduce.h"
|
||||
#include "../../../../src/common/common.h" // for AllVisibleGPUs
|
||||
#include "../../../../src/common/device_helpers.cuh" // for device_vector
|
||||
#include "../../../../src/common/type.h" // for EraseType
|
||||
#include "../../collective/test_worker.h" // for SocketTest
|
||||
#include "../../helpers.h" // for MakeCUDACtx
|
||||
#include "federated_coll.cuh"
|
||||
#include "federated_comm.cuh"
|
||||
#include "test_worker.h" // for TestFederated
|
||||
|
||||
namespace xgboost::collective {
|
||||
@@ -71,7 +71,7 @@ void TestAllgather(std::shared_ptr<FederatedComm> comm, std::int32_t rank, std::
|
||||
|
||||
dh::device_vector<std::int32_t> buffer(n_workers, 0);
|
||||
buffer[comm->Rank()] = comm->Rank();
|
||||
auto rc = w.coll->Allgather(*w.nccl_comm, common::EraseType(dh::ToSpan(buffer)), sizeof(int));
|
||||
auto rc = w.coll->Allgather(*w.nccl_comm, common::EraseType(dh::ToSpan(buffer)));
|
||||
ASSERT_TRUE(rc.OK());
|
||||
for (auto i = 0; i < n_workers; i++) {
|
||||
ASSERT_EQ(buffer[i], i);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright 2023, XGBoost Contributors
|
||||
* Copyright 2023-2024, XGBoost Contributors
|
||||
*/
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
#include "../../../../src/collective/tracker.h" // for GetHostAddress
|
||||
#include "federated_tracker.h"
|
||||
#include "test_worker.h"
|
||||
#include "xgboost/json.h" // for Json
|
||||
|
||||
namespace xgboost::collective {
|
||||
@@ -26,7 +25,7 @@ TEST(FederatedTrackerTest, Basic) {
|
||||
ASSERT_GE(tracker->Port(), 1);
|
||||
std::string host;
|
||||
auto rc = GetHostAddress(&host);
|
||||
ASSERT_EQ(get<String const>(args["DMLC_TRACKER_URI"]), host);
|
||||
ASSERT_EQ(get<String const>(args["dmlc_tracker_uri"]), host);
|
||||
|
||||
rc = tracker->Shutdown();
|
||||
ASSERT_TRUE(rc.OK());
|
||||
|
||||
@@ -8,22 +8,23 @@
|
||||
namespace xgboost::sycl {
|
||||
template<typename T, typename Container>
|
||||
void VerifySyclVector(const USMVector<T, MemoryType::shared>& sycl_vector,
|
||||
const Container& host_vector) {
|
||||
const Container& host_vector, T eps = T()) {
|
||||
ASSERT_EQ(sycl_vector.Size(), host_vector.size());
|
||||
|
||||
size_t size = sycl_vector.Size();
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
ASSERT_EQ(sycl_vector[i], host_vector[i]);
|
||||
EXPECT_NEAR(sycl_vector[i], host_vector[i], eps);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, typename Container>
|
||||
void VerifySyclVector(const std::vector<T>& sycl_vector, const Container& host_vector) {
|
||||
void VerifySyclVector(const std::vector<T>& sycl_vector,
|
||||
const Container& host_vector, T eps = T()) {
|
||||
ASSERT_EQ(sycl_vector.size(), host_vector.size());
|
||||
|
||||
size_t size = sycl_vector.size();
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
ASSERT_EQ(sycl_vector[i], host_vector[i]);
|
||||
EXPECT_NEAR(sycl_vector[i], host_vector[i], eps);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ TEST(FederatedAdapterSimpleTest, ThrowOnInvalidDeviceOrdinal) {
|
||||
namespace {
|
||||
void VerifyAllReduceSum() {
|
||||
auto const world_size = collective::GetWorldSize();
|
||||
auto const rank = collective::GetRank();
|
||||
auto const device = GPUIDX;
|
||||
int count = 3;
|
||||
common::SetDevice(device);
|
||||
|
||||
157
tests/cpp/plugin/test_sycl_ghist_builder.cc
Normal file
157
tests/cpp/plugin/test_sycl_ghist_builder.cc
Normal file
@@ -0,0 +1,157 @@
|
||||
/**
|
||||
* Copyright 2020-2024 by XGBoost contributors
|
||||
*/
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wtautological-constant-compare"
|
||||
#pragma GCC diagnostic ignored "-W#pragma-messages"
|
||||
#include "../../../src/data/gradient_index.h" // for GHistIndexMatrix
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#include "../../../plugin/sycl/common/hist_util.h"
|
||||
#include "../../../plugin/sycl/device_manager.h"
|
||||
#include "sycl_helpers.h"
|
||||
#include "../helpers.h"
|
||||
|
||||
namespace xgboost::sycl::common {
|
||||
|
||||
template <typename GradientSumT>
|
||||
void GHistBuilderTest(float sparsity, bool force_atomic_use) {
|
||||
const size_t num_rows = 8;
|
||||
const size_t num_columns = 1;
|
||||
const int n_bins = 2;
|
||||
const GradientSumT eps = 1e-6;
|
||||
|
||||
Context ctx;
|
||||
ctx.UpdateAllowUnknown(Args{{"device", "sycl"}});
|
||||
|
||||
DeviceManager device_manager;
|
||||
auto qu = device_manager.GetQueue(ctx.Device());
|
||||
|
||||
auto p_fmat = RandomDataGenerator{num_rows, num_columns, sparsity}.GenerateDMatrix();
|
||||
sycl::DeviceMatrix dmat;
|
||||
dmat.Init(qu, p_fmat.get());
|
||||
|
||||
GHistIndexMatrix gmat_sycl;
|
||||
gmat_sycl.Init(qu, &ctx, dmat, n_bins);
|
||||
|
||||
xgboost::GHistIndexMatrix gmat{&ctx, p_fmat.get(), n_bins, 0.3, false};
|
||||
|
||||
RowSetCollection row_set_collection;
|
||||
auto& row_indices = row_set_collection.Data();
|
||||
row_indices.Resize(&qu, num_rows);
|
||||
size_t* p_row_indices = row_indices.Data();
|
||||
|
||||
qu.submit([&](::sycl::handler& cgh) {
|
||||
cgh.parallel_for<>(::sycl::range<1>(num_rows),
|
||||
[p_row_indices](::sycl::item<1> pid) {
|
||||
const size_t idx = pid.get_id(0);
|
||||
p_row_indices[idx] = idx;
|
||||
});
|
||||
}).wait_and_throw();
|
||||
row_set_collection.Init();
|
||||
|
||||
auto builder = GHistBuilder<GradientSumT>(qu, n_bins);
|
||||
|
||||
std::vector<GradientPair> gpair = {
|
||||
{0.1f, 0.2f}, {0.3f, 0.4f}, {0.5f, 0.6f}, {0.7f, 0.8f},
|
||||
{0.9f, 0.1f}, {0.2f, 0.3f}, {0.4f, 0.5f}, {0.6f, 0.7f}};
|
||||
CHECK_EQ(gpair.size(), num_rows);
|
||||
USMVector<GradientPair, MemoryType::on_device> gpair_device(&qu, gpair);
|
||||
|
||||
std::vector<GradientSumT> hist_host(2*n_bins);
|
||||
GHistRow<GradientSumT, MemoryType::on_device> hist(&qu, 2 * n_bins);
|
||||
::sycl::event event;
|
||||
|
||||
const size_t nblocks = 2;
|
||||
GHistRow<GradientSumT, MemoryType::on_device> hist_buffer(&qu, 2 * nblocks * n_bins);
|
||||
|
||||
InitHist(qu, &hist, hist.Size(), &event);
|
||||
InitHist(qu, &hist_buffer, hist_buffer.Size(), &event);
|
||||
|
||||
event = builder.BuildHist(gpair_device, row_set_collection[0], gmat_sycl, &hist,
|
||||
sparsity < eps , &hist_buffer, event, force_atomic_use);
|
||||
qu.memcpy(hist_host.data(), hist.Data(),
|
||||
2 * n_bins * sizeof(GradientSumT), event);
|
||||
qu.wait_and_throw();
|
||||
|
||||
// Build hist on host to compare
|
||||
std::vector<GradientSumT> hist_desired(2*n_bins);
|
||||
for (size_t rid = 0; rid < num_rows; ++rid) {
|
||||
const size_t ibegin = gmat.row_ptr[rid];
|
||||
const size_t iend = gmat.row_ptr[rid + 1];
|
||||
for (size_t i = ibegin; i < iend; ++i) {
|
||||
const size_t bin_idx = gmat.index[i];
|
||||
hist_desired[2*bin_idx] += gpair[rid].GetGrad();
|
||||
hist_desired[2*bin_idx+1] += gpair[rid].GetHess();
|
||||
}
|
||||
}
|
||||
|
||||
VerifySyclVector(hist_host, hist_desired, eps);
|
||||
}
|
||||
|
||||
template <typename GradientSumT>
|
||||
void GHistSubtractionTest() {
|
||||
const size_t n_bins = 4;
|
||||
using GHistType = GHistRow<GradientSumT, MemoryType::on_device>;
|
||||
|
||||
Context ctx;
|
||||
ctx.UpdateAllowUnknown(Args{{"device", "sycl"}});
|
||||
|
||||
DeviceManager device_manager;
|
||||
auto qu = device_manager.GetQueue(ctx.Device());
|
||||
|
||||
::sycl::event event;
|
||||
std::vector<GradientSumT> hist1_host = {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8};
|
||||
GHistType hist1(&qu, 2 * n_bins);
|
||||
event = qu.memcpy(hist1.Data(), hist1_host.data(),
|
||||
2 * n_bins * sizeof(GradientSumT), event);
|
||||
|
||||
std::vector<GradientSumT> hist2_host = {0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1};
|
||||
GHistType hist2(&qu, 2 * n_bins);
|
||||
event = qu.memcpy(hist2.Data(), hist2_host.data(),
|
||||
2 * n_bins * sizeof(GradientSumT), event);
|
||||
|
||||
std::vector<GradientSumT> hist3_host(2 * n_bins);
|
||||
GHistType hist3(&qu, 2 * n_bins);
|
||||
event = SubtractionHist(qu, &hist3, hist1, hist2, n_bins, event);
|
||||
qu.memcpy(hist3_host.data(), hist3.Data(),
|
||||
2 * n_bins * sizeof(GradientSumT), event);
|
||||
qu.wait_and_throw();
|
||||
|
||||
std::vector<GradientSumT> hist3_desired(2 * n_bins);
|
||||
for (size_t idx = 0; idx < 2 * n_bins; ++idx) {
|
||||
hist3_desired[idx] = hist1_host[idx] - hist2_host[idx];
|
||||
}
|
||||
|
||||
const GradientSumT eps = 1e-6;
|
||||
VerifySyclVector(hist3_host, hist3_desired, eps);
|
||||
}
|
||||
|
||||
TEST(SyclGHistBuilder, ByBlockDenseCase) {
|
||||
GHistBuilderTest<float>(0.0, false);
|
||||
GHistBuilderTest<double>(0.0, false);
|
||||
}
|
||||
|
||||
TEST(SyclGHistBuilder, ByBlockSparseCase) {
|
||||
GHistBuilderTest<float>(0.3, false);
|
||||
GHistBuilderTest<double>(0.3, false);
|
||||
}
|
||||
|
||||
TEST(SyclGHistBuilder, ByAtomicDenseCase) {
|
||||
GHistBuilderTest<float>(0.0, true);
|
||||
GHistBuilderTest<double>(0.0, true);
|
||||
}
|
||||
|
||||
TEST(SyclGHistBuilder, ByAtomicSparseCase) {
|
||||
GHistBuilderTest<float>(0.3, true);
|
||||
GHistBuilderTest<double>(0.3, true);
|
||||
}
|
||||
|
||||
TEST(SyclGHistBuilder, Subtraction) {
|
||||
GHistSubtractionTest<float>();
|
||||
GHistSubtractionTest<double>();
|
||||
}
|
||||
|
||||
} // namespace xgboost::sycl::common
|
||||
55
tests/cpp/plugin/test_sycl_quantile_hist_builder.cc
Normal file
55
tests/cpp/plugin/test_sycl_quantile_hist_builder.cc
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Copyright 2020-2024 by XGBoost contributors
|
||||
*/
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wtautological-constant-compare"
|
||||
#pragma GCC diagnostic ignored "-W#pragma-messages"
|
||||
#include <xgboost/json.h>
|
||||
#include <xgboost/task.h>
|
||||
#include "../../../plugin/sycl/tree/updater_quantile_hist.h" // for QuantileHistMaker
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
namespace xgboost::sycl::tree {
|
||||
TEST(SyclQuantileHistMaker, Basic) {
|
||||
Context ctx;
|
||||
ctx.UpdateAllowUnknown(Args{{"device", "sycl"}});
|
||||
|
||||
ObjInfo task{ObjInfo::kRegression};
|
||||
std::unique_ptr<TreeUpdater> updater{TreeUpdater::Create("grow_quantile_histmaker_sycl", &ctx, &task)};
|
||||
|
||||
ASSERT_EQ(updater->Name(), "grow_quantile_histmaker_sycl");
|
||||
}
|
||||
|
||||
TEST(SyclQuantileHistMaker, JsonIO) {
|
||||
Context ctx;
|
||||
ctx.UpdateAllowUnknown(Args{{"device", "sycl"}});
|
||||
|
||||
ObjInfo task{ObjInfo::kRegression};
|
||||
Json config {Object()};
|
||||
{
|
||||
std::unique_ptr<TreeUpdater> updater{TreeUpdater::Create("grow_quantile_histmaker_sycl", &ctx, &task)};
|
||||
updater->Configure({{"max_depth", std::to_string(42)}});
|
||||
updater->Configure({{"single_precision_histogram", std::to_string(true)}});
|
||||
updater->SaveConfig(&config);
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<TreeUpdater> updater{TreeUpdater::Create("grow_quantile_histmaker_sycl", &ctx, &task)};
|
||||
updater->LoadConfig(config);
|
||||
|
||||
Json new_config {Object()};
|
||||
updater->SaveConfig(&new_config);
|
||||
|
||||
ASSERT_EQ(config, new_config);
|
||||
|
||||
auto max_depth = atoi(get<String const>(new_config["train_param"]["max_depth"]).c_str());
|
||||
ASSERT_EQ(max_depth, 42);
|
||||
|
||||
auto single_precision_histogram = atoi(get<String const>(new_config["sycl_hist_train_param"]["single_precision_histogram"]).c_str());
|
||||
ASSERT_EQ(single_precision_histogram, 1);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace xgboost::sycl::tree
|
||||
Reference in New Issue
Block a user