Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove RAFT memory management (2/2) #4526

Merged
merged 2 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cpp/bench/common/ml_benchmark.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <cuml/common/utils.hpp>
#include <memory>
#include <raft/cudart_utils.h>
#include <raft/mr/device/allocator.hpp>
#include <sstream>
#include <string>
#include <vector>
Expand Down
1 change: 0 additions & 1 deletion cpp/bench/prims/permute.cu
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include <common/ml_benchmark.hpp>
#include <raft/cudart_utils.h>
#include <raft/mr/device/allocator.hpp>
#include <raft/random/rng.hpp>
#include <random/permute.cuh>

Expand Down
1 change: 0 additions & 1 deletion cpp/bench/sg/benchmark.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <cuml/common/logger.hpp>
#include <raft/cudart_utils.h>
#include <raft/handle.hpp>
#include <raft/mr/device/allocator.hpp>

namespace ML {
namespace Bench {
Expand Down
1 change: 0 additions & 1 deletion cpp/examples/symreg/symreg_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ int main(int argc, char* argv[])

/* ======================= Begin GPU memory allocation ======================= */
std::cout << "***************************************" << std::endl;
std::shared_ptr<raft::mr::device::allocator> allocator(new raft::mr::device::default_allocator());

cudaStream_t stream;
raft::handle_t handle{stream};
Expand Down
160 changes: 0 additions & 160 deletions cpp/src/common/allocatorAdapter.hpp

This file was deleted.

55 changes: 0 additions & 55 deletions cpp/src/common/cuml_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,64 +20,9 @@
#include <cuml/cuml_api.h>

#include <raft/cudart_utils.h>
#include <raft/mr/device/allocator.hpp>
#include <raft/mr/host/allocator.hpp>

#include <cstddef>
#include <functional>
namespace ML {
namespace detail {

class hostAllocatorFunctionWrapper : public raft::mr::host::allocator {
public:
hostAllocatorFunctionWrapper(cuml_allocate allocate_fn, cuml_deallocate deallocate_fn)
: _allocate_fn(allocate_fn), _deallocate_fn(deallocate_fn)
{
}

virtual void* allocate(std::size_t n, cudaStream_t stream)
{
void* ptr = 0;
RAFT_CUDA_TRY(_allocate_fn(&ptr, n, stream));
return ptr;
}

virtual void deallocate(void* p, std::size_t n, cudaStream_t stream)
{
RAFT_CUDA_TRY_NO_THROW(_deallocate_fn(p, n, stream));
}

private:
const std::function<cudaError_t(void**, size_t, cudaStream_t)> _allocate_fn;
const std::function<cudaError_t(void*, size_t, cudaStream_t)> _deallocate_fn;
};

class deviceAllocatorFunctionWrapper : public raft::mr::device::default_allocator {
public:
deviceAllocatorFunctionWrapper(cuml_allocate allocate_fn, cuml_deallocate deallocate_fn)
: _allocate_fn(allocate_fn), _deallocate_fn(deallocate_fn)
{
}

virtual void* allocate(std::size_t n, cudaStream_t stream)
{
void* ptr = 0;
RAFT_CUDA_TRY(_allocate_fn(&ptr, n, stream));
return ptr;
}

virtual void deallocate(void* p, std::size_t n, cudaStream_t stream)
{
RAFT_CUDA_TRY_NO_THROW(_deallocate_fn(p, n, stream));
}

private:
const std::function<cudaError_t(void**, size_t, cudaStream_t)> _allocate_fn;
const std::function<cudaError_t(void*, size_t, cudaStream_t)> _deallocate_fn;
};

} // end namespace detail
} // end namespace ML

extern "C" const char* cumlGetErrorString(cumlError_t error)
{
Expand Down
2 changes: 0 additions & 2 deletions cpp/src/pca/sign_flip_mg.cu
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#include <thrust/device_vector.h>
#include <thrust/execution_policy.h>

#include <common/allocatorAdapter.hpp>

#include <raft/comms/comms.hpp>
#include <raft/cuda_utils.cuh>
#include <raft/handle.hpp>
Expand Down
1 change: 0 additions & 1 deletion cpp/test/mg/knn_classify.cu
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ void generate_partitions(float* data,
int n_cols,
int n_clusters,
int my_rank,
std::shared_ptr<raft::mr::device::allocator> allocator,
cudaStream_t stream)
{
Random::make_blobs<float, int>(data,
Expand Down
48 changes: 24 additions & 24 deletions cpp/test/prims/batched/information_criterion.cu
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <metrics/batched/information_criterion.cuh>

#include <raft/cudart_utils.h>
#include <raft/mr/device/allocator.hpp>
#include <rmm/device_uvector.hpp>

#include <gtest/gtest.h>

Expand Down Expand Up @@ -61,20 +61,23 @@ struct BatchedICInputs {
template <typename T>
class BatchedICTest : public ::testing::TestWithParam<BatchedICInputs<T>> {
protected:
BatchedICTest()
: params(::testing::TestWithParam<BatchedICInputs<T>>::GetParam()),
res_d(sizeof(T) * params.batch_size, stream)
{
}

void SetUp() override
{
using std::vector;
params = ::testing::TestWithParam<BatchedICInputs<T>>::GetParam();

// Create stream and allocator
// Create stream
RAFT_CUDA_TRY(cudaStreamCreate(&stream));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not something that needs to be updated in this PR, but we should be creating just about all streams in the handle.

allocator = std::make_shared<raft::mr::device::default_allocator>();

// Create arrays
std::vector<T> loglike_h = std::vector<T>(params.batch_size);
res_h.resize(params.batch_size);
T* loglike_d = (T*)allocator->allocate(sizeof(T) * params.batch_size, stream);
res_d = (T*)allocator->allocate(sizeof(T) * params.batch_size, stream);
rmm::device_uvector<T> loglike_d(sizeof(T) * params.batch_size, stream);

// Generate random data
std::random_device rd;
Expand All @@ -84,11 +87,11 @@ class BatchedICTest : public ::testing::TestWithParam<BatchedICInputs<T>> {
loglike_h[i] = std::log(udis(gen));

// Copy the data to the device
raft::update_device(loglike_d, loglike_h.data(), params.batch_size, stream);
raft::update_device(loglike_d.data(), loglike_h.data(), params.batch_size, stream);

// Compute the tested results
information_criterion(res_d,
loglike_d,
information_criterion(res_d.data(),
loglike_d.data(),
params.ic_type,
params.n_params,
params.batch_size,
Expand All @@ -102,22 +105,13 @@ class BatchedICTest : public ::testing::TestWithParam<BatchedICInputs<T>> {
params.n_params,
params.batch_size,
params.n_samples);

allocator->deallocate(loglike_d, sizeof(T) * params.batch_size, stream);
}

void TearDown() override
{
allocator->deallocate(res_d, sizeof(T) * params.batch_size, stream);
RAFT_CUDA_TRY(cudaStreamDestroy(stream));
}

protected:
std::shared_ptr<raft::mr::device::default_allocator> allocator;
cudaStream_t stream = 0;
BatchedICInputs<T> params;
T* res_d;
rmm::device_uvector<T> res_d;
std::vector<T> res_h;
cudaStream_t stream = 0;
};

// Test parameters (op, n_batches, m, n, p, q, tolerance)
Expand All @@ -132,13 +126,19 @@ using BatchedICTestD = BatchedICTest<double>;
using BatchedICTestF = BatchedICTest<float>;
TEST_P(BatchedICTestD, Result)
{
ASSERT_TRUE(devArrMatchHost(
res_h.data(), res_d, params.batch_size, raft::CompareApprox<double>(params.tolerance), stream));
ASSERT_TRUE(devArrMatchHost(res_h.data(),
res_d.data(),
params.batch_size,
raft::CompareApprox<double>(params.tolerance),
stream));
}
TEST_P(BatchedICTestF, Result)
{
ASSERT_TRUE(devArrMatchHost(
res_h.data(), res_d, params.batch_size, raft::CompareApprox<float>(params.tolerance), stream));
ASSERT_TRUE(devArrMatchHost(res_h.data(),
res_d.data(),
params.batch_size,
raft::CompareApprox<float>(params.tolerance),
stream));
}

INSTANTIATE_TEST_CASE_P(BatchedICTests, BatchedICTestD, ::testing::ValuesIn(inputsd));
Expand Down