From 332f6a89a981e428183754d5f9222bd740154214 Mon Sep 17 00:00:00 2001 From: amdsc21 <96135754+amdsc21@users.noreply.github.com> Date: Sat, 11 Mar 2023 01:33:48 +0100 Subject: [PATCH] more tests --- .../test_nccl_device_communicator.hip | 4 ++++ tests/cpp/data/test_array_interface.cu | 21 +++++++++++++++++++ tests/cpp/data/test_array_interface.hip | 4 ++++ tests/cpp/data/test_device_adapter.cu | 11 ++++++++++ tests/cpp/data/test_device_adapter.hip | 4 ++++ tests/cpp/data/test_ellpack_page.cu | 4 ++++ tests/cpp/data/test_ellpack_page.hip | 4 ++++ .../cpp/data/test_ellpack_page_raw_format.hip | 4 ++++ tests/cpp/data/test_gradient_index.cc | 4 ++-- tests/cpp/data/test_iterative_dmatrix.cu | 5 +++++ tests/cpp/data/test_iterative_dmatrix.hip | 4 ++++ tests/cpp/data/test_metainfo.cc | 4 ++-- tests/cpp/data/test_metainfo.cu | 20 ++++++++++++++++++ tests/cpp/data/test_metainfo.hip | 4 ++++ tests/cpp/data/test_proxy_dmatrix.cu | 6 ++++++ tests/cpp/data/test_proxy_dmatrix.hip | 4 ++++ tests/cpp/data/test_simple_dmatrix.cu | 12 +++++++++++ tests/cpp/data/test_simple_dmatrix.hip | 4 ++++ tests/cpp/data/test_sparse_page_dmatrix.hip | 4 ++++ tests/cpp/plugin/test_federated_adapter.hip | 4 ++++ tests/cpp/tree/gpu_hist/test_driver.hip | 4 ++++ .../tree/gpu_hist/test_evaluate_splits.hip | 4 ++++ .../gpu_hist/test_gradient_based_sampler.hip | 4 ++++ tests/cpp/tree/gpu_hist/test_histogram.cu | 18 ++++++++++++++++ tests/cpp/tree/gpu_hist/test_histogram.hip | 4 ++++ .../cpp/tree/gpu_hist/test_row_partitioner.cu | 7 +++++++ .../tree/gpu_hist/test_row_partitioner.hip | 4 ++++ tests/cpp/tree/test_constraints.cu | 5 +++++ tests/cpp/tree/test_constraints.hip | 4 ++++ tests/cpp/tree/test_fit_stump.cc | 4 ++-- tests/cpp/tree/test_gpu_hist.cu | 10 +++++++++ tests/cpp/tree/test_gpu_hist.hip | 4 ++++ tests/cpp/tree/test_node_partition.cc | 4 ++-- tests/cpp/tree/test_prediction_cache.cc | 4 ++-- tests/cpp/tree/test_regen.cc | 4 ++-- tests/cpp/tree/test_tree_policy.cc | 4 ++-- tests/cpp/tree/test_tree_stat.cc | 12 +++++------ 37 files changed, 211 insertions(+), 20 deletions(-) diff --git a/tests/cpp/collective/test_nccl_device_communicator.hip b/tests/cpp/collective/test_nccl_device_communicator.hip index e69de29bb..d4678e044 100644 --- a/tests/cpp/collective/test_nccl_device_communicator.hip +++ b/tests/cpp/collective/test_nccl_device_communicator.hip @@ -0,0 +1,4 @@ + +#if defined(XGBOOST_USE_HIP) +#include "test_nccl_device_communicator.cu" +#endif diff --git a/tests/cpp/data/test_array_interface.cu b/tests/cpp/data/test_array_interface.cu index c8e078525..02c3ca8e3 100644 --- a/tests/cpp/data/test_array_interface.cu +++ b/tests/cpp/data/test_array_interface.cu @@ -22,8 +22,13 @@ TEST(ArrayInterface, Stream) { HostDeviceVector storage; auto arr_str = RandomDataGenerator{kRows, kCols, 0}.GenerateArrayInterface(&storage); +#if defined(XGBOOST_USE_CUDA) cudaStream_t stream; cudaStreamCreate(&stream); +#elif defined(XGBOOST_USE_HIP) + hipStream_t stream; + hipStreamCreate(&stream); +#endif auto j_arr =Json::Load(StringView{arr_str}); j_arr["stream"] = Integer(reinterpret_cast(stream)); @@ -37,19 +42,35 @@ TEST(ArrayInterface, Stream) { auto t = out[0]; CHECK_GE(t, dur); +#if defined(XGBOOST_USE_CUDA) cudaStreamDestroy(stream); +#elif defined(XGBOOST_USE_HIP) + hipStreamDestroy(stream); +#endif } TEST(ArrayInterface, Ptr) { std::vector h_data(10); ASSERT_FALSE(ArrayInterfaceHandler::IsCudaPtr(h_data.data())); +#if defined(XGBOOST_USE_CUDA) dh::safe_cuda(cudaGetLastError()); +#elif defined(XGBOOST_USE_HIP) + dh::safe_cuda(hipGetLastError()); +#endif dh::device_vector d_data(10); ASSERT_TRUE(ArrayInterfaceHandler::IsCudaPtr(d_data.data().get())); +#if defined(XGBOOST_USE_CUDA) dh::safe_cuda(cudaGetLastError()); +#elif defined(XGBOOST_USE_HIP) + dh::safe_cuda(hipGetLastError()); +#endif ASSERT_FALSE(ArrayInterfaceHandler::IsCudaPtr(nullptr)); +#if defined(XGBOOST_USE_CUDA) dh::safe_cuda(cudaGetLastError()); +#elif defined(XGBOOST_USE_HIP) + dh::safe_cuda(hipGetLastError()); +#endif } } // namespace xgboost diff --git a/tests/cpp/data/test_array_interface.hip b/tests/cpp/data/test_array_interface.hip index e69de29bb..55f0063bd 100644 --- a/tests/cpp/data/test_array_interface.hip +++ b/tests/cpp/data/test_array_interface.hip @@ -0,0 +1,4 @@ + +#if defined(XGBOOST_USE_HIP) +#include "test_array_interface.cu" +#endif diff --git a/tests/cpp/data/test_device_adapter.cu b/tests/cpp/data/test_device_adapter.cu index f62b3dd80..dc00b0dc6 100644 --- a/tests/cpp/data/test_device_adapter.cu +++ b/tests/cpp/data/test_device_adapter.cu @@ -6,7 +6,13 @@ #include "../../../src/common/timer.h" #include "../helpers.h" #include + +#if defined(XGBOOST_USE_CUDA) #include "../../../src/data/device_adapter.cuh" +#elif defined(XGBOOST_USE_HIP) +#include "../../../src/data/device_adapter.hip.h" +#endif + #include "test_array_interface.h" using namespace xgboost; // NOLINT @@ -44,7 +50,12 @@ void TestCudfAdapter() KERNEL_CHECK(element.value == element.row_idx * 2.0f); } }); + +#if defined(XGBOOST_USE_CUDA) dh::safe_cuda(cudaDeviceSynchronize()); +#elif defined(XGBOOST_USE_HIP) + dh::safe_cuda(hipDeviceSynchronize()); +#endif }); } diff --git a/tests/cpp/data/test_device_adapter.hip b/tests/cpp/data/test_device_adapter.hip index e69de29bb..ba760b039 100644 --- a/tests/cpp/data/test_device_adapter.hip +++ b/tests/cpp/data/test_device_adapter.hip @@ -0,0 +1,4 @@ + +#if defined(XGBOOST_USE_HIP) +#include "test_device_adapter.cu" +#endif diff --git a/tests/cpp/data/test_ellpack_page.cu b/tests/cpp/data/test_ellpack_page.cu index dccf85092..ee40a6430 100644 --- a/tests/cpp/data/test_ellpack_page.cu +++ b/tests/cpp/data/test_ellpack_page.cu @@ -223,7 +223,11 @@ TEST(EllpackPage, Compact) { dh::LaunchN(kCols, ReadRowFunction(impl->GetDeviceAccessor(0), current_row, row_d.data().get())); +#if defined(XGBOOST_USE_CUDA) dh::safe_cuda(cudaDeviceSynchronize()); +#elif defined(XGBOOST_USE_HIP) + dh::safe_cuda(hipDeviceSynchronize()); +#endif thrust::copy(row_d.begin(), row_d.end(), row.begin()); dh::LaunchN(kCols, diff --git a/tests/cpp/data/test_ellpack_page.hip b/tests/cpp/data/test_ellpack_page.hip index e69de29bb..01ffb4b4a 100644 --- a/tests/cpp/data/test_ellpack_page.hip +++ b/tests/cpp/data/test_ellpack_page.hip @@ -0,0 +1,4 @@ + +#if defined(XGBOOST_USE_HIP) +#include "test_ellpack_page.cu" +#endif diff --git a/tests/cpp/data/test_ellpack_page_raw_format.hip b/tests/cpp/data/test_ellpack_page_raw_format.hip index e69de29bb..b843a06f9 100644 --- a/tests/cpp/data/test_ellpack_page_raw_format.hip +++ b/tests/cpp/data/test_ellpack_page_raw_format.hip @@ -0,0 +1,4 @@ + +#if defined(XGBOOST_USE_HIP) +#include "test_ellpack_page_raw_format.cu" +#endif diff --git a/tests/cpp/data/test_gradient_index.cc b/tests/cpp/data/test_gradient_index.cc index 93194972f..c623ecfae 100644 --- a/tests/cpp/data/test_gradient_index.cc +++ b/tests/cpp/data/test_gradient_index.cc @@ -133,7 +133,7 @@ TEST(GradientIndex, PushBatch) { test(0.9f); } -#if defined(XGBOOST_USE_CUDA) +#if defined(XGBOOST_USE_CUDA) || defined(XGBOOST_USE_HIP) namespace { class GHistIndexMatrixTest : public testing::TestWithParam> { @@ -207,6 +207,6 @@ INSTANTIATE_TEST_SUITE_P(GHistIndexMatrix, GHistIndexMatrixTest, std::make_tuple(.5f, .6), // sparse columns std::make_tuple(.6f, .4))); // dense columns -#endif // defined(XGBOOST_USE_CUDA) +#endif // defined(XGBOOST_USE_CUDA) || defined(XGBOOST_USE_HIP) } // namespace data } // namespace xgboost diff --git a/tests/cpp/data/test_iterative_dmatrix.cu b/tests/cpp/data/test_iterative_dmatrix.cu index be97a3f6a..43c1d0d82 100644 --- a/tests/cpp/data/test_iterative_dmatrix.cu +++ b/tests/cpp/data/test_iterative_dmatrix.cu @@ -3,7 +3,12 @@ */ #include +#if defined(XGBOOST_USE_CUDA) #include "../../../src/data/device_adapter.cuh" +#elif defined(XGBOOST_USE_HIP) +#include "../../../src/data/device_adapter.hip.h" +#endif + #include "../../../src/data/ellpack_page.cuh" #include "../../../src/data/iterative_dmatrix.h" #include "../helpers.h" diff --git a/tests/cpp/data/test_iterative_dmatrix.hip b/tests/cpp/data/test_iterative_dmatrix.hip index e69de29bb..62c0741c4 100644 --- a/tests/cpp/data/test_iterative_dmatrix.hip +++ b/tests/cpp/data/test_iterative_dmatrix.hip @@ -0,0 +1,4 @@ + +#if defined(XGBOOST_USE_HIP) +#include "test_iterative_dmatrix.cu" +#endif diff --git a/tests/cpp/data/test_metainfo.cc b/tests/cpp/data/test_metainfo.cc index 895844180..1d0d0d340 100644 --- a/tests/cpp/data/test_metainfo.cc +++ b/tests/cpp/data/test_metainfo.cc @@ -258,7 +258,7 @@ TEST(MetaInfo, Validate) { EXPECT_THROW(info.SetInfo(ctx, "group", groups.data(), xgboost::DataType::kUInt32, groups.size()), dmlc::Error); -#if defined(XGBOOST_USE_CUDA) +#if defined(XGBOOST_USE_CUDA) || defined(XGBOOST_USE_HIP) info.group_ptr_.clear(); labels.resize(info.num_row_); info.SetInfo(ctx, "label", labels.data(), xgboost::DataType::kFloat32, info.num_row_); @@ -271,7 +271,7 @@ TEST(MetaInfo, Validate) { std::string arr_interface_str{ArrayInterfaceStr( xgboost::linalg::MakeVec(d_groups.ConstDevicePointer(), d_groups.Size(), 0))}; EXPECT_THROW(info.SetInfo(ctx, "group", xgboost::StringView{arr_interface_str}), dmlc::Error); -#endif // defined(XGBOOST_USE_CUDA) +#endif // defined(XGBOOST_USE_CUDA) || defined(XGBOOST_USE_HIP) } TEST(MetaInfo, HostExtend) { diff --git a/tests/cpp/data/test_metainfo.cu b/tests/cpp/data/test_metainfo.cu index 95c8f5f39..cf70ac987 100644 --- a/tests/cpp/data/test_metainfo.cu +++ b/tests/cpp/data/test_metainfo.cu @@ -6,7 +6,12 @@ #include #include +#if defined(XGBOOST_USE_CUDA) #include "../../../src/common/device_helpers.cuh" +#elif defined(XGBOOST_USE_HIP) +#include "../../../src/common/device_helpers.hip.h" +#endif + #include "test_array_interface.h" #include "test_metainfo.h" @@ -43,7 +48,12 @@ std::string PrepareData(std::string typestr, thrust::device_vector* out, cons } TEST(MetaInfo, FromInterface) { +#if defined(XGBOOST_USE_CUDA) cudaSetDevice(0); +#elif defined(XGBOOST_USE_HIP) + hipSetDevice(0); +#endif + Context ctx; thrust::device_vector d_data; @@ -87,7 +97,12 @@ TEST(MetaInfo, GPUStridedData) { } TEST(MetaInfo, Group) { +#if defined(XGBOOST_USE_CUDA) cudaSetDevice(0); +#elif defined(XGBOOST_USE_HIP) + hipSetDevice(0); +#endif + MetaInfo info; Context ctx; @@ -141,7 +156,12 @@ TEST(MetaInfo, GPUQid) { TEST(MetaInfo, DeviceExtend) { +#if defined(XGBOOST_USE_CUDA) dh::safe_cuda(cudaSetDevice(0)); +#elif defined(XGBOOST_USE_HIP) + dh::safe_cuda(hipSetDevice(0)); +#endif + size_t const kRows = 100; MetaInfo lhs, rhs; Context ctx; diff --git a/tests/cpp/data/test_metainfo.hip b/tests/cpp/data/test_metainfo.hip index e69de29bb..27feb1f40 100644 --- a/tests/cpp/data/test_metainfo.hip +++ b/tests/cpp/data/test_metainfo.hip @@ -0,0 +1,4 @@ + +#if defined(XGBOOST_USE_HIP) +#include "test_metainfo.cu" +#endif diff --git a/tests/cpp/data/test_proxy_dmatrix.cu b/tests/cpp/data/test_proxy_dmatrix.cu index a599ada6d..fcc27ba3b 100644 --- a/tests/cpp/data/test_proxy_dmatrix.cu +++ b/tests/cpp/data/test_proxy_dmatrix.cu @@ -2,7 +2,13 @@ #include #include #include "../helpers.h" + +#if defined(XGBOOST_USE_CUDA) #include "../../../src/data/device_adapter.cuh" +#elif defined(XGBOOST_USE_HIP) +#include "../../../src/data/device_adapter.hip.h" +#endif + #include "../../../src/data/proxy_dmatrix.h" namespace xgboost { diff --git a/tests/cpp/data/test_proxy_dmatrix.hip b/tests/cpp/data/test_proxy_dmatrix.hip index e69de29bb..21c53c91d 100644 --- a/tests/cpp/data/test_proxy_dmatrix.hip +++ b/tests/cpp/data/test_proxy_dmatrix.hip @@ -0,0 +1,4 @@ + +#if defined(XGBOOST_USE_HIP) +#include "test_proxy_dmatrix.cu" +#endif diff --git a/tests/cpp/data/test_simple_dmatrix.cu b/tests/cpp/data/test_simple_dmatrix.cu index 04859ed1e..938150683 100644 --- a/tests/cpp/data/test_simple_dmatrix.cu +++ b/tests/cpp/data/test_simple_dmatrix.cu @@ -3,7 +3,13 @@ #include "../../../src/data/simple_dmatrix.h" #include + +#if defined(XGBOOST_USE_CUDA) #include "../../../src/data/device_adapter.cuh" +#elif defined(XGBOOST_USE_HIP) +#include "../../../src/data/device_adapter.hip.h" +#endif + #include "../helpers.h" #include "test_array_interface.h" #include "../../../src/data/array_interface.h" @@ -109,8 +115,14 @@ TEST(SimpleDMatrix, FromColumnarWithEmptyRows) { auto& data = columns_data[i]; data.resize(kRows); thrust::sequence(data.begin(), data.end(), 0); + +#if defined(XGBOOST_USE_CUDA) dh::safe_cuda(cudaDeviceSynchronize()); dh::safe_cuda(cudaGetLastError()); +#elif defined(XGBOOST_USE_HIP) + dh::safe_cuda(hipDeviceSynchronize()); + dh::safe_cuda(hipGetLastError()); +#endif ASSERT_EQ(data.size(), kRows); diff --git a/tests/cpp/data/test_simple_dmatrix.hip b/tests/cpp/data/test_simple_dmatrix.hip index e69de29bb..ee8a20afb 100644 --- a/tests/cpp/data/test_simple_dmatrix.hip +++ b/tests/cpp/data/test_simple_dmatrix.hip @@ -0,0 +1,4 @@ + +#if defined(XGBOOST_USE_HIP) +#include "test_simple_dmatrix.cu" +#endif diff --git a/tests/cpp/data/test_sparse_page_dmatrix.hip b/tests/cpp/data/test_sparse_page_dmatrix.hip index e69de29bb..659dee4c7 100644 --- a/tests/cpp/data/test_sparse_page_dmatrix.hip +++ b/tests/cpp/data/test_sparse_page_dmatrix.hip @@ -0,0 +1,4 @@ + +#if defined(XGBOOST_USE_HIP) +#include "test_sparse_page_dmatrix.cu" +#endif diff --git a/tests/cpp/plugin/test_federated_adapter.hip b/tests/cpp/plugin/test_federated_adapter.hip index e69de29bb..c83561fe4 100644 --- a/tests/cpp/plugin/test_federated_adapter.hip +++ b/tests/cpp/plugin/test_federated_adapter.hip @@ -0,0 +1,4 @@ + +#if defined(XGBOOST_USE_HIP) +#include "test_federated_adapter.cu" +#endif diff --git a/tests/cpp/tree/gpu_hist/test_driver.hip b/tests/cpp/tree/gpu_hist/test_driver.hip index e69de29bb..1b8e19fb8 100644 --- a/tests/cpp/tree/gpu_hist/test_driver.hip +++ b/tests/cpp/tree/gpu_hist/test_driver.hip @@ -0,0 +1,4 @@ + +#if defined(XGBOOST_USE_HIP) +#include "test_driver.cu" +#endif diff --git a/tests/cpp/tree/gpu_hist/test_evaluate_splits.hip b/tests/cpp/tree/gpu_hist/test_evaluate_splits.hip index e69de29bb..5a1f87adb 100644 --- a/tests/cpp/tree/gpu_hist/test_evaluate_splits.hip +++ b/tests/cpp/tree/gpu_hist/test_evaluate_splits.hip @@ -0,0 +1,4 @@ + +#if defined(XGBOOST_USE_HIP) +#include "test_evaluate_splits.cu" +#endif diff --git a/tests/cpp/tree/gpu_hist/test_gradient_based_sampler.hip b/tests/cpp/tree/gpu_hist/test_gradient_based_sampler.hip index e69de29bb..a831f24fe 100644 --- a/tests/cpp/tree/gpu_hist/test_gradient_based_sampler.hip +++ b/tests/cpp/tree/gpu_hist/test_gradient_based_sampler.hip @@ -0,0 +1,4 @@ + +#if defined(XGBOOST_USE_HIP) +#include "test_gradient_based_sampler.cu" +#endif diff --git a/tests/cpp/tree/gpu_hist/test_histogram.cu b/tests/cpp/tree/gpu_hist/test_histogram.cu index 95fe66138..6f7700b6a 100644 --- a/tests/cpp/tree/gpu_hist/test_histogram.cu +++ b/tests/cpp/tree/gpu_hist/test_histogram.cu @@ -40,9 +40,15 @@ void TestDeterministicHistogram(bool is_dense, int shm_size) { quantiser); std::vector histogram_h(num_bins); +#if defined(XGBOOST_USE_CUDA) dh::safe_cuda(cudaMemcpy(histogram_h.data(), d_histogram.data(), num_bins * sizeof(GradientPairInt64), cudaMemcpyDeviceToHost)); +#elif defined(XGBOOST_USE_HIP) + dh::safe_cuda(hipMemcpy(histogram_h.data(), d_histogram.data(), + num_bins * sizeof(GradientPairInt64), + hipMemcpyDeviceToHost)); +#endif for (size_t i = 0; i < kRounds; ++i) { dh::device_vector new_histogram(num_bins); @@ -54,9 +60,15 @@ void TestDeterministicHistogram(bool is_dense, int shm_size) { d_new_histogram, quantiser); std::vector new_histogram_h(num_bins); +#if defined(XGBOOST_USE_CUDA) dh::safe_cuda(cudaMemcpy(new_histogram_h.data(), d_new_histogram.data(), num_bins * sizeof(GradientPairInt64), cudaMemcpyDeviceToHost)); +#elif defined(XGBOOST_USE_HIP) + dh::safe_cuda(hipMemcpy(new_histogram_h.data(), d_new_histogram.data(), + num_bins * sizeof(GradientPairInt64), + hipMemcpyDeviceToHost)); +#endif for (size_t j = 0; j < new_histogram_h.size(); ++j) { ASSERT_EQ(new_histogram_h[j].GetQuantisedGrad(), histogram_h[j].GetQuantisedGrad()); ASSERT_EQ(new_histogram_h[j].GetQuantisedHess(), histogram_h[j].GetQuantisedHess()); @@ -76,9 +88,15 @@ void TestDeterministicHistogram(bool is_dense, int shm_size) { dh::ToSpan(baseline), quantiser); std::vector baseline_h(num_bins); +#if defined(XGBOOST_USE_CUDA) dh::safe_cuda(cudaMemcpy(baseline_h.data(), baseline.data().get(), num_bins * sizeof(GradientPairInt64), cudaMemcpyDeviceToHost)); +#elif defined(XGBOOST_USE_HIP) + dh::safe_cuda(hipMemcpy(baseline_h.data(), baseline.data().get(), + num_bins * sizeof(GradientPairInt64), + hipMemcpyDeviceToHost)); +#endif for (size_t i = 0; i < baseline.size(); ++i) { EXPECT_NEAR(baseline_h[i].GetQuantisedGrad(), histogram_h[i].GetQuantisedGrad(), diff --git a/tests/cpp/tree/gpu_hist/test_histogram.hip b/tests/cpp/tree/gpu_hist/test_histogram.hip index e69de29bb..3d91b4c6a 100644 --- a/tests/cpp/tree/gpu_hist/test_histogram.hip +++ b/tests/cpp/tree/gpu_hist/test_histogram.hip @@ -0,0 +1,4 @@ + +#if defined(XGBOOST_USE_HIP) +#include "test_histogram.cu" +#endif diff --git a/tests/cpp/tree/gpu_hist/test_row_partitioner.cu b/tests/cpp/tree/gpu_hist/test_row_partitioner.cu index f82123452..30fcb12df 100644 --- a/tests/cpp/tree/gpu_hist/test_row_partitioner.cu +++ b/tests/cpp/tree/gpu_hist/test_row_partitioner.cu @@ -67,9 +67,16 @@ void TestSortPositionBatch(const std::vector& ridx_in, const std::vector), cudaMemcpyDefault, nullptr)); +#elif defined(XGBOOST_USE_HIP) + dh::safe_cuda(hipMemcpyAsync(d_batch_info.data().get(), h_batch_info.data(), + h_batch_info.size() * sizeof(PerNodeData), hipMemcpyDefault, + nullptr)); +#endif dh::device_vector tmp; SortPositionBatch(dh::ToSpan(d_batch_info), dh::ToSpan(ridx), dh::ToSpan(ridx_tmp), dh::ToSpan(counts), diff --git a/tests/cpp/tree/gpu_hist/test_row_partitioner.hip b/tests/cpp/tree/gpu_hist/test_row_partitioner.hip index e69de29bb..77bd2a0cd 100644 --- a/tests/cpp/tree/gpu_hist/test_row_partitioner.hip +++ b/tests/cpp/tree/gpu_hist/test_row_partitioner.hip @@ -0,0 +1,4 @@ + +#if defined(XGBOOST_USE_HIP) +#include "test_row_partitioner.cu" +#endif diff --git a/tests/cpp/tree/test_constraints.cu b/tests/cpp/tree/test_constraints.cu index c9f1639b3..393dc4ebf 100644 --- a/tests/cpp/tree/test_constraints.cu +++ b/tests/cpp/tree/test_constraints.cu @@ -10,7 +10,12 @@ #include #include "../../../src/tree/constraints.cuh" #include "../../../src/tree/param.h" + +#if defined(XGBOOST_USE_CUDA) #include "../../../src/common/device_helpers.cuh" +#elif defined(XGBOOST_USE_HIP) +#include "../../../src/common/device_helpers.hip.h" +#endif namespace xgboost { namespace { diff --git a/tests/cpp/tree/test_constraints.hip b/tests/cpp/tree/test_constraints.hip index e69de29bb..69350c3bb 100644 --- a/tests/cpp/tree/test_constraints.hip +++ b/tests/cpp/tree/test_constraints.hip @@ -0,0 +1,4 @@ + +#if defined(XGBOOST_USE_HIP) +#include "test_constraints.cu" +#endif diff --git a/tests/cpp/tree/test_fit_stump.cc b/tests/cpp/tree/test_fit_stump.cc index ef608e575..7fdb6f6ea 100644 --- a/tests/cpp/tree/test_fit_stump.cc +++ b/tests/cpp/tree/test_fit_stump.cc @@ -37,12 +37,12 @@ TEST(InitEstimation, FitStump) { TestFitStump(&ctx); } -#if defined(XGBOOST_USE_CUDA) +#if defined(XGBOOST_USE_CUDA) || defined(XGBOOST_USE_HIP) TEST(InitEstimation, GPUFitStump) { Context ctx; ctx.UpdateAllowUnknown(Args{{"gpu_id", "0"}}); TestFitStump(&ctx); } -#endif // defined(XGBOOST_USE_CUDA) +#endif // defined(XGBOOST_USE_CUDA) || defined(XGBOOST_USE_HIP) } // namespace tree } // namespace xgboost diff --git a/tests/cpp/tree/test_gpu_hist.cu b/tests/cpp/tree/test_gpu_hist.cu index ed21230ed..490dc7175 100644 --- a/tests/cpp/tree/test_gpu_hist.cu +++ b/tests/cpp/tree/test_gpu_hist.cu @@ -25,7 +25,11 @@ namespace xgboost::tree { TEST(GpuHist, DeviceHistogram) { // Ensures that node allocates correctly after reaching `kStopGrowingSize`. +#if defined(XGBOOST_USE_CUDA) dh::safe_cuda(cudaSetDevice(0)); +#elif defined(XGBOOST_USE_HIP) + dh::safe_cuda(hipSetDevice(0)); +#endif constexpr size_t kNBins = 128; constexpr int kNNodes = 4; constexpr size_t kStopGrowing = kNNodes * kNBins * 2u; @@ -120,8 +124,14 @@ void TestBuildHist(bool use_shared_memory_histograms) { auto node_histogram = d_hist.GetNodeHistogram(0); // d_hist.data stored in float, not gradient pair thrust::host_vector h_result (node_histogram.size()); + +#if defined(XGBOOST_USE_CUDA) dh::safe_cuda(cudaMemcpy(h_result.data(), node_histogram.data(), node_histogram.size_bytes(), cudaMemcpyDeviceToHost)); +#elif defined(XGBOOST_USE_HIP) + dh::safe_cuda(hipMemcpy(h_result.data(), node_histogram.data(), node_histogram.size_bytes(), + hipMemcpyDeviceToHost)); +#endif std::vector solution = GetHostHistGpair(); for (size_t i = 0; i < h_result.size(); ++i) { diff --git a/tests/cpp/tree/test_gpu_hist.hip b/tests/cpp/tree/test_gpu_hist.hip index e69de29bb..5c5825bfe 100644 --- a/tests/cpp/tree/test_gpu_hist.hip +++ b/tests/cpp/tree/test_gpu_hist.hip @@ -0,0 +1,4 @@ + +#if defined(XGBOOST_USE_HIP) +#include "test_gpu_hist.cu" +#endif diff --git a/tests/cpp/tree/test_node_partition.cc b/tests/cpp/tree/test_node_partition.cc index d7254fa60..1255c0b7c 100644 --- a/tests/cpp/tree/test_node_partition.cc +++ b/tests/cpp/tree/test_node_partition.cc @@ -18,10 +18,10 @@ TEST(Updater, HasNodePosition) { up.reset(TreeUpdater::Create("grow_quantile_histmaker", &ctx, &task)); ASSERT_TRUE(up->HasNodePosition()); -#if defined(XGBOOST_USE_CUDA) +#if defined(XGBOOST_USE_CUDA) || defined(XGBOOST_USE_HIP) ctx.gpu_id = 0; up.reset(TreeUpdater::Create("grow_gpu_hist", &ctx, &task)); ASSERT_TRUE(up->HasNodePosition()); -#endif // defined(XGBOOST_USE_CUDA) +#endif // defined(XGBOOST_USE_CUDA) || defined(XGBOOST_USE_HIP) } } // namespace xgboost diff --git a/tests/cpp/tree/test_prediction_cache.cc b/tests/cpp/tree/test_prediction_cache.cc index 4f5a05eb6..f2cc3ef67 100644 --- a/tests/cpp/tree/test_prediction_cache.cc +++ b/tests/cpp/tree/test_prediction_cache.cc @@ -106,7 +106,7 @@ TEST_F(TestPredictionCache, Approx) { this->RunTest("grow_histmaker"); } TEST_F(TestPredictionCache, Hist) { this->RunTest("grow_quantile_histmaker"); } -#if defined(XGBOOST_USE_CUDA) +#if defined(XGBOOST_USE_CUDA) || defined(XGBOOST_USE_HIP) TEST_F(TestPredictionCache, GpuHist) { this->RunTest("grow_gpu_hist"); } -#endif // defined(XGBOOST_USE_CUDA) +#endif // defined(XGBOOST_USE_CUDA) || defined(XGBOOST_USE_HIP) } // namespace xgboost diff --git a/tests/cpp/tree/test_regen.cc b/tests/cpp/tree/test_regen.cc index b766e0775..24884b1cf 100644 --- a/tests/cpp/tree/test_regen.cc +++ b/tests/cpp/tree/test_regen.cc @@ -111,7 +111,7 @@ TEST_F(RegenTest, Mixed) { ASSERT_EQ(n, this->Iter() + 1); } -#if defined(XGBOOST_USE_CUDA) +#if defined(XGBOOST_USE_CUDA) || defined(XGBOOST_USE_HIP) TEST_F(RegenTest, GpuHist) { auto n = this->TestTreeMethod("gpu_hist", "reg:squarederror"); ASSERT_EQ(n, 1); @@ -121,5 +121,5 @@ TEST_F(RegenTest, GpuHist) { n = this->TestTreeMethod("hist", "reg:logistic"); ASSERT_EQ(n, 2); } -#endif // defined(XGBOOST_USE_CUDA) +#endif // defined(XGBOOST_USE_CUDA) || defined(XGBOOST_USE_HIP) } // namespace xgboost diff --git a/tests/cpp/tree/test_tree_policy.cc b/tests/cpp/tree/test_tree_policy.cc index 15f4cd31b..15d57ee86 100644 --- a/tests/cpp/tree/test_tree_policy.cc +++ b/tests/cpp/tree/test_tree_policy.cc @@ -146,12 +146,12 @@ TEST_F(TestGrowPolicy, Hist) { this->TestCombination("hist"); } -#if defined(XGBOOST_USE_CUDA) +#if defined(XGBOOST_USE_CUDA) || defined(XGBOOST_USE_HIP) TEST_F(TestGrowPolicy, GpuHist) { this->TestTreeGrowPolicy("gpu_hist", "depthwise"); this->TestTreeGrowPolicy("gpu_hist", "lossguide"); this->TestCombination("gpu_hist"); } -#endif // defined(XGBOOST_USE_CUDA) +#endif // defined(XGBOOST_USE_CUDA) || defined(XGBOOST_USE_HIP) } // namespace xgboost diff --git a/tests/cpp/tree/test_tree_stat.cc b/tests/cpp/tree/test_tree_stat.cc index a3f5cf9d3..eab34f752 100644 --- a/tests/cpp/tree/test_tree_stat.cc +++ b/tests/cpp/tree/test_tree_stat.cc @@ -52,9 +52,9 @@ class UpdaterTreeStatTest : public ::testing::Test { } }; -#if defined(XGBOOST_USE_CUDA) +#if defined(XGBOOST_USE_CUDA) || defined(XGBOOST_USE_HIP) TEST_F(UpdaterTreeStatTest, GpuHist) { this->RunTest("grow_gpu_hist"); } -#endif // defined(XGBOOST_USE_CUDA) +#endif // defined(XGBOOST_USE_CUDA) || defined(XGBOOST_USE_HIP) TEST_F(UpdaterTreeStatTest, Hist) { this->RunTest("grow_quantile_histmaker"); } @@ -124,9 +124,9 @@ TEST_F(UpdaterEtaTest, Exact) { this->RunTest("grow_colmaker"); } TEST_F(UpdaterEtaTest, Approx) { this->RunTest("grow_histmaker"); } -#if defined(XGBOOST_USE_CUDA) +#if defined(XGBOOST_USE_CUDA) || defined(XGBOOST_USE_HIP) TEST_F(UpdaterEtaTest, GpuHist) { this->RunTest("grow_gpu_hist"); } -#endif // defined(XGBOOST_USE_CUDA) +#endif // defined(XGBOOST_USE_CUDA) || defined(XGBOOST_USE_HIP) class TestMinSplitLoss : public ::testing::Test { std::shared_ptr dmat_; @@ -194,7 +194,7 @@ class TestMinSplitLoss : public ::testing::Test { TEST_F(TestMinSplitLoss, Approx) { this->RunTest("grow_histmaker"); } TEST_F(TestMinSplitLoss, Hist) { this->RunTest("grow_quantile_histmaker"); } -#if defined(XGBOOST_USE_CUDA) +#if defined(XGBOOST_USE_CUDA) || defined(XGBOOST_USE_HIP) TEST_F(TestMinSplitLoss, GpuHist) { this->RunTest("grow_gpu_hist"); } -#endif // defined(XGBOOST_USE_CUDA) +#endif // defined(XGBOOST_USE_CUDA) || defined(XGBOOST_USE_HIP) } // namespace xgboost