Merge branch 'master' into sync-2024Jan24
This commit is contained in:
@@ -19,8 +19,38 @@ if (USE_HIP)
|
||||
endif (USE_HIP)
|
||||
|
||||
file(GLOB_RECURSE SYCL_TEST_SOURCES "plugin/test_sycl_*.cc")
|
||||
if(NOT PLUGIN_SYCL)
|
||||
list(REMOVE_ITEM TEST_SOURCES ${SYCL_TEST_SOURCES})
|
||||
list(REMOVE_ITEM TEST_SOURCES ${SYCL_TEST_SOURCES})
|
||||
|
||||
if(PLUGIN_SYCL)
|
||||
set(CMAKE_CXX_COMPILER "icpx")
|
||||
file(GLOB_RECURSE SYCL_TEST_SOURCES "plugin/test_sycl_*.cc")
|
||||
add_library(plugin_sycl_test OBJECT ${SYCL_TEST_SOURCES})
|
||||
|
||||
target_include_directories(plugin_sycl_test
|
||||
PRIVATE
|
||||
${gtest_SOURCE_DIR}/include
|
||||
${xgboost_SOURCE_DIR}/include
|
||||
${xgboost_SOURCE_DIR}/dmlc-core/include
|
||||
${xgboost_SOURCE_DIR}/rabit/include)
|
||||
|
||||
target_compile_definitions(plugin_sycl_test PUBLIC -DXGBOOST_USE_SYCL=1)
|
||||
|
||||
target_link_libraries(plugin_sycl_test PUBLIC -fsycl)
|
||||
|
||||
set_target_properties(plugin_sycl_test PROPERTIES
|
||||
COMPILE_FLAGS -fsycl
|
||||
CXX_STANDARD 17
|
||||
CXX_STANDARD_REQUIRED ON
|
||||
POSITION_INDEPENDENT_CODE ON)
|
||||
if(USE_OPENMP)
|
||||
find_package(OpenMP REQUIRED)
|
||||
set_target_properties(plugin_sycl_test PROPERTIES
|
||||
COMPILE_FLAGS "-fsycl -qopenmp")
|
||||
endif()
|
||||
# Get compilation and link flags of plugin_sycl and propagate to testxgboost
|
||||
target_link_libraries(testxgboost PUBLIC plugin_sycl_test)
|
||||
# Add all objects of plugin_sycl to testxgboost
|
||||
target_sources(testxgboost INTERFACE $<TARGET_OBJECTS:plugin_sycl_test>)
|
||||
endif()
|
||||
|
||||
if(PLUGIN_FEDERATED)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright 2019-2023 XGBoost contributors
|
||||
* Copyright 2019-2024 XGBoost contributors
|
||||
*/
|
||||
#include <gtest/gtest.h>
|
||||
#include <xgboost/c_api.h>
|
||||
@@ -212,8 +212,8 @@ TEST(CAPI, JsonModelIO) {
|
||||
bst_ulong saved_len{0};
|
||||
XGBoosterSaveModelToBuffer(handle, R"({"format": "ubj"})", &saved_len, &saved);
|
||||
ASSERT_EQ(len, saved_len);
|
||||
auto l = StringView{data, len};
|
||||
auto r = StringView{saved, saved_len};
|
||||
auto l = StringView{data, static_cast<size_t>(len)};
|
||||
auto r = StringView{saved, static_cast<size_t>(saved_len)};
|
||||
ASSERT_EQ(l.size(), r.size());
|
||||
ASSERT_EQ(l, r);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright 2016-2023 by XGBoost contributors
|
||||
* Copyright 2016-2024 by XGBoost contributors
|
||||
*/
|
||||
#include "helpers.h"
|
||||
|
||||
@@ -216,7 +216,7 @@ SimpleLCG::StateType SimpleLCG::Max() const { return max(); }
|
||||
static_assert(SimpleLCG::max() - SimpleLCG::min());
|
||||
|
||||
void RandomDataGenerator::GenerateLabels(std::shared_ptr<DMatrix> p_fmat) const {
|
||||
RandomDataGenerator{p_fmat->Info().num_row_, this->n_targets_, 0.0f}.GenerateDense(
|
||||
RandomDataGenerator{static_cast<bst_row_t>(p_fmat->Info().num_row_), this->n_targets_, 0.0f}.GenerateDense(
|
||||
p_fmat->Info().labels.Data());
|
||||
CHECK_EQ(p_fmat->Info().labels.Size(), this->rows_ * this->n_targets_);
|
||||
p_fmat->Info().labels.Reshape(this->rows_, this->n_targets_);
|
||||
@@ -458,7 +458,7 @@ void RandomDataGenerator::GenerateCSR(
|
||||
EXPECT_EQ(row_count, dmat->Info().num_row_);
|
||||
|
||||
if (with_label) {
|
||||
RandomDataGenerator{dmat->Info().num_row_, this->n_targets_, 0.0f}.GenerateDense(
|
||||
RandomDataGenerator{static_cast<bst_row_t>(dmat->Info().num_row_), this->n_targets_, 0.0f}.GenerateDense(
|
||||
dmat->Info().labels.Data());
|
||||
CHECK_EQ(dmat->Info().labels.Size(), this->rows_ * this->n_targets_);
|
||||
dmat->Info().labels.Reshape(this->rows_, this->n_targets_);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright 2016-2023 by XGBoost contributors
|
||||
* Copyright 2016-2024 by XGBoost contributors
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
@@ -238,7 +238,7 @@ class RandomDataGenerator {
|
||||
|
||||
bst_bin_t bins_{0};
|
||||
std::vector<FeatureType> ft_;
|
||||
bst_cat_t max_cat_;
|
||||
bst_cat_t max_cat_{32};
|
||||
|
||||
Json ArrayInterfaceImpl(HostDeviceVector<float>* storage, size_t rows, size_t cols) const;
|
||||
|
||||
|
||||
@@ -2,7 +2,11 @@
|
||||
* Copyright 2018-2023 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/context.h>
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#include "../objective/test_multiclass_obj.h"
|
||||
|
||||
|
||||
91
tests/cpp/plugin/test_sycl_partition_builder.cc
Normal file
91
tests/cpp/plugin/test_sycl_partition_builder.cc
Normal file
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* Copyright 2020-2024 by XGBoost contributors
|
||||
*/
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "../../../plugin/sycl/common/partition_builder.h"
|
||||
#include "../../../plugin/sycl/device_manager.h"
|
||||
#include "../helpers.h"
|
||||
|
||||
namespace xgboost::sycl::common {
|
||||
|
||||
TEST(SyclPartitionBuilder, BasicTest) {
|
||||
constexpr size_t kNodes = 5;
|
||||
// Number of rows for each node
|
||||
std::vector<size_t> rows = { 5, 5, 10, 1, 2 };
|
||||
|
||||
DeviceManager device_manager;
|
||||
auto qu = device_manager.GetQueue(DeviceOrd::SyclDefault());
|
||||
PartitionBuilder builder;
|
||||
builder.Init(&qu, kNodes, [&](size_t i) {
|
||||
return rows[i];
|
||||
});
|
||||
|
||||
// We test here only the basics, thus syntetic partition builder is adopted
|
||||
// Number of rows to go left for each node.
|
||||
std::vector<size_t> rows_for_left_node = { 2, 0, 7, 1, 2 };
|
||||
|
||||
size_t first_row_id = 0;
|
||||
for(size_t nid = 0; nid < kNodes; ++nid) {
|
||||
size_t n_rows_nodes = rows[nid];
|
||||
|
||||
auto rid_buff = builder.GetData(nid);
|
||||
size_t rid_buff_size = rid_buff.size();
|
||||
auto* rid_buff_ptr = rid_buff.data();
|
||||
|
||||
size_t n_left = rows_for_left_node[nid];
|
||||
size_t n_right = rows[nid] - n_left;
|
||||
|
||||
qu.submit([&](::sycl::handler& cgh) {
|
||||
cgh.parallel_for<>(::sycl::range<1>(n_left), [=](::sycl::id<1> pid) {
|
||||
int row_id = first_row_id + pid[0];
|
||||
rid_buff_ptr[pid[0]] = row_id;
|
||||
});
|
||||
});
|
||||
qu.wait();
|
||||
first_row_id += n_left;
|
||||
|
||||
// We are storing indexes for the right side in the tail of the array to save some memory
|
||||
qu.submit([&](::sycl::handler& cgh) {
|
||||
cgh.parallel_for<>(::sycl::range<1>(n_right), [=](::sycl::id<1> pid) {
|
||||
int row_id = first_row_id + pid[0];
|
||||
rid_buff_ptr[rid_buff_size - pid[0] - 1] = row_id;
|
||||
});
|
||||
});
|
||||
qu.wait();
|
||||
first_row_id += n_right;
|
||||
|
||||
builder.SetNLeftElems(nid, n_left);
|
||||
builder.SetNRightElems(nid, n_right);
|
||||
}
|
||||
|
||||
::sycl::event event;
|
||||
std::vector<size_t> v(*std::max_element(rows.begin(), rows.end()));
|
||||
size_t row_id = 0;
|
||||
for(size_t nid = 0; nid < kNodes; ++nid) {
|
||||
builder.MergeToArray(nid, v.data(), event);
|
||||
qu.wait();
|
||||
|
||||
// Check that row_id for left side are correct
|
||||
for(size_t j = 0; j < rows_for_left_node[nid]; ++j) {
|
||||
ASSERT_EQ(v[j], row_id++);
|
||||
}
|
||||
|
||||
// Check that row_id for right side are correct
|
||||
for(size_t j = 0; j < rows[nid] - rows_for_left_node[nid]; ++j) {
|
||||
ASSERT_EQ(v[rows[nid] - j - 1], row_id++);
|
||||
}
|
||||
|
||||
// Check that number of left/right rows are correct
|
||||
size_t n_left = builder.GetNLeftElems(nid);
|
||||
size_t n_right = builder.GetNRightElems(nid);
|
||||
ASSERT_EQ(n_left, rows_for_left_node[nid]);
|
||||
ASSERT_EQ(n_right, (rows[nid] - rows_for_left_node[nid]));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace xgboost::common
|
||||
@@ -2,11 +2,19 @@
|
||||
* Copyright 2017-2023 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/predictor.h>
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wtautological-constant-compare"
|
||||
#include "../../../src/data/adapter.h"
|
||||
#include "../../../src/data/proxy_dmatrix.h"
|
||||
#include "../../../src/gbm/gbtree.h"
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#include "../../../src/data/proxy_dmatrix.h"
|
||||
#include "../../../src/gbm/gbtree_model.h"
|
||||
#include "../filesystem.h" // dmlc::TemporaryDirectory
|
||||
#include "../helpers.h"
|
||||
|
||||
@@ -2,7 +2,11 @@
|
||||
* Copyright 2017-2019 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/objective.h>
|
||||
#pragma GCC diagnostic pop
|
||||
#include <xgboost/context.h>
|
||||
|
||||
#include "../helpers.h"
|
||||
|
||||
Reference in New Issue
Block a user