Add managed memory allocator. (#10711)
This commit is contained in:
36
tests/cpp/common/test_cuda_host_allocator.cu
Normal file
36
tests/cpp/common/test_cuda_host_allocator.cu
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Copyright 2024, XGBoost Contributors
|
||||
*/
|
||||
#include <gtest/gtest.h>
|
||||
#include <xgboost/context.h> // for Context
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "../../../src/common/cuda_pinned_allocator.h"
|
||||
#include "../../../src/common/device_helpers.cuh" // for DefaultStream
|
||||
#include "../../../src/common/numeric.h" // for Iota
|
||||
|
||||
namespace xgboost {
|
||||
TEST(CudaHostMalloc, Pinned) {
|
||||
std::vector<float, common::cuda_impl::pinned_allocator<float>> vec;
|
||||
vec.resize(10);
|
||||
ASSERT_EQ(vec.size(), 10);
|
||||
Context ctx;
|
||||
common::Iota(&ctx, vec.begin(), vec.end(), 0);
|
||||
float k = 0;
|
||||
for (auto v : vec) {
|
||||
ASSERT_EQ(v, k);
|
||||
++k;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(CudaHostMalloc, Managed) {
|
||||
std::vector<float, common::cuda_impl::managed_allocator<float>> vec;
|
||||
vec.resize(10);
|
||||
#if defined(__linux__)
|
||||
dh::safe_cuda(
|
||||
cudaMemPrefetchAsync(vec.data(), vec.size() * sizeof(float), 0, dh::DefaultStream()));
|
||||
#endif
|
||||
dh::DefaultStream().Sync();
|
||||
}
|
||||
} // namespace xgboost
|
||||
Reference in New Issue
Block a user