From 34d7162a9cec1234c5e681eda275968a6c133c9e Mon Sep 17 00:00:00 2001 From: viclafargue Date: Mon, 11 Oct 2021 17:00:27 +0200 Subject: [PATCH 1/3] Update RAFT test directory --- cpp/test/distance/dist_adj.cu | 46 +++--- cpp/test/distance/dist_canberra.cu | 4 +- cpp/test/distance/dist_chebyshev.cu | 4 +- cpp/test/distance/dist_correlation.cu | 4 +- cpp/test/distance/dist_cos.cu | 4 +- cpp/test/distance/dist_euc_exp.cu | 4 +- cpp/test/distance/dist_euc_unexp.cu | 4 +- cpp/test/distance/dist_hamming.cu | 4 +- cpp/test/distance/dist_hellinger.cu | 4 +- cpp/test/distance/dist_jensen_shannon.cu | 4 +- cpp/test/distance/dist_kl_divergence.cu | 4 +- cpp/test/distance/dist_l1.cu | 4 +- cpp/test/distance/dist_minkowski.cu | 4 +- cpp/test/distance/dist_russell_rao.cu | 4 +- cpp/test/distance/distance_base.cuh | 58 ++++---- cpp/test/distance/fused_l2_nn.cu | 108 ++++++++------ cpp/test/label/label.cu | 39 ++--- cpp/test/linalg/add.cu | 38 ++--- cpp/test/linalg/binary_op.cu | 54 ++++--- cpp/test/linalg/coalesced_reduction.cu | 36 ++--- cpp/test/linalg/divide.cu | 35 ++--- cpp/test/linalg/eig.cu | 112 ++++++++------- cpp/test/linalg/eig_sel.cu | 50 +++---- cpp/test/linalg/eltwise.cu | 64 ++++----- cpp/test/linalg/map.cu | 61 ++++---- cpp/test/linalg/map_then_reduce.cu | 36 ++--- cpp/test/linalg/matrix_vector_op.cu | 51 ++++--- cpp/test/linalg/multiply.cu | 31 ++-- cpp/test/linalg/norm.cu | 85 +++++------ cpp/test/linalg/reduce.cu | 42 +++--- cpp/test/linalg/strided_reduction.cu | 34 ++--- cpp/test/linalg/subtract.cu | 51 ++++--- cpp/test/linalg/svd.cu | 87 ++++++----- cpp/test/linalg/transpose.cu | 40 +++--- cpp/test/linalg/unary_op.cu | 44 +++--- cpp/test/matrix/math.cu | 130 ++++++++--------- cpp/test/matrix/matrix.cu | 36 ++--- cpp/test/random/rng.cu | 135 +++++++++--------- cpp/test/random/rng_int.cu | 30 ++-- cpp/test/random/sample_without_replacement.cu | 44 +++--- cpp/test/sparse/add.cu | 99 +++++++------ cpp/test/sparse/convert_coo.cu | 35 +++-- cpp/test/sparse/convert_csr.cu | 69 ++++----- cpp/test/sparse/csr_row_slice.cu | 88 ++++++------ cpp/test/sparse/csr_to_dense.cu | 61 ++++---- cpp/test/sparse/csr_transpose.cu | 78 +++++----- cpp/test/sparse/degree.cu | 41 +++--- cpp/test/sparse/dist_coo_spmv.cu | 61 ++++---- cpp/test/sparse/distance.cu | 62 ++++---- cpp/test/sparse/knn.cu | 74 +++++----- cpp/test/sparse/knn_graph.cu | 37 +++-- cpp/test/sparse/linkage.cu | 34 +++-- cpp/test/sparse/norm.cu | 50 ++++--- cpp/test/sparse/row_op.cu | 40 +++--- cpp/test/sparse/sort.cu | 33 ++--- cpp/test/sparse/symmetrize.cu | 45 +++--- cpp/test/spatial/haversine.cu | 57 ++++---- cpp/test/spatial/knn.cu | 77 +++++----- cpp/test/spatial/selection.cu | 76 +++++----- cpp/test/stats/mean.cu | 40 +++--- cpp/test/stats/mean_center.cu | 56 ++++---- cpp/test/stats/stddev.cu | 55 +++---- cpp/test/stats/sum.cu | 34 ++--- 63 files changed, 1463 insertions(+), 1468 deletions(-) diff --git a/cpp/test/distance/dist_adj.cu b/cpp/test/distance/dist_adj.cu index 8d5cd68f13..9d97755f03 100644 --- a/cpp/test/distance/dist_adj.cu +++ b/cpp/test/distance/dist_adj.cu @@ -19,6 +19,7 @@ #include #include #include +#include #include "../test_utils.h" namespace raft { @@ -70,38 +71,42 @@ template class DistanceAdjTest : public ::testing::TestWithParam> { public: + DistanceAdjTest() + : params(::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + dist(params.m * params.n, stream), + dist_ref(params.m * params.n, stream) {} + void SetUp() override { - params = ::testing::TestWithParam>::GetParam(); raft::random::Rng r(params.seed); int m = params.m; int n = params.n; int k = params.k; bool isRowMajor = params.isRowMajor; - CUDA_CHECK(cudaStreamCreate(&stream)); - raft::allocate(x, m * k, stream); - raft::allocate(y, n * k, stream); - raft::allocate(dist_ref, m * n, stream); - raft::allocate(dist, m * n, stream); - r.uniform(x, m * k, DataType(-1.0), DataType(1.0), stream); - r.uniform(y, n * k, DataType(-1.0), DataType(1.0), stream); + + rmm::device_uvector x(m * k, stream); + rmm::device_uvector y(n * k, stream); + + r.uniform(x.data(), m * k, DataType(-1.0), DataType(1.0), stream); + r.uniform(y.data(), n * k, DataType(-1.0), DataType(1.0), stream); DataType threshold = params.eps; - naiveDistanceAdj(dist_ref, x, y, m, n, k, threshold, isRowMajor); - char *workspace = nullptr; + naiveDistanceAdj(dist_ref.data(), x.data(), y.data(), m, n, k, threshold, + isRowMajor); size_t worksize = raft::distance::getWorkspaceSize(x, y, m, n, k); - if (worksize != 0) { - raft::allocate(workspace, worksize, stream); - } + DataType, DataType, bool>( + x.data(), y.data(), m, n, k); + rmm::device_uvector workspace(worksize, stream); auto fin_op = [threshold] __device__(DataType d_val, int g_d_idx) { return d_val <= threshold; }; raft::distance::distance( - x, y, dist, m, n, k, workspace, worksize, fin_op, stream, isRowMajor); + x.data(), y.data(), dist.data(), m, n, k, workspace.data(), + workspace.size(), fin_op, stream, isRowMajor); CUDA_CHECK(cudaStreamSynchronize(stream)); } @@ -109,8 +114,9 @@ class DistanceAdjTest protected: DistanceAdjInputs params; - DataType *x, *y; - bool *dist_ref, *dist; + rmm::device_uvector dist_ref; + rmm::device_uvector dist; + raft::handle_t handle; cudaStream_t stream; }; @@ -128,7 +134,8 @@ typedef DistanceAdjTest DistanceAdjTestF; TEST_P(DistanceAdjTestF, Result) { int m = params.isRowMajor ? params.m : params.n; int n = params.isRowMajor ? params.n : params.m; - ASSERT_TRUE(devArrMatch(dist_ref, dist, m, n, raft::Compare())); + ASSERT_TRUE( + devArrMatch(dist_ref.data(), dist.data(), m, n, raft::Compare())); } INSTANTIATE_TEST_CASE_P(DistanceAdjTests, DistanceAdjTestF, ::testing::ValuesIn(inputsf)); @@ -147,7 +154,8 @@ typedef DistanceAdjTest DistanceAdjTestD; TEST_P(DistanceAdjTestD, Result) { int m = params.isRowMajor ? params.m : params.n; int n = params.isRowMajor ? params.n : params.m; - ASSERT_TRUE(devArrMatch(dist_ref, dist, m, n, raft::Compare())); + ASSERT_TRUE( + devArrMatch(dist_ref.data(), dist.data(), m, n, raft::Compare())); } INSTANTIATE_TEST_CASE_P(DistanceAdjTests, DistanceAdjTestD, ::testing::ValuesIn(inputsd)); diff --git a/cpp/test/distance/dist_canberra.cu b/cpp/test/distance/dist_canberra.cu index 10bc4d1899..bddfdff3b6 100644 --- a/cpp/test/distance/dist_canberra.cu +++ b/cpp/test/distance/dist_canberra.cu @@ -38,7 +38,7 @@ typedef DistanceCanberra DistanceCanberraF; TEST_P(DistanceCanberraF, Result) { int m = params.isRowMajor ? params.m : params.n; int n = params.isRowMajor ? params.n : params.m; - ASSERT_TRUE(raft::devArrMatch(dist_ref, dist, m, n, + ASSERT_TRUE(raft::devArrMatch(dist_ref.data(), dist.data(), m, n, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_CASE_P(DistanceTests, DistanceCanberraF, @@ -58,7 +58,7 @@ typedef DistanceCanberra DistanceCanberraD; TEST_P(DistanceCanberraD, Result) { int m = params.isRowMajor ? params.m : params.n; int n = params.isRowMajor ? params.n : params.m; - ASSERT_TRUE(raft::devArrMatch(dist_ref, dist, m, n, + ASSERT_TRUE(raft::devArrMatch(dist_ref.data(), dist.data(), m, n, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_CASE_P(DistanceTests, DistanceCanberraD, diff --git a/cpp/test/distance/dist_chebyshev.cu b/cpp/test/distance/dist_chebyshev.cu index 6a2b02863a..0dc6edfaad 100644 --- a/cpp/test/distance/dist_chebyshev.cu +++ b/cpp/test/distance/dist_chebyshev.cu @@ -38,7 +38,7 @@ typedef DistanceLinf DistanceLinfF; TEST_P(DistanceLinfF, Result) { int m = params.isRowMajor ? params.m : params.n; int n = params.isRowMajor ? params.n : params.m; - ASSERT_TRUE(raft::devArrMatch(dist_ref, dist, m, n, + ASSERT_TRUE(raft::devArrMatch(dist_ref.data(), dist.data(), m, n, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_CASE_P(DistanceTests, DistanceLinfF, @@ -58,7 +58,7 @@ typedef DistanceLinf DistanceLinfD; TEST_P(DistanceLinfD, Result) { int m = params.isRowMajor ? params.m : params.n; int n = params.isRowMajor ? params.n : params.m; - ASSERT_TRUE(raft::devArrMatch(dist_ref, dist, m, n, + ASSERT_TRUE(raft::devArrMatch(dist_ref.data(), dist.data(), m, n, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_CASE_P(DistanceTests, DistanceLinfD, diff --git a/cpp/test/distance/dist_correlation.cu b/cpp/test/distance/dist_correlation.cu index 5d84f18e52..f6dc015738 100644 --- a/cpp/test/distance/dist_correlation.cu +++ b/cpp/test/distance/dist_correlation.cu @@ -39,7 +39,7 @@ typedef DistanceCorrelation DistanceCorrelationF; TEST_P(DistanceCorrelationF, Result) { int m = params.isRowMajor ? params.m : params.n; int n = params.isRowMajor ? params.n : params.m; - ASSERT_TRUE(raft::devArrMatch(dist_ref, dist, m, n, + ASSERT_TRUE(raft::devArrMatch(dist_ref.data(), dist.data(), m, n, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_CASE_P(DistanceTests, DistanceCorrelationF, @@ -59,7 +59,7 @@ typedef DistanceCorrelation DistanceCorrelationD; TEST_P(DistanceCorrelationD, Result) { int m = params.isRowMajor ? params.m : params.n; int n = params.isRowMajor ? params.n : params.m; - ASSERT_TRUE(raft::devArrMatch(dist_ref, dist, m, n, + ASSERT_TRUE(raft::devArrMatch(dist_ref.data(), dist.data(), m, n, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_CASE_P(DistanceTests, DistanceCorrelationD, diff --git a/cpp/test/distance/dist_cos.cu b/cpp/test/distance/dist_cos.cu index 291c4196f9..2487bcbd95 100644 --- a/cpp/test/distance/dist_cos.cu +++ b/cpp/test/distance/dist_cos.cu @@ -39,7 +39,7 @@ typedef DistanceExpCos DistanceExpCosF; TEST_P(DistanceExpCosF, Result) { int m = params.isRowMajor ? params.m : params.n; int n = params.isRowMajor ? params.n : params.m; - ASSERT_TRUE(devArrMatch(dist_ref, dist, m, n, + ASSERT_TRUE(devArrMatch(dist_ref.data(), dist.data(), m, n, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_CASE_P(DistanceTests, DistanceExpCosF, @@ -59,7 +59,7 @@ typedef DistanceExpCos DistanceExpCosD; TEST_P(DistanceExpCosD, Result) { int m = params.isRowMajor ? params.m : params.n; int n = params.isRowMajor ? params.n : params.m; - ASSERT_TRUE(devArrMatch(dist_ref, dist, m, n, + ASSERT_TRUE(devArrMatch(dist_ref.data(), dist.data(), m, n, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_CASE_P(DistanceTests, DistanceExpCosD, diff --git a/cpp/test/distance/dist_euc_exp.cu b/cpp/test/distance/dist_euc_exp.cu index 46e7ded0ec..a6ef01aa45 100644 --- a/cpp/test/distance/dist_euc_exp.cu +++ b/cpp/test/distance/dist_euc_exp.cu @@ -38,7 +38,7 @@ typedef DistanceEucExpTest DistanceEucExpTestF; TEST_P(DistanceEucExpTestF, Result) { int m = params.isRowMajor ? params.m : params.n; int n = params.isRowMajor ? params.n : params.m; - ASSERT_TRUE(devArrMatch(dist_ref, dist, m, n, + ASSERT_TRUE(devArrMatch(dist_ref.data(), dist.data(), m, n, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_CASE_P(DistanceTests, DistanceEucExpTestF, @@ -58,7 +58,7 @@ typedef DistanceEucExpTest DistanceEucExpTestD; TEST_P(DistanceEucExpTestD, Result) { int m = params.isRowMajor ? params.m : params.n; int n = params.isRowMajor ? params.n : params.m; - ASSERT_TRUE(devArrMatch(dist_ref, dist, m, n, + ASSERT_TRUE(devArrMatch(dist_ref.data(), dist.data(), m, n, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_CASE_P(DistanceTests, DistanceEucExpTestD, diff --git a/cpp/test/distance/dist_euc_unexp.cu b/cpp/test/distance/dist_euc_unexp.cu index 92f424647d..290abda352 100644 --- a/cpp/test/distance/dist_euc_unexp.cu +++ b/cpp/test/distance/dist_euc_unexp.cu @@ -39,7 +39,7 @@ typedef DistanceEucUnexpTest DistanceEucUnexpTestF; TEST_P(DistanceEucUnexpTestF, Result) { int m = params.isRowMajor ? params.m : params.n; int n = params.isRowMajor ? params.n : params.m; - ASSERT_TRUE(devArrMatch(dist_ref, dist, m, n, + ASSERT_TRUE(devArrMatch(dist_ref.data(), dist.data(), m, n, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_CASE_P(DistanceTests, DistanceEucUnexpTestF, @@ -59,7 +59,7 @@ typedef DistanceEucUnexpTest DistanceEucUnexpTestD; TEST_P(DistanceEucUnexpTestD, Result) { int m = params.isRowMajor ? params.m : params.n; int n = params.isRowMajor ? params.n : params.m; - ASSERT_TRUE(devArrMatch(dist_ref, dist, m, n, + ASSERT_TRUE(devArrMatch(dist_ref.data(), dist.data(), m, n, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_CASE_P(DistanceTests, DistanceEucUnexpTestD, diff --git a/cpp/test/distance/dist_hamming.cu b/cpp/test/distance/dist_hamming.cu index 47febd825b..0123c8bada 100644 --- a/cpp/test/distance/dist_hamming.cu +++ b/cpp/test/distance/dist_hamming.cu @@ -39,7 +39,7 @@ typedef DistanceHamming DistanceHammingF; TEST_P(DistanceHammingF, Result) { int m = params.isRowMajor ? params.m : params.n; int n = params.isRowMajor ? params.n : params.m; - ASSERT_TRUE(raft::devArrMatch(dist_ref, dist, m, n, + ASSERT_TRUE(raft::devArrMatch(dist_ref.data(), dist.data(), m, n, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_CASE_P(DistanceTests, DistanceHammingF, @@ -59,7 +59,7 @@ typedef DistanceHamming DistanceHammingD; TEST_P(DistanceHammingD, Result) { int m = params.isRowMajor ? params.m : params.n; int n = params.isRowMajor ? params.n : params.m; - ASSERT_TRUE(raft::devArrMatch(dist_ref, dist, m, n, + ASSERT_TRUE(raft::devArrMatch(dist_ref.data(), dist.data(), m, n, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_CASE_P(DistanceTests, DistanceHammingD, diff --git a/cpp/test/distance/dist_hellinger.cu b/cpp/test/distance/dist_hellinger.cu index 39dc7aaeff..39d197f786 100644 --- a/cpp/test/distance/dist_hellinger.cu +++ b/cpp/test/distance/dist_hellinger.cu @@ -39,7 +39,7 @@ typedef DistanceHellingerExp DistanceHellingerExpF; TEST_P(DistanceHellingerExpF, Result) { int m = params.isRowMajor ? params.m : params.n; int n = params.isRowMajor ? params.n : params.m; - ASSERT_TRUE(raft::devArrMatch(dist_ref, dist, m, n, + ASSERT_TRUE(raft::devArrMatch(dist_ref.data(), dist.data(), m, n, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_CASE_P(DistanceTests, DistanceHellingerExpF, @@ -59,7 +59,7 @@ typedef DistanceHellingerExp DistanceHellingerExpD; TEST_P(DistanceHellingerExpD, Result) { int m = params.isRowMajor ? params.m : params.n; int n = params.isRowMajor ? params.n : params.m; - ASSERT_TRUE(raft::devArrMatch(dist_ref, dist, m, n, + ASSERT_TRUE(raft::devArrMatch(dist_ref.data(), dist.data(), m, n, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_CASE_P(DistanceTests, DistanceHellingerExpD, diff --git a/cpp/test/distance/dist_jensen_shannon.cu b/cpp/test/distance/dist_jensen_shannon.cu index bc0b56f506..9070ce92c1 100644 --- a/cpp/test/distance/dist_jensen_shannon.cu +++ b/cpp/test/distance/dist_jensen_shannon.cu @@ -39,7 +39,7 @@ typedef DistanceJensenShannon DistanceJensenShannonF; TEST_P(DistanceJensenShannonF, Result) { int m = params.isRowMajor ? params.m : params.n; int n = params.isRowMajor ? params.n : params.m; - ASSERT_TRUE(raft::devArrMatch(dist_ref, dist, m, n, + ASSERT_TRUE(raft::devArrMatch(dist_ref.data(), dist.data(), m, n, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_CASE_P(DistanceTests, DistanceJensenShannonF, @@ -59,7 +59,7 @@ typedef DistanceJensenShannon DistanceJensenShannonD; TEST_P(DistanceJensenShannonD, Result) { int m = params.isRowMajor ? params.m : params.n; int n = params.isRowMajor ? params.n : params.m; - ASSERT_TRUE(raft::devArrMatch(dist_ref, dist, m, n, + ASSERT_TRUE(raft::devArrMatch(dist_ref.data(), dist.data(), m, n, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_CASE_P(DistanceTests, DistanceJensenShannonD, diff --git a/cpp/test/distance/dist_kl_divergence.cu b/cpp/test/distance/dist_kl_divergence.cu index 884ac4b948..7c32596527 100644 --- a/cpp/test/distance/dist_kl_divergence.cu +++ b/cpp/test/distance/dist_kl_divergence.cu @@ -39,7 +39,7 @@ typedef DistanceKLDivergence DistanceKLDivergenceF; TEST_P(DistanceKLDivergenceF, Result) { int m = params.isRowMajor ? params.m : params.n; int n = params.isRowMajor ? params.n : params.m; - ASSERT_TRUE(raft::devArrMatch(dist_ref, dist, m, n, + ASSERT_TRUE(raft::devArrMatch(dist_ref.data(), dist.data(), m, n, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_CASE_P(DistanceTests, DistanceKLDivergenceF, @@ -59,7 +59,7 @@ typedef DistanceKLDivergence DistanceKLDivergenceD; TEST_P(DistanceKLDivergenceD, Result) { int m = params.isRowMajor ? params.m : params.n; int n = params.isRowMajor ? params.n : params.m; - ASSERT_TRUE(raft::devArrMatch(dist_ref, dist, m, n, + ASSERT_TRUE(raft::devArrMatch(dist_ref.data(), dist.data(), m, n, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_CASE_P(DistanceTests, DistanceKLDivergenceD, diff --git a/cpp/test/distance/dist_l1.cu b/cpp/test/distance/dist_l1.cu index bd32837e45..ff7705d195 100644 --- a/cpp/test/distance/dist_l1.cu +++ b/cpp/test/distance/dist_l1.cu @@ -38,7 +38,7 @@ typedef DistanceUnexpL1 DistanceUnexpL1F; TEST_P(DistanceUnexpL1F, Result) { int m = params.isRowMajor ? params.m : params.n; int n = params.isRowMajor ? params.n : params.m; - ASSERT_TRUE(raft::devArrMatch(dist_ref, dist, m, n, + ASSERT_TRUE(raft::devArrMatch(dist_ref.data(), dist.data(), m, n, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_CASE_P(DistanceTests, DistanceUnexpL1F, @@ -58,7 +58,7 @@ typedef DistanceUnexpL1 DistanceUnexpL1D; TEST_P(DistanceUnexpL1D, Result) { int m = params.isRowMajor ? params.m : params.n; int n = params.isRowMajor ? params.n : params.m; - ASSERT_TRUE(raft::devArrMatch(dist_ref, dist, m, n, + ASSERT_TRUE(raft::devArrMatch(dist_ref.data(), dist.data(), m, n, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_CASE_P(DistanceTests, DistanceUnexpL1D, diff --git a/cpp/test/distance/dist_minkowski.cu b/cpp/test/distance/dist_minkowski.cu index 42b8e294ac..7d87bbc2c7 100644 --- a/cpp/test/distance/dist_minkowski.cu +++ b/cpp/test/distance/dist_minkowski.cu @@ -39,7 +39,7 @@ typedef DistanceLpUnexp DistanceLpUnexpF; TEST_P(DistanceLpUnexpF, Result) { int m = params.isRowMajor ? params.m : params.n; int n = params.isRowMajor ? params.n : params.m; - ASSERT_TRUE(raft::devArrMatch(dist_ref, dist, m, n, + ASSERT_TRUE(raft::devArrMatch(dist_ref.data(), dist.data(), m, n, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_CASE_P(DistanceTests, DistanceLpUnexpF, @@ -59,7 +59,7 @@ typedef DistanceLpUnexp DistanceLpUnexpD; TEST_P(DistanceLpUnexpD, Result) { int m = params.isRowMajor ? params.m : params.n; int n = params.isRowMajor ? params.n : params.m; - ASSERT_TRUE(raft::devArrMatch(dist_ref, dist, m, n, + ASSERT_TRUE(raft::devArrMatch(dist_ref.data(), dist.data(), m, n, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_CASE_P(DistanceTests, DistanceLpUnexpD, diff --git a/cpp/test/distance/dist_russell_rao.cu b/cpp/test/distance/dist_russell_rao.cu index 74ccfb0c2e..ae735951a8 100644 --- a/cpp/test/distance/dist_russell_rao.cu +++ b/cpp/test/distance/dist_russell_rao.cu @@ -39,7 +39,7 @@ typedef DistanceRussellRao DistanceRussellRaoF; TEST_P(DistanceRussellRaoF, Result) { int m = params.isRowMajor ? params.m : params.n; int n = params.isRowMajor ? params.n : params.m; - ASSERT_TRUE(raft::devArrMatch(dist_ref, dist, m, n, + ASSERT_TRUE(raft::devArrMatch(dist_ref.data(), dist.data(), m, n, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_CASE_P(DistanceTests, DistanceRussellRaoF, @@ -59,7 +59,7 @@ typedef DistanceRussellRao DistanceRussellRaoD; TEST_P(DistanceRussellRaoD, Result) { int m = params.isRowMajor ? params.m : params.n; int n = params.isRowMajor ? params.n : params.m; - ASSERT_TRUE(raft::devArrMatch(dist_ref, dist, m, n, + ASSERT_TRUE(raft::devArrMatch(dist_ref.data(), dist.data(), m, n, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_CASE_P(DistanceTests, DistanceRussellRaoD, diff --git a/cpp/test/distance/distance_base.cuh b/cpp/test/distance/distance_base.cuh index 4798d102f3..946f69753c 100644 --- a/cpp/test/distance/distance_base.cuh +++ b/cpp/test/distance/distance_base.cuh @@ -384,61 +384,57 @@ void distanceLauncher(DataType *x, DataType *y, DataType *dist, DataType *dist2, template class DistanceTest : public ::testing::TestWithParam> { public: + DistanceTest() + : params(::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + x(params.m * params.k, stream), + y(params.n * params.k, stream), + dist_ref(params.m * params.n, stream), + dist(params.m * params.n, stream), + dist2(params.m * params.n, stream) {} + void SetUp() override { - params = ::testing::TestWithParam>::GetParam(); raft::random::Rng r(params.seed); int m = params.m; int n = params.n; int k = params.k; DataType metric_arg = params.metric_arg; bool isRowMajor = params.isRowMajor; - CUDA_CHECK(cudaStreamCreate(&stream)); - raft::allocate(x, m * k, stream); - raft::allocate(y, n * k, stream); - raft::allocate(dist_ref, m * n, stream); - raft::allocate(dist, m * n, stream); - raft::allocate(dist2, m * n, stream); if (distanceType == raft::distance::DistanceType::HellingerExpanded || distanceType == raft::distance::DistanceType::JensenShannon || distanceType == raft::distance::DistanceType::KLDivergence) { // Hellinger works only on positive numbers - r.uniform(x, m * k, DataType(0.0), DataType(1.0), stream); - r.uniform(y, n * k, DataType(0.0), DataType(1.0), stream); + r.uniform(x.data(), m * k, DataType(0.0), DataType(1.0), stream); + r.uniform(y.data(), n * k, DataType(0.0), DataType(1.0), stream); } else if (distanceType == raft::distance::DistanceType::RusselRaoExpanded) { - r.uniform(x, m * k, DataType(0.0), DataType(1.0), stream); - r.uniform(y, n * k, DataType(0.0), DataType(1.0), stream); + r.uniform(x.data(), m * k, DataType(0.0), DataType(1.0), stream); + r.uniform(y.data(), n * k, DataType(0.0), DataType(1.0), stream); // Russel rao works on boolean values. - r.bernoulli(x, m * k, 0.5f, stream); - r.bernoulli(y, n * k, 0.5f, stream); + r.bernoulli(x.data(), m * k, 0.5f, stream); + r.bernoulli(y.data(), n * k, 0.5f, stream); } else { - r.uniform(x, m * k, DataType(-1.0), DataType(1.0), stream); - r.uniform(y, n * k, DataType(-1.0), DataType(1.0), stream); + r.uniform(x.data(), m * k, DataType(-1.0), DataType(1.0), stream); + r.uniform(y.data(), n * k, DataType(-1.0), DataType(1.0), stream); } - naiveDistance(dist_ref, x, y, m, n, k, distanceType, isRowMajor, - metric_arg); - char *workspace = nullptr; + naiveDistance(dist_ref.data(), x.data(), y.data(), m, n, k, distanceType, + isRowMajor, metric_arg); size_t worksize = raft::distance::getWorkspaceSize(x, y, m, n, k); - if (worksize != 0) { - raft::allocate(workspace, worksize, stream); - } + DataType>(x.data(), y.data(), m, n, k); + rmm::device_uvector workspace(worksize, stream); DataType threshold = -10000.f; - distanceLauncher(x, y, dist, dist2, m, n, k, params, - threshold, workspace, worksize, - stream, isRowMajor, metric_arg); - } - - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); + distanceLauncher( + x.data(), y.data(), dist.data(), dist2.data(), m, n, k, params, threshold, + workspace.data(), workspace.size(), stream, isRowMajor, metric_arg); + CUDA_CHECK(cudaStreamSynchronize(stream)); } protected: DistanceInputs params; - DataType *x, *y, *dist_ref, *dist, *dist2; + rmm::device_uvector x, y, dist_ref, dist, dist2; + raft::handle_t handle; cudaStream_t stream; }; diff --git a/cpp/test/distance/fused_l2_nn.cu b/cpp/test/distance/fused_l2_nn.cu index cfea4ee2d9..0664c35440 100644 --- a/cpp/test/distance/fused_l2_nn.cu +++ b/cpp/test/distance/fused_l2_nn.cu @@ -100,44 +100,51 @@ struct Inputs { template class FusedL2NNTest : public ::testing::TestWithParam> { public: + FusedL2NNTest() + : params(::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + x(params.m * params.k, stream), + y(params.n * params.k, stream), + xn(params.m, stream), + yn(params.n, stream), + min(params.m, stream), + min_ref(params.m, stream), + workspace(params.m * sizeof(int), stream) {} + + protected: void SetUp() override { - params = ::testing::TestWithParam>::GetParam(); raft::random::Rng r(params.seed); int m = params.m; int n = params.n; int k = params.k; - CUDA_CHECK(cudaStreamCreate(&stream)); - raft::allocate(x, m * k, stream); - raft::allocate(y, n * k, stream); - raft::allocate(xn, m, stream); - raft::allocate(yn, n, stream); - raft::allocate(workspace, sizeof(int) * m, stream); - raft::allocate(min, m, stream); - raft::allocate(min_ref, m, stream); - r.uniform(x, m * k, DataT(-1.0), DataT(1.0), stream); - r.uniform(y, n * k, DataT(-1.0), DataT(1.0), stream); + r.uniform(x.data(), m * k, DataT(-1.0), DataT(1.0), stream); + r.uniform(y.data(), n * k, DataT(-1.0), DataT(1.0), stream); generateGoldenResult(); - raft::linalg::rowNorm(xn, x, k, m, raft::linalg::L2Norm, true, stream); - raft::linalg::rowNorm(yn, y, k, n, raft::linalg::L2Norm, true, stream); - } - - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); + raft::linalg::rowNorm(xn.data(), x.data(), k, m, raft::linalg::L2Norm, true, + stream); + raft::linalg::rowNorm(yn.data(), y.data(), k, n, raft::linalg::L2Norm, true, + stream); + CUDA_CHECK(cudaStreamSynchronize(stream)); } protected: Inputs params; - DataT *x, *y, *xn, *yn; - char *workspace; - cub::KeyValuePair *min, *min_ref; + rmm::device_uvector x; + rmm::device_uvector y; + rmm::device_uvector xn; + rmm::device_uvector yn; + rmm::device_uvector> min; + rmm::device_uvector> min_ref; + rmm::device_uvector workspace; + raft::handle_t handle; cudaStream_t stream; virtual void generateGoldenResult() { int m = params.m; int n = params.n; int k = params.k; - naive(min_ref, x, y, m, n, k, (int *)workspace, stream); + naive(min_ref.data(), x.data(), y.data(), m, n, k, + (int *)workspace.data(), stream); } void runTest(cub::KeyValuePair *out) { @@ -146,7 +153,8 @@ class FusedL2NNTest : public ::testing::TestWithParam> { int k = params.k; MinAndDistanceReduceOp redOp; fusedL2NN, int>( - out, x, y, xn, yn, m, n, k, (void *)workspace, redOp, + out, x.data(), y.data(), xn.data(), yn.data(), m, n, k, + (void *)workspace.data(), redOp, raft::distance::KVPMinReduce(), Sqrt, true, stream); CUDA_CHECK(cudaStreamSynchronize(stream)); } @@ -219,16 +227,16 @@ const std::vector> inputsf = { }; typedef FusedL2NNTest FusedL2NNTestF_Sq; TEST_P(FusedL2NNTestF_Sq, Result) { - runTest(min); - ASSERT_TRUE(devArrMatch(min_ref, min, params.m, + runTest(min.data()); + ASSERT_TRUE(devArrMatch(min_ref.data(), min.data(), params.m, CompareApproxAbsKVP(params.tolerance))); } INSTANTIATE_TEST_CASE_P(FusedL2NNTests, FusedL2NNTestF_Sq, ::testing::ValuesIn(inputsf)); typedef FusedL2NNTest FusedL2NNTestF_Sqrt; TEST_P(FusedL2NNTestF_Sqrt, Result) { - runTest(min); - ASSERT_TRUE(devArrMatch(min_ref, min, params.m, + runTest(min.data()); + ASSERT_TRUE(devArrMatch(min_ref.data(), min.data(), params.m, CompareApproxAbsKVP(params.tolerance))); } INSTANTIATE_TEST_CASE_P(FusedL2NNTests, FusedL2NNTestF_Sqrt, @@ -254,16 +262,16 @@ const std::vector> inputsd = { }; typedef FusedL2NNTest FusedL2NNTestD_Sq; TEST_P(FusedL2NNTestD_Sq, Result) { - runTest(min); - ASSERT_TRUE(devArrMatch(min_ref, min, params.m, + runTest(min.data()); + ASSERT_TRUE(devArrMatch(min_ref.data(), min.data(), params.m, CompareApproxAbsKVP(params.tolerance))); } INSTANTIATE_TEST_CASE_P(FusedL2NNTests, FusedL2NNTestD_Sq, ::testing::ValuesIn(inputsd)); typedef FusedL2NNTest FusedL2NNTestD_Sqrt; TEST_P(FusedL2NNTestD_Sqrt, Result) { - runTest(min); - ASSERT_TRUE(devArrMatch(min_ref, min, params.m, + runTest(min.data()); + ASSERT_TRUE(devArrMatch(min_ref.data(), min.data(), params.m, CompareApproxAbsKVP(params.tolerance))); } INSTANTIATE_TEST_CASE_P(FusedL2NNTests, FusedL2NNTestD_Sqrt, @@ -272,19 +280,23 @@ INSTANTIATE_TEST_CASE_P(FusedL2NNTests, FusedL2NNTestD_Sqrt, /// This is to test output determinism of the prim template class FusedL2NNDetTest : public FusedL2NNTest { + public: + FusedL2NNDetTest() : stream(handle.get_stream()), min1(0, stream) {} + void SetUp() override { FusedL2NNTest::SetUp(); int m = this->params.m; - CUDA_CHECK(cudaStreamCreate(&stream)); - raft::allocate(min1, m, stream); + min1.resize(m, stream); + CUDA_CHECK(cudaStreamSynchronize(stream)); } void TearDown() override { FusedL2NNTest::TearDown(); } protected: - cub::KeyValuePair *min1; + rmm::device_uvector> min1; static const int NumRepeats = 100; + raft::handle_t handle; cudaStream_t stream; void generateGoldenResult() override {} @@ -292,20 +304,22 @@ class FusedL2NNDetTest : public FusedL2NNTest { typedef FusedL2NNDetTest FusedL2NNDetTestF_Sq; TEST_P(FusedL2NNDetTestF_Sq, Result) { - runTest(min); // assumed to be golden + runTest(min.data()); // assumed to be golden for (int i = 0; i < NumRepeats; ++i) { - runTest(min1); - ASSERT_TRUE(devArrMatch(min, min1, params.m, CompareExactKVP())); + runTest(min1.data()); + ASSERT_TRUE( + devArrMatch(min.data(), min1.data(), params.m, CompareExactKVP())); } } INSTANTIATE_TEST_CASE_P(FusedL2NNDetTests, FusedL2NNDetTestF_Sq, ::testing::ValuesIn(inputsf)); typedef FusedL2NNDetTest FusedL2NNDetTestF_Sqrt; TEST_P(FusedL2NNDetTestF_Sqrt, Result) { - runTest(min); // assumed to be golden + runTest(min.data()); // assumed to be golden for (int i = 0; i < NumRepeats; ++i) { - runTest(min1); - ASSERT_TRUE(devArrMatch(min, min1, params.m, CompareExactKVP())); + runTest(min1.data()); + ASSERT_TRUE( + devArrMatch(min.data(), min1.data(), params.m, CompareExactKVP())); } } INSTANTIATE_TEST_CASE_P(FusedL2NNDetTests, FusedL2NNDetTestF_Sqrt, @@ -313,20 +327,22 @@ INSTANTIATE_TEST_CASE_P(FusedL2NNDetTests, FusedL2NNDetTestF_Sqrt, typedef FusedL2NNDetTest FusedL2NNDetTestD_Sq; TEST_P(FusedL2NNDetTestD_Sq, Result) { - runTest(min); // assumed to be golden + runTest(min.data()); // assumed to be golden for (int i = 0; i < NumRepeats; ++i) { - runTest(min1); - ASSERT_TRUE(devArrMatch(min, min1, params.m, CompareExactKVP())); + runTest(min1.data()); + ASSERT_TRUE(devArrMatch(min.data(), min1.data(), params.m, + CompareExactKVP())); } } INSTANTIATE_TEST_CASE_P(FusedL2NNDetTests, FusedL2NNDetTestD_Sq, ::testing::ValuesIn(inputsd)); typedef FusedL2NNDetTest FusedL2NNDetTestD_Sqrt; TEST_P(FusedL2NNDetTestD_Sqrt, Result) { - runTest(min); // assumed to be golden + runTest(min.data()); // assumed to be golden for (int i = 0; i < NumRepeats; ++i) { - runTest(min1); - ASSERT_TRUE(devArrMatch(min, min1, params.m, CompareExactKVP())); + runTest(min1.data()); + ASSERT_TRUE(devArrMatch(min.data(), min1.data(), params.m, + CompareExactKVP())); } } INSTANTIATE_TEST_CASE_P(FusedL2NNDetTests, FusedL2NNDetTestD_Sqrt, diff --git a/cpp/test/label/label.cu b/cpp/test/label/label.cu index b28c754a5a..f79d8f10c8 100644 --- a/cpp/test/label/label.cu +++ b/cpp/test/label/label.cu @@ -41,11 +41,9 @@ TEST_F(MakeMonotonicTest, Result) { int m = 12; - float *data, *actual, *expected; - - raft::allocate(data, m, stream, true); - raft::allocate(actual, m, stream, true); - raft::allocate(expected, m, stream, true); + rmm::device_uvector data(m, stream); + rmm::device_uvector actual(m, stream); + rmm::device_uvector expected(m, stream); float *data_h = new float[m]{1.0, 2.0, 2.0, 2.0, 2.0, 3.0, 8.0, 7.0, 8.0, 8.0, 25.0, 80.0}; @@ -53,17 +51,15 @@ TEST_F(MakeMonotonicTest, Result) { float *expected_h = new float[m]{1.0, 2.0, 2.0, 2.0, 2.0, 3.0, 5.0, 4.0, 5.0, 5.0, 6.0, 7.0}; - raft::update_device(data, data_h, m, stream); - raft::update_device(expected, expected_h, m, stream); + raft::update_device(data.data(), data_h, m, stream); + raft::update_device(expected.data(), expected_h, m, stream); - make_monotonic(actual, data, m, stream); + make_monotonic(actual.data(), data.data(), m, stream); CUDA_CHECK(cudaStreamSynchronize(stream)); - ASSERT_TRUE(devArrMatch(actual, expected, m, raft::Compare(), stream)); - - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); + ASSERT_TRUE(devArrMatch(actual.data(), expected.data(), m, + raft::Compare(), stream)); delete data_h; delete expected_h; @@ -74,14 +70,13 @@ TEST(labelTest, Classlabels) { CUDA_CHECK(cudaStreamCreate(&stream)); int n_rows = 6; - float *y_d; - raft::allocate(y_d, n_rows, stream); + rmm::device_uvector y_d(n_rows, stream); float y_h[] = {2, -1, 1, 2, 1, 1}; - raft::update_device(y_d, y_h, n_rows, stream); + raft::update_device(y_d.data(), y_h, n_rows, stream); rmm::device_uvector y_unique_d(0, stream); - int n_classes = getUniquelabels(y_unique_d, y_d, n_rows, stream); + int n_classes = getUniquelabels(y_unique_d, y_d.data(), n_rows, stream); ASSERT_EQ(n_classes, 3); @@ -89,18 +84,14 @@ TEST(labelTest, Classlabels) { EXPECT_TRUE(devArrMatchHost(y_unique_exp, y_unique_d.data(), n_classes, raft::Compare(), stream)); - float *y_relabeled_d; - raft::allocate(y_relabeled_d, n_rows, stream); + rmm::device_uvector y_relabeled_d(n_rows, stream); - getOvrlabels(y_d, n_rows, y_unique_d.data(), n_classes, y_relabeled_d, 2, - stream); + getOvrlabels(y_d.data(), n_rows, y_unique_d.data(), n_classes, + y_relabeled_d.data(), 2, stream); float y_relabeled_exp[] = {1, -1, -1, 1, -1, -1}; - EXPECT_TRUE(devArrMatchHost(y_relabeled_exp, y_relabeled_d, n_rows, + EXPECT_TRUE(devArrMatchHost(y_relabeled_exp, y_relabeled_d.data(), n_rows, raft::Compare(), stream)); - - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); } }; // namespace label }; // namespace raft diff --git a/cpp/test/linalg/add.cu b/cpp/test/linalg/add.cu index 301f069a33..50eea07b88 100644 --- a/cpp/test/linalg/add.cu +++ b/cpp/test/linalg/add.cu @@ -26,36 +26,40 @@ namespace linalg { template class AddTest : public ::testing::TestWithParam> { + public: + AddTest() + : params(::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + in1(params.len, stream), + in2(params.len, stream), + out_ref(params.len, stream), + out(params.len, stream) {} + protected: void SetUp() override { params = ::testing::TestWithParam>::GetParam(); raft::random::Rng r(params.seed); int len = params.len; - CUDA_CHECK(cudaStreamCreate(&stream)); - raft::allocate(in1, len, stream); - raft::allocate(in2, len, stream); - raft::allocate(out_ref, len, stream); - raft::allocate(out, len, stream); - r.uniform(in1, len, InT(-1.0), InT(1.0), stream); - r.uniform(in2, len, InT(-1.0), InT(1.0), stream); - naiveAddElem(out_ref, in1, in2, len); - add(out, in1, in2, len, stream); - } - - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); + r.uniform(in1.data(), len, InT(-1.0), InT(1.0), stream); + r.uniform(in2.data(), len, InT(-1.0), InT(1.0), stream); + naiveAddElem(out_ref.data(), in1.data(), in2.data(), len); + add(out.data(), in1.data(), in2.data(), len, stream); + CUDA_CHECK(cudaStreamSynchronize(stream)); } void compare() { - ASSERT_TRUE(raft::devArrMatch(out_ref, out, params.len, + ASSERT_TRUE(raft::devArrMatch(out_ref.data(), out.data(), params.len, raft::CompareApprox(params.tolerance))); } protected: AddInputs params; - InT *in1, *in2; - OutT *out_ref, *out; + rmm::device_uvector in1; + rmm::device_uvector in2; + rmm::device_uvector out_ref; + rmm::device_uvector out; + + raft::handle_t handle; cudaStream_t stream; }; diff --git a/cpp/test/linalg/binary_op.cu b/cpp/test/linalg/binary_op.cu index 475d8e58ff..e282a49351 100644 --- a/cpp/test/linalg/binary_op.cu +++ b/cpp/test/linalg/binary_op.cu @@ -39,44 +39,42 @@ void binaryOpLaunch(OutType *out, const InType *in1, const InType *in2, template class BinaryOpTest : public ::testing::TestWithParam> { + public: + BinaryOpTest() + : params(::testing::TestWithParam< + BinaryOpInputs>::GetParam()), + stream(handle.get_stream()), + in1(params.len, stream), + in2(params.len, stream), + out_ref(params.len, stream), + out(params.len, stream) {} + protected: void SetUp() override { - params = ::testing::TestWithParam< - BinaryOpInputs>::GetParam(); raft::random::Rng r(params.seed); - - cudaStream_t stream; - CUDA_CHECK(cudaStreamCreate(&stream)); IdxType len = params.len; - raft::allocate(in1, len, stream); - raft::allocate(in2, len, stream); - raft::allocate(out_ref, len, stream); - raft::allocate(out, len, stream); - r.uniform(in1, len, InType(-1.0), InType(1.0), stream); - r.uniform(in2, len, InType(-1.0), InType(1.0), stream); - naiveAdd(out_ref, in1, in2, len); - binaryOpLaunch(out, in1, in2, len, stream); - CUDA_CHECK(cudaStreamDestroy(stream)); - } - - void TearDown() override { - CUDA_CHECK(cudaFree(in1)); - CUDA_CHECK(cudaFree(in2)); - CUDA_CHECK(cudaFree(out_ref)); - CUDA_CHECK(cudaFree(out)); + r.uniform(in1.data(), len, InType(-1.0), InType(1.0), stream); + r.uniform(in2.data(), len, InType(-1.0), InType(1.0), stream); + naiveAdd(out_ref.data(), in1.data(), in2.data(), len); + binaryOpLaunch(out.data(), in1.data(), in2.data(), len, stream); + CUDA_CHECK(cudaStreamSynchronize(stream)); } protected: BinaryOpInputs params; - InType *in1, *in2; - OutType *out_ref, *out; + rmm::device_uvector in1; + rmm::device_uvector in2; + rmm::device_uvector out_ref; + rmm::device_uvector out; + raft::handle_t handle; + cudaStream_t stream; }; const std::vector> inputsf_i32 = { {0.000001f, 1024 * 1024, 1234ULL}}; typedef BinaryOpTest BinaryOpTestF_i32; TEST_P(BinaryOpTestF_i32, Result) { - ASSERT_TRUE(devArrMatch(out_ref, out, params.len, + ASSERT_TRUE(devArrMatch(out_ref.data(), out.data(), params.len, CompareApprox(params.tolerance))); } INSTANTIATE_TEST_SUITE_P(BinaryOpTests, BinaryOpTestF_i32, @@ -86,7 +84,7 @@ const std::vector> inputsf_i64 = { {0.000001f, 1024 * 1024, 1234ULL}}; typedef BinaryOpTest BinaryOpTestF_i64; TEST_P(BinaryOpTestF_i64, Result) { - ASSERT_TRUE(devArrMatch(out_ref, out, params.len, + ASSERT_TRUE(devArrMatch(out_ref.data(), out.data(), params.len, CompareApprox(params.tolerance))); } INSTANTIATE_TEST_SUITE_P(BinaryOpTests, BinaryOpTestF_i64, @@ -96,7 +94,7 @@ const std::vector> inputsf_i32_d = { {0.000001f, 1024 * 1024, 1234ULL}}; typedef BinaryOpTest BinaryOpTestF_i32_D; TEST_P(BinaryOpTestF_i32_D, Result) { - ASSERT_TRUE(devArrMatch(out_ref, out, params.len, + ASSERT_TRUE(devArrMatch(out_ref.data(), out.data(), params.len, CompareApprox(params.tolerance))); } INSTANTIATE_TEST_SUITE_P(BinaryOpTests, BinaryOpTestF_i32_D, @@ -106,7 +104,7 @@ const std::vector> inputsd_i32 = { {0.00000001, 1024 * 1024, 1234ULL}}; typedef BinaryOpTest BinaryOpTestD_i32; TEST_P(BinaryOpTestD_i32, Result) { - ASSERT_TRUE(devArrMatch(out_ref, out, params.len, + ASSERT_TRUE(devArrMatch(out_ref.data(), out.data(), params.len, CompareApprox(params.tolerance))); } INSTANTIATE_TEST_SUITE_P(BinaryOpTests, BinaryOpTestD_i32, @@ -116,7 +114,7 @@ const std::vector> inputsd_i64 = { {0.00000001, 1024 * 1024, 1234ULL}}; typedef BinaryOpTest BinaryOpTestD_i64; TEST_P(BinaryOpTestD_i64, Result) { - ASSERT_TRUE(devArrMatch(out_ref, out, params.len, + ASSERT_TRUE(devArrMatch(out_ref.data(), out.data(), params.len, CompareApprox(params.tolerance))); } INSTANTIATE_TEST_SUITE_P(BinaryOpTests, BinaryOpTestD_i64, diff --git a/cpp/test/linalg/coalesced_reduction.cu b/cpp/test/linalg/coalesced_reduction.cu index 45dbd9dcc4..841cf0d9fe 100644 --- a/cpp/test/linalg/coalesced_reduction.cu +++ b/cpp/test/linalg/coalesced_reduction.cu @@ -51,35 +51,37 @@ void coalescedReductionLaunch(T *dots, const T *data, int cols, int rows, template class coalescedReductionTest : public ::testing::TestWithParam> { + public: + coalescedReductionTest() + : params(::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + data(params.rows * params.cols, stream), + dots_exp(params.rows * params.cols, stream), + dots_act(params.rows * params.cols, stream) {} + protected: void SetUp() override { - params = ::testing::TestWithParam>::GetParam(); raft::random::Rng r(params.seed); int rows = params.rows, cols = params.cols; int len = rows * cols; - CUDA_CHECK(cudaStreamCreate(&stream)); - raft::allocate(data, len, stream); - raft::allocate(dots_exp, rows, stream); - raft::allocate(dots_act, rows, stream); - r.uniform(data, len, T(-1.0), T(1.0), stream); - naiveCoalescedReduction(dots_exp, data, cols, rows, stream); + r.uniform(data.data(), len, T(-1.0), T(1.0), stream); + naiveCoalescedReduction(dots_exp.data(), data.data(), cols, rows, stream); // Perform reduction with default inplace = false first - coalescedReductionLaunch(dots_act, data, cols, rows, stream); + coalescedReductionLaunch(dots_act.data(), data.data(), cols, rows, stream); // Add to result with inplace = true next - coalescedReductionLaunch(dots_act, data, cols, rows, stream, true); + coalescedReductionLaunch(dots_act.data(), data.data(), cols, rows, stream, + true); CUDA_CHECK(cudaStreamSynchronize(stream)); } - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); - } - protected: coalescedReductionInputs params; - T *data, *dots_exp, *dots_act; + rmm::device_uvector data; + rmm::device_uvector dots_exp; + rmm::device_uvector dots_act; + raft::handle_t handle; cudaStream_t stream; }; @@ -97,13 +99,13 @@ const std::vector> inputsd = { typedef coalescedReductionTest coalescedReductionTestF; TEST_P(coalescedReductionTestF, Result) { - ASSERT_TRUE(raft::devArrMatch(dots_exp, dots_act, params.rows, + ASSERT_TRUE(raft::devArrMatch(dots_exp.data(), dots_act.data(), params.rows, raft::CompareApprox(params.tolerance))); } typedef coalescedReductionTest coalescedReductionTestD; TEST_P(coalescedReductionTestD, Result) { - ASSERT_TRUE(raft::devArrMatch(dots_exp, dots_act, params.rows, + ASSERT_TRUE(raft::devArrMatch(dots_exp.data(), dots_act.data(), params.rows, raft::CompareApprox(params.tolerance))); } diff --git a/cpp/test/linalg/divide.cu b/cpp/test/linalg/divide.cu index 563f96c835..391a6f8b63 100644 --- a/cpp/test/linalg/divide.cu +++ b/cpp/test/linalg/divide.cu @@ -45,31 +45,32 @@ void naiveDivide(Type *out, const Type *in, Type scalar, int len, template class DivideTest : public ::testing::TestWithParam> { + public: + DivideTest() + : params( + ::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + in(params.len, stream), + out_ref(params.len, stream), + out(params.len, stream) {} + protected: void SetUp() override { - params = - ::testing::TestWithParam>::GetParam(); raft::random::Rng r(params.seed); int len = params.len; CUDA_CHECK(cudaStreamCreate(&stream)); - - raft::allocate(in, len, stream); - raft::allocate(out_ref, len, stream); - raft::allocate(out, len, stream); - r.uniform(in, len, T(-1.0), T(1.0), stream); - naiveDivide(out_ref, in, params.scalar, len, stream); - divideScalar(out, in, params.scalar, len, stream); + r.uniform(in.data(), len, T(-1.0), T(1.0), stream); + naiveDivide(out_ref.data(), in.data(), params.scalar, len, stream); + divideScalar(out.data(), in.data(), params.scalar, len, stream); CUDA_CHECK(cudaStreamSynchronize(stream)); } - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); - } - protected: UnaryOpInputs params; - T *in, *out_ref, *out; + rmm::device_uvector in; + rmm::device_uvector out_ref; + rmm::device_uvector out; + raft::handle_t handle; cudaStream_t stream; }; @@ -77,7 +78,7 @@ const std::vector> inputsf = { {0.000001f, 1024 * 1024, 2.f, 1234ULL}}; typedef DivideTest DivideTestF; TEST_P(DivideTestF, Result) { - ASSERT_TRUE(devArrMatch(out_ref, out, params.len, + ASSERT_TRUE(devArrMatch(out_ref.data(), out.data(), params.len, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_SUITE_P(DivideTests, DivideTestF, @@ -87,7 +88,7 @@ typedef DivideTest DivideTestD; const std::vector> inputsd = { {0.000001f, 1024 * 1024, 2.f, 1234ULL}}; TEST_P(DivideTestD, Result) { - ASSERT_TRUE(devArrMatch(out_ref, out, params.len, + ASSERT_TRUE(devArrMatch(out_ref.data(), out.data(), params.len, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_SUITE_P(DivideTests, DivideTestD, diff --git a/cpp/test/linalg/eig.cu b/cpp/test/linalg/eig.cu index 6e26757cf3..74870a62bb 100644 --- a/cpp/test/linalg/eig.cu +++ b/cpp/test/linalg/eig.cu @@ -41,72 +41,74 @@ template template class EigTest : public ::testing::TestWithParam> { + public: + EigTest() + : params(::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + cov_matrix(params.len, stream), + eig_vectors(params.len, stream), + eig_vectors_jacobi(params.len, stream), + eig_vectors_ref(params.len, stream), + eig_vals(params.n_col, stream), + eig_vals_jacobi(params.n_col, stream), + eig_vals_ref(params.n_col, stream), + cov_matrix_large(params.n * params.n, stream), + eig_vectors_large(params.n * params.n, stream), + eig_vectors_jacobi_large(params.n * params.n, stream), + eig_vals_large(params.n, stream), + eig_vals_jacobi_large(params.n, stream) {} + protected: void SetUp() override { - raft::handle_t handle; - stream = handle.get_stream(); - - params = ::testing::TestWithParam>::GetParam(); raft::random::Rng r(params.seed); int len = params.len; - raft::allocate(cov_matrix, len, stream); T cov_matrix_h[] = {1.0, 0.9, 0.81, 0.729, 0.9, 1.0, 0.9, 0.81, 0.81, 0.9, 1.0, 0.9, 0.729, 0.81, 0.9, 1.0}; ASSERT(len == 16, "This test only works with 4x4 matrices!"); - raft::update_device(cov_matrix, cov_matrix_h, len, stream); - - raft::allocate(eig_vectors, len, stream); - raft::allocate(eig_vals, params.n_col, stream); - raft::allocate(eig_vectors_jacobi, len, stream); - raft::allocate(eig_vals_jacobi, params.n_col, stream); + raft::update_device(cov_matrix.data(), cov_matrix_h, len, stream); T eig_vectors_ref_h[] = {0.2790, -0.6498, 0.6498, -0.2789, -0.5123, 0.4874, 0.4874, -0.5123, 0.6498, 0.2789, -0.2789, -0.6498, 0.4874, 0.5123, 0.5123, 0.4874}; T eig_vals_ref_h[] = {0.0614, 0.1024, 0.3096, 3.5266}; - raft::allocate(eig_vectors_ref, len, stream); - raft::allocate(eig_vals_ref, params.n_col, stream); + raft::update_device(eig_vectors_ref.data(), eig_vectors_ref_h, len, stream); + raft::update_device(eig_vals_ref.data(), eig_vals_ref_h, params.n_col, + stream); - raft::update_device(eig_vectors_ref, eig_vectors_ref_h, len, stream); - raft::update_device(eig_vals_ref, eig_vals_ref_h, params.n_col, stream); - - eigDC(handle, cov_matrix, params.n_row, params.n_col, eig_vectors, eig_vals, - stream); + eigDC(handle, cov_matrix.data(), params.n_row, params.n_col, + eig_vectors.data(), eig_vals.data(), stream); T tol = 1.e-7; int sweeps = 15; - eigJacobi(handle, cov_matrix, params.n_row, params.n_col, - eig_vectors_jacobi, eig_vals_jacobi, stream, tol, sweeps); + eigJacobi(handle, cov_matrix.data(), params.n_row, params.n_col, + eig_vectors_jacobi.data(), eig_vals_jacobi.data(), stream, tol, + sweeps); // test code for comparing two methods len = params.n * params.n; - raft::allocate(cov_matrix_large, len, stream); - raft::allocate(eig_vectors_large, len, stream); - raft::allocate(eig_vectors_jacobi_large, len, stream); - raft::allocate(eig_vals_large, params.n, stream); - raft::allocate(eig_vals_jacobi_large, params.n, stream); - - r.uniform(cov_matrix_large, len, T(-1.0), T(1.0), stream); - - eigDC(handle, cov_matrix_large, params.n, params.n, eig_vectors_large, - eig_vals_large, stream); - eigJacobi(handle, cov_matrix_large, params.n, params.n, - eig_vectors_jacobi_large, eig_vals_jacobi_large, stream, tol, - sweeps); - } - void TearDown() override { raft::deallocate_all(stream); } + r.uniform(cov_matrix_large.data(), len, T(-1.0), T(1.0), stream); + + eigDC(handle, cov_matrix_large.data(), params.n, params.n, + eig_vectors_large.data(), eig_vals_large.data(), stream); + eigJacobi(handle, cov_matrix_large.data(), params.n, params.n, + eig_vectors_jacobi_large.data(), eig_vals_jacobi_large.data(), + stream, tol, sweeps); + CUDA_CHECK(cudaStreamSynchronize(stream)); + } protected: EigInputs params; - T *cov_matrix, *eig_vectors, *eig_vectors_jacobi, *eig_vectors_ref, *eig_vals, - *eig_vals_jacobi, *eig_vals_ref; - T *cov_matrix_large, *eig_vectors_large, *eig_vectors_jacobi_large, - *eig_vals_large, *eig_vals_jacobi_large; + rmm::device_uvector cov_matrix, eig_vectors, eig_vectors_jacobi, + eig_vectors_ref, eig_vals, eig_vals_jacobi, eig_vals_ref; + + rmm::device_uvector cov_matrix_large, eig_vectors_large, + eig_vectors_jacobi_large, eig_vals_large, eig_vals_jacobi_large; + raft::handle_t handle; cudaStream_t stream; }; @@ -119,71 +121,71 @@ const std::vector> inputsd2 = { typedef EigTest EigTestValF; TEST_P(EigTestValF, Result) { ASSERT_TRUE( - raft::devArrMatch(eig_vals_ref, eig_vals, params.n_col, + raft::devArrMatch(eig_vals_ref.data(), eig_vals.data(), params.n_col, raft::CompareApproxAbs(params.tolerance))); } typedef EigTest EigTestValD; TEST_P(EigTestValD, Result) { ASSERT_TRUE( - raft::devArrMatch(eig_vals_ref, eig_vals, params.n_col, + raft::devArrMatch(eig_vals_ref.data(), eig_vals.data(), params.n_col, raft::CompareApproxAbs(params.tolerance))); } typedef EigTest EigTestVecF; TEST_P(EigTestVecF, Result) { ASSERT_TRUE( - raft::devArrMatch(eig_vectors_ref, eig_vectors, params.len, + raft::devArrMatch(eig_vectors_ref.data(), eig_vectors.data(), params.len, raft::CompareApproxAbs(params.tolerance))); } typedef EigTest EigTestVecD; TEST_P(EigTestVecD, Result) { ASSERT_TRUE( - raft::devArrMatch(eig_vectors_ref, eig_vectors, params.len, + raft::devArrMatch(eig_vectors_ref.data(), eig_vectors.data(), params.len, raft::CompareApproxAbs(params.tolerance))); } typedef EigTest EigTestValJacobiF; TEST_P(EigTestValJacobiF, Result) { ASSERT_TRUE( - raft::devArrMatch(eig_vals_ref, eig_vals_jacobi, params.n_col, + raft::devArrMatch(eig_vals_ref.data(), eig_vals_jacobi.data(), params.n_col, raft::CompareApproxAbs(params.tolerance))); } typedef EigTest EigTestValJacobiD; TEST_P(EigTestValJacobiD, Result) { ASSERT_TRUE( - raft::devArrMatch(eig_vals_ref, eig_vals_jacobi, params.n_col, + raft::devArrMatch(eig_vals_ref.data(), eig_vals_jacobi.data(), params.n_col, raft::CompareApproxAbs(params.tolerance))); } typedef EigTest EigTestVecJacobiF; TEST_P(EigTestVecJacobiF, Result) { - ASSERT_TRUE( - raft::devArrMatch(eig_vectors_ref, eig_vectors_jacobi, params.len, - raft::CompareApproxAbs(params.tolerance))); + ASSERT_TRUE(raft::devArrMatch( + eig_vectors_ref.data(), eig_vectors_jacobi.data(), params.len, + raft::CompareApproxAbs(params.tolerance))); } typedef EigTest EigTestVecJacobiD; TEST_P(EigTestVecJacobiD, Result) { - ASSERT_TRUE( - raft::devArrMatch(eig_vectors_ref, eig_vectors_jacobi, params.len, - raft::CompareApproxAbs(params.tolerance))); + ASSERT_TRUE(raft::devArrMatch( + eig_vectors_ref.data(), eig_vectors_jacobi.data(), params.len, + raft::CompareApproxAbs(params.tolerance))); } typedef EigTest EigTestVecCompareF; TEST_P(EigTestVecCompareF, Result) { ASSERT_TRUE(raft::devArrMatch( - eig_vectors_large, eig_vectors_jacobi_large, (params.n * params.n), - raft::CompareApproxAbs(params.tolerance))); + eig_vectors_large.data(), eig_vectors_jacobi_large.data(), + (params.n * params.n), raft::CompareApproxAbs(params.tolerance))); } typedef EigTest EigTestVecCompareD; TEST_P(EigTestVecCompareD, Result) { ASSERT_TRUE(raft::devArrMatch( - eig_vectors_large, eig_vectors_jacobi_large, (params.n * params.n), - raft::CompareApproxAbs(params.tolerance))); + eig_vectors_large.data(), eig_vectors_jacobi_large.data(), + (params.n * params.n), raft::CompareApproxAbs(params.tolerance))); } INSTANTIATE_TEST_SUITE_P(EigTests, EigTestValF, ::testing::ValuesIn(inputsf2)); diff --git a/cpp/test/linalg/eig_sel.cu b/cpp/test/linalg/eig_sel.cu index bdd0a08ff6..bd4c95b451 100644 --- a/cpp/test/linalg/eig_sel.cu +++ b/cpp/test/linalg/eig_sel.cu @@ -43,44 +43,46 @@ template template class EigSelTest : public ::testing::TestWithParam> { + public: + EigSelTest() + : params(::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + cov_matrix(params.len, stream), + eig_vectors(12, stream), + eig_vectors_ref(12, stream), + eig_vals(params.n_col, stream), + eig_vals_ref(params.n_col, stream) {} + protected: void SetUp() override { - raft::handle_t handle; - stream = handle.get_stream(); - - params = ::testing::TestWithParam>::GetParam(); int len = params.len; - raft::allocate(cov_matrix, len, stream); T cov_matrix_h[] = {1.0, 0.9, 0.81, 0.729, 0.9, 1.0, 0.9, 0.81, 0.81, 0.9, 1.0, 0.9, 0.729, 0.81, 0.9, 1.0}; ASSERT(len == 16, "This test only works with 4x4 matrices!"); - raft::update_device(cov_matrix, cov_matrix_h, len, stream); - - raft::allocate(eig_vectors, 12, stream); - raft::allocate(eig_vals, params.n_col, stream); + raft::update_device(cov_matrix.data(), cov_matrix_h, len, stream); T eig_vectors_ref_h[] = {-0.5123, 0.4874, 0.4874, -0.5123, 0.6498, 0.2789, -0.2789, -0.6498, 0.4874, 0.5123, 0.5123, 0.4874}; T eig_vals_ref_h[] = {0.1024, 0.3096, 3.5266, 3.5266}; - raft::allocate(eig_vectors_ref, 12, stream); - raft::allocate(eig_vals_ref, params.n_col, stream); + raft::update_device(eig_vectors_ref.data(), eig_vectors_ref_h, 12, stream); + raft::update_device(eig_vals_ref.data(), eig_vals_ref_h, 4, stream); - raft::update_device(eig_vectors_ref, eig_vectors_ref_h, 12, stream); - raft::update_device(eig_vals_ref, eig_vals_ref_h, 4, stream); - - eigSelDC(handle, cov_matrix, params.n_row, params.n_col, 3, eig_vectors, - eig_vals, EigVecMemUsage::OVERWRITE_INPUT, stream); + eigSelDC(handle, cov_matrix.data(), params.n_row, params.n_col, 3, + eig_vectors.data(), eig_vals.data(), + EigVecMemUsage::OVERWRITE_INPUT, stream); CUDA_CHECK(cudaStreamSynchronize(stream)); } - void TearDown() override { raft::deallocate_all(stream); } - protected: EigSelInputs params; - T *cov_matrix, *eig_vectors, *eig_vectors_ref, *eig_vals, *eig_vals_ref; - + rmm::device_uvector cov_matrix; + rmm::device_uvector eig_vectors; + rmm::device_uvector eig_vectors_ref; + rmm::device_uvector eig_vals; + rmm::device_uvector eig_vals_ref; + raft::handle_t handle; cudaStream_t stream; }; @@ -93,28 +95,28 @@ const std::vector> inputsd2 = { typedef EigSelTest EigSelTestValF; TEST_P(EigSelTestValF, Result) { ASSERT_TRUE( - raft::devArrMatch(eig_vals_ref, eig_vals, params.n_col, + raft::devArrMatch(eig_vals_ref.data(), eig_vals.data(), params.n_col, raft::CompareApproxAbs(params.tolerance))); } typedef EigSelTest EigSelTestValD; TEST_P(EigSelTestValD, Result) { ASSERT_TRUE( - raft::devArrMatch(eig_vals_ref, eig_vals, params.n_col, + raft::devArrMatch(eig_vals_ref.data(), eig_vals.data(), params.n_col, raft::CompareApproxAbs(params.tolerance))); } typedef EigSelTest EigSelTestVecF; TEST_P(EigSelTestVecF, Result) { ASSERT_TRUE( - raft::devArrMatch(eig_vectors_ref, eig_vectors, 12, + raft::devArrMatch(eig_vectors_ref.data(), eig_vectors.data(), 12, raft::CompareApproxAbs(params.tolerance))); } typedef EigSelTest EigSelTestVecD; TEST_P(EigSelTestVecD, Result) { ASSERT_TRUE( - raft::devArrMatch(eig_vectors_ref, eig_vectors, 12, + raft::devArrMatch(eig_vectors_ref.data(), eig_vectors.data(), 12, raft::CompareApproxAbs(params.tolerance))); } diff --git a/cpp/test/linalg/eltwise.cu b/cpp/test/linalg/eltwise.cu index e955f7a354..25ecb75f7d 100644 --- a/cpp/test/linalg/eltwise.cu +++ b/cpp/test/linalg/eltwise.cu @@ -60,33 +60,30 @@ template template class ScalarMultiplyTest : public ::testing::TestWithParam> { + public: + ScalarMultiplyTest() + : params(::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + in(len, stream), + out_ref(len, stream), + out(len, stream) {} + protected: void SetUp() override { - params = ::testing::TestWithParam>::GetParam(); raft::random::Rng r(params.seed); int len = params.len; T scalar = params.scalar; - - cudaStream_t stream; - CUDA_CHECK(cudaStreamCreate(&stream)); - raft::allocate(in, len, stream); - raft::allocate(out_ref, len, stream); - raft::allocate(out, len, stream); r.uniform(in, len, T(-1.0), T(1.0), stream); naiveScale(out_ref, in, scalar, len, stream); scalarMultiply(out, in, scalar, len, stream); - CUDA_CHECK(cudaStreamDestroy(stream)); - } - - void TearDown() override { - CUDA_CHECK(cudaFree(in)); - CUDA_CHECK(cudaFree(out_ref)); - CUDA_CHECK(cudaFree(out)); + CUDA_CHECK(cudaStreamSynchronize(stream)); } protected: ScalarMultiplyInputs params; - T *in, *out_ref, *out; + rmm::device_uvector in, out_ref, out; + raft::handle_t handle; + cudaStream_t stream; }; const std::vector> inputsf1 = { @@ -97,13 +94,13 @@ const std::vector> inputsd1 = { typedef ScalarMultiplyTest ScalarMultiplyTestF; TEST_P(ScalarMultiplyTestF, Result) { - ASSERT_TRUE(devArrMatch(out_ref, out, params.len, + ASSERT_TRUE(devArrMatch(out_ref.data(), out.data(), params.len, CompareApprox(params.tolerance))); } typedef ScalarMultiplyTest ScalarMultiplyTestD; TEST_P(ScalarMultiplyTestD, Result) { - ASSERT_TRUE(devArrMatch(out_ref, out, params.len, + ASSERT_TRUE(devArrMatch(out_ref.data(), out.data(), params.len, CompareApprox(params.tolerance))); } @@ -148,35 +145,32 @@ template template class EltwiseAddTest : public ::testing::TestWithParam> { + public: + EltwiseAddTest() + : params(::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + in1(params.len, stream), + in2(params.len, stream), + out_ref(params.len, stream), + out(params.len, stream) {} + protected: void SetUp() override { params = ::testing::TestWithParam>::GetParam(); raft::random::Rng r(params.seed); - - cudaStream_t stream; - CUDA_CHECK(cudaStreamCreate(&stream)); int len = params.len; - raft::allocate(in1, len, stream); - raft::allocate(in2, len, stream); - raft::allocate(out_ref, len, stream); - raft::allocate(out, len, stream); r.uniform(in1, len, T(-1.0), T(1.0), stream); r.uniform(in2, len, T(-1.0), T(1.0), stream); naiveAdd(out_ref, in1, in2, len, stream); eltwiseAdd(out, in1, in2, len, stream); - CUDA_CHECK(cudaStreamDestroy(stream)); - } - - void TearDown() override { - CUDA_CHECK(cudaFree(in1)); - CUDA_CHECK(cudaFree(in2)); - CUDA_CHECK(cudaFree(out_ref)); - CUDA_CHECK(cudaFree(out)); + CUDA_CHECK(cudaStreamSynchronize(stream)); } protected: EltwiseAddInputs params; - T *in1, *in2, *out_ref, *out; + rmm::device_uvector in1, in2, out_ref, out; + raft::handle_t handle; + cudaStream_t stream; }; const std::vector> inputsf2 = { @@ -187,13 +181,13 @@ const std::vector> inputsd2 = { typedef EltwiseAddTest EltwiseAddTestF; TEST_P(EltwiseAddTestF, Result) { - ASSERT_TRUE(devArrMatch(out_ref, out, params.len, + ASSERT_TRUE(devArrMatch(out_ref.data(), out.data(), params.len, CompareApprox(params.tolerance))); } typedef EltwiseAddTest EltwiseAddTestD; TEST_P(EltwiseAddTestD, Result) { - ASSERT_TRUE(devArrMatch(out_ref, out, params.len, + ASSERT_TRUE(devArrMatch(out_ref.data(), out.data(), params.len, CompareApprox(params.tolerance))); } diff --git a/cpp/test/linalg/map.cu b/cpp/test/linalg/map.cu index 5b13fb5362..a5677c0539 100644 --- a/cpp/test/linalg/map.cu +++ b/cpp/test/linalg/map.cu @@ -46,47 +46,48 @@ template void create_ref(OutType *out_ref, const InType *in1, const InType *in2, const InType *in3, InType scalar, IdxType len, cudaStream_t stream) { - InType *tmp; - raft::allocate(tmp, len, stream); - eltwiseAdd(tmp, in1, in2, len, stream); - eltwiseAdd(out_ref, tmp, in3, len, stream); + rmm::device_uvector tmp(len, stream); + eltwiseAdd(tmp.data(), in1, in2, len, stream); + eltwiseAdd(out_ref, tmp.data(), in3, len, stream); scalarAdd(out_ref, out_ref, (OutType)scalar, len, stream); + CUDA_CHECK(cudaStreamSynchronize(stream)); } template class MapTest : public ::testing::TestWithParam> { + public: + MapTest() + : params(::testing::TestWithParam< + MapInputs>::GetParam()), + stream(handle.get_stream()), + in1(params.len, stream), + in2(params.len, stream), + in3(params.len, stream), + out_ref(params.len, stream), + out(params.len, stream) {} + protected: void SetUp() override { - params = - ::testing::TestWithParam>::GetParam(); raft::random::Rng r(params.seed); - CUDA_CHECK(cudaStreamCreate(&stream)); IdxType len = params.len; - raft::allocate(in1, len, stream); - raft::allocate(in2, len, stream); - raft::allocate(in3, len, stream); - raft::allocate(out_ref, len, stream); - raft::allocate(out, len, stream); - r.uniform(in1, len, InType(-1.0), InType(1.0), stream); - r.uniform(in2, len, InType(-1.0), InType(1.0), stream); - r.uniform(in3, len, InType(-1.0), InType(1.0), stream); - - create_ref(out_ref, in1, in2, in3, params.scalar, len, stream); - mapLaunch(out, in1, in2, in3, params.scalar, len, stream); + r.uniform(in1.data(), len, InType(-1.0), InType(1.0), stream); + r.uniform(in2.data(), len, InType(-1.0), InType(1.0), stream); + r.uniform(in3.data(), len, InType(-1.0), InType(1.0), stream); + + create_ref(out_ref.data(), in1.data(), in2.data(), in3.data(), + params.scalar, len, stream); + mapLaunch(out.data(), in1.data(), in2.data(), in3.data(), params.scalar, + len, stream); CUDA_CHECK(cudaStreamSynchronize(stream)); } - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); - } - protected: MapInputs params; - InType *in1, *in2, *in3; - OutType *out_ref, *out; + rmm::device_uvector in1, in2, in3; + rmm::device_uvector out_ref, out; + raft::handle_t handle; cudaStream_t stream; }; @@ -94,7 +95,7 @@ const std::vector> inputsf_i32 = { {0.000001f, 1024 * 1024, 1234ULL, 3.2}}; typedef MapTest MapTestF_i32; TEST_P(MapTestF_i32, Result) { - ASSERT_TRUE(devArrMatch(out_ref, out, params.len, + ASSERT_TRUE(devArrMatch(out_ref.data(), out.data(), params.len, CompareApprox(params.tolerance))); } INSTANTIATE_TEST_SUITE_P(MapTests, MapTestF_i32, @@ -104,7 +105,7 @@ const std::vector> inputsf_i64 = { {0.000001f, 1024 * 1024, 1234ULL, 9.4}}; typedef MapTest MapTestF_i64; TEST_P(MapTestF_i64, Result) { - ASSERT_TRUE(devArrMatch(out_ref, out, params.len, + ASSERT_TRUE(devArrMatch(out_ref.data(), out.data(), params.len, CompareApprox(params.tolerance))); } INSTANTIATE_TEST_SUITE_P(MapTests, MapTestF_i64, @@ -114,7 +115,7 @@ const std::vector> inputsf_i32_d = { {0.000001f, 1024 * 1024, 1234ULL, 5.9}}; typedef MapTest MapTestF_i32_D; TEST_P(MapTestF_i32_D, Result) { - ASSERT_TRUE(devArrMatch(out_ref, out, params.len, + ASSERT_TRUE(devArrMatch(out_ref.data(), out.data(), params.len, CompareApprox(params.tolerance))); } INSTANTIATE_TEST_SUITE_P(MapTests, MapTestF_i32_D, @@ -124,7 +125,7 @@ const std::vector> inputsd_i32 = { {0.00000001, 1024 * 1024, 1234ULL, 7.5}}; typedef MapTest MapTestD_i32; TEST_P(MapTestD_i32, Result) { - ASSERT_TRUE(devArrMatch(out_ref, out, params.len, + ASSERT_TRUE(devArrMatch(out_ref.data(), out.data(), params.len, CompareApprox(params.tolerance))); } INSTANTIATE_TEST_SUITE_P(MapTests, MapTestD_i32, @@ -134,7 +135,7 @@ const std::vector> inputsd_i64 = { {0.00000001, 1024 * 1024, 1234ULL, 5.2}}; typedef MapTest MapTestD_i64; TEST_P(MapTestD_i64, Result) { - ASSERT_TRUE(devArrMatch(out_ref, out, params.len, + ASSERT_TRUE(devArrMatch(out_ref.data(), out.data(), params.len, CompareApprox(params.tolerance))); } INSTANTIATE_TEST_SUITE_P(MapTests, MapTestD_i64, diff --git a/cpp/test/linalg/map_then_reduce.cu b/cpp/test/linalg/map_then_reduce.cu index 4a44e59504..84d47e8212 100644 --- a/cpp/test/linalg/map_then_reduce.cu +++ b/cpp/test/linalg/map_then_reduce.cu @@ -70,30 +70,30 @@ void mapReduceLaunch(OutType *out_ref, OutType *out, const InType *in, template class MapReduceTest : public ::testing::TestWithParam> { + public: + MapReduceTest() + : params(::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + in(params.len, stream), + out_ref(params.len, stream), + out(params.len, stream) + + {} + protected: void SetUp() override { - params = ::testing::TestWithParam>::GetParam(); raft::random::Rng r(params.seed); auto len = params.len; - - CUDA_CHECK(cudaStreamCreate(&stream)); - raft::allocate(in, len, stream); - raft::allocate(out_ref, len, stream); - raft::allocate(out, len, stream); - r.uniform(in, len, InType(-1.0), InType(1.0), stream); - mapReduceLaunch(out_ref, out, in, len, stream); + r.uniform(in.data(), len, InType(-1.0), InType(1.0), stream); + mapReduceLaunch(out_ref.data(), out.data(), in.data(), len, stream); CUDA_CHECK(cudaStreamSynchronize(stream)); } - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); - } - protected: MapReduceInputs params; - InType *in; - OutType *out_ref, *out; + rmm::device_uvector in; + rmm::device_uvector out_ref, out; + raft::handle_t handle; cudaStream_t stream; }; @@ -101,7 +101,7 @@ const std::vector> inputsf = { {0.001f, 1024 * 1024, 1234ULL}}; typedef MapReduceTest MapReduceTestFF; TEST_P(MapReduceTestFF, Result) { - ASSERT_TRUE(devArrMatch(out_ref, out, params.len, + ASSERT_TRUE(devArrMatch(out_ref.data(), out.data(), params.len, CompareApprox(params.tolerance))); } INSTANTIATE_TEST_SUITE_P(MapReduceTests, MapReduceTestFF, @@ -109,7 +109,7 @@ INSTANTIATE_TEST_SUITE_P(MapReduceTests, MapReduceTestFF, typedef MapReduceTest MapReduceTestFD; TEST_P(MapReduceTestFD, Result) { - ASSERT_TRUE(devArrMatch(out_ref, out, params.len, + ASSERT_TRUE(devArrMatch(out_ref.data(), out.data(), params.len, CompareApprox(params.tolerance))); } INSTANTIATE_TEST_SUITE_P(MapReduceTests, MapReduceTestFD, @@ -119,7 +119,7 @@ const std::vector> inputsd = { {0.000001, 1024 * 1024, 1234ULL}}; typedef MapReduceTest MapReduceTestDD; TEST_P(MapReduceTestDD, Result) { - ASSERT_TRUE(devArrMatch(out_ref, out, params.len, + ASSERT_TRUE(devArrMatch(out_ref.data(), out.data(), params.len, CompareApprox(params.tolerance))); } INSTANTIATE_TEST_SUITE_P(MapReduceTests, MapReduceTestDD, diff --git a/cpp/test/linalg/matrix_vector_op.cu b/cpp/test/linalg/matrix_vector_op.cu index e017ee0918..3f029de743 100644 --- a/cpp/test/linalg/matrix_vector_op.cu +++ b/cpp/test/linalg/matrix_vector_op.cu @@ -59,43 +59,42 @@ void matrixVectorOpLaunch(T *out, const T *in, const T *vec1, const T *vec2, template class MatVecOpTest : public ::testing::TestWithParam> { + public: + MatVecOpTest() + : params(::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + in(params.rows * params.cols, stream), + out_ref(params.rows * params.cols, stream), + out(params.rows * params.cols, stream), + vec1(params.bcastAlongRows ? params.cols : params.rows, stream), + vec2(params.bcastAlongRows ? params.cols : params.rows, stream) {} + protected: void SetUp() override { - params = ::testing::TestWithParam>::GetParam(); raft::random::Rng r(params.seed); IdxType N = params.rows, D = params.cols; IdxType len = N * D; - - CUDA_CHECK(cudaStreamCreate(&stream)); - raft::allocate(in, len, stream); - raft::allocate(out_ref, len, stream); - raft::allocate(out, len, stream); IdxType vecLen = params.bcastAlongRows ? D : N; - raft::allocate(vec1, vecLen, stream); - raft::allocate(vec2, vecLen, stream); - r.uniform(in, len, (T)-1.0, (T)1.0, stream); - r.uniform(vec1, vecLen, (T)-1.0, (T)1.0, stream); - r.uniform(vec2, vecLen, (T)-1.0, (T)1.0, stream); + r.uniform(in.data(), len, (T)-1.0, (T)1.0, stream); + r.uniform(vec1.data(), vecLen, (T)-1.0, (T)1.0, stream); + r.uniform(vec2.data(), vecLen, (T)-1.0, (T)1.0, stream); if (params.useTwoVectors) { - naiveMatVec(out_ref, in, vec1, vec2, D, N, params.rowMajor, - params.bcastAlongRows, (T)1.0); + naiveMatVec(out_ref.data(), in.data(), vec1.data(), vec2.data(), D, N, + params.rowMajor, params.bcastAlongRows, (T)1.0); } else { - naiveMatVec(out_ref, in, vec1, D, N, params.rowMajor, + naiveMatVec(out_ref.data(), in.data(), vec1.data(), D, N, params.rowMajor, params.bcastAlongRows, (T)1.0); } - matrixVectorOpLaunch(out, in, vec1, vec2, D, N, params.rowMajor, - params.bcastAlongRows, params.useTwoVectors, stream); + matrixVectorOpLaunch(out.data(), in.data(), vec1.data(), vec2.data(), D, N, + params.rowMajor, params.bcastAlongRows, + params.useTwoVectors, stream); CUDA_CHECK(cudaStreamSynchronize(stream)); } - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); - } - protected: MatVecOpInputs params; - T *in, *out, *out_ref, *vec1, *vec2; + rmm::device_uvector in, out, out_ref, vec1, vec2; + raft::handle_t handle; cudaStream_t stream; }; @@ -119,7 +118,7 @@ const std::vector> inputsf_i32 = { {0.00001f, 1024, 64, false, false, true, 1234ULL}}; typedef MatVecOpTest MatVecOpTestF_i32; TEST_P(MatVecOpTestF_i32, Result) { - ASSERT_TRUE(devArrMatch(out_ref, out, params.rows * params.cols, + ASSERT_TRUE(devArrMatch(out_ref.data(), out.data(), params.rows * params.cols, CompareApprox(params.tolerance))); } INSTANTIATE_TEST_SUITE_P(MatVecOpTests, MatVecOpTestF_i32, @@ -130,7 +129,7 @@ const std::vector> inputsf_i64 = { {0.00001f, 2500, 250, false, false, true, 1234ULL}}; typedef MatVecOpTest MatVecOpTestF_i64; TEST_P(MatVecOpTestF_i64, Result) { - ASSERT_TRUE(devArrMatch(out_ref, out, params.rows * params.cols, + ASSERT_TRUE(devArrMatch(out_ref.data(), out.data(), params.rows * params.cols, CompareApprox(params.tolerance))); } INSTANTIATE_TEST_SUITE_P(MatVecOpTests, MatVecOpTestF_i64, @@ -156,7 +155,7 @@ const std::vector> inputsd_i32 = { {0.0000001, 1024, 64, false, false, true, 1234ULL}}; typedef MatVecOpTest MatVecOpTestD_i32; TEST_P(MatVecOpTestD_i32, Result) { - ASSERT_TRUE(devArrMatch(out_ref, out, params.rows * params.cols, + ASSERT_TRUE(devArrMatch(out_ref.data(), out.data(), params.rows * params.cols, CompareApprox(params.tolerance))); } INSTANTIATE_TEST_SUITE_P(MatVecOpTests, MatVecOpTestD_i32, @@ -167,7 +166,7 @@ const std::vector> inputsd_i64 = { {0.0000001, 2500, 250, false, false, true, 1234ULL}}; typedef MatVecOpTest MatVecOpTestD_i64; TEST_P(MatVecOpTestD_i64, Result) { - ASSERT_TRUE(devArrMatch(out_ref, out, params.rows * params.cols, + ASSERT_TRUE(devArrMatch(out_ref.data(), out.data(), params.rows * params.cols, CompareApprox(params.tolerance))); } INSTANTIATE_TEST_SUITE_P(MatVecOpTests, MatVecOpTestD_i64, diff --git a/cpp/test/linalg/multiply.cu b/cpp/test/linalg/multiply.cu index d7bda7c27d..7aedde71ef 100644 --- a/cpp/test/linalg/multiply.cu +++ b/cpp/test/linalg/multiply.cu @@ -26,30 +26,29 @@ namespace linalg { template class MultiplyTest : public ::testing::TestWithParam> { + public: + MultiplyTest() + : params(::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + in(params.len, stream), + out_ref(params.len, stream), + out(params.len, stream) {} + protected: void SetUp() override { params = ::testing::TestWithParam>::GetParam(); raft::random::Rng r(params.seed); int len = params.len; - CUDA_CHECK(cudaStreamCreate(&stream)); - - raft::allocate(in, len, stream); - raft::allocate(out_ref, len, stream); - raft::allocate(out, len, stream); - r.uniform(in, len, T(-1.0), T(1.0), stream); - naiveScale(out_ref, in, params.scalar, len, stream); - multiplyScalar(out, in, params.scalar, len, stream); + r.uniform(in.data(), len, T(-1.0), T(1.0), stream); + naiveScale(out_ref.data(), in.data(), params.scalar, len, stream); + multiplyScalar(out.data(), in.data(), params.scalar, len, stream); CUDA_CHECK(cudaStreamSynchronize(stream)); } - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); - } - protected: UnaryOpInputs params; - T *in, *out_ref, *out; + rmm::device_uvector in, out_ref, out; + raft::handle_t handle; cudaStream_t stream; }; @@ -57,7 +56,7 @@ const std::vector> inputsf = { {0.000001f, 1024 * 1024, 2.f, 1234ULL}}; typedef MultiplyTest MultiplyTestF; TEST_P(MultiplyTestF, Result) { - ASSERT_TRUE(devArrMatch(out_ref, out, params.len, + ASSERT_TRUE(devArrMatch(out_ref.data(), out.data(), params.len, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_SUITE_P(MultiplyTests, MultiplyTestF, @@ -67,7 +66,7 @@ typedef MultiplyTest MultiplyTestD; const std::vector> inputsd = { {0.000001f, 1024 * 1024, 2.f, 1234ULL}}; TEST_P(MultiplyTestD, Result) { - ASSERT_TRUE(devArrMatch(out_ref, out, params.len, + ASSERT_TRUE(devArrMatch(out_ref.data(), out.data(), params.len, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_SUITE_P(MultiplyTests, MultiplyTestD, diff --git a/cpp/test/linalg/norm.cu b/cpp/test/linalg/norm.cu index 5563064982..d248ec6b77 100644 --- a/cpp/test/linalg/norm.cu +++ b/cpp/test/linalg/norm.cu @@ -71,39 +71,34 @@ void naiveRowNorm(Type *dots, const Type *data, int D, int N, NormType type, template class RowNormTest : public ::testing::TestWithParam> { public: + RowNormTest() + : params(::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + data(params.rows * params.cols, stream), + dots_exp(params.rows, stream), + dots_act(params.rows, stream) {} + void SetUp() override { - CUDA_CHECK(cudaStreamCreate(&stream)); - params = ::testing::TestWithParam>::GetParam(); raft::random::Rng r(params.seed); int rows = params.rows, cols = params.cols, len = rows * cols; - cudaStream_t stream; - CUDA_CHECK(cudaStreamCreate(&stream)); - raft::allocate(data, len, stream); - raft::allocate(dots_exp, rows, stream); - raft::allocate(dots_act, rows, stream); - r.uniform(data, len, T(-1.0), T(1.0), stream); - naiveRowNorm(dots_exp, data, cols, rows, params.type, params.do_sqrt, - stream); + r.uniform(data.data(), len, T(-1.0), T(1.0), stream); + naiveRowNorm(dots_exp.data(), data.data(), cols, rows, params.type, + params.do_sqrt, stream); if (params.do_sqrt) { auto fin_op = [] __device__(T in) { return raft::mySqrt(in); }; - rowNorm(dots_act, data, cols, rows, params.type, params.rowMajor, stream, - fin_op); + rowNorm(dots_act.data(), data.data(), cols, rows, params.type, + params.rowMajor, stream, fin_op); } else { - rowNorm(dots_act, data, cols, rows, params.type, params.rowMajor, stream); + rowNorm(dots_act.data(), data.data(), cols, rows, params.type, + params.rowMajor, stream); } - CUDA_CHECK(cudaStreamDestroy(stream)); - } - - void TearDown() override { - CUDA_CHECK(cudaFree(data)); - CUDA_CHECK(cudaFree(dots_exp)); - CUDA_CHECK(cudaFree(dots_act)); - CUDA_CHECK(cudaStreamDestroy(stream)); + CUDA_CHECK(cudaStreamSynchronize(stream)); } protected: NormInputs params; - T *data, *dots_exp, *dots_act; + rmm::device_uvector data, dots_exp, dots_act; + raft::handle_t handle; cudaStream_t stream; }; @@ -136,38 +131,36 @@ void naiveColNorm(Type *dots, const Type *data, int D, int N, NormType type, template class ColNormTest : public ::testing::TestWithParam> { public: + ColNormTest() + : params(::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + data(params.rows * params.cols, stream), + dots_exp(params.cols, stream), + dots_act(params.cols, stream) {} + void SetUp() override { - CUDA_CHECK(cudaStreamCreate(&stream)); - params = ::testing::TestWithParam>::GetParam(); raft::random::Rng r(params.seed); int rows = params.rows, cols = params.cols, len = rows * cols; - cudaStream_t stream; - CUDA_CHECK(cudaStreamCreate(&stream)); - raft::allocate(data, len, stream); - r.uniform(data, len, T(-1.0), T(1.0), stream); - raft::allocate(dots_exp, cols, stream); - raft::allocate(dots_act, cols, stream); - - naiveColNorm(dots_exp, data, cols, rows, params.type, params.do_sqrt, - stream); + r.uniform(data.data(), len, T(-1.0), T(1.0), stream); + + naiveColNorm(dots_exp.data(), data.data(), cols, rows, params.type, + params.do_sqrt, stream); if (params.do_sqrt) { auto fin_op = [] __device__(T in) { return raft::mySqrt(in); }; - colNorm(dots_act, data, cols, rows, params.type, params.rowMajor, stream, - fin_op); + colNorm(dots_act.data(), data.data(), cols, rows, params.type, + params.rowMajor, stream, fin_op); } else { - colNorm(dots_act, data, cols, rows, params.type, params.rowMajor, stream); + colNorm(dots_act.data(), data.data(), cols, rows, params.type, + params.rowMajor, stream); } CUDA_CHECK(cudaStreamSynchronize(stream)); } - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); - } - protected: NormInputs params; - T *data, *dots_exp, *dots_act; + rmm::device_uvector data, dots_exp, dots_act; + + raft::handle_t handle; cudaStream_t stream; }; @@ -212,13 +205,13 @@ const std::vector> inputsd = { typedef RowNormTest RowNormTestF; TEST_P(RowNormTestF, Result) { - ASSERT_TRUE(raft::devArrMatch(dots_exp, dots_act, params.rows, + ASSERT_TRUE(raft::devArrMatch(dots_exp.data(), dots_act.data(), params.rows, raft::CompareApprox(params.tolerance))); } typedef RowNormTest RowNormTestD; TEST_P(RowNormTestD, Result) { - ASSERT_TRUE(raft::devArrMatch(dots_exp, dots_act, params.rows, + ASSERT_TRUE(raft::devArrMatch(dots_exp.data(), dots_act.data(), params.rows, raft::CompareApprox(params.tolerance))); } @@ -268,13 +261,13 @@ const std::vector> inputscd = { typedef ColNormTest ColNormTestF; TEST_P(ColNormTestF, Result) { - ASSERT_TRUE(raft::devArrMatch(dots_exp, dots_act, params.cols, + ASSERT_TRUE(raft::devArrMatch(dots_exp.data(), dots_act.data(), params.cols, raft::CompareApprox(params.tolerance))); } typedef ColNormTest ColNormTestD; TEST_P(ColNormTestD, Result) { - ASSERT_TRUE(raft::devArrMatch(dots_exp, dots_act, params.cols, + ASSERT_TRUE(raft::devArrMatch(dots_exp.data(), dots_act.data(), params.cols, raft::CompareApprox(params.tolerance))); } diff --git a/cpp/test/linalg/reduce.cu b/cpp/test/linalg/reduce.cu index 7ceeaf7f8e..304b4b9a68 100644 --- a/cpp/test/linalg/reduce.cu +++ b/cpp/test/linalg/reduce.cu @@ -54,43 +54,43 @@ void reduceLaunch(OutType *dots, const InType *data, int cols, int rows, template class ReduceTest : public ::testing::TestWithParam> { + public: + ReduceTest() + : params( + ::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + data(params.rows * params.cols, stream), + dots_exp(params.alongRows ? params.rows : params.cols, stream), + dots_act(params.alongRows ? params.rows : params.cols, stream) {} + protected: void SetUp() override { - CUDA_CHECK(cudaStreamCreate(&stream)); - params = - ::testing::TestWithParam>::GetParam(); raft::random::Rng r(params.seed); int rows = params.rows, cols = params.cols; int len = rows * cols; outlen = params.alongRows ? rows : cols; - raft::allocate(data, len, stream); - raft::allocate(dots_exp, outlen, stream); - raft::allocate(dots_act, outlen, stream); - r.uniform(data, len, InType(-1.0), InType(1.0), stream); - naiveReduction(dots_exp, data, cols, rows, params.rowMajor, + r.uniform(data.data(), len, InType(-1.0), InType(1.0), stream); + naiveReduction(dots_exp.data(), data.data(), cols, rows, params.rowMajor, params.alongRows, stream); // Perform reduction with default inplace = false first - reduceLaunch(dots_act, data, cols, rows, params.rowMajor, params.alongRows, - false, stream); + reduceLaunch(dots_act.data(), data.data(), cols, rows, params.rowMajor, + params.alongRows, false, stream); // Add to result with inplace = true next, which shouldn't affect // in the case of coalescedReduction! if (!(params.rowMajor ^ params.alongRows)) { - reduceLaunch(dots_act, data, cols, rows, params.rowMajor, + reduceLaunch(dots_act.data(), data.data(), cols, rows, params.rowMajor, params.alongRows, true, stream); } - } - - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); + CUDA_CHECK(cudaStreamSynchronize(stream)); } protected: ReduceInputs params; - InType *data; - OutType *dots_exp, *dots_act; + rmm::device_uvector data; + rmm::device_uvector dots_exp, dots_act; int outlen; + raft::handle_t handle; cudaStream_t stream; }; @@ -150,19 +150,19 @@ const std::vector> inputsfd = { typedef ReduceTest ReduceTestFF; TEST_P(ReduceTestFF, Result) { - ASSERT_TRUE(devArrMatch(dots_exp, dots_act, outlen, + ASSERT_TRUE(devArrMatch(dots_exp.data(), dots_act.data(), outlen, raft::CompareApprox(params.tolerance))); } typedef ReduceTest ReduceTestDD; TEST_P(ReduceTestDD, Result) { - ASSERT_TRUE(devArrMatch(dots_exp, dots_act, outlen, + ASSERT_TRUE(devArrMatch(dots_exp.data(), dots_act.data(), outlen, raft::CompareApprox(params.tolerance))); } typedef ReduceTest ReduceTestFD; TEST_P(ReduceTestFD, Result) { - ASSERT_TRUE(devArrMatch(dots_exp, dots_act, outlen, + ASSERT_TRUE(devArrMatch(dots_exp.data(), dots_act.data(), outlen, raft::CompareApprox(params.tolerance))); } diff --git a/cpp/test/linalg/strided_reduction.cu b/cpp/test/linalg/strided_reduction.cu index 55d8cc0e92..f0bf5410eb 100644 --- a/cpp/test/linalg/strided_reduction.cu +++ b/cpp/test/linalg/strided_reduction.cu @@ -41,32 +41,32 @@ void stridedReductionLaunch(T *dots, const T *data, int cols, int rows, template class stridedReductionTest : public ::testing::TestWithParam> { + public: + stridedReductionTest() + : params(::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + data(params.rows * params.cols, stream), + dots_exp(params.cols, stream), // expected dot products (from test) + dots_act(params.cols, stream) // actual dot products (from prim) + {} + protected: void SetUp() override { - CUDA_CHECK(cudaStreamCreate(&stream)); - params = ::testing::TestWithParam>::GetParam(); raft::random::Rng r(params.seed); int rows = params.rows, cols = params.cols; int len = rows * cols; - - raft::allocate(data, len, stream); - raft::allocate(dots_exp, cols, stream); //expected dot products (from test) - raft::allocate(dots_act, cols, stream); //actual dot products (from prim) - r.uniform(data, len, T(-1.0), T(1.0), + r.uniform(data.data(), len, T(-1.0), T(1.0), stream); //initialize matrix to random - unaryAndGemv(dots_exp, data, cols, rows, stream); - stridedReductionLaunch(dots_act, data, cols, rows, stream); - } - - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); + unaryAndGemv(dots_exp.data(), data.data(), cols, rows, stream); + stridedReductionLaunch(dots_act.data(), data.data(), cols, rows, stream); + CUDA_CHECK(cudaStreamSynchronize(stream)); } protected: stridedReductionInputs params; - T *data, *dots_exp, *dots_act; + rmm::device_uvector data, dots_exp, dots_act; + raft::handle_t handle; cudaStream_t stream; }; @@ -84,13 +84,13 @@ const std::vector> inputsd = { typedef stridedReductionTest stridedReductionTestF; TEST_P(stridedReductionTestF, Result) { - ASSERT_TRUE(devArrMatch(dots_exp, dots_act, params.cols, + ASSERT_TRUE(devArrMatch(dots_exp.data(), dots_act.data(), params.cols, raft::CompareApprox(params.tolerance))); } typedef stridedReductionTest stridedReductionTestD; TEST_P(stridedReductionTestD, Result) { - ASSERT_TRUE(devArrMatch(dots_exp, dots_act, params.cols, + ASSERT_TRUE(devArrMatch(dots_exp.data(), dots_act.data(), params.cols, raft::CompareApprox(params.tolerance))); } diff --git a/cpp/test/linalg/subtract.cu b/cpp/test/linalg/subtract.cu index 27dea8503f..945ce8bf88 100644 --- a/cpp/test/linalg/subtract.cu +++ b/cpp/test/linalg/subtract.cu @@ -74,37 +74,36 @@ template template class SubtractTest : public ::testing::TestWithParam> { + public: + SubtractTest() + : params(::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + in1(params.len, stream), + in2(params.len, stream), + out_ref(params.len, stream), + out(params.len, stream) {} + protected: void SetUp() override { - params = ::testing::TestWithParam>::GetParam(); raft::random::Rng r(params.seed); int len = params.len; - CUDA_CHECK(cudaStreamCreate(&stream)); - raft::allocate(in1, len, stream); - raft::allocate(in2, len, stream); - raft::allocate(out_ref, len, stream); - raft::allocate(out, len, stream); - r.uniform(in1, len, T(-1.0), T(1.0), stream); - r.uniform(in2, len, T(-1.0), T(1.0), stream); - - naiveSubtractElem(out_ref, in1, in2, len, stream); - naiveSubtractScalar(out_ref, out_ref, T(1), len, stream); - - subtract(out, in1, in2, len, stream); - subtractScalar(out, out, T(1), len, stream); - subtract(in1, in1, in2, len, stream); - subtractScalar(in1, in1, T(1), len, stream); - CUDA_CHECK(cudaStreamSynchronize(stream)); - } + r.uniform(in1.data(), len, T(-1.0), T(1.0), stream); + r.uniform(in2.data(), len, T(-1.0), T(1.0), stream); - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); + naiveSubtractElem(out_ref.data(), in1.data(), in2.data(), len, stream); + naiveSubtractScalar(out_ref.data(), out_ref.data(), T(1), len, stream); + + subtract(out.data(), in1.data(), in2.data(), len, stream); + subtractScalar(out.data(), out.data(), T(1), len, stream); + subtract(in1.data(), in1.data(), in2.data(), len, stream); + subtractScalar(in1.data(), in1.data(), T(1), len, stream); + CUDA_CHECK(cudaStreamSynchronize(stream)); } protected: SubtractInputs params; - T *in1, *in2, *out_ref, *out; + rmm::device_uvector in1, in2, out_ref, out; + raft::handle_t handle; cudaStream_t stream; }; @@ -116,19 +115,19 @@ const std::vector> inputsd2 = { typedef SubtractTest SubtractTestF; TEST_P(SubtractTestF, Result) { - ASSERT_TRUE(raft::devArrMatch(out_ref, out, params.len, + ASSERT_TRUE(raft::devArrMatch(out_ref.data(), out.data(), params.len, raft::CompareApprox(params.tolerance))); - ASSERT_TRUE(raft::devArrMatch(out_ref, in1, params.len, + ASSERT_TRUE(raft::devArrMatch(out_ref.data(), in1.data(), params.len, raft::CompareApprox(params.tolerance))); } typedef SubtractTest SubtractTestD; TEST_P(SubtractTestD, Result) { - ASSERT_TRUE(raft::devArrMatch(out_ref, out, params.len, + ASSERT_TRUE(raft::devArrMatch(out_ref.data(), out.data(), params.len, raft::CompareApprox(params.tolerance))); - ASSERT_TRUE(raft::devArrMatch(out_ref, in1, params.len, + ASSERT_TRUE(raft::devArrMatch(out_ref.data(), in1.data(), params.len, raft::CompareApprox(params.tolerance))); } diff --git a/cpp/test/linalg/svd.cu b/cpp/test/linalg/svd.cu index 72a27790de..3227bed603 100644 --- a/cpp/test/linalg/svd.cu +++ b/cpp/test/linalg/svd.cu @@ -41,32 +41,31 @@ template template class SvdTest : public ::testing::TestWithParam> { + public: + SvdTest() + : params(::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + data(params.len, stream), + left_eig_vectors_qr(params.n_row * params.n_col, stream), + right_eig_vectors_trans_qr(params.n_col * params.n_col, stream), + sing_vals_qr(params.n_col, stream), + left_eig_vectors_ref(params.n_row * params.n_col, stream), + right_eig_vectors_ref(params.n_col * params.n_col, stream), + sing_vals_ref(params.len, stream) {} + protected: void SetUp() override { - raft::handle_t handle; - - params = ::testing::TestWithParam>::GetParam(); raft::random::Rng r(params.seed); int len = params.len; - stream = handle.get_stream(); - raft::allocate(data, len, stream); ASSERT(params.n_row == 3, "This test only supports nrows=3!"); ASSERT(params.len == 6, "This test only supports len=6!"); T data_h[] = {1.0, 4.0, 2.0, 2.0, 5.0, 1.0}; - raft::update_device(data, data_h, len, stream); + raft::update_device(data.data(), data_h, len, stream); int left_evl = params.n_row * params.n_col; int right_evl = params.n_col * params.n_col; - raft::allocate(left_eig_vectors_qr, left_evl, stream); - raft::allocate(right_eig_vectors_trans_qr, right_evl, stream); - raft::allocate(sing_vals_qr, params.n_col, stream); - - // allocate(left_eig_vectors_jacobi, left_evl); - // allocate(right_eig_vectors_trans_jacobi, right_evl); - // allocate(sing_vals_jacobi, params.n_col); - T left_eig_vectors_ref_h[] = {-0.308219, -0.906133, -0.289695, 0.488195, 0.110706, -0.865685}; @@ -74,28 +73,24 @@ class SvdTest : public ::testing::TestWithParam> { T sing_vals_ref_h[] = {7.065283, 1.040081}; - raft::allocate(left_eig_vectors_ref, left_evl, stream); - raft::allocate(right_eig_vectors_ref, right_evl, stream); - raft::allocate(sing_vals_ref, params.n_col, stream); - - raft::update_device(left_eig_vectors_ref, left_eig_vectors_ref_h, left_evl, - stream); - raft::update_device(right_eig_vectors_ref, right_eig_vectors_ref_h, + raft::update_device(left_eig_vectors_ref.data(), left_eig_vectors_ref_h, + left_evl, stream); + raft::update_device(right_eig_vectors_ref.data(), right_eig_vectors_ref_h, right_evl, stream); - raft::update_device(sing_vals_ref, sing_vals_ref_h, params.n_col, stream); + raft::update_device(sing_vals_ref.data(), sing_vals_ref_h, params.n_col, + stream); - svdQR(handle, data, params.n_row, params.n_col, sing_vals_qr, - left_eig_vectors_qr, right_eig_vectors_trans_qr, true, true, true, - stream); + svdQR(handle, data.data(), params.n_row, params.n_col, sing_vals_qr.data(), + left_eig_vectors_qr.data(), right_eig_vectors_trans_qr.data(), true, + true, true, stream); CUDA_CHECK(cudaStreamSynchronize(stream)); } - void TearDown() override { raft::deallocate_all(stream); } - protected: SvdInputs params; - T *data, *left_eig_vectors_qr, *right_eig_vectors_trans_qr, *sing_vals_qr, - *left_eig_vectors_ref, *right_eig_vectors_ref, *sing_vals_ref; + rmm::device_uvector data, left_eig_vectors_qr, right_eig_vectors_trans_qr, + sing_vals_qr, left_eig_vectors_ref, right_eig_vectors_ref, sing_vals_ref; + raft::handle_t handle; cudaStream_t stream; }; @@ -108,45 +103,47 @@ const std::vector> inputsd2 = { typedef SvdTest SvdTestValF; TEST_P(SvdTestValF, Result) { ASSERT_TRUE( - raft::devArrMatch(sing_vals_ref, sing_vals_qr, params.n_col, + raft::devArrMatch(sing_vals_ref.data(), sing_vals_qr.data(), params.n_col, raft::CompareApproxAbs(params.tolerance))); } typedef SvdTest SvdTestValD; TEST_P(SvdTestValD, Result) { ASSERT_TRUE( - raft::devArrMatch(sing_vals_ref, sing_vals_qr, params.n_col, + raft::devArrMatch(sing_vals_ref.data(), sing_vals_qr.data(), params.n_col, raft::CompareApproxAbs(params.tolerance))); } typedef SvdTest SvdTestLeftVecF; TEST_P(SvdTestLeftVecF, Result) { - ASSERT_TRUE(raft::devArrMatch( - left_eig_vectors_ref, left_eig_vectors_qr, params.n_row * params.n_col, - raft::CompareApproxAbs(params.tolerance))); + ASSERT_TRUE( + raft::devArrMatch(left_eig_vectors_ref.data(), left_eig_vectors_qr.data(), + params.n_row * params.n_col, + raft::CompareApproxAbs(params.tolerance))); } typedef SvdTest SvdTestLeftVecD; TEST_P(SvdTestLeftVecD, Result) { - ASSERT_TRUE(raft::devArrMatch( - left_eig_vectors_ref, left_eig_vectors_qr, params.n_row * params.n_col, - raft::CompareApproxAbs(params.tolerance))); + ASSERT_TRUE( + raft::devArrMatch(left_eig_vectors_ref.data(), left_eig_vectors_qr.data(), + params.n_row * params.n_col, + raft::CompareApproxAbs(params.tolerance))); } typedef SvdTest SvdTestRightVecF; TEST_P(SvdTestRightVecF, Result) { - ASSERT_TRUE( - raft::devArrMatch(right_eig_vectors_ref, right_eig_vectors_trans_qr, - params.n_col * params.n_col, - raft::CompareApproxAbs(params.tolerance))); + ASSERT_TRUE(raft::devArrMatch( + right_eig_vectors_ref.data(), right_eig_vectors_trans_qr.data(), + params.n_col * params.n_col, + raft::CompareApproxAbs(params.tolerance))); } typedef SvdTest SvdTestRightVecD; TEST_P(SvdTestRightVecD, Result) { - ASSERT_TRUE( - raft::devArrMatch(right_eig_vectors_ref, right_eig_vectors_trans_qr, - params.n_col * params.n_col, - raft::CompareApproxAbs(params.tolerance))); + ASSERT_TRUE(raft::devArrMatch( + right_eig_vectors_ref.data(), right_eig_vectors_trans_qr.data(), + params.n_col * params.n_col, + raft::CompareApproxAbs(params.tolerance))); } INSTANTIATE_TEST_SUITE_P(SvdTests, SvdTestValF, ::testing::ValuesIn(inputsf2)); diff --git a/cpp/test/linalg/transpose.cu b/cpp/test/linalg/transpose.cu index c574f54a05..5158891362 100644 --- a/cpp/test/linalg/transpose.cu +++ b/cpp/test/linalg/transpose.cu @@ -40,34 +40,32 @@ template template class TransposeTest : public ::testing::TestWithParam> { + public: + TransposeTest() + : params(::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + data(params.len, stream), + data_trans_ref(params.len, stream), + data_trans(params.len, stream) {} + protected: void SetUp() override { - params = ::testing::TestWithParam>::GetParam(); - - stream = handle.get_stream(); - int len = params.len; - - raft::allocate(data, len, stream); ASSERT(params.len == 9, "This test works only with len=9!"); T data_h[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; - raft::update_device(data, data_h, len, stream); - - raft::allocate(data_trans_ref, len, stream); + raft::update_device(data.data(), data_h, len, stream); T data_ref_h[] = {1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0}; - raft::update_device(data_trans_ref, data_ref_h, len, stream); - - raft::allocate(data_trans, len, stream); + raft::update_device(data_trans_ref.data(), data_ref_h, len, stream); - transpose(handle, data, data_trans, params.n_row, params.n_col, stream); - transpose(data, params.n_row, stream); + transpose(handle, data.data(), data_trans.data(), params.n_row, + params.n_col, stream); + transpose(data.data(), params.n_row, stream); + CUDA_CHECK(cudaStreamSynchronize(stream)); } - void TearDown() override { raft::deallocate_all(stream); } - protected: TranposeInputs params; - T *data, *data_trans, *data_trans_ref; + rmm::device_uvector data, data_trans, data_trans_ref; raft::handle_t handle; cudaStream_t stream; }; @@ -81,22 +79,22 @@ const std::vector> inputsd2 = { typedef TransposeTest TransposeTestValF; TEST_P(TransposeTestValF, Result) { ASSERT_TRUE( - raft::devArrMatch(data_trans_ref, data_trans, params.len, + raft::devArrMatch(data_trans_ref.data(), data_trans.data(), params.len, raft::CompareApproxAbs(params.tolerance))); ASSERT_TRUE( - raft::devArrMatch(data_trans_ref, data, params.len, + raft::devArrMatch(data_trans_ref.data(), data.data(), params.len, raft::CompareApproxAbs(params.tolerance))); } typedef TransposeTest TransposeTestValD; TEST_P(TransposeTestValD, Result) { ASSERT_TRUE( - raft::devArrMatch(data_trans_ref, data_trans, params.len, + raft::devArrMatch(data_trans_ref.data(), data_trans.data(), params.len, raft::CompareApproxAbs(params.tolerance))); ASSERT_TRUE( - raft::devArrMatch(data_trans_ref, data, params.len, + raft::devArrMatch(data_trans_ref.data(), data.data(), params.len, raft::CompareApproxAbs(params.tolerance))); } diff --git a/cpp/test/linalg/unary_op.cu b/cpp/test/linalg/unary_op.cu index 042e8b9cbf..22f610b935 100644 --- a/cpp/test/linalg/unary_op.cu +++ b/cpp/test/linalg/unary_op.cu @@ -46,37 +46,38 @@ void unaryOpLaunch(OutType *out, const InType *in, InType scalar, IdxType len, template class UnaryOpTest : public ::testing::TestWithParam> { + public: + UnaryOpTest() + : params(::testing::TestWithParam< + UnaryOpInputs>::GetParam()), + stream(handle.get_stream()), + in(params.len, stream), + out_ref(params.len, stream), + out(params.len, stream) {} + protected: void SetUp() override { - params = ::testing::TestWithParam< - UnaryOpInputs>::GetParam(); raft::random::Rng r(params.seed); - CUDA_CHECK(cudaStreamCreate(&stream)); auto len = params.len; - raft::allocate(in, len, stream); - raft::allocate(out_ref, len, stream); - raft::allocate(out, len, stream); - r.uniform(in, len, InType(-1.0), InType(1.0), stream); - } - - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); + r.uniform(in.data(), len, InType(-1.0), InType(1.0), stream); + CUDA_CHECK(cudaStreamSynchronize(stream)); } virtual void DoTest() { auto len = params.len; auto scalar = params.scalar; - naiveScale(out_ref, in, scalar, len, stream); - unaryOpLaunch(out, in, scalar, len, stream); + naiveScale(out_ref.data(), in.data(), scalar, len, stream); + unaryOpLaunch(out.data(), in.data(), scalar, len, stream); CUDA_CHECK(cudaStreamSynchronize(stream)); - ASSERT_TRUE(devArrMatch(out_ref, out, params.len, + ASSERT_TRUE(devArrMatch(out_ref.data(), out.data(), params.len, CompareApprox(params.tolerance))); } + protected: UnaryOpInputs params; - InType *in; - OutType *out_ref, *out; + rmm::device_uvector in; + rmm::device_uvector out_ref, out; + raft::handle_t handle; cudaStream_t stream; }; @@ -86,10 +87,13 @@ class WriteOnlyUnaryOpTest : public UnaryOpTest { void DoTest() override { auto len = this->params.len; auto scalar = this->params.scalar; - naiveScale(this->out_ref, (OutType *)nullptr, scalar, len, this->stream); - unaryOpLaunch(this->out, (OutType *)nullptr, scalar, len, this->stream); + naiveScale(this->out_ref.data(), (OutType *)nullptr, scalar, len, + this->stream); + unaryOpLaunch(this->out.data(), (OutType *)nullptr, scalar, len, + this->stream); CUDA_CHECK(cudaStreamSynchronize(this->stream)); - ASSERT_TRUE(devArrMatch(this->out_ref, this->out, this->params.len, + ASSERT_TRUE(devArrMatch(this->out_ref.data(), this->out.data(), + this->params.len, CompareApprox(this->params.tolerance))); } }; diff --git a/cpp/test/matrix/math.cu b/cpp/test/matrix/math.cu index 63381dec07..81d7f76344 100644 --- a/cpp/test/matrix/math.cu +++ b/cpp/test/matrix/math.cu @@ -109,80 +109,82 @@ template template class MathTest : public ::testing::TestWithParam> { + public: + MathTest() + : params(::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + in_power(params.len, stream), + out_power_ref(params.len, stream), + in_sqrt(params.len, stream), + out_sqrt_ref(params.len, stream), + in_sign_flip(params.len, stream), + out_sign_flip_ref(params.len, stream), + in_ratio(4, stream), + out_ratio_ref(4, stream), + in_recip(4, stream), + in_recip_ref(4, stream), + out_recip(4, stream), + in_smallzero(4, stream), + out_smallzero(4, stream), + out_smallzero_ref(4, stream) {} + protected: void SetUp() override { - params = ::testing::TestWithParam>::GetParam(); random::Rng r(params.seed); int len = params.len; - - raft::handle_t handle; - stream = handle.get_stream(); - CUDA_CHECK(cudaStreamCreate(&stream)); - - raft::allocate(in_power, len, stream); - raft::allocate(out_power_ref, len, stream); - raft::allocate(in_sqrt, len, stream); - raft::allocate(out_sqrt_ref, len, stream); - raft::allocate(in_sign_flip, len, stream); - raft::allocate(out_sign_flip_ref, len, stream); - - raft::allocate(in_ratio, 4, stream); T in_ratio_h[4] = {1.0, 2.0, 2.0, 3.0}; - update_device(in_ratio, in_ratio_h, 4, stream); + update_device(in_ratio.data(), in_ratio_h, 4, stream); - raft::allocate(out_ratio_ref, 4, stream); T out_ratio_ref_h[4] = {0.125, 0.25, 0.25, 0.375}; - update_device(out_ratio_ref, out_ratio_ref_h, 4, stream); + update_device(out_ratio_ref.data(), out_ratio_ref_h, 4, stream); - r.uniform(in_power, len, T(-1.0), T(1.0), stream); - r.uniform(in_sqrt, len, T(0.0), T(1.0), stream); + r.uniform(in_power.data(), len, T(-1.0), T(1.0), stream); + r.uniform(in_sqrt.data(), len, T(0.0), T(1.0), stream); // r.uniform(in_ratio, len, T(0.0), T(1.0)); - r.uniform(in_sign_flip, len, T(-100.0), T(100.0), stream); + r.uniform(in_sign_flip.data(), len, T(-100.0), T(100.0), stream); - naivePower(in_power, out_power_ref, len, stream); - power(in_power, len, stream); + naivePower(in_power.data(), out_power_ref.data(), len, stream); + power(in_power.data(), len, stream); - naiveSqrt(in_sqrt, out_sqrt_ref, len); - seqRoot(in_sqrt, len, stream); + naiveSqrt(in_sqrt.data(), out_sqrt_ref.data(), len); + seqRoot(in_sqrt.data(), len, stream); - ratio(handle, in_ratio, in_ratio, 4, stream); + ratio(handle, in_ratio.data(), in_ratio.data(), 4, stream); - naiveSignFlip(in_sign_flip, out_sign_flip_ref, params.n_row, params.n_col); - signFlip(in_sign_flip, params.n_row, params.n_col, stream); + naiveSignFlip(in_sign_flip.data(), out_sign_flip_ref.data(), params.n_row, + params.n_col); + signFlip(in_sign_flip.data(), params.n_row, params.n_col, stream); - raft::allocate(in_recip, 4, stream); - raft::allocate(in_recip_ref, 4, stream); - raft::allocate(out_recip, 4, stream); // default threshold is 1e-15 std::vector in_recip_h = {0.1, 0.01, -0.01, 0.1e-16}; std::vector in_recip_ref_h = {10.0, 100.0, -100.0, 0.0}; - update_device(in_recip, in_recip_h.data(), 4, stream); - update_device(in_recip_ref, in_recip_ref_h.data(), 4, stream); + update_device(in_recip.data(), in_recip_h.data(), 4, stream); + update_device(in_recip_ref.data(), in_recip_ref_h.data(), 4, stream); T recip_scalar = T(1.0); // this `reciprocal()` has to go first bc next one modifies its input - reciprocal(in_recip, out_recip, recip_scalar, 4, stream); + reciprocal(in_recip.data(), out_recip.data(), recip_scalar, 4, stream); - reciprocal(in_recip, recip_scalar, 4, stream, true); + reciprocal(in_recip.data(), recip_scalar, 4, stream, true); std::vector in_small_val_zero_h = {0.1, 1e-16, -1e-16, -0.1}; std::vector in_small_val_zero_ref_h = {0.1, 0.0, 0.0, -0.1}; - raft::allocate(in_smallzero, 4, stream); - raft::allocate(out_smallzero, 4, stream); - raft::allocate(out_smallzero_ref, 4, stream); - update_device(in_smallzero, in_small_val_zero_h.data(), 4, stream); - update_device(out_smallzero_ref, in_small_val_zero_ref_h.data(), 4, stream); - setSmallValuesZero(out_smallzero, in_smallzero, 4, stream); - setSmallValuesZero(in_smallzero, 4, stream); - } - void TearDown() override { raft::deallocate_all(stream); } + update_device(in_smallzero.data(), in_small_val_zero_h.data(), 4, stream); + update_device(out_smallzero_ref.data(), in_small_val_zero_ref_h.data(), 4, + stream); + setSmallValuesZero(out_smallzero.data(), in_smallzero.data(), 4, stream); + setSmallValuesZero(in_smallzero.data(), 4, stream); + CUDA_CHECK(cudaStreamSynchronize(stream)); + } protected: MathInputs params; - T *in_power, *out_power_ref, *in_sqrt, *out_sqrt_ref, *in_ratio, - *out_ratio_ref, *in_sign_flip, *out_sign_flip_ref, *in_recip, *in_recip_ref, - *out_recip, *in_smallzero, *out_smallzero, *out_smallzero_ref; + rmm::device_uvector in_power, out_power_ref, in_sqrt, out_sqrt_ref, + in_ratio, out_ratio_ref, in_sign_flip, out_sign_flip_ref, in_recip, + in_recip_ref, out_recip, in_smallzero, out_smallzero, out_smallzero_ref; + + raft::handle_t handle; cudaStream_t stream; }; @@ -194,87 +196,87 @@ const std::vector> inputsd = { typedef MathTest MathPowerTestF; TEST_P(MathPowerTestF, Result) { - ASSERT_TRUE(devArrMatch(in_power, out_power_ref, params.len, + ASSERT_TRUE(devArrMatch(in_power.data(), out_power_ref.data(), params.len, CompareApprox(params.tolerance))); } typedef MathTest MathPowerTestD; TEST_P(MathPowerTestD, Result) { - ASSERT_TRUE(devArrMatch(in_power, out_power_ref, params.len, + ASSERT_TRUE(devArrMatch(in_power.data(), out_power_ref.data(), params.len, CompareApprox(params.tolerance))); } typedef MathTest MathSqrtTestF; TEST_P(MathSqrtTestF, Result) { - ASSERT_TRUE(devArrMatch(in_sqrt, out_sqrt_ref, params.len, + ASSERT_TRUE(devArrMatch(in_sqrt.data(), out_sqrt_ref.data(), params.len, CompareApprox(params.tolerance))); } typedef MathTest MathSqrtTestD; TEST_P(MathSqrtTestD, Result) { - ASSERT_TRUE(devArrMatch(in_sqrt, out_sqrt_ref, params.len, + ASSERT_TRUE(devArrMatch(in_sqrt.data(), out_sqrt_ref.data(), params.len, CompareApprox(params.tolerance))); } typedef MathTest MathRatioTestF; TEST_P(MathRatioTestF, Result) { - ASSERT_TRUE(devArrMatch(in_ratio, out_ratio_ref, 4, + ASSERT_TRUE(devArrMatch(in_ratio.data(), out_ratio_ref.data(), 4, CompareApprox(params.tolerance))); } typedef MathTest MathRatioTestD; TEST_P(MathRatioTestD, Result) { - ASSERT_TRUE(devArrMatch(in_ratio, out_ratio_ref, 4, + ASSERT_TRUE(devArrMatch(in_ratio.data(), out_ratio_ref.data(), 4, CompareApprox(params.tolerance))); } typedef MathTest MathSignFlipTestF; TEST_P(MathSignFlipTestF, Result) { - ASSERT_TRUE(devArrMatch(in_sign_flip, out_sign_flip_ref, params.len, - CompareApprox(params.tolerance))); + ASSERT_TRUE(devArrMatch(in_sign_flip.data(), out_sign_flip_ref.data(), + params.len, CompareApprox(params.tolerance))); } typedef MathTest MathSignFlipTestD; TEST_P(MathSignFlipTestD, Result) { - ASSERT_TRUE(devArrMatch(in_sign_flip, out_sign_flip_ref, params.len, - CompareApprox(params.tolerance))); + ASSERT_TRUE(devArrMatch(in_sign_flip.data(), out_sign_flip_ref.data(), + params.len, CompareApprox(params.tolerance))); } typedef MathTest MathReciprocalTestF; TEST_P(MathReciprocalTestF, Result) { - ASSERT_TRUE(devArrMatch(in_recip, in_recip_ref, 4, + ASSERT_TRUE(devArrMatch(in_recip.data(), in_recip_ref.data(), 4, CompareApprox(params.tolerance))); // 4-th term tests `setzero=true` functionality, not present in this version of `reciprocal`. - ASSERT_TRUE(devArrMatch(out_recip, in_recip_ref, 3, + ASSERT_TRUE(devArrMatch(out_recip.data(), in_recip_ref.data(), 3, CompareApprox(params.tolerance))); } typedef MathTest MathReciprocalTestD; TEST_P(MathReciprocalTestD, Result) { - ASSERT_TRUE(devArrMatch(in_recip, in_recip_ref, 4, + ASSERT_TRUE(devArrMatch(in_recip.data(), in_recip_ref.data(), 4, CompareApprox(params.tolerance))); // 4-th term tests `setzero=true` functionality, not present in this version of `reciprocal`. - ASSERT_TRUE(devArrMatch(out_recip, in_recip_ref, 3, + ASSERT_TRUE(devArrMatch(out_recip.data(), in_recip_ref.data(), 3, CompareApprox(params.tolerance))); } typedef MathTest MathSetSmallZeroTestF; TEST_P(MathSetSmallZeroTestF, Result) { - ASSERT_TRUE(devArrMatch(in_smallzero, out_smallzero_ref, 4, + ASSERT_TRUE(devArrMatch(in_smallzero.data(), out_smallzero_ref.data(), 4, CompareApprox(params.tolerance))); - ASSERT_TRUE(devArrMatch(out_smallzero, out_smallzero_ref, 4, + ASSERT_TRUE(devArrMatch(out_smallzero.data(), out_smallzero_ref.data(), 4, CompareApprox(params.tolerance))); } typedef MathTest MathSetSmallZeroTestD; TEST_P(MathSetSmallZeroTestD, Result) { - ASSERT_TRUE(devArrMatch(in_smallzero, out_smallzero_ref, 4, + ASSERT_TRUE(devArrMatch(in_smallzero.data(), out_smallzero_ref.data(), 4, CompareApprox(params.tolerance))); - ASSERT_TRUE(devArrMatch(out_smallzero, out_smallzero_ref, 4, + ASSERT_TRUE(devArrMatch(out_smallzero.data(), out_smallzero_ref.data(), 4, CompareApprox(params.tolerance))); } diff --git a/cpp/test/matrix/matrix.cu b/cpp/test/matrix/matrix.cu index cc88df0a73..3f8803a471 100644 --- a/cpp/test/matrix/matrix.cu +++ b/cpp/test/matrix/matrix.cu @@ -39,35 +39,33 @@ template template class MatrixTest : public ::testing::TestWithParam> { + public: + MatrixTest() + : params(::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + in1(params.n_row * params.n_col, stream), + in2(params.n_row * params.n_col, stream), + in1_revr(params.n_row * params.n_col, stream) {} + protected: void SetUp() override { - params = ::testing::TestWithParam>::GetParam(); raft::random::Rng r(params.seed); int len = params.n_row * params.n_col; - CUDA_CHECK(cudaStreamCreate(&stream)); - raft::allocate(in1, len, stream); - raft::allocate(in2, len, stream); - raft::allocate(in1_revr, len, stream); - r.uniform(in1, len, T(-1.0), T(1.0), stream); + r.uniform(in1.data(), len, T(-1.0), T(1.0), stream); - copy(in1, in2, params.n_row, params.n_col, stream); + copy(in1.data(), in2.data(), params.n_row, params.n_col, stream); // copy(in1, in1_revr, params.n_row, params.n_col); // colReverse(in1_revr, params.n_row, params.n_col); - T *outTrunc; - raft::allocate(outTrunc, 6, stream); - truncZeroOrigin(in1, params.n_row, outTrunc, 3, 2, stream); + rmm::device_uvector outTrunc(6, stream); + truncZeroOrigin(in1.data(), params.n_row, outTrunc.data(), 3, 2, stream); CUDA_CHECK(cudaStreamSynchronize(stream)); } - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); - } - protected: MatrixInputs params; - T *in1, *in2, *in1_revr; + rmm::device_uvector in1, in2, in1_revr; + raft::handle_t handle; cudaStream_t stream; }; @@ -78,13 +76,15 @@ const std::vector> inputsd2 = { typedef MatrixTest MatrixTestF; TEST_P(MatrixTestF, Result) { - ASSERT_TRUE(raft::devArrMatch(in1, in2, params.n_row * params.n_col, + ASSERT_TRUE(raft::devArrMatch(in1.data(), in2.data(), + params.n_row * params.n_col, raft::CompareApprox(params.tolerance))); } typedef MatrixTest MatrixTestD; TEST_P(MatrixTestD, Result) { - ASSERT_TRUE(raft::devArrMatch(in1, in2, params.n_row * params.n_col, + ASSERT_TRUE(raft::devArrMatch(in1.data(), in2.data(), + params.n_row * params.n_col, raft::CompareApprox(params.tolerance))); } diff --git a/cpp/test/random/rng.cu b/cpp/test/random/rng.cu index c2ec7a340f..511effbb93 100644 --- a/cpp/test/random/rng.cu +++ b/cpp/test/random/rng.cu @@ -79,58 +79,56 @@ template template class RngTest : public ::testing::TestWithParam> { + public: + RngTest() + : params(::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + data(params.len, stream), + stats(2, stream) {} + protected: void SetUp() override { // Tests are configured with their expected test-values sigma. For example, // 4 x sigma indicates the test shouldn't fail 99.9% of the time. num_sigma = 10; - params = ::testing::TestWithParam>::GetParam(); - CUDA_CHECK(cudaStreamCreate(&stream)); Rng r(params.seed, params.gtype); - raft::allocate(data, params.len, stream); - raft::allocate(stats, 2, stream, true); switch (params.type) { case RNG_Normal: - r.normal(data, params.len, params.start, params.end, stream); + r.normal(data.data(), params.len, params.start, params.end, stream); break; case RNG_LogNormal: - r.lognormal(data, params.len, params.start, params.end, stream); + r.lognormal(data.data(), params.len, params.start, params.end, stream); break; case RNG_Uniform: - r.uniform(data, params.len, params.start, params.end, stream); + r.uniform(data.data(), params.len, params.start, params.end, stream); break; case RNG_Gumbel: - r.gumbel(data, params.len, params.start, params.end, stream); + r.gumbel(data.data(), params.len, params.start, params.end, stream); break; case RNG_Logistic: - r.logistic(data, params.len, params.start, params.end, stream); + r.logistic(data.data(), params.len, params.start, params.end, stream); break; case RNG_Exp: - r.exponential(data, params.len, params.start, stream); + r.exponential(data.data(), params.len, params.start, stream); break; case RNG_Rayleigh: - r.rayleigh(data, params.len, params.start, stream); + r.rayleigh(data.data(), params.len, params.start, stream); break; case RNG_Laplace: - r.laplace(data, params.len, params.start, params.end, stream); + r.laplace(data.data(), params.len, params.start, params.end, stream); break; }; static const int threads = 128; meanKernel - <<>>(stats, data, - params.len); - update_host(h_stats, stats, 2, stream); + <<>>( + stats.data(), data.data(), params.len); + update_host(h_stats, stats.data(), 2, stream); CUDA_CHECK(cudaStreamSynchronize(stream)); h_stats[0] /= params.len; h_stats[1] = (h_stats[1] / params.len) - (h_stats[0] * h_stats[0]); CUDA_CHECK(cudaStreamSynchronize(stream)); } - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); - } - void getExpectedMeanVar(T meanvar[2]) { switch (params.type) { case RNG_Normal: @@ -178,9 +176,11 @@ class RngTest : public ::testing::TestWithParam> { protected: RngInputs params; - T *data, *stats; + rmm::device_uvector data, stats; T h_stats[2]; // mean, var int num_sigma; + + raft::handle_t handle; cudaStream_t stream; }; @@ -375,30 +375,29 @@ TEST(Rng, MeanError) { int seed = time_struct.millitm; int num_samples = 1024; int num_experiments = 1024; - float* data; - float* mean_result; - float* std_result; int len = num_samples * num_experiments; cudaStream_t stream; CUDA_CHECK(cudaStreamCreate(&stream)); - raft::allocate(data, len, stream); - raft::allocate(mean_result, num_experiments, stream); - raft::allocate(std_result, num_experiments, stream); + rmm::device_uvector data(len, stream); + rmm::device_uvector mean_result(num_experiments, stream); + rmm::device_uvector std_result(num_experiments, stream); for (auto rtype : {GenPhilox, GenKiss99 /*, raft::random::GenTaps */}) { Rng r(seed, rtype); - r.normal(data, len, 3.3f, 0.23f, stream); + r.normal(data.data(), len, 3.3f, 0.23f, stream); // r.uniform(data, len, -1.0, 2.0); - raft::stats::mean(mean_result, data, num_samples, num_experiments, false, - false, stream); - raft::stats::stddev(std_result, data, mean_result, num_samples, - num_experiments, false, false, stream); + raft::stats::mean(mean_result.data(), data.data(), num_samples, + num_experiments, false, false, stream); + raft::stats::stddev(std_result.data(), data.data(), mean_result.data(), + num_samples, num_experiments, false, false, stream); std::vector h_mean_result(num_experiments); std::vector h_std_result(num_experiments); - update_host(h_mean_result.data(), mean_result, num_experiments, stream); - update_host(h_std_result.data(), std_result, num_experiments, stream); + update_host(h_mean_result.data(), mean_result.data(), num_experiments, + stream); + update_host(h_std_result.data(), std_result.data(), num_experiments, + stream); CUDA_CHECK(cudaStreamSynchronize(stream)); auto d_mean = quick_mean(h_mean_result); @@ -416,7 +415,6 @@ TEST(Rng, MeanError) { ASSERT_TRUE( (diff_expected_vs_measured_mean_error / d_std_of_mean_analytical < 0.5)); } - raft::deallocate_all(stream); CUDA_CHECK(cudaStreamDestroy(stream)); // std::cout << "mean_res:" << h_mean_result << "\n"; @@ -424,28 +422,28 @@ TEST(Rng, MeanError) { template class ScaledBernoulliTest : public ::testing::Test { + public: + ScaledBernoulliTest() : stream(handle.get_stream()), data(len, stream) {} + protected: void SetUp() override { CUDA_CHECK(cudaStreamCreate(&stream)); - Rng r(42); - - raft::allocate(data, len * sizeof(T), stream); - r.scaled_bernoulli(data, len, T(0.5), T(scale), stream); + r.scaled_bernoulli(data.data(), len, T(0.5), T(scale), stream); } - void TearDown() override { CUDA_CHECK(cudaFree(data)); } - void rangeCheck() { T* h_data = new T[len]; - update_host(h_data, data, len, stream); + update_host(h_data, data.data(), len, stream); ASSERT_TRUE(std::none_of(h_data, h_data + len, [](const T& a) { return a < -scale || a > scale; })); delete[] h_data; } - T* data; + rmm::device_uvector data; + + raft::handle_t handle; cudaStream_t stream; }; @@ -457,26 +455,28 @@ TEST_F(ScaledBernoulliTest2, RangeCheck) { rangeCheck(); } template class BernoulliTest : public ::testing::Test { + public: + BernoulliTest() : stream(handle.get_stream()), data(len, stream) {} + protected: void SetUp() override { - CUDA_CHECK(cudaStreamCreate(&stream)); Rng r(42); - raft::allocate(data, len * sizeof(bool), stream); - r.bernoulli(data, len, T(0.5), stream); + r.bernoulli(data.data(), len, T(0.5), stream); + CUDA_CHECK(cudaStreamSynchronize(stream)); } - void TearDown() override { CUDA_CHECK(cudaFree(data)); } - void trueFalseCheck() { // both true and false values must be present bool* h_data = new bool[len]; - update_host(h_data, data, len, stream); + update_host(h_data, data.data(), len, stream); ASSERT_TRUE(std::any_of(h_data, h_data + len, [](bool a) { return a; })); ASSERT_TRUE(std::any_of(h_data, h_data + len, [](bool a) { return !a; })); delete[] h_data; } - bool* data; + rmm::device_uvector data; + + raft::handle_t handle; cudaStream_t stream; }; @@ -505,38 +505,35 @@ template template class RngNormalTableTest : public ::testing::TestWithParam> { + public: + RngNormalTableTest() + : params(::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + data(params.rows * params.cols, stream), + stats(2, stream), + mu_vec(params.cols, stream) {} + protected: void SetUp() override { // Tests are configured with their expected test-values sigma. For example, // 4 x sigma indicates the test shouldn't fail 99.9% of the time. num_sigma = 10; - params = ::testing::TestWithParam>::GetParam(); int len = params.rows * params.cols; - - CUDA_CHECK(cudaStreamCreate(&stream)); Rng r(params.seed, params.gtype); - raft::allocate(data, len, stream); - raft::allocate(stats, 2, stream, true); - raft::allocate(mu_vec, params.cols, stream); - r.fill(mu_vec, params.cols, params.mu, stream); + r.fill(mu_vec.data(), params.cols, params.mu, stream); T* sigma_vec = nullptr; - r.normalTable(data, params.rows, params.cols, mu_vec, sigma_vec, - params.sigma, stream); + r.normalTable(data.data(), params.rows, params.cols, mu_vec.data(), + sigma_vec, params.sigma, stream); static const int threads = 128; - meanKernel - <<>>(stats, data, len); - update_host(h_stats, stats, 2, stream); + meanKernel<<>>( + stats.data(), data.data(), len); + update_host(h_stats, stats.data(), 2, stream); CUDA_CHECK(cudaStreamSynchronize(stream)); h_stats[0] /= len; h_stats[1] = (h_stats[1] / len) - (h_stats[0] * h_stats[0]); CUDA_CHECK(cudaStreamSynchronize(stream)); } - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); - } - void getExpectedMeanVar(T meanvar[2]) { meanvar[0] = params.mu; meanvar[1] = params.sigma * params.sigma; @@ -544,9 +541,11 @@ class RngNormalTableTest protected: RngNormalTableInputs params; - T *data, *stats, *mu_vec; + rmm::device_uvector data, stats, mu_vec; T h_stats[2]; // mean, var int num_sigma; + + raft::handle_t handle; cudaStream_t stream; }; diff --git a/cpp/test/random/rng_int.cu b/cpp/test/random/rng_int.cu index a98619e5b4..8bf5aaac77 100644 --- a/cpp/test/random/rng_int.cu +++ b/cpp/test/random/rng_int.cu @@ -65,35 +65,33 @@ template template class RngTest : public ::testing::TestWithParam> { + public: + RngTest() + : params(::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + data(params.len, stream), + stats(2, stream) {} + protected: void SetUp() override { - params = ::testing::TestWithParam>::GetParam(); Rng r(params.seed, params.gtype); - CUDA_CHECK(cudaStreamCreate(&stream)); - raft::allocate(data, params.len, stream); - raft::allocate(stats, 2, stream, true); switch (params.type) { case RNG_Uniform: - r.uniformInt(data, params.len, params.start, params.end, stream); + r.uniformInt(data.data(), params.len, params.start, params.end, stream); break; }; static const int threads = 128; meanKernel - <<>>(stats, data, - params.len); - update_host(h_stats, stats, 2, stream); + <<>>( + stats.data(), data.data(), params.len); + update_host(h_stats, stats.data(), 2, stream); CUDA_CHECK(cudaStreamSynchronize(stream)); h_stats[0] /= params.len; h_stats[1] = (h_stats[1] / params.len) - (h_stats[0] * h_stats[0]); CUDA_CHECK(cudaStreamSynchronize(stream)); } - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); - } - void getExpectedMeanVar(float meanvar[2]) { switch (params.type) { case RNG_Uniform: @@ -106,9 +104,11 @@ class RngTest : public ::testing::TestWithParam> { protected: RngInputs params; - T *data; - float *stats; + rmm::device_uvector data; + rmm::device_uvector stats; float h_stats[2]; // mean, var + + raft::handle_t handle; cudaStream_t stream; }; diff --git a/cpp/test/random/sample_without_replacement.cu b/cpp/test/random/sample_without_replacement.cu index cf60f46afe..22f524c5ed 100644 --- a/cpp/test/random/sample_without_replacement.cu +++ b/cpp/test/random/sample_without_replacement.cu @@ -44,40 +44,40 @@ template template class SWoRTest : public ::testing::TestWithParam> { + public: + SWoRTest() + : params(::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + in(params.len, stream), + wts(params.len, stream), + out(params.sampledLen, stream), + outIdx(params.sampledLen, stream) {} + protected: void SetUp() override { - params = ::testing::TestWithParam>::GetParam(); - CUDA_CHECK(cudaStreamCreate(&stream)); - Rng r(params.seed, params.gtype); - raft::allocate(in, params.len, stream); - raft::allocate(wts, params.len, stream); - raft::allocate(out, params.sampledLen, stream); - raft::allocate(outIdx, params.sampledLen, stream); h_outIdx.resize(params.sampledLen); - r.uniform(in, params.len, T(-1.0), T(1.0), stream); - r.uniform(wts, params.len, T(1.0), T(2.0), stream); + r.uniform(in.data(), params.len, T(-1.0), T(1.0), stream); + r.uniform(wts.data(), params.len, T(1.0), T(2.0), stream); if (params.largeWeightIndex >= 0) { - update_device(wts + params.largeWeightIndex, ¶ms.largeWeight, 1, - stream); + update_device(wts.data() + params.largeWeightIndex, ¶ms.largeWeight, + 1, stream); } - r.sampleWithoutReplacement(handle, out, outIdx, in, wts, params.sampledLen, - params.len, stream); - update_host(&(h_outIdx[0]), outIdx, params.sampledLen, stream); - } - - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); + r.sampleWithoutReplacement(handle, out.data(), outIdx.data(), in.data(), + wts.data(), params.sampledLen, params.len, + stream); + update_host(&(h_outIdx[0]), outIdx.data(), params.sampledLen, stream); + CUDA_CHECK(cudaStreamSynchronize(stream)); } protected: SWoRInputs params; - T *in, *out, *wts; - int* outIdx; + rmm::device_uvector in, out, wts; + rmm::device_uvector outIdx; std::vector h_outIdx; - cudaStream_t stream; + raft::handle_t handle; + cudaStream_t stream; }; typedef SWoRTest SWoRTestF; diff --git a/cpp/test/sparse/add.cu b/cpp/test/sparse/add.cu index 8429a46941..64519f5078 100644 --- a/cpp/test/sparse/add.cu +++ b/cpp/test/sparse/add.cu @@ -46,81 +46,86 @@ struct CSRAddInputs { template class CSRAddTest : public ::testing::TestWithParam> { + public: + CSRAddTest() + : params( + ::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + ind_a(params.matrix_a.row_ind.size(), stream), + ind_ptr_a(params.matrix_a.row_ind_ptr.size(), stream), + values_a(params.matrix_a.row_ind_ptr.size(), stream), + ind_b(params.matrix_a.row_ind.size(), stream), + ind_ptr_b(params.matrix_b.row_ind_ptr.size(), stream), + values_b(params.matrix_b.row_ind_ptr.size(), stream), + ind_verify(params.matrix_a.row_ind.size(), stream), + ind_ptr_verify(params.matrix_verify.row_ind_ptr.size(), stream), + values_verify(params.matrix_verify.row_ind_ptr.size(), stream), + ind_result(params.matrix_a.row_ind.size(), stream), + ind_ptr_result(params.matrix_verify.row_ind_ptr.size(), stream), + values_result(params.matrix_verify.row_ind_ptr.size(), stream) {} + protected: void SetUp() override { - params = ::testing::TestWithParam>::GetParam(); n_rows = params.matrix_a.row_ind.size(); nnz_a = params.matrix_a.row_ind_ptr.size(); nnz_b = params.matrix_b.row_ind_ptr.size(); nnz_result = params.matrix_verify.row_ind_ptr.size(); - - cudaStreamCreate(&stream); - - raft::allocate(ind_a, n_rows, stream); - raft::allocate(ind_ptr_a, nnz_a, stream); - raft::allocate(values_a, nnz_a, stream); - - raft::allocate(ind_b, n_rows, stream); - raft::allocate(ind_ptr_b, nnz_b, stream); - raft::allocate(values_b, nnz_b, stream); - - raft::allocate(ind_verify, n_rows, stream); - raft::allocate(ind_ptr_verify, nnz_result, stream); - raft::allocate(values_verify, nnz_result, stream); - - raft::allocate(ind_result, n_rows, stream); - raft::allocate(ind_ptr_result, nnz_result, stream); - raft::allocate(values_result, nnz_result, stream); } void Run() { - raft::update_device(ind_a, params.matrix_a.row_ind.data(), n_rows, stream); - raft::update_device(ind_ptr_a, params.matrix_a.row_ind_ptr.data(), nnz_a, + raft::update_device(ind_a.data(), params.matrix_a.row_ind.data(), n_rows, + stream); + raft::update_device(ind_ptr_a.data(), params.matrix_a.row_ind_ptr.data(), + nnz_a, stream); + raft::update_device(values_a.data(), params.matrix_a.values.data(), nnz_a, stream); - raft::update_device(values_a, params.matrix_a.values.data(), nnz_a, stream); - raft::update_device(ind_b, params.matrix_b.row_ind.data(), n_rows, stream); - raft::update_device(ind_ptr_b, params.matrix_b.row_ind_ptr.data(), nnz_b, + raft::update_device(ind_b.data(), params.matrix_b.row_ind.data(), n_rows, + stream); + raft::update_device(ind_ptr_b.data(), params.matrix_b.row_ind_ptr.data(), + nnz_b, stream); + raft::update_device(values_b.data(), params.matrix_b.values.data(), nnz_b, stream); - raft::update_device(values_b, params.matrix_b.values.data(), nnz_b, stream); - raft::update_device(ind_verify, params.matrix_verify.row_ind.data(), n_rows, + raft::update_device(ind_verify.data(), params.matrix_verify.row_ind.data(), + n_rows, stream); + raft::update_device(ind_ptr_verify.data(), + params.matrix_verify.row_ind_ptr.data(), nnz_result, stream); - raft::update_device(ind_ptr_verify, params.matrix_verify.row_ind_ptr.data(), - nnz_result, stream); - raft::update_device(values_verify, params.matrix_verify.values.data(), - nnz_result, stream); + raft::update_device(values_verify.data(), + params.matrix_verify.values.data(), nnz_result, stream); Index_ nnz = linalg::csr_add_calc_inds( - ind_a, ind_ptr_a, values_a, nnz_a, ind_b, ind_ptr_b, values_b, nnz_b, - n_rows, ind_result, stream); + ind_a.data(), ind_ptr_a.data(), values_a.data(), nnz_a, ind_b.data(), + ind_ptr_b.data(), values_b.data(), nnz_b, n_rows, ind_result.data(), + stream); ASSERT_TRUE(nnz == nnz_result); - ASSERT_TRUE(raft::devArrMatch(ind_verify, ind_result, n_rows, - raft::Compare())); + ASSERT_TRUE(raft::devArrMatch(ind_verify.data(), ind_result.data(), + n_rows, raft::Compare())); linalg::csr_add_finalize( - ind_a, ind_ptr_a, values_a, nnz_a, ind_b, ind_ptr_b, values_b, nnz_b, - n_rows, ind_result, ind_ptr_result, values_result, stream); + ind_a.data(), ind_ptr_a.data(), values_a.data(), nnz_a, ind_b.data(), + ind_ptr_b.data(), values_b.data(), nnz_b, n_rows, ind_result.data(), + ind_ptr_result.data(), values_result.data(), stream); - ASSERT_TRUE(raft::devArrMatch(ind_ptr_verify, ind_ptr_result, nnz, + ASSERT_TRUE(raft::devArrMatch(ind_ptr_verify.data(), + ind_ptr_result.data(), nnz, raft::Compare())); - ASSERT_TRUE(raft::devArrMatch(values_verify, values_result, nnz, + ASSERT_TRUE(raft::devArrMatch(values_verify.data(), + values_result.data(), nnz, raft::Compare())); } - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); - } - protected: CSRAddInputs params; - cudaStream_t stream; Index_ n_rows, nnz_a, nnz_b, nnz_result; - Index_ *ind_a, *ind_b, *ind_verify, *ind_result, *ind_ptr_a, *ind_ptr_b, - *ind_ptr_verify, *ind_ptr_result; - Type_f *values_a, *values_b, *values_verify, *values_result; + rmm::device_uvector ind_a, ind_b, ind_verify, ind_result, ind_ptr_a, + ind_ptr_b, ind_ptr_verify, ind_ptr_result; + rmm::device_uvector values_a, values_b, values_verify, values_result; + + raft::handle_t handle; + cudaStream_t stream; }; using CSRAddTestF = CSRAddTest; diff --git a/cpp/test/sparse/convert_coo.cu b/cpp/test/sparse/convert_coo.cu index 4f9c00c7ab..339fe5ad7d 100644 --- a/cpp/test/sparse/convert_coo.cu +++ b/cpp/test/sparse/convert_coo.cu @@ -38,38 +38,37 @@ struct CSRtoCOOInputs { template class CSRtoCOOTest : public ::testing::TestWithParam> { - protected: - void SetUp() override { - params = ::testing::TestWithParam>::GetParam(); + public: + CSRtoCOOTest() + : params(::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + ex_scan(params.ex_scan.size(), stream), + verify(params.verify.size(), stream), + result(params.verify.size(), stream) {} - cudaStreamCreate(&stream); - raft::allocate(ex_scan, params.ex_scan.size(), stream); - raft::allocate(verify, params.verify.size(), stream); - raft::allocate(result, params.verify.size(), stream, true); - } + protected: + void SetUp() override {} void Run() { Index_ n_rows = params.ex_scan.size(); Index_ nnz = params.verify.size(); - raft::update_device(ex_scan, params.ex_scan.data(), n_rows, stream); - raft::update_device(verify, params.verify.data(), nnz, stream); + raft::update_device(ex_scan.data(), params.ex_scan.data(), n_rows, stream); + raft::update_device(verify.data(), params.verify.data(), nnz, stream); - convert::csr_to_coo(ex_scan, n_rows, result, nnz, stream); + convert::csr_to_coo(ex_scan.data(), n_rows, result.data(), nnz, + stream); - ASSERT_TRUE(raft::devArrMatch(verify, result, nnz, + ASSERT_TRUE(raft::devArrMatch(verify.data(), result.data(), nnz, raft::Compare(), stream)); } - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); - } - protected: CSRtoCOOInputs params; + rmm::device_uvector ex_scan, verify, result; + + raft::handle_t handle; cudaStream_t stream; - Index_ *ex_scan, *verify, *result; }; using CSRtoCOOTestI = CSRtoCOOTest; diff --git a/cpp/test/sparse/convert_csr.cu b/cpp/test/sparse/convert_csr.cu index 465aad4e7f..72b6acb34b 100644 --- a/cpp/test/sparse/convert_csr.cu +++ b/cpp/test/sparse/convert_csr.cu @@ -63,30 +63,25 @@ TEST_P(SortedCOOToCSR, Result) { int nnz = 8; - int *in, *out, *exp; - int *in_h = new int[nnz]{0, 0, 1, 1, 2, 2, 3, 3}; int *exp_h = new int[4]{0, 2, 4, 6}; - raft::allocate(in, nnz, stream, true); - raft::allocate(exp, 4, stream, true); - raft::allocate(out, 4, stream, true); + rmm::device_uvector in(nnz, stream); + rmm::device_uvector exp(4, stream); + rmm::device_uvector out(4, stream); - raft::update_device(in, in_h, nnz, stream); - raft::update_device(exp, exp_h, 4, stream); + raft::update_device(in.data(), in_h, nnz, stream); + raft::update_device(exp.data(), exp_h, 4, stream); - convert::sorted_coo_to_csr(in, nnz, out, 4, stream); + convert::sorted_coo_to_csr(in.data(), nnz, out.data(), 4, stream); - ASSERT_TRUE(raft::devArrMatch(out, exp, 4, raft::Compare())); + ASSERT_TRUE( + raft::devArrMatch(out.data(), exp.data(), 4, raft::Compare())); cudaStreamDestroy(stream); delete[] in_h; delete[] exp_h; - - CUDA_CHECK(cudaFree(in)); - CUDA_CHECK(cudaFree(exp)); - CUDA_CHECK(cudaFree(out)); } INSTANTIATE_TEST_CASE_P(SparseConvertCSRTest, SortedCOOToCSR, @@ -106,42 +101,40 @@ struct CSRAdjGraphInputs { template class CSRAdjGraphTest : public ::testing::TestWithParam> { + public: + CSRAdjGraphTest() + : params(::testing::TestWithParam>::GetParam()), + row_ind(params.n_rows, stream), + adj(params.n_rows * params.n_cols, stream), + result(params.verify.size(), stream), + verify(params.verify.size(), stream) {} + protected: - void SetUp() override { - params = ::testing::TestWithParam>::GetParam(); - cudaStreamCreate(&stream); - nnz = params.verify.size(); - - raft::allocate(row_ind, params.n_rows, stream); - raft::allocate(adj, params.n_rows * params.n_cols, stream); - raft::allocate(result, nnz, stream, true); - raft::allocate(verify, nnz, stream); - } + void SetUp() override { nnz = params.verify.size(); } void Run() { - raft::update_device(row_ind, params.row_ind.data(), params.n_rows, stream); - raft::update_device(adj, reinterpret_cast(params.adj.data()), + raft::update_device(row_ind.data(), params.row_ind.data(), params.n_rows, + stream); + raft::update_device(adj.data(), reinterpret_cast(params.adj.data()), params.n_rows * params.n_cols, stream); - raft::update_device(verify, params.verify.data(), nnz, stream); + raft::update_device(verify.data(), params.verify.data(), nnz, stream); - convert::csr_adj_graph_batched( - row_ind, params.n_cols, nnz, params.n_rows, adj, result, stream); + convert::csr_adj_graph_batched(row_ind.data(), params.n_cols, + nnz, params.n_rows, adj.data(), + result.data(), stream); - ASSERT_TRUE( - raft::devArrMatch(verify, result, nnz, raft::Compare())); - } - - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); + ASSERT_TRUE(raft::devArrMatch(verify.data(), result.data(), nnz, + raft::Compare())); } protected: CSRAdjGraphInputs params; - cudaStream_t stream; Index_ nnz; - Index_ *row_ind, *result, *verify; - bool *adj; + rmm::device_uvector row_ind, result, verify; + rmm::device_uvector adj; + + raft::handle_t handle; + cudaStream_t stream; }; using CSRAdjGraphTestI = CSRAdjGraphTest; diff --git a/cpp/test/sparse/csr_row_slice.cu b/cpp/test/sparse/csr_row_slice.cu index 00e6899cb2..b58ef56d33 100644 --- a/cpp/test/sparse/csr_row_slice.cu +++ b/cpp/test/sparse/csr_row_slice.cu @@ -16,12 +16,14 @@ #include #include +#include #include #include - #include +#include + #include "../test_utils.h" namespace raft { @@ -53,93 +55,89 @@ template template class CSRRowSliceTest : public ::testing::TestWithParam> { + public: + CSRRowSliceTest() + : params(::testing::TestWithParam< + CSRRowSliceInputs>::GetParam()), + stream(handle.get_stream()), + indptr(params.indptr_h.size(), stream), + indices(params.indices_h.size(), stream), + data(params.data_h.size(), stream), + out_indptr_ref(params.out_indptr_ref_h.size(), stream), + out_indices_ref(params.out_indices_ref_h.size(), stream), + out_data_ref(params.out_data_ref_h.size(), stream), + out_indptr(params.out_indptr_ref_h.size(), stream), + out_indices(params.out_indices_ref_h.size(), stream), + out_data(params.out_data_ref_h.size(), stream) {} + protected: void make_data() { std::vector indptr_h = params.indptr_h; std::vector indices_h = params.indices_h; std::vector data_h = params.data_h; - raft::allocate(indptr, indptr_h.size(), stream); - raft::allocate(indices, indices_h.size(), stream); - raft::allocate(data, data_h.size(), stream); - - update_device(indptr, indptr_h.data(), indptr_h.size(), stream); - update_device(indices, indices_h.data(), indices_h.size(), stream); - update_device(data, data_h.data(), data_h.size(), stream); + update_device(indptr.data(), indptr_h.data(), indptr_h.size(), stream); + update_device(indices.data(), indices_h.data(), indices_h.size(), stream); + update_device(data.data(), data_h.data(), data_h.size(), stream); std::vector out_indptr_ref_h = params.out_indptr_ref_h; std::vector out_indices_ref_h = params.out_indices_ref_h; std::vector out_data_ref_h = params.out_data_ref_h; - raft::allocate(out_indptr_ref, out_indptr_ref_h.size(), stream); - raft::allocate(out_indices_ref, out_indices_ref_h.size(), stream); - raft::allocate(out_data_ref, out_data_ref_h.size(), stream); - - update_device(out_indptr_ref, out_indptr_ref_h.data(), + update_device(out_indptr_ref.data(), out_indptr_ref_h.data(), out_indptr_ref_h.size(), stream); - update_device(out_indices_ref, out_indices_ref_h.data(), + update_device(out_indices_ref.data(), out_indices_ref_h.data(), out_indices_ref_h.size(), stream); - update_device(out_data_ref, out_data_ref_h.data(), out_data_ref_h.size(), - stream); - - raft::allocate(out_indptr, out_indptr_ref_h.size(), stream); - raft::allocate(out_indices, out_indices_ref_h.size(), stream); - raft::allocate(out_data, out_data_ref_h.size(), stream); + update_device(out_data_ref.data(), out_data_ref_h.data(), + out_data_ref_h.size(), stream); + CUDA_CHECK(cudaStreamSynchronize(stream)); } void SetUp() override { - params = ::testing::TestWithParam< - CSRRowSliceInputs>::GetParam(); - CUDA_CHECK(cudaStreamCreate(&stream)); - make_data(); int csr_start_offset; int csr_stop_offset; raft::sparse::op::csr_row_slice_indptr( - params.start_row, params.stop_row, indptr, out_indptr, &csr_start_offset, - &csr_stop_offset, stream); + params.start_row, params.stop_row, indptr.data(), out_indptr.data(), + &csr_start_offset, &csr_stop_offset, stream); - raft::sparse::op::csr_row_slice_populate(csr_start_offset, csr_stop_offset, - indices, data, out_indices, - out_data, stream); + raft::sparse::op::csr_row_slice_populate( + csr_start_offset, csr_stop_offset, indices.data(), data.data(), + out_indices.data(), out_data.data(), stream); CUDA_CHECK(cudaStreamSynchronize(stream)); } - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); - } - void compare() { - ASSERT_TRUE(devArrMatch(out_indptr, out_indptr_ref, + ASSERT_TRUE(devArrMatch(out_indptr.data(), out_indptr_ref.data(), params.out_indptr_ref_h.size(), Compare())); - ASSERT_TRUE(devArrMatch(out_indices, out_indices_ref, + ASSERT_TRUE(devArrMatch(out_indices.data(), out_indices_ref.data(), params.out_indices_ref_h.size(), Compare())); - ASSERT_TRUE(devArrMatch(out_data, out_data_ref, + ASSERT_TRUE(devArrMatch(out_data.data(), out_data_ref.data(), params.out_data_ref_h.size(), Compare())); } protected: - cudaStream_t stream; - // input data - value_idx *indptr, *indices; - value_t *data; + rmm::device_uvector indptr, indices; + rmm::device_uvector data; // output data - value_idx *out_indptr, *out_indices; - value_t *out_data; + rmm::device_uvector out_indptr, out_indices; + rmm::device_uvector out_data; // expected output data - value_idx *out_indptr_ref, *out_indices_ref; - value_t *out_data_ref; + rmm::device_uvector out_indptr_ref, out_indices_ref; + rmm::device_uvector out_data_ref; CSRRowSliceInputs params; + + raft::handle_t handle; + cudaStream_t stream; }; const std::vector> inputs_i32_f = { diff --git a/cpp/test/sparse/csr_to_dense.cu b/cpp/test/sparse/csr_to_dense.cu index 7f6b7dad07..256fd89183 100644 --- a/cpp/test/sparse/csr_to_dense.cu +++ b/cpp/test/sparse/csr_to_dense.cu @@ -16,10 +16,14 @@ #include #include +#include #include #include #include + +#include + #include "../test_utils.h" namespace raft { @@ -49,69 +53,68 @@ template template class CSRToDenseTest : public ::testing::TestWithParam> { + public: + CSRToDenseTest() + : params(::testing::TestWithParam< + CSRToDenseInputs>::GetParam()), + stream(raft_handle.get_stream()), + indptr(params.indptr_h.size(), stream), + indices(params.indices_h.size(), stream), + data(params.data_h.size(), stream), + out_ref(params.out_ref_h.size(), stream), + out(params.out_ref_h.size(), stream) {} + protected: void make_data() { std::vector indptr_h = params.indptr_h; std::vector indices_h = params.indices_h; std::vector data_h = params.data_h; - raft::allocate(indptr, indptr_h.size(), stream); - raft::allocate(indices, indices_h.size(), stream); - raft::allocate(data, data_h.size(), stream); - - update_device(indptr, indptr_h.data(), indptr_h.size(), stream); - update_device(indices, indices_h.data(), indices_h.size(), stream); - update_device(data, data_h.data(), data_h.size(), stream); + update_device(indptr.data(), indptr_h.data(), indptr_h.size(), stream); + update_device(indices.data(), indices_h.data(), indices_h.size(), stream); + update_device(data.data(), data_h.data(), data_h.size(), stream); std::vector out_ref_h = params.out_ref_h; - raft::allocate(out_ref, out_ref_h.size(), stream); - - update_device(out_ref, out_ref_h.data(), out_ref_h.size(), stream); - - raft::allocate(out, out_ref_h.size(), stream); + update_device(out_ref.data(), out_ref_h.data(), out_ref_h.size(), stream); + CUDA_CHECK(cudaStreamSynchronize(stream)); } void SetUp() override { - params = ::testing::TestWithParam< - CSRToDenseInputs>::GetParam(); - CUDA_CHECK(cudaStreamCreate(&stream)); CUSPARSE_CHECK(cusparseCreate(&handle)); make_data(); - convert::csr_to_dense(handle, params.nrows, params.ncols, indptr, indices, - data, params.nrows, out, stream, true); + convert::csr_to_dense(handle, params.nrows, params.ncols, indptr.data(), + indices.data(), data.data(), params.nrows, out.data(), + stream, true); CUDA_CHECK(cudaStreamSynchronize(stream)); CUSPARSE_CHECK(cusparseDestroy(handle)); } - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); - } - void compare() { - ASSERT_TRUE( - devArrMatch(out, out_ref, params.out_ref_h.size(), Compare())); + ASSERT_TRUE(devArrMatch(out.data(), out_ref.data(), params.out_ref_h.size(), + Compare())); } protected: - cudaStream_t stream; cusparseHandle_t handle; // input data - value_idx *indptr, *indices; - value_t *data; + rmm::device_uvector indptr, indices; + rmm::device_uvector data; // output data - value_t *out; + rmm::device_uvector out; // expected output data - value_t *out_ref; + rmm::device_uvector out_ref; CSRToDenseInputs params; + + raft::handle_t raft_handle; + cudaStream_t stream; }; const std::vector> inputs_i32_f = { diff --git a/cpp/test/sparse/csr_transpose.cu b/cpp/test/sparse/csr_transpose.cu index e50a9d94a9..a8827d065f 100644 --- a/cpp/test/sparse/csr_transpose.cu +++ b/cpp/test/sparse/csr_transpose.cu @@ -20,8 +20,8 @@ #include #include - #include +#include #include "../test_utils.h" @@ -55,89 +55,87 @@ template template class CSRTransposeTest : public ::testing::TestWithParam> { + public: + CSRTransposeTest() + : params(::testing::TestWithParam< + CSRTransposeInputs>::GetParam()), + stream(raft_handle.get_stream()), + indptr(params.indptr_h.size(), stream), + indices(params.indices_h.size(), stream), + data(params.data_h.size(), stream), + out_indptr_ref(params.out_indptr_ref_h.size(), stream), + out_indices_ref(params.out_indices_ref_h.size(), stream), + out_data_ref(params.out_data_ref_h.size(), stream), + out_indptr(params.out_indptr_ref_h.size(), stream), + out_indices(params.out_indices_ref_h.size(), stream), + out_data(params.out_data_ref_h.size(), stream) {} + protected: void make_data() { std::vector indptr_h = params.indptr_h; std::vector indices_h = params.indices_h; std::vector data_h = params.data_h; - raft::allocate(indptr, indptr_h.size(), stream); - raft::allocate(indices, indices_h.size(), stream); - raft::allocate(data, data_h.size(), stream); - - update_device(indptr, indptr_h.data(), indptr_h.size(), stream); - update_device(indices, indices_h.data(), indices_h.size(), stream); - update_device(data, data_h.data(), data_h.size(), stream); + update_device(indptr.data(), indptr_h.data(), indptr_h.size(), stream); + update_device(indices.data(), indices_h.data(), indices_h.size(), stream); + update_device(data.data(), data_h.data(), data_h.size(), stream); std::vector out_indptr_ref_h = params.out_indptr_ref_h; std::vector out_indices_ref_h = params.out_indices_ref_h; std::vector out_data_ref_h = params.out_data_ref_h; - raft::allocate(out_indptr_ref, out_indptr_ref_h.size(), stream); - raft::allocate(out_indices_ref, out_indices_ref_h.size(), stream); - raft::allocate(out_data_ref, out_data_ref_h.size(), stream); - - update_device(out_indptr_ref, out_indptr_ref_h.data(), + update_device(out_indptr_ref.data(), out_indptr_ref_h.data(), out_indptr_ref_h.size(), stream); - update_device(out_indices_ref, out_indices_ref_h.data(), + update_device(out_indices_ref.data(), out_indices_ref_h.data(), out_indices_ref_h.size(), stream); - update_device(out_data_ref, out_data_ref_h.data(), out_data_ref_h.size(), - stream); - - raft::allocate(out_indptr, out_indptr_ref_h.size(), stream); - raft::allocate(out_indices, out_indices_ref_h.size(), stream); - raft::allocate(out_data, out_data_ref_h.size(), stream); + update_device(out_data_ref.data(), out_data_ref_h.data(), + out_data_ref_h.size(), stream); } void SetUp() override { - params = ::testing::TestWithParam< - CSRTransposeInputs>::GetParam(); - CUDA_CHECK(cudaStreamCreate(&stream)); CUSPARSE_CHECK(cusparseCreate(&handle)); make_data(); raft::sparse::linalg::csr_transpose( - handle, indptr, indices, data, out_indptr, out_indices, out_data, - params.nrows, params.ncols, params.nnz, stream); + handle, indptr.data(), indices.data(), data.data(), out_indptr.data(), + out_indices.data(), out_data.data(), params.nrows, params.ncols, + params.nnz, stream); CUDA_CHECK(cudaStreamSynchronize(stream)); CUSPARSE_CHECK(cusparseDestroy(handle)); } - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); - } - void compare() { - ASSERT_TRUE(devArrMatch(out_indptr, out_indptr_ref, + ASSERT_TRUE(devArrMatch(out_indptr.data(), out_indptr_ref.data(), params.out_indptr_ref_h.size(), Compare())); - ASSERT_TRUE(devArrMatch(out_indices, out_indices_ref, + ASSERT_TRUE(devArrMatch(out_indices.data(), out_indices_ref.data(), params.out_indices_ref_h.size(), Compare())); - ASSERT_TRUE(devArrMatch(out_data, out_data_ref, + ASSERT_TRUE(devArrMatch(out_data.data(), out_data_ref.data(), params.out_data_ref_h.size(), Compare())); } protected: - cudaStream_t stream; cusparseHandle_t handle; // input data - value_idx *indptr, *indices; - value_t *data; + rmm::device_uvector indptr, indices; + rmm::device_uvector data; // output data - value_idx *out_indptr, *out_indices; - value_t *out_data; + rmm::device_uvector out_indptr, out_indices; + rmm::device_uvector out_data; // expected output data - value_idx *out_indptr_ref, *out_indices_ref; - value_t *out_data_ref; + rmm::device_uvector out_indptr_ref, out_indices_ref; + rmm::device_uvector out_data_ref; CSRTransposeInputs params; + + cudaStream_t stream; + raft::handle_t raft_handle; }; const std::vector> inputs_i32_f = { diff --git a/cpp/test/sparse/degree.cu b/cpp/test/sparse/degree.cu index f8a469af45..7c23c0b3d7 100644 --- a/cpp/test/sparse/degree.cu +++ b/cpp/test/sparse/degree.cu @@ -50,24 +50,23 @@ typedef SparseDegreeTests COODegree; TEST_P(COODegree, Result) { cudaStream_t stream; cudaStreamCreate(&stream); - int *in_rows, *verify, *results; int in_rows_h[5] = {0, 0, 1, 2, 2}; int verify_h[5] = {2, 1, 2, 0, 0}; - raft::allocate(in_rows, 5, stream); - raft::allocate(verify, 5, stream, true); - raft::allocate(results, 5, stream, true); + rmm::device_uvector in_rows(5, stream); + rmm::device_uvector verify(5, stream); + rmm::device_uvector results(5, stream); - raft::update_device(in_rows, *&in_rows_h, 5, stream); - raft::update_device(verify, *&verify_h, 5, stream); + raft::update_device(in_rows.data(), *&in_rows_h, 5, stream); + raft::update_device(verify.data(), *&verify_h, 5, stream); - linalg::coo_degree<32>(in_rows, 5, results, stream); + linalg::coo_degree<32>(in_rows.data(), 5, results.data(), stream); cudaDeviceSynchronize(); - ASSERT_TRUE(raft::devArrMatch(verify, results, 5, raft::Compare())); + ASSERT_TRUE(raft::devArrMatch(verify.data(), results.data(), 5, + raft::Compare())); - raft::deallocate_all(stream); CUDA_CHECK(cudaStreamDestroy(stream)); } @@ -76,28 +75,26 @@ TEST_P(COODegreeNonzero, Result) { cudaStream_t stream; cudaStreamCreate(&stream); - int *in_rows, *verify, *results; - float *in_vals; - int in_rows_h[5] = {0, 0, 1, 2, 2}; float in_vals_h[5] = {0.0, 5.0, 0.0, 1.0, 1.0}; int verify_h[5] = {1, 0, 2, 0, 0}; - raft::allocate(in_rows, 5, stream); - raft::allocate(verify, 5, stream, true); - raft::allocate(results, 5, stream, true); - raft::allocate(in_vals, 5, stream, true); + rmm::device_uvector in_rows(5, stream); + rmm::device_uvector verify(5, stream); + rmm::device_uvector results(5, stream); + rmm::device_uvector in_vals(5, stream); - raft::update_device(in_rows, *&in_rows_h, 5, stream); - raft::update_device(verify, *&verify_h, 5, stream); - raft::update_device(in_vals, *&in_vals_h, 5, stream); + raft::update_device(in_rows.data(), *&in_rows_h, 5, stream); + raft::update_device(verify.data(), *&verify_h, 5, stream); + raft::update_device(in_vals.data(), *&in_vals_h, 5, stream); - linalg::coo_degree_nz<32, float>(in_rows, in_vals, 5, results, stream); + linalg::coo_degree_nz<32, float>(in_rows.data(), in_vals.data(), 5, + results.data(), stream); cudaDeviceSynchronize(); - ASSERT_TRUE(raft::devArrMatch(verify, results, 5, raft::Compare())); + ASSERT_TRUE(raft::devArrMatch(verify.data(), results.data(), 5, + raft::Compare())); - raft::deallocate_all(stream); CUDA_CHECK(cudaStreamDestroy(stream)); } diff --git a/cpp/test/sparse/dist_coo_spmv.cu b/cpp/test/sparse/dist_coo_spmv.cu index 563dcf6f15..cd3e69bdd2 100644 --- a/cpp/test/sparse/dist_coo_spmv.cu +++ b/cpp/test/sparse/dist_coo_spmv.cu @@ -77,7 +77,13 @@ class SparseDistanceCOOSPMVTest : public ::testing::TestWithParam< SparseDistanceCOOSPMVInputs> { public: - SparseDistanceCOOSPMVTest() : dist_config(handle) {} + SparseDistanceCOOSPMVTest() + : dist_config(handle), + indptr(0, handle.get_stream()), + indices(0, handle.get_stream()), + data(0, handle.get_stream()), + out_dists(0, handle.get_stream()), + out_dists_ref(0, handle.get_stream()) {} template > * = nullptr> @@ -104,7 +110,7 @@ class SparseDistanceCOOSPMVTest strategy_t selected_strategy = make_strategy(); balanced_coo_pairwise_generalized_spmv( - out_dists, dist_config, coo_rows.data(), reduce_func, accum_func, + out_dists.data(), dist_config, coo_rows.data(), reduce_func, accum_func, write_func, selected_strategy); if (rev) { @@ -113,7 +119,7 @@ class SparseDistanceCOOSPMVTest dist_config.a_nnz, dist_config.handle.get_stream()); balanced_coo_pairwise_generalized_spmv_rev( - out_dists, dist_config, coo_rows.data(), reduce_func, accum_func, + out_dists.data(), dist_config, coo_rows.data(), reduce_func, accum_func, write_func, selected_strategy); } } @@ -144,7 +150,8 @@ class SparseDistanceCOOSPMVTest AtomicAdd()); float p = 1.0f / params.input_configuration.metric_arg; raft::linalg::unaryOp( - out_dists, out_dists, dist_config.a_nrows * dist_config.b_nrows, + out_dists.data(), out_dists.data(), + dist_config.a_nrows * dist_config.b_nrows, [=] __device__(value_t input) { return powf(input, p); }, dist_config.handle.get_stream()); @@ -160,24 +167,22 @@ class SparseDistanceCOOSPMVTest std::vector indices_h = params.input_configuration.indices_h; std::vector data_h = params.input_configuration.data_h; - raft::allocate(indptr, indptr_h.size(), handle.get_stream()); - raft::allocate(indices, indices_h.size(), handle.get_stream()); - raft::allocate(data, data_h.size(), handle.get_stream()); + auto stream = handle.get_stream(); + indptr.resize(indptr_h.size(), stream); + indices.resize(indices_h.size(), stream); + data.resize(data_h.size(), stream); - update_device(indptr, indptr_h.data(), indptr_h.size(), - handle.get_stream()); - update_device(indices, indices_h.data(), indices_h.size(), - handle.get_stream()); - update_device(data, data_h.data(), data_h.size(), handle.get_stream()); + update_device(indptr.data(), indptr_h.data(), indptr_h.size(), stream); + update_device(indices.data(), indices_h.data(), indices_h.size(), stream); + update_device(data.data(), data_h.data(), data_h.size(), stream); std::vector out_dists_ref_h = params.input_configuration.out_dists_ref_h; - raft::allocate(out_dists_ref, (indptr_h.size() - 1) * (indptr_h.size() - 1), - handle.get_stream()); + out_dists_ref.resize((indptr_h.size() - 1) * (indptr_h.size() - 1), stream); - update_device(out_dists_ref, out_dists_ref_h.data(), out_dists_ref_h.size(), - handle.get_stream()); + update_device(out_dists_ref.data(), out_dists_ref_h.data(), + out_dists_ref_h.size(), stream); } void SetUp() override { @@ -189,29 +194,27 @@ class SparseDistanceCOOSPMVTest dist_config.b_nrows = params.input_configuration.indptr_h.size() - 1; dist_config.b_ncols = params.input_configuration.n_cols; dist_config.b_nnz = params.input_configuration.indices_h.size(); - dist_config.b_indptr = indptr; - dist_config.b_indices = indices; - dist_config.b_data = data; + dist_config.b_indptr = indptr.data(); + dist_config.b_indices = indices.data(); + dist_config.b_data = data.data(); dist_config.a_nrows = params.input_configuration.indptr_h.size() - 1; dist_config.a_ncols = params.input_configuration.n_cols; dist_config.a_nnz = params.input_configuration.indices_h.size(); - dist_config.a_indptr = indptr; - dist_config.a_indices = indices; - dist_config.a_data = data; + dist_config.a_indptr = indptr.data(); + dist_config.a_indices = indices.data(); + dist_config.a_data = data.data(); int out_size = dist_config.a_nrows * dist_config.b_nrows; - raft::allocate(out_dists, out_size, handle.get_stream()); + out_dists.resize(out_size, handle.get_stream()); run_spmv(); CUDA_CHECK(cudaStreamSynchronize(handle.get_stream())); } - void TearDown() override { raft::deallocate_all(handle.get_stream()); } - void compare() { - ASSERT_TRUE(devArrMatch(out_dists_ref, out_dists, + ASSERT_TRUE(devArrMatch(out_dists_ref.data(), out_dists.data(), params.input_configuration.out_dists_ref_h.size(), CompareApprox(1e-3))); } @@ -220,11 +223,11 @@ class SparseDistanceCOOSPMVTest raft::handle_t handle; // input data - value_idx *indptr, *indices; - value_t *data; + rmm::device_uvector indptr, indices; + rmm::device_uvector data; // output data - value_t *out_dists, *out_dists_ref; + rmm::device_uvector out_dists, out_dists_ref; raft::sparse::distance::distances_config_t dist_config; diff --git a/cpp/test/sparse/distance.cu b/cpp/test/sparse/distance.cu index 4b531992f0..efe49c6470 100644 --- a/cpp/test/sparse/distance.cu +++ b/cpp/test/sparse/distance.cu @@ -58,40 +58,44 @@ template class SparseDistanceTest : public ::testing::TestWithParam> { public: - SparseDistanceTest() : dist_config(handle) {} + SparseDistanceTest() + : params(::testing::TestWithParam< + SparseDistanceInputs>::GetParam()), + dist_config(handle), + indptr(0, handle.get_stream()), + indices(0, handle.get_stream()), + data(0, handle.get_stream()), + out_dists(0, handle.get_stream()), + out_dists_ref(0, handle.get_stream()) {} void SetUp() override { - params = ::testing::TestWithParam< - SparseDistanceInputs>::GetParam(); - make_data(); dist_config.b_nrows = params.indptr_h.size() - 1; dist_config.b_ncols = params.n_cols; dist_config.b_nnz = params.indices_h.size(); - dist_config.b_indptr = indptr; - dist_config.b_indices = indices; - dist_config.b_data = data; + dist_config.b_indptr = indptr.data(); + dist_config.b_indices = indices.data(); + dist_config.b_data = data.data(); dist_config.a_nrows = params.indptr_h.size() - 1; dist_config.a_ncols = params.n_cols; dist_config.a_nnz = params.indices_h.size(); - dist_config.a_indptr = indptr; - dist_config.a_indices = indices; - dist_config.a_data = data; + dist_config.a_indptr = indptr.data(); + dist_config.a_indices = indices.data(); + dist_config.a_data = data.data(); int out_size = dist_config.a_nrows * dist_config.b_nrows; - raft::allocate(out_dists, out_size, handle.get_stream()); + out_dists.resize(out_size, handle.get_stream()); - pairwiseDistance(out_dists, dist_config, params.metric, params.metric_arg); + pairwiseDistance(out_dists.data(), dist_config, params.metric, + params.metric_arg); CUDA_CHECK(cudaStreamSynchronize(handle.get_stream())); } - void TearDown() override { raft::deallocate_all(handle.get_stream()); } - void compare() { - ASSERT_TRUE(devArrMatch(out_dists_ref, out_dists, + ASSERT_TRUE(devArrMatch(out_dists_ref.data(), out_dists.data(), params.out_dists_ref_h.size(), CompareApprox(1e-3))); } @@ -102,33 +106,31 @@ class SparseDistanceTest std::vector indices_h = params.indices_h; std::vector data_h = params.data_h; - raft::allocate(indptr, indptr_h.size(), handle.get_stream()); - raft::allocate(indices, indices_h.size(), handle.get_stream()); - raft::allocate(data, data_h.size(), handle.get_stream()); + auto stream = handle.get_stream(); + indptr.resize(indptr_h.size(), stream); + indices.resize(indices_h.size(), stream); + data.resize(data_h.size(), stream); - update_device(indptr, indptr_h.data(), indptr_h.size(), - handle.get_stream()); - update_device(indices, indices_h.data(), indices_h.size(), - handle.get_stream()); - update_device(data, data_h.data(), data_h.size(), handle.get_stream()); + update_device(indptr.data(), indptr_h.data(), indptr_h.size(), stream); + update_device(indices.data(), indices_h.data(), indices_h.size(), stream); + update_device(data.data(), data_h.data(), data_h.size(), stream); std::vector out_dists_ref_h = params.out_dists_ref_h; - raft::allocate(out_dists_ref, (indptr_h.size() - 1) * (indptr_h.size() - 1), - handle.get_stream()); + out_dists_ref.resize((indptr_h.size() - 1) * (indptr_h.size() - 1), stream); - update_device(out_dists_ref, out_dists_ref_h.data(), out_dists_ref_h.size(), - dist_config.handle.get_stream()); + update_device(out_dists_ref.data(), out_dists_ref_h.data(), + out_dists_ref_h.size(), dist_config.handle.get_stream()); } raft::handle_t handle; // input data - value_idx *indptr, *indices; - value_t *data; + rmm::device_uvector indptr, indices; + rmm::device_uvector data; // output data - value_t *out_dists, *out_dists_ref; + rmm::device_uvector out_dists, out_dists_ref; SparseDistanceInputs params; raft::sparse::distance::distances_config_t dist_config; diff --git a/cpp/test/sparse/knn.cu b/cpp/test/sparse/knn.cu index 22f97559b1..86b3b3d382 100644 --- a/cpp/test/sparse/knn.cu +++ b/cpp/test/sparse/knn.cu @@ -62,10 +62,19 @@ template class SparseKNNTest : public ::testing::TestWithParam> { public: - void SetUp() override { - params = - ::testing::TestWithParam>::GetParam(); + SparseKNNTest() + : params(::testing::TestWithParam< + SparseKNNInputs>::GetParam()), + indptr(0, handle.get_stream()), + indices(0, handle.get_stream()), + data(0, handle.get_stream()), + out_indices(0, handle.get_stream()), + out_dists(0, handle.get_stream()), + out_indices_ref(0, handle.get_stream()), + out_dists_ref(0, handle.get_stream()) {} + protected: + void SetUp() override { n_rows = params.indptr_h.size() - 1; nnz = params.indices_h.size(); k = params.k; @@ -73,20 +82,19 @@ class SparseKNNTest make_data(); raft::sparse::selection::brute_force_knn( - indptr, indices, data, nnz, n_rows, params.n_cols, indptr, indices, data, - nnz, n_rows, params.n_cols, out_indices, out_dists, k, handle, - params.batch_size_index, params.batch_size_query, params.metric); + indptr.data(), indices.data(), data.data(), nnz, n_rows, params.n_cols, + indptr.data(), indices.data(), data.data(), nnz, n_rows, params.n_cols, + out_indices.data(), out_dists.data(), k, handle, params.batch_size_index, + params.batch_size_query, params.metric); CUDA_CHECK(cudaStreamSynchronize(handle.get_stream())); } - void TearDown() override { raft::deallocate_all(handle.get_stream()); } - void compare() { - ASSERT_TRUE(devArrMatch(out_dists_ref, out_dists, n_rows * k, + ASSERT_TRUE(devArrMatch(out_dists_ref.data(), out_dists.data(), n_rows * k, CompareApprox(1e-4))); - ASSERT_TRUE(devArrMatch(out_indices_ref, out_indices, n_rows * k, - Compare())); + ASSERT_TRUE(devArrMatch(out_indices_ref.data(), out_indices.data(), + n_rows * k, Compare())); } protected: @@ -95,30 +103,28 @@ class SparseKNNTest std::vector indices_h = params.indices_h; std::vector data_h = params.data_h; - raft::allocate(indptr, indptr_h.size(), handle.get_stream()); - raft::allocate(indices, indices_h.size(), handle.get_stream()); - raft::allocate(data, data_h.size(), handle.get_stream()); + auto stream = handle.get_stream(); + indptr.resize(indptr_h.size(), stream); + indices.resize(indices_h.size(), stream); + data.resize(data_h.size(), stream); - update_device(indptr, indptr_h.data(), indptr_h.size(), - handle.get_stream()); - update_device(indices, indices_h.data(), indices_h.size(), - handle.get_stream()); - update_device(data, data_h.data(), data_h.size(), handle.get_stream()); + update_device(indptr.data(), indptr_h.data(), indptr_h.size(), stream); + update_device(indices.data(), indices_h.data(), indices_h.size(), stream); + update_device(data.data(), data_h.data(), data_h.size(), stream); std::vector out_dists_ref_h = params.out_dists_ref_h; std::vector out_indices_ref_h = params.out_indices_ref_h; - raft::allocate(out_indices_ref, out_indices_ref_h.size(), - handle.get_stream()); - raft::allocate(out_dists_ref, out_dists_ref_h.size(), handle.get_stream()); + out_indices_ref.resize(out_indices_ref_h.size(), stream); + out_dists_ref.resize(out_dists_ref_h.size(), stream); - update_device(out_indices_ref, out_indices_ref_h.data(), - out_indices_ref_h.size(), handle.get_stream()); - update_device(out_dists_ref, out_dists_ref_h.data(), out_dists_ref_h.size(), - handle.get_stream()); + update_device(out_indices_ref.data(), out_indices_ref_h.data(), + out_indices_ref_h.size(), stream); + update_device(out_dists_ref.data(), out_dists_ref_h.data(), + out_dists_ref_h.size(), stream); - raft::allocate(out_dists, n_rows * k, handle.get_stream()); - raft::allocate(out_indices, n_rows * k, handle.get_stream()); + out_dists.resize(n_rows * k, stream); + out_indices.resize(n_rows * k, stream); } raft::handle_t handle; @@ -126,15 +132,15 @@ class SparseKNNTest int n_rows, nnz, k; // input data - value_idx *indptr, *indices; - value_t *data; + rmm::device_uvector indptr, indices; + rmm::device_uvector data; // output data - value_idx *out_indices; - value_t *out_dists; + rmm::device_uvector out_indices; + rmm::device_uvector out_dists; - value_idx *out_indices_ref; - value_t *out_dists_ref; + rmm::device_uvector out_indices_ref; + rmm::device_uvector out_dists_ref; SparseKNNInputs params; }; diff --git a/cpp/test/sparse/knn_graph.cu b/cpp/test/sparse/knn_graph.cu index e259eafa70..3256adb3f5 100644 --- a/cpp/test/sparse/knn_graph.cu +++ b/cpp/test/sparse/knn_graph.cu @@ -59,23 +59,22 @@ template template class KNNGraphTest : public ::testing::TestWithParam> { - void SetUp() override { - params = - ::testing::TestWithParam>::GetParam(); - - raft::handle_t handle; - - stream = handle.get_stream(); + public: + KNNGraphTest() + : params(::testing::TestWithParam< + KNNGraphInputs>::GetParam()), + stream(handle.get_stream()), + X(params.X.size(), stream) {} + protected: + void SetUp() override { out = new raft::sparse::COO(stream); - raft::allocate(X, params.X.size(), stream); - - update_device(X, params.X.data(), params.X.size(), stream); + update_device(X.data(), params.X.data(), params.X.size(), stream); raft::sparse::selection::knn_graph( - handle, X, params.m, params.n, raft::distance::DistanceType::L2Unexpanded, - *out); + handle, X.data(), params.m, params.n, + raft::distance::DistanceType::L2Unexpanded, *out); rmm::device_scalar sum(stream); sum.set_value_to_zero_async(stream); @@ -90,24 +89,20 @@ class KNNGraphTest CUDA_CHECK(cudaStreamSynchronize(stream)); } - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamSynchronize(stream)); - - delete out; - } + void TearDown() override { delete out; } protected: - cudaStream_t stream; - // input data raft::sparse::COO *out; - value_t *X; + rmm::device_uvector X; value_idx sum_h; KNNGraphInputs params; + + raft::handle_t handle; + cudaStream_t stream; }; const std::vector> knn_graph_inputs_fint = { diff --git a/cpp/test/sparse/linkage.cu b/cpp/test/sparse/linkage.cu index 3bd144ef54..a4caaff11c 100644 --- a/cpp/test/sparse/linkage.cu +++ b/cpp/test/sparse/linkage.cu @@ -153,23 +153,23 @@ template template class LinkageTest : public ::testing::TestWithParam> { + public: + LinkageTest() + : params(::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + labels(params.n_row, stream), + labels_ref(params.n_row, stream) {} + protected: void basicTest() { - CUDA_CHECK(cudaStreamCreate(&stream)); - - params = ::testing::TestWithParam>::GetParam(); - rmm::device_uvector data(params.n_row * params.n_col, stream); - // Allocate result labels and expected labels on device - raft::allocate(labels, params.n_row, stream); - raft::allocate(labels_ref, params.n_row, stream); - raft::copy(data.data(), params.data.data(), data.size(), stream); - raft::copy(labels_ref, params.expected_labels.data(), params.n_row, stream); + raft::copy(labels_ref.data(), params.expected_labels.data(), params.n_row, + stream); raft::hierarchy::linkage_output out_arrs; - out_arrs.labels = labels; + out_arrs.labels = labels.data(); rmm::device_uvector out_children(params.n_row * 2, stream); @@ -182,22 +182,20 @@ class LinkageTest : public ::testing::TestWithParam> { raft::distance::DistanceType::L2SqrtExpanded, &out_arrs, params.c, params.n_clusters); - CUDA_CHECK(cudaStreamSynchronize(handle.get_stream())); + CUDA_CHECK(cudaStreamSynchronize(stream)); - score = compute_rand_index(labels, labels_ref, params.n_row, stream); + score = compute_rand_index(labels.data(), labels_ref.data(), params.n_row, + stream); } void SetUp() override { basicTest(); } - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); - } - protected: LinkageInputs params; - IdxT *labels, *labels_ref; + rmm::device_uvector labels, labels_ref; double score; + + raft::handle_t handle; cudaStream_t stream; }; diff --git a/cpp/test/sparse/norm.cu b/cpp/test/sparse/norm.cu index d69dd15c57..92aa9048b5 100644 --- a/cpp/test/sparse/norm.cu +++ b/cpp/test/sparse/norm.cu @@ -41,51 +41,49 @@ struct CSRRowNormalizeInputs { template class CSRRowNormalizeTest : public ::testing::TestWithParam> { + public: + CSRRowNormalizeTest() + : params(::testing::TestWithParam< + CSRRowNormalizeInputs>::GetParam()), + stream(handle.get_stream()), + in_vals(params.in_vals.size(), stream), + verify(params.verify.size(), stream), + ex_scan(params.ex_scan.size(), stream), + result(params.verify.size(), stream) {} + protected: - void SetUp() override { - params = ::testing::TestWithParam< - CSRRowNormalizeInputs>::GetParam(); - cudaStreamCreate(&stream); - - raft::allocate(in_vals, params.in_vals.size(), stream); - raft::allocate(verify, params.verify.size(), stream); - raft::allocate(ex_scan, params.ex_scan.size(), stream); - raft::allocate(result, params.verify.size(), stream, true); - } + void SetUp() override {} void Run() { Index_ n_rows = params.ex_scan.size(); Index_ nnz = params.in_vals.size(); - raft::update_device(ex_scan, params.ex_scan.data(), n_rows, stream); - raft::update_device(in_vals, params.in_vals.data(), nnz, stream); - raft::update_device(verify, params.verify.data(), nnz, stream); + raft::update_device(ex_scan.data(), params.ex_scan.data(), n_rows, stream); + raft::update_device(in_vals.data(), params.in_vals.data(), nnz, stream); + raft::update_device(verify.data(), params.verify.data(), nnz, stream); switch (params.method) { case MAX: - linalg::csr_row_normalize_max<32, Type_f>(ex_scan, in_vals, nnz, n_rows, - result, stream); + linalg::csr_row_normalize_max<32, Type_f>( + ex_scan.data(), in_vals.data(), nnz, n_rows, result.data(), stream); break; case L1: - linalg::csr_row_normalize_l1<32, Type_f>(ex_scan, in_vals, nnz, n_rows, - result, stream); + linalg::csr_row_normalize_l1<32, Type_f>( + ex_scan.data(), in_vals.data(), nnz, n_rows, result.data(), stream); break; } - ASSERT_TRUE( - raft::devArrMatch(verify, result, nnz, raft::Compare())); - } - - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); + ASSERT_TRUE(raft::devArrMatch(verify.data(), result.data(), nnz, + raft::Compare())); } protected: CSRRowNormalizeInputs params; + rmm::device_uvector ex_scan; + rmm::device_uvector in_vals, result, verify; + + raft::handle_t handle; cudaStream_t stream; - Index_ *ex_scan; - Type_f *in_vals, *result, *verify; }; using CSRRowNormalizeTestF = CSRRowNormalizeTest; diff --git a/cpp/test/sparse/row_op.cu b/cpp/test/sparse/row_op.cu index 805a3d85da..9b24a971a0 100644 --- a/cpp/test/sparse/row_op.cu +++ b/cpp/test/sparse/row_op.cu @@ -51,40 +51,40 @@ void csr_row_op_wrapper(const Index_ *row_ind, Index_ n_rows, Index_ nnz, template class CSRRowOpTest : public ::testing::TestWithParam> { + public: + CSRRowOpTest() + : params( + ::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + verify(params.verify.size(), stream), + ex_scan(params.ex_scan.size(), stream), + result(params.verify.size(), stream) {} + protected: void SetUp() override { - params = - ::testing::TestWithParam>::GetParam(); - cudaStreamCreate(&stream); n_rows = params.ex_scan.size(); nnz = params.verify.size(); - - raft::allocate(verify, nnz, stream); - raft::allocate(ex_scan, n_rows, stream); - raft::allocate(result, nnz, stream, true); } void Run() { - raft::update_device(ex_scan, params.ex_scan.data(), n_rows, stream); - raft::update_device(verify, params.verify.data(), nnz, stream); + raft::update_device(ex_scan.data(), params.ex_scan.data(), n_rows, stream); + raft::update_device(verify.data(), params.verify.data(), nnz, stream); - csr_row_op_wrapper(ex_scan, n_rows, nnz, result, stream); - - ASSERT_TRUE( - raft::devArrMatch(verify, result, nnz, raft::Compare())); - } + csr_row_op_wrapper(ex_scan.data(), n_rows, nnz, + result.data(), stream); - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); + ASSERT_TRUE(raft::devArrMatch(verify.data(), result.data(), nnz, + raft::Compare())); } protected: CSRRowOpInputs params; - cudaStream_t stream; Index_ n_rows, nnz; - Index_ *ex_scan; - Type_f *result, *verify; + rmm::device_uvector ex_scan; + rmm::device_uvector result, verify; + + raft::handle_t handle; + cudaStream_t stream; }; using CSRRowOpTestF = CSRRowOpTest; diff --git a/cpp/test/sparse/sort.cu b/cpp/test/sparse/sort.cu index e73a8a547b..92833630dd 100644 --- a/cpp/test/sparse/sort.cu +++ b/cpp/test/sparse/sort.cu @@ -47,16 +47,17 @@ const std::vector> inputsf = {{5, 10, 5, 1234ULL}}; typedef SparseSortTest COOSort; TEST_P(COOSort, Result) { - int *in_rows, *in_cols, *verify; - float *in_vals; - params = ::testing::TestWithParam>::GetParam(); raft::random::Rng r(params.seed); cudaStream_t stream; CUDA_CHECK(cudaStreamCreate(&stream)); - raft::allocate(in_vals, params.nnz, stream); - r.uniform(in_vals, params.nnz, float(-1.0), float(1.0), stream); + rmm::device_uvector in_rows(params.nnz, stream); + rmm::device_uvector in_cols(params.nnz, stream); + rmm::device_uvector verify(params.nnz, stream); + rmm::device_uvector in_vals(params.nnz, stream); + + r.uniform(in_vals.data(), params.nnz, float(-1.0), float(1.0), stream); int *in_rows_h = (int *)malloc(params.nnz * sizeof(int)); int *in_cols_h = (int *)malloc(params.nnz * sizeof(int)); @@ -68,29 +69,21 @@ TEST_P(COOSort, Result) { in_cols_h[i] = i; } - raft::allocate(in_rows, params.nnz, stream); - raft::allocate(in_cols, params.nnz, stream); - raft::allocate(verify, params.nnz, stream); - - raft::update_device(in_rows, in_rows_h, params.nnz, stream); + raft::update_device(in_rows.data(), in_rows_h, params.nnz, stream); - raft::update_device(in_cols, in_cols_h, params.nnz, stream); - raft::update_device(verify, verify_h, params.nnz, stream); + raft::update_device(in_cols.data(), in_cols_h, params.nnz, stream); + raft::update_device(verify.data(), verify_h, params.nnz, stream); - op::coo_sort(params.m, params.n, params.nnz, in_rows, in_cols, in_vals, - stream); + op::coo_sort(params.m, params.n, params.nnz, in_rows.data(), in_cols.data(), + in_vals.data(), stream); - ASSERT_TRUE( - raft::devArrMatch(verify, in_rows, params.nnz, raft::Compare())); + ASSERT_TRUE(raft::devArrMatch(verify.data(), in_rows.data(), params.nnz, + raft::Compare())); delete[] in_rows_h; delete[] in_cols_h; delete[] verify_h; - CUDA_CHECK(cudaFree(in_rows)); - CUDA_CHECK(cudaFree(in_cols)); - CUDA_CHECK(cudaFree(in_vals)); - CUDA_CHECK(cudaFree(verify)); CUDA_CHECK(cudaStreamDestroy(stream)); } diff --git a/cpp/test/sparse/symmetrize.cu b/cpp/test/sparse/symmetrize.cu index 35233dc473..3acd4615fe 100644 --- a/cpp/test/sparse/symmetrize.cu +++ b/cpp/test/sparse/symmetrize.cu @@ -59,29 +59,27 @@ template template class SparseSymmetrizeTest : public ::testing::TestWithParam< SparseSymmetrizeInputs> { + public: + SparseSymmetrizeTest() + : params(::testing::TestWithParam< + SparseSymmetrizeInputs>::GetParam()), + stream(handle.get_stream()), + indptr(params.indptr_h.size(), stream), + indices(params.indices_h.size(), stream), + data(params.data_h.size(), stream) {} + protected: void make_data() { std::vector indptr_h = params.indptr_h; std::vector indices_h = params.indices_h; std::vector data_h = params.data_h; - raft::allocate(indptr, indptr_h.size(), stream); - raft::allocate(indices, indices_h.size(), stream); - raft::allocate(data, data_h.size(), stream); - - update_device(indptr, indptr_h.data(), indptr_h.size(), stream); - update_device(indices, indices_h.data(), indices_h.size(), stream); - update_device(data, data_h.data(), data_h.size(), stream); + update_device(indptr.data(), indptr_h.data(), indptr_h.size(), stream); + update_device(indices.data(), indices_h.data(), indices_h.size(), stream); + update_device(data.data(), data_h.data(), data_h.size(), stream); } void SetUp() override { - params = ::testing::TestWithParam< - SparseSymmetrizeInputs>::GetParam(); - - raft::handle_t handle; - - stream = handle.get_stream(); - make_data(); value_idx m = params.indptr_h.size() - 1; @@ -90,12 +88,13 @@ class SparseSymmetrizeTest : public ::testing::TestWithParam< rmm::device_uvector coo_rows(nnz, stream); - raft::sparse::convert::csr_to_coo(indptr, m, coo_rows.data(), nnz, stream); + raft::sparse::convert::csr_to_coo(indptr.data(), m, coo_rows.data(), nnz, + stream); raft::sparse::COO out(stream); - raft::sparse::linalg::symmetrize(handle, coo_rows.data(), indices, data, m, - n, coo_rows.size(), out); + raft::sparse::linalg::symmetrize(handle, coo_rows.data(), indices.data(), + data.data(), m, n, coo_rows.size(), out); rmm::device_scalar sum(stream); sum.set_value_to_zero_async(stream); @@ -107,19 +106,13 @@ class SparseSymmetrizeTest : public ::testing::TestWithParam< CUDA_CHECK(cudaStreamSynchronize(stream)); } - void TearDown() override { - CUDA_CHECK(cudaStreamSynchronize(stream)); - CUDA_CHECK(cudaFree(indptr)); - CUDA_CHECK(cudaFree(indices)); - CUDA_CHECK(cudaFree(data)); - } - protected: + raft::handle_t handle; cudaStream_t stream; // input data - value_idx *indptr, *indices; - value_t *data; + rmm::device_uvector indptr, indices; + rmm::device_uvector data; value_idx sum_h; diff --git a/cpp/test/spatial/haversine.cu b/cpp/test/spatial/haversine.cu index 122d7f2d6a..ea8e7fd9f3 100644 --- a/cpp/test/spatial/haversine.cu +++ b/cpp/test/spatial/haversine.cu @@ -18,6 +18,7 @@ #include #include #include +#include #include #include "../test_utils.h" @@ -27,20 +28,27 @@ namespace knn { template class HaversineKNNTest : public ::testing::Test { + public: + HaversineKNNTest() + : stream(handle.get_stream()), + d_train_inputs(n * d, stream), + d_ref_I(n * n, stream), + d_ref_D(n * n, stream), + d_pred_I(n * n, stream), + d_pred_D(n * n, stream) {} + protected: void basicTest() { - CUDA_CHECK(cudaStreamCreate(&stream)); - // Allocate input - raft::allocate(d_train_inputs, n * d, stream); + d_train_inputs.resize(n * d, stream); // Allocate reference arrays - raft::allocate(d_ref_I, n * n, stream); - raft::allocate(d_ref_D, n * n, stream); + d_ref_I.resize(n * n, stream); + d_ref_D.resize(n * n, stream); // Allocate predicted arrays - raft::allocate(d_pred_I, n * n, stream); - raft::allocate(d_pred_D, n * n, stream); + d_pred_I.resize(n * n, stream); + d_pred_D.resize(n * n, stream); // make testdata on host std::vector h_train_inputs = { @@ -49,7 +57,8 @@ class HaversineKNNTest : public ::testing::Test { 0.53154002, -1.47049808, 0.72891737, -1.54095137}; h_train_inputs.resize(n); - raft::update_device(d_train_inputs, h_train_inputs.data(), n * d, stream); + raft::update_device(d_train_inputs.data(), h_train_inputs.data(), n * d, + stream); std::vector h_res_D = { 0., 0.05041587, 0.18767063, 0.23048252, 0.35749438, 0.62925595, @@ -59,54 +68,52 @@ class HaversineKNNTest : public ::testing::Test { 0., 0.16461092, 0.20535265, 0.23048252, 0.2426416, 0.5170737, 0., 0.152463, 0.18767063, 0.20535265, 0.2345792, 0.44288665}; h_res_D.resize(n * n); - raft::update_device(d_ref_D, h_res_D.data(), n * n, stream); + raft::update_device(d_ref_D.data(), h_res_D.data(), n * n, stream); std::vector h_res_I = {0, 2, 5, 4, 3, 1, 1, 3, 5, 4, 2, 0, 2, 0, 5, 4, 3, 1, 3, 4, 5, 2, 0, 1, 4, 3, 5, 0, 2, 1, 5, 2, 0, 4, 3, 1}; h_res_I.resize(n * n); - raft::update_device(d_ref_I, h_res_I.data(), n * n, stream); + raft::update_device(d_ref_I.data(), h_res_I.data(), n * n, + stream); - std::vector input_vec = {d_train_inputs}; + std::vector input_vec = {d_train_inputs.data()}; std::vector sizes_vec = {n}; raft::spatial::knn::detail::haversine_knn( - d_pred_I, d_pred_D, d_train_inputs, d_train_inputs, n, n, k, stream); + d_pred_I.data(), d_pred_D.data(), d_train_inputs.data(), + d_train_inputs.data(), n, n, k, stream); CUDA_CHECK(cudaStreamSynchronize(stream)); } void SetUp() override { basicTest(); } - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); - } - protected: - value_t *d_train_inputs; + rmm::device_uvector d_train_inputs; int n = 6; int d = 2; int k = 6; - value_idx *d_pred_I; - value_t *d_pred_D; + rmm::device_uvector d_pred_I; + rmm::device_uvector d_pred_D; - value_idx *d_ref_I; - value_t *d_ref_D; + rmm::device_uvector d_ref_I; + rmm::device_uvector d_ref_D; + raft::handle_t handle; cudaStream_t stream; }; typedef HaversineKNNTest HaversineKNNTestF; TEST_F(HaversineKNNTestF, Fit) { - ASSERT_TRUE(raft::devArrMatch(d_ref_D, d_pred_D, n * n, + ASSERT_TRUE(raft::devArrMatch(d_ref_D.data(), d_pred_D.data(), n * n, raft::CompareApprox(1e-3))); - ASSERT_TRUE( - raft::devArrMatch(d_ref_I, d_pred_I, n * n, raft::Compare())); + ASSERT_TRUE(raft::devArrMatch(d_ref_I.data(), d_pred_I.data(), n * n, + raft::Compare())); } } // namespace knn diff --git a/cpp/test/spatial/knn.cu b/cpp/test/spatial/knn.cu index 7c70f6ffac..09557ae890 100644 --- a/cpp/test/spatial/knn.cu +++ b/cpp/test/spatial/knn.cu @@ -58,45 +58,52 @@ __global__ void build_expected_output(int *output, int n_rows, int k, template class KNNTest : public ::testing::TestWithParam { + public: + KNNTest() + : params_(::testing::TestWithParam::GetParam()), + stream(handle.get_stream()), + rows_(params_.input.size()), + cols_(params_.input[0].size()), + k_(params_.k), + actual_labels_(rows_ * k_, stream), + expected_labels_(rows_ * k_, stream), + input_(rows_ * cols_, stream), + search_data_(rows_ * cols_, stream), + indices_(rows_ * k_, stream), + distances_(rows_ * k_, stream), + search_labels_(rows_, stream) {} + protected: void testBruteForce() { - raft::print_device_vector("Input array: ", input_, rows_ * cols_, + raft::print_device_vector("Input array: ", input_.data(), rows_ * cols_, std::cout); std::cout << "K: " << k_ << "\n"; - raft::print_device_vector("Labels array: ", search_labels_, rows_, + raft::print_device_vector("Labels array: ", search_labels_.data(), rows_, std::cout); - auto stream = handle_.get_stream(); - - raft::allocate(actual_labels_, rows_ * k_, stream, true); - raft::allocate(expected_labels_, rows_ * k_, stream, true); - std::vector input_vec; std::vector sizes_vec; - input_vec.push_back(input_); + input_vec.push_back(input_.data()); sizes_vec.push_back(rows_); - brute_force_knn(handle_, input_vec, sizes_vec, cols_, search_data_, rows_, - indices_, distances_, k_, true, true); + brute_force_knn(handle, input_vec, sizes_vec, cols_, search_data_.data(), + rows_, indices_.data(), distances_.data(), k_, true, true); build_actual_output<<>>( - actual_labels_, rows_, k_, search_labels_, indices_); + actual_labels_.data(), rows_, k_, search_labels_.data(), indices_.data()); build_expected_output<<>>( - expected_labels_, rows_, k_, search_labels_); + expected_labels_.data(), rows_, k_, search_labels_.data()); - ASSERT_TRUE(devArrMatch(expected_labels_, actual_labels_, rows_ * k_, - raft::Compare())); + ASSERT_TRUE(devArrMatch(expected_labels_.data(), actual_labels_.data(), + rows_ * k_, raft::Compare())); } void SetUp() override { - params_ = ::testing::TestWithParam::GetParam(); rows_ = params_.input.size(); cols_ = params_.input[0].size(); k_ = params_.k; - cudaStream_t stream = handle_.get_stream(); - std::vector row_major_input; for (std::size_t i = 0; i < params_.input.size(); ++i) { for (std::size_t j = 0; j < params_.input[i].size(); ++j) { @@ -111,36 +118,28 @@ class KNNTest : public ::testing::TestWithParam { params_.labels.data(), params_.labels.size() * sizeof(int), stream); int *labels_ptr = static_cast(labels_d.data()); - raft::allocate(input_, rows_ * cols_, stream, true); - raft::allocate(search_data_, rows_ * cols_, stream, true); - raft::allocate(indices_, rows_ * k_, stream, true); - raft::allocate(distances_, rows_ * k_, stream, true); - raft::allocate(search_labels_, rows_, stream, true); - - raft::copy(input_, input_ptr, rows_ * cols_, stream); - raft::copy(search_data_, input_ptr, rows_ * cols_, stream); - raft::copy(search_labels_, labels_ptr, rows_, stream); - } - - void TearDown() override { - cudaStream_t stream = handle_.get_stream(); - raft::deallocate_all(stream); + raft::copy(input_.data(), input_ptr, rows_ * cols_, stream); + raft::copy(search_data_.data(), input_ptr, rows_ * cols_, stream); + raft::copy(search_labels_.data(), labels_ptr, rows_, stream); + CUDA_CHECK(cudaStreamSynchronize(stream)); } private: - raft::handle_t handle_; KNNInputs params_; int rows_; int cols_; - float *input_; - float *search_data_; - int64_t *indices_; - float *distances_; + rmm::device_uvector input_; + rmm::device_uvector search_data_; + rmm::device_uvector indices_; + rmm::device_uvector distances_; int k_; - int *search_labels_; - int *actual_labels_; - int *expected_labels_; + rmm::device_uvector search_labels_; + rmm::device_uvector actual_labels_; + rmm::device_uvector expected_labels_; + + raft::handle_t handle; + cudaStream_t stream; }; const std::vector inputs = { diff --git a/cpp/test/spatial/selection.cu b/cpp/test/spatial/selection.cu index a7f1af6034..727eecd7ee 100644 --- a/cpp/test/spatial/selection.cu +++ b/cpp/test/spatial/selection.cu @@ -53,77 +53,73 @@ template template class SparseSelectionTest : public ::testing::TestWithParam> { + public: + SparseSelectionTest() + : params(::testing::TestWithParam< + SparseSelectionInputs>::GetParam()), + stream(handle.get_stream()), + n_rows(params.n_rows), + n_cols(params.n_cols), + k(params.k), + dists(n_rows * n_cols, stream), + inds(n_rows * n_cols, stream), + out_indices_ref(params.out_indices_ref_h.size(), stream), + out_dists_ref(params.out_dists_ref_h.size(), stream), + out_dists(n_rows * k, stream), + out_indices(n_rows * k, stream) {} + protected: void make_data() { std::vector dists_h = params.dists_h; - raft::allocate(dists, n_rows * n_cols, stream); - update_device(dists, dists_h.data(), dists_h.size(), stream); + update_device(dists.data(), dists_h.data(), dists_h.size(), stream); - raft::allocate(inds, n_rows * n_cols, stream); - iota_fill(inds, n_rows, n_cols, stream); + iota_fill(inds.data(), n_rows, n_cols, stream); std::vector out_dists_ref_h = params.out_dists_ref_h; std::vector out_indices_ref_h = params.out_indices_ref_h; - raft::allocate(out_indices_ref, out_indices_ref_h.size(), stream); - raft::allocate(out_dists_ref, out_dists_ref_h.size(), stream); - - update_device(out_indices_ref, out_indices_ref_h.data(), + update_device(out_indices_ref.data(), out_indices_ref_h.data(), out_indices_ref_h.size(), stream); - update_device(out_dists_ref, out_dists_ref_h.data(), out_dists_ref_h.size(), - stream); - - raft::allocate(out_dists, n_rows * k, stream); - raft::allocate(out_indices, n_rows * k, stream); + update_device(out_dists_ref.data(), out_dists_ref_h.data(), + out_dists_ref_h.size(), stream); } void SetUp() override { - params = ::testing::TestWithParam< - SparseSelectionInputs>::GetParam(); - CUDA_CHECK(cudaStreamCreate(&stream)); - - n_rows = params.n_rows; - n_cols = params.n_cols; - k = params.k; - make_data(); - raft::spatial::knn::select_k(dists, inds, n_rows, n_cols, out_dists, - out_indices, params.select_min, k, stream); + raft::spatial::knn::select_k(dists.data(), inds.data(), n_rows, n_cols, + out_dists.data(), out_indices.data(), + params.select_min, k, stream); CUDA_CHECK(cudaStreamSynchronize(stream)); } - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); - } - void compare() { - ASSERT_TRUE( - devArrMatch(out_dists_ref, out_dists, n_rows * k, Compare())); - ASSERT_TRUE(devArrMatch(out_indices_ref, out_indices, n_rows * k, - Compare())); + ASSERT_TRUE(devArrMatch(out_dists_ref.data(), out_dists.data(), n_rows * k, + Compare())); + ASSERT_TRUE(devArrMatch(out_indices_ref.data(), out_indices.data(), + n_rows * k, Compare())); } protected: - cudaStream_t stream; - int n_rows, n_cols, k; // input data - value_t *dists; - value_idx *inds; + rmm::device_uvector dists; + rmm::device_uvector inds; // output data - value_idx *out_indices; - value_t *out_dists; + rmm::device_uvector out_indices; + rmm::device_uvector out_dists; - value_idx *out_indices_ref; - value_t *out_dists_ref; + rmm::device_uvector out_indices_ref; + rmm::device_uvector out_dists_ref; SparseSelectionInputs params; + + raft::handle_t handle; + cudaStream_t stream; }; const std::vector> inputs_i32_f = { diff --git a/cpp/test/stats/mean.cu b/cpp/test/stats/mean.cu index a3c88a92be..de4a2e4507 100644 --- a/cpp/test/stats/mean.cu +++ b/cpp/test/stats/mean.cu @@ -41,37 +41,35 @@ template template class MeanTest : public ::testing::TestWithParam> { + public: + MeanTest() + : params(::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + rows(params.rows), + cols(params.cols), + data(rows * cols, stream), + mean_act(rows * cols, stream) {} + protected: void SetUp() override { - params = ::testing::TestWithParam>::GetParam(); raft::random::Rng r(params.seed); - - int rows = params.rows, cols = params.cols; int len = rows * cols; - - CUDA_CHECK(cudaStreamCreate(&stream)); - - raft::allocate(data, len, stream); - raft::allocate(mean_act, cols, stream); - r.normal(data, len, params.mean, (T)1.0, stream); - - meanSGtest(data, stream); + r.normal(data.data(), len, params.mean, (T)1.0, stream); + meanSGtest(data.data(), stream); } void meanSGtest(T *data, cudaStream_t stream) { int rows = params.rows, cols = params.cols; - - mean(mean_act, data, cols, rows, params.sample, params.rowMajor, stream); - } - - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); + mean(mean_act.data(), data, cols, rows, params.sample, params.rowMajor, + stream); } protected: MeanInputs params; - T *data, *mean_act; + int rows, cols; + rmm::device_uvector data, mean_act; + + raft::handle_t handle; cudaStream_t stream; }; @@ -116,13 +114,13 @@ const std::vector> inputsd = { typedef MeanTest MeanTestF; TEST_P(MeanTestF, Result) { - ASSERT_TRUE(devArrMatch(params.mean, mean_act, params.cols, + ASSERT_TRUE(devArrMatch(params.mean, mean_act.data(), params.cols, CompareApprox(params.tolerance))); } typedef MeanTest MeanTestD; TEST_P(MeanTestD, Result) { - ASSERT_TRUE(devArrMatch(params.mean, mean_act, params.cols, + ASSERT_TRUE(devArrMatch(params.mean, mean_act.data(), params.cols, CompareApprox(params.tolerance))); } diff --git a/cpp/test/stats/mean_center.cu b/cpp/test/stats/mean_center.cu index b827230b5d..13eb3546b5 100644 --- a/cpp/test/stats/mean_center.cu +++ b/cpp/test/stats/mean_center.cu @@ -42,39 +42,39 @@ template template class MeanCenterTest : public ::testing::TestWithParam> { + public: + MeanCenterTest() + : params( + ::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + rows(params.rows), + cols(params.cols), + out(rows * cols, stream), + out_ref(rows * cols, stream), + data(rows * cols, stream), + meanVec(params.bcastAlongRows ? cols : rows, stream) {} + protected: void SetUp() override { - params = ::testing::TestWithParam>::GetParam(); raft::random::Rng r(params.seed); - - CUDA_CHECK(cudaStreamCreate(&stream)); - - auto rows = params.rows, cols = params.cols; auto len = rows * cols; - IdxType vecLen = params.bcastAlongRows ? cols : rows; - - raft::allocate(out, len, stream); - raft::allocate(out_ref, len, stream); - raft::allocate(data, len, stream); - raft::allocate(meanVec, vecLen, stream); - r.normal(data, len, params.mean, (T)1.0, stream); - raft::stats::mean(meanVec, data, cols, rows, params.sample, params.rowMajor, - stream); - meanCenter(out, data, meanVec, cols, rows, params.rowMajor, - params.bcastAlongRows, stream); - raft::linalg::naiveMatVec(out_ref, data, meanVec, cols, rows, - params.rowMajor, params.bcastAlongRows, (T)-1.0); + r.normal(data.data(), len, params.mean, (T)1.0, stream); + raft::stats::mean(meanVec.data(), data.data(), cols, rows, params.sample, + params.rowMajor, stream); + meanCenter(out.data(), data.data(), meanVec.data(), cols, rows, + params.rowMajor, params.bcastAlongRows, stream); + raft::linalg::naiveMatVec(out_ref.data(), data.data(), meanVec.data(), cols, + rows, params.rowMajor, params.bcastAlongRows, + (T)-1.0); CUDA_CHECK(cudaStreamSynchronize(stream)); } - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); - } - protected: MeanCenterInputs params; - T *data, *meanVec, *out, *out_ref; + int rows, cols; + rmm::device_uvector data, meanVec, out, out_ref; + + raft::handle_t handle; cudaStream_t stream; }; @@ -105,7 +105,7 @@ const std::vector> inputsf_i32 = { {0.05f, -1.f, 1024, 128, false, true, false, 1234ULL}}; typedef MeanCenterTest MeanCenterTestF_i32; TEST_P(MeanCenterTestF_i32, Result) { - ASSERT_TRUE(devArrMatch(out, out_ref, params.cols, + ASSERT_TRUE(devArrMatch(out.data(), out_ref.data(), params.cols, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_SUITE_P(MeanCenterTests, MeanCenterTestF_i32, @@ -138,7 +138,7 @@ const std::vector> inputsf_i64 = { {0.05f, -1.f, 1024, 128, false, true, false, 1234ULL}}; typedef MeanCenterTest MeanCenterTestF_i64; TEST_P(MeanCenterTestF_i64, Result) { - ASSERT_TRUE(devArrMatch(out, out_ref, params.cols, + ASSERT_TRUE(devArrMatch(out.data(), out_ref.data(), params.cols, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_SUITE_P(MeanCenterTests, MeanCenterTestF_i64, @@ -171,7 +171,7 @@ const std::vector> inputsd_i32 = { {0.05, -1.0, 1024, 128, false, true, false, 1234ULL}}; typedef MeanCenterTest MeanCenterTestD_i32; TEST_P(MeanCenterTestD_i32, Result) { - ASSERT_TRUE(devArrMatch(out, out_ref, params.cols, + ASSERT_TRUE(devArrMatch(out.data(), out_ref.data(), params.cols, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_SUITE_P(MeanCenterTests, MeanCenterTestD_i32, @@ -204,7 +204,7 @@ const std::vector> inputsd_i64 = { {0.05, -1.0, 1024, 128, false, true, false, 1234ULL}}; typedef MeanCenterTest MeanCenterTestD_i64; TEST_P(MeanCenterTestD_i64, Result) { - ASSERT_TRUE(devArrMatch(out, out_ref, params.cols, + ASSERT_TRUE(devArrMatch(out.data(), out_ref.data(), params.cols, raft::CompareApprox(params.tolerance))); } INSTANTIATE_TEST_SUITE_P(MeanCenterTests, MeanCenterTestD_i64, diff --git a/cpp/test/stats/stddev.cu b/cpp/test/stats/stddev.cu index fd374249d2..99720cdbef 100644 --- a/cpp/test/stats/stddev.cu +++ b/cpp/test/stats/stddev.cu @@ -40,45 +40,52 @@ template template class StdDevTest : public ::testing::TestWithParam> { + public: + StdDevTest() + : params(::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + rows(params.rows), + cols(params.cols), + data(rows * cols, stream), + mean_act(cols, stream), + stddev_act(cols, stream), + vars_act(cols, stream) {} + protected: void SetUp() override { - params = ::testing::TestWithParam>::GetParam(); random::Rng r(params.seed); - int rows = params.rows, cols = params.cols; int len = rows * cols; - CUDA_CHECK(cudaStreamCreate(&stream)); - raft::allocate(data, len, stream); - raft::allocate(mean_act, cols, stream); - raft::allocate(stddev_act, cols, stream); - raft::allocate(vars_act, cols, stream); - r.normal(data, len, params.mean, params.stddev, stream); - stdVarSGtest(data, stream); + data.resize(len, stream); + mean_act.resize(cols, stream); + stddev_act.resize(cols, stream); + vars_act.resize(cols, stream); + r.normal(data.data(), len, params.mean, params.stddev, stream); + stdVarSGtest(data.data(), stream); CUDA_CHECK(cudaStreamSynchronize(stream)); } void stdVarSGtest(T *data, cudaStream_t stream) { int rows = params.rows, cols = params.cols; - mean(mean_act, data, cols, rows, params.sample, params.rowMajor, stream); + mean(mean_act.data(), data, cols, rows, params.sample, params.rowMajor, + stream); - stddev(stddev_act, data, mean_act, cols, rows, params.sample, + stddev(stddev_act.data(), data, mean_act.data(), cols, rows, params.sample, params.rowMajor, stream); - vars(vars_act, data, mean_act, cols, rows, params.sample, params.rowMajor, - stream); - - raft::matrix::seqRoot(vars_act, T(1), cols, stream); - } + vars(vars_act.data(), data, mean_act.data(), cols, rows, params.sample, + params.rowMajor, stream); - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); + raft::matrix::seqRoot(vars_act.data(), T(1), cols, stream); } protected: StdDevInputs params; - T *data, *mean_act, *stddev_act, *vars_act; + int rows, cols; + rmm::device_uvector data, mean_act, stddev_act, vars_act; + + raft::handle_t handle; cudaStream_t stream; }; @@ -120,19 +127,19 @@ const std::vector> inputsd = { typedef StdDevTest StdDevTestF; TEST_P(StdDevTestF, Result) { - ASSERT_TRUE(devArrMatch(params.stddev, stddev_act, params.cols, + ASSERT_TRUE(devArrMatch(params.stddev, stddev_act.data(), params.cols, CompareApprox(params.tolerance))); - ASSERT_TRUE(devArrMatch(stddev_act, vars_act, params.cols, + ASSERT_TRUE(devArrMatch(stddev_act.data(), vars_act.data(), params.cols, CompareApprox(params.tolerance))); } typedef StdDevTest StdDevTestD; TEST_P(StdDevTestD, Result) { - ASSERT_TRUE(devArrMatch(params.stddev, stddev_act, params.cols, + ASSERT_TRUE(devArrMatch(params.stddev, stddev_act.data(), params.cols, CompareApprox(params.tolerance))); - ASSERT_TRUE(devArrMatch(stddev_act, vars_act, params.cols, + ASSERT_TRUE(devArrMatch(stddev_act.data(), vars_act.data(), params.cols, CompareApprox(params.tolerance))); } diff --git a/cpp/test/stats/sum.cu b/cpp/test/stats/sum.cu index 58ebec7859..6bfd1f3a30 100644 --- a/cpp/test/stats/sum.cu +++ b/cpp/test/stats/sum.cu @@ -38,34 +38,35 @@ template template class SumTest : public ::testing::TestWithParam> { + public: + SumTest() + : params(::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), + rows(params.rows), + cols(params.cols), + data(rows * cols, stream), + sum_act(cols, stream) {} + protected: void SetUp() override { - params = ::testing::TestWithParam>::GetParam(); - int rows = params.rows, cols = params.cols; int len = rows * cols; - CUDA_CHECK(cudaStreamCreate(&stream)); - raft::allocate(data, len, stream); T data_h[len]; for (int i = 0; i < len; i++) { data_h[i] = T(1); } - raft::update_device(data, data_h, len, stream); - - raft::allocate(sum_act, cols, stream); - sum(sum_act, data, cols, rows, false, stream); + raft::update_device(data.data(), data_h, len, stream); + sum(sum_act.data(), data.data(), cols, rows, false, stream); CUDA_CHECK(cudaStreamSynchronize(stream)); } - void TearDown() override { - raft::deallocate_all(stream); - CUDA_CHECK(cudaStreamDestroy(stream)); - } - protected: SumInputs params; - T *data, *sum_act; + int rows, cols; + rmm::device_uvector data, sum_act; + + raft::handle_t handle; cudaStream_t stream; }; @@ -77,13 +78,14 @@ const std::vector> inputsd = {{0.05, 1024, 32, 1234ULL}, typedef SumTest SumTestF; TEST_P(SumTestF, Result) { - ASSERT_TRUE(raft::devArrMatch(float(params.rows), sum_act, params.cols, + ASSERT_TRUE(raft::devArrMatch(float(params.rows), sum_act.data(), params.cols, raft::CompareApprox(params.tolerance))); } typedef SumTest SumTestD; TEST_P(SumTestD, Result) { - ASSERT_TRUE(raft::devArrMatch(double(params.rows), sum_act, params.cols, + ASSERT_TRUE(raft::devArrMatch(double(params.rows), sum_act.data(), + params.cols, raft::CompareApprox(params.tolerance))); } From cb04bdab4a9494945514af7e5c1dd1f68fb3eb9c Mon Sep 17 00:00:00 2001 From: viclafargue Date: Wed, 13 Oct 2021 13:39:23 +0200 Subject: [PATCH 2/3] Fix of Gtests --- cpp/test/random/rng.cu | 11 ++++++--- cpp/test/random/rng_int.cu | 7 ++++-- cpp/test/sparse/convert_csr.cu | 4 ++++ cpp/test/sparse/csr_row_slice.cu | 28 +++++++++++++++------- cpp/test/sparse/csr_to_dense.cu | 16 +++++++++---- cpp/test/sparse/csr_transpose.cu | 28 +++++++++++++++------- cpp/test/sparse/degree.cu | 10 ++++++++ cpp/test/sparse/knn_graph.cu | 4 +++- cpp/test/sparse/symmetrize.cu | 16 ++++++++----- cpp/test/spatial/knn.cu | 40 ++++++++++++++++++++++++-------- cpp/test/spatial/selection.cu | 27 +++++++++++++-------- 11 files changed, 136 insertions(+), 55 deletions(-) diff --git a/cpp/test/random/rng.cu b/cpp/test/random/rng.cu index 511effbb93..2b4ee992c8 100644 --- a/cpp/test/random/rng.cu +++ b/cpp/test/random/rng.cu @@ -83,8 +83,11 @@ class RngTest : public ::testing::TestWithParam> { RngTest() : params(::testing::TestWithParam>::GetParam()), stream(handle.get_stream()), - data(params.len, stream), - stats(2, stream) {} + data(0, stream), + stats(2, stream) { + data.resize(params.len, stream); + CUDA_CHECK(cudaMemsetAsync(stats.data(), 0, 2 * sizeof(T), stream)); + } protected: void SetUp() override { @@ -511,7 +514,9 @@ class RngNormalTableTest stream(handle.get_stream()), data(params.rows * params.cols, stream), stats(2, stream), - mu_vec(params.cols, stream) {} + mu_vec(params.cols, stream) { + CUDA_CHECK(cudaMemsetAsync(stats.data(), 0, 2 * sizeof(T), stream)); + } protected: void SetUp() override { diff --git a/cpp/test/random/rng_int.cu b/cpp/test/random/rng_int.cu index 8bf5aaac77..cf9da9e2ff 100644 --- a/cpp/test/random/rng_int.cu +++ b/cpp/test/random/rng_int.cu @@ -69,8 +69,11 @@ class RngTest : public ::testing::TestWithParam> { RngTest() : params(::testing::TestWithParam>::GetParam()), stream(handle.get_stream()), - data(params.len, stream), - stats(2, stream) {} + data(0, stream), + stats(2, stream) { + data.resize(params.len, stream); + CUDA_CHECK(cudaMemsetAsync(stats.data(), 0, 2 * sizeof(float), stream)); + } protected: void SetUp() override { diff --git a/cpp/test/sparse/convert_csr.cu b/cpp/test/sparse/convert_csr.cu index 72b6acb34b..f67104bcac 100644 --- a/cpp/test/sparse/convert_csr.cu +++ b/cpp/test/sparse/convert_csr.cu @@ -69,6 +69,9 @@ TEST_P(SortedCOOToCSR, Result) { rmm::device_uvector in(nnz, stream); rmm::device_uvector exp(4, stream); rmm::device_uvector out(4, stream); + CUDA_CHECK(cudaMemsetAsync(in.data(), 0, in.size() * sizeof(int), stream)); + CUDA_CHECK(cudaMemsetAsync(exp.data(), 0, exp.size() * sizeof(int), stream)); + CUDA_CHECK(cudaMemsetAsync(out.data(), 0, out.size() * sizeof(int), stream)); raft::update_device(in.data(), in_h, nnz, stream); raft::update_device(exp.data(), exp_h, 4, stream); @@ -104,6 +107,7 @@ class CSRAdjGraphTest public: CSRAdjGraphTest() : params(::testing::TestWithParam>::GetParam()), + stream(handle.get_stream()), row_ind(params.n_rows, stream), adj(params.n_rows * params.n_cols, stream), result(params.verify.size(), stream), diff --git a/cpp/test/sparse/csr_row_slice.cu b/cpp/test/sparse/csr_row_slice.cu index b58ef56d33..ff9ee22817 100644 --- a/cpp/test/sparse/csr_row_slice.cu +++ b/cpp/test/sparse/csr_row_slice.cu @@ -60,15 +60,25 @@ class CSRRowSliceTest : params(::testing::TestWithParam< CSRRowSliceInputs>::GetParam()), stream(handle.get_stream()), - indptr(params.indptr_h.size(), stream), - indices(params.indices_h.size(), stream), - data(params.data_h.size(), stream), - out_indptr_ref(params.out_indptr_ref_h.size(), stream), - out_indices_ref(params.out_indices_ref_h.size(), stream), - out_data_ref(params.out_data_ref_h.size(), stream), - out_indptr(params.out_indptr_ref_h.size(), stream), - out_indices(params.out_indices_ref_h.size(), stream), - out_data(params.out_data_ref_h.size(), stream) {} + indptr(0, stream), + indices(0, stream), + data(0, stream), + out_indptr_ref(0, stream), + out_indices_ref(0, stream), + out_data_ref(0, stream), + out_indptr(0, stream), + out_indices(0, stream), + out_data(0, stream) { + indptr.resize(params.indptr_h.size(), stream); + indices.resize(params.indices_h.size(), stream); + data.resize(params.data_h.size(), stream); + out_indptr_ref.resize(params.out_indptr_ref_h.size(), stream); + out_indices_ref.resize(params.out_indices_ref_h.size(), stream); + out_data_ref.resize(params.out_data_ref_h.size(), stream); + out_indptr.resize(params.out_indptr_ref_h.size(), stream); + out_indices.resize(params.out_indices_ref_h.size(), stream); + out_data.resize(params.out_data_ref_h.size(), stream); + } protected: void make_data() { diff --git a/cpp/test/sparse/csr_to_dense.cu b/cpp/test/sparse/csr_to_dense.cu index 256fd89183..5f5af00f6c 100644 --- a/cpp/test/sparse/csr_to_dense.cu +++ b/cpp/test/sparse/csr_to_dense.cu @@ -58,11 +58,17 @@ class CSRToDenseTest : params(::testing::TestWithParam< CSRToDenseInputs>::GetParam()), stream(raft_handle.get_stream()), - indptr(params.indptr_h.size(), stream), - indices(params.indices_h.size(), stream), - data(params.data_h.size(), stream), - out_ref(params.out_ref_h.size(), stream), - out(params.out_ref_h.size(), stream) {} + indptr(0, stream), + indices(0, stream), + data(0, stream), + out_ref(0, stream), + out(0, stream) { + indptr.resize(params.indptr_h.size(), stream); + indices.resize(params.indices_h.size(), stream); + data.resize(params.data_h.size(), stream); + out_ref.resize(params.out_ref_h.size(), stream); + out.resize(params.out_ref_h.size(), stream); + } protected: void make_data() { diff --git a/cpp/test/sparse/csr_transpose.cu b/cpp/test/sparse/csr_transpose.cu index a8827d065f..ce042c7dc3 100644 --- a/cpp/test/sparse/csr_transpose.cu +++ b/cpp/test/sparse/csr_transpose.cu @@ -60,15 +60,25 @@ class CSRTransposeTest : params(::testing::TestWithParam< CSRTransposeInputs>::GetParam()), stream(raft_handle.get_stream()), - indptr(params.indptr_h.size(), stream), - indices(params.indices_h.size(), stream), - data(params.data_h.size(), stream), - out_indptr_ref(params.out_indptr_ref_h.size(), stream), - out_indices_ref(params.out_indices_ref_h.size(), stream), - out_data_ref(params.out_data_ref_h.size(), stream), - out_indptr(params.out_indptr_ref_h.size(), stream), - out_indices(params.out_indices_ref_h.size(), stream), - out_data(params.out_data_ref_h.size(), stream) {} + indptr(0, stream), + indices(0, stream), + data(0, stream), + out_indptr_ref(0, stream), + out_indices_ref(0, stream), + out_data_ref(0, stream), + out_indptr(0, stream), + out_indices(0, stream), + out_data(0, stream) { + indptr.resize(params.indptr_h.size(), stream); + indices.resize(params.indices_h.size(), stream); + data.resize(params.data_h.size(), stream); + out_indptr_ref.resize(params.out_indptr_ref_h.size(), stream); + out_indices_ref.resize(params.out_indices_ref_h.size(), stream); + out_data_ref.resize(params.out_data_ref_h.size(), stream); + out_indptr.resize(params.out_indptr_ref_h.size(), stream); + out_indices.resize(params.out_indices_ref_h.size(), stream); + out_data.resize(params.out_data_ref_h.size(), stream); + } protected: void make_data() { diff --git a/cpp/test/sparse/degree.cu b/cpp/test/sparse/degree.cu index 7c23c0b3d7..2201702b03 100644 --- a/cpp/test/sparse/degree.cu +++ b/cpp/test/sparse/degree.cu @@ -57,6 +57,10 @@ TEST_P(COODegree, Result) { rmm::device_uvector in_rows(5, stream); rmm::device_uvector verify(5, stream); rmm::device_uvector results(5, stream); + CUDA_CHECK( + cudaMemsetAsync(verify.data(), 0, verify.size() * sizeof(int), stream)); + CUDA_CHECK( + cudaMemsetAsync(results.data(), 0, results.size() * sizeof(int), stream)); raft::update_device(in_rows.data(), *&in_rows_h, 5, stream); raft::update_device(verify.data(), *&verify_h, 5, stream); @@ -83,6 +87,12 @@ TEST_P(COODegreeNonzero, Result) { rmm::device_uvector verify(5, stream); rmm::device_uvector results(5, stream); rmm::device_uvector in_vals(5, stream); + CUDA_CHECK( + cudaMemsetAsync(verify.data(), 0, verify.size() * sizeof(int), stream)); + CUDA_CHECK( + cudaMemsetAsync(results.data(), 0, results.size() * sizeof(int), stream)); + CUDA_CHECK( + cudaMemsetAsync(in_vals.data(), 0, in_vals.size() * sizeof(float), stream)); raft::update_device(in_rows.data(), *&in_rows_h, 5, stream); raft::update_device(verify.data(), *&verify_h, 5, stream); diff --git a/cpp/test/sparse/knn_graph.cu b/cpp/test/sparse/knn_graph.cu index 3256adb3f5..67dc4fe36b 100644 --- a/cpp/test/sparse/knn_graph.cu +++ b/cpp/test/sparse/knn_graph.cu @@ -64,7 +64,9 @@ class KNNGraphTest : params(::testing::TestWithParam< KNNGraphInputs>::GetParam()), stream(handle.get_stream()), - X(params.X.size(), stream) {} + X(0, stream) { + X.resize(params.X.size(), stream); + } protected: void SetUp() override { diff --git a/cpp/test/sparse/symmetrize.cu b/cpp/test/sparse/symmetrize.cu index 3acd4615fe..5b3732a982 100644 --- a/cpp/test/sparse/symmetrize.cu +++ b/cpp/test/sparse/symmetrize.cu @@ -64,9 +64,9 @@ class SparseSymmetrizeTest : public ::testing::TestWithParam< : params(::testing::TestWithParam< SparseSymmetrizeInputs>::GetParam()), stream(handle.get_stream()), - indptr(params.indptr_h.size(), stream), - indices(params.indices_h.size(), stream), - data(params.data_h.size(), stream) {} + indptr(0, stream), + indices(0, stream), + data(0, stream) {} protected: void make_data() { @@ -74,6 +74,10 @@ class SparseSymmetrizeTest : public ::testing::TestWithParam< std::vector indices_h = params.indices_h; std::vector data_h = params.data_h; + indptr.resize(indptr_h.size(), stream); + indices.resize(indices_h.size(), stream); + data.resize(data_h.size(), stream); + update_device(indptr.data(), indptr_h.data(), indptr_h.size(), stream); update_device(indices.data(), indices_h.data(), indices_h.size(), stream); update_device(data.data(), data_h.data(), data_h.size(), stream); @@ -107,9 +111,6 @@ class SparseSymmetrizeTest : public ::testing::TestWithParam< } protected: - raft::handle_t handle; - cudaStream_t stream; - // input data rmm::device_uvector indptr, indices; rmm::device_uvector data; @@ -117,6 +118,9 @@ class SparseSymmetrizeTest : public ::testing::TestWithParam< value_idx sum_h; SparseSymmetrizeInputs params; + + raft::handle_t handle; + cudaStream_t stream; }; template diff --git a/cpp/test/spatial/knn.cu b/cpp/test/spatial/knn.cu index 09557ae890..d2b98a1f6a 100644 --- a/cpp/test/spatial/knn.cu +++ b/cpp/test/spatial/knn.cu @@ -62,16 +62,13 @@ class KNNTest : public ::testing::TestWithParam { KNNTest() : params_(::testing::TestWithParam::GetParam()), stream(handle.get_stream()), - rows_(params_.input.size()), - cols_(params_.input[0].size()), - k_(params_.k), - actual_labels_(rows_ * k_, stream), - expected_labels_(rows_ * k_, stream), - input_(rows_ * cols_, stream), - search_data_(rows_ * cols_, stream), - indices_(rows_ * k_, stream), - distances_(rows_ * k_, stream), - search_labels_(rows_, stream) {} + actual_labels_(0, stream), + expected_labels_(0, stream), + input_(0, stream), + search_data_(0, stream), + indices_(0, stream), + distances_(0, stream), + search_labels_(0, stream) {} protected: void testBruteForce() { @@ -104,6 +101,29 @@ class KNNTest : public ::testing::TestWithParam { cols_ = params_.input[0].size(); k_ = params_.k; + actual_labels_.resize(rows_ * k_, stream); + expected_labels_.resize(rows_ * k_, stream); + input_.resize(rows_ * cols_, stream); + search_data_.resize(rows_ * cols_, stream); + indices_.resize(rows_ * k_, stream); + distances_.resize(rows_ * k_, stream); + search_labels_.resize(rows_, stream); + + CUDA_CHECK(cudaMemsetAsync(actual_labels_.data(), 0, + actual_labels_.size() * sizeof(int), stream)); + CUDA_CHECK(cudaMemsetAsync(expected_labels_.data(), 0, + expected_labels_.size() * sizeof(int), stream)); + CUDA_CHECK( + cudaMemsetAsync(input_.data(), 0, input_.size() * sizeof(float), stream)); + CUDA_CHECK(cudaMemsetAsync(search_data_.data(), 0, + search_data_.size() * sizeof(float), stream)); + CUDA_CHECK(cudaMemsetAsync(indices_.data(), 0, + indices_.size() * sizeof(int64_t), stream)); + CUDA_CHECK(cudaMemsetAsync(distances_.data(), 0, + distances_.size() * sizeof(float), stream)); + CUDA_CHECK(cudaMemsetAsync(search_labels_.data(), 0, + search_labels_.size() * sizeof(int), stream)); + std::vector row_major_input; for (std::size_t i = 0; i < params_.input.size(); ++i) { for (std::size_t j = 0; j < params_.input[i].size(); ++j) { diff --git a/cpp/test/spatial/selection.cu b/cpp/test/spatial/selection.cu index 727eecd7ee..791cf1fcb6 100644 --- a/cpp/test/spatial/selection.cu +++ b/cpp/test/spatial/selection.cu @@ -58,26 +58,29 @@ class SparseSelectionTest : params(::testing::TestWithParam< SparseSelectionInputs>::GetParam()), stream(handle.get_stream()), - n_rows(params.n_rows), - n_cols(params.n_cols), - k(params.k), - dists(n_rows * n_cols, stream), - inds(n_rows * n_cols, stream), - out_indices_ref(params.out_indices_ref_h.size(), stream), - out_dists_ref(params.out_dists_ref_h.size(), stream), - out_dists(n_rows * k, stream), - out_indices(n_rows * k, stream) {} + dists(0, stream), + inds(0, stream), + out_indices_ref(0, stream), + out_dists_ref(0, stream), + out_dists(0, stream), + out_indices(0, stream) {} protected: void make_data() { std::vector dists_h = params.dists_h; - update_device(dists.data(), dists_h.data(), dists_h.size(), stream); + dists.resize(n_rows * n_cols, stream); + inds.resize(n_rows * n_cols, stream); + out_dists.resize(n_rows * k, stream); + out_indices.resize(n_rows * k, stream); + update_device(dists.data(), dists_h.data(), dists_h.size(), stream); iota_fill(inds.data(), n_rows, n_cols, stream); std::vector out_dists_ref_h = params.out_dists_ref_h; std::vector out_indices_ref_h = params.out_indices_ref_h; + out_indices_ref.resize(out_indices_ref_h.size(), stream); + out_dists_ref.resize(out_dists_ref_h.size(), stream); update_device(out_indices_ref.data(), out_indices_ref_h.data(), out_indices_ref_h.size(), stream); @@ -86,6 +89,10 @@ class SparseSelectionTest } void SetUp() override { + n_rows = params.n_rows; + n_cols = params.n_cols; + k = params.k; + make_data(); raft::spatial::knn::select_k(dists.data(), inds.data(), n_rows, n_cols, From 6c1771b52669b0367aa873c6198ace181af41b2d Mon Sep 17 00:00:00 2001 From: viclafargue Date: Thu, 14 Oct 2021 13:32:45 +0200 Subject: [PATCH 3/3] Fix testing --- cpp/test/distance/distance_base.cuh | 5 +++-- cpp/test/distance/fused_l2_nn.cu | 5 +++-- cpp/test/label/merge_labels.cu | 3 ++- cpp/test/linalg/add.cu | 6 +++--- cpp/test/linalg/binary_op.cu | 5 +++-- cpp/test/linalg/cholesky_r1.cu | 3 ++- cpp/test/linalg/coalesced_reduction.cu | 5 +++-- cpp/test/linalg/divide.cu | 5 +++-- cpp/test/linalg/eig.cu | 6 +++--- cpp/test/linalg/eig_sel.cu | 5 +++-- cpp/test/linalg/eltwise.cu | 10 ++++++---- cpp/test/linalg/map.cu | 5 +++-- cpp/test/linalg/map_then_reduce.cu | 8 +++++--- cpp/test/linalg/matrix_vector_op.cu | 5 +++-- cpp/test/linalg/multiply.cu | 5 +++-- cpp/test/linalg/norm.cu | 11 +++++----- cpp/test/linalg/reduce.cu | 5 +++-- cpp/test/linalg/strided_reduction.cu | 5 +++-- cpp/test/linalg/subtract.cu | 5 +++-- cpp/test/linalg/svd.cu | 5 +++-- cpp/test/linalg/transpose.cu | 5 +++-- cpp/test/linalg/unary_op.cu | 5 +++-- cpp/test/matrix/math.cu | 6 +++--- cpp/test/matrix/matrix.cu | 10 ++++++---- cpp/test/random/rng.cu | 20 +++++++++---------- cpp/test/random/rng_int.cu | 6 +++--- cpp/test/random/sample_without_replacement.cu | 6 +++--- cpp/test/sparse/add.cu | 6 +++--- cpp/test/sparse/convert_coo.cu | 6 +++--- cpp/test/sparse/convert_csr.cu | 6 +++--- cpp/test/sparse/csr_row_slice.cu | 6 +++--- cpp/test/sparse/csr_to_dense.cu | 6 +++--- cpp/test/sparse/csr_transpose.cu | 6 +++--- cpp/test/sparse/knn_graph.cu | 6 +++--- cpp/test/sparse/linkage.cu | 6 +++--- cpp/test/sparse/norm.cu | 6 +++--- cpp/test/sparse/row_op.cu | 6 +++--- cpp/test/sparse/symmetrize.cu | 6 +++--- cpp/test/spatial/haversine.cu | 6 +++--- cpp/test/spatial/knn.cu | 6 +++--- cpp/test/spatial/selection.cu | 6 +++--- cpp/test/stats/mean.cu | 6 +++--- cpp/test/stats/mean_center.cu | 6 +++--- cpp/test/stats/stddev.cu | 6 +++--- cpp/test/stats/sum.cu | 6 +++--- 45 files changed, 151 insertions(+), 127 deletions(-) diff --git a/cpp/test/distance/distance_base.cuh b/cpp/test/distance/distance_base.cuh index 946f69753c..a10710e622 100644 --- a/cpp/test/distance/distance_base.cuh +++ b/cpp/test/distance/distance_base.cuh @@ -432,10 +432,11 @@ class DistanceTest : public ::testing::TestWithParam> { } protected: - DistanceInputs params; - rmm::device_uvector x, y, dist_ref, dist, dist2; raft::handle_t handle; cudaStream_t stream; + + DistanceInputs params; + rmm::device_uvector x, y, dist_ref, dist, dist2; }; } // end namespace distance diff --git a/cpp/test/distance/fused_l2_nn.cu b/cpp/test/distance/fused_l2_nn.cu index 0664c35440..33f7dbf828 100644 --- a/cpp/test/distance/fused_l2_nn.cu +++ b/cpp/test/distance/fused_l2_nn.cu @@ -293,11 +293,12 @@ class FusedL2NNDetTest : public FusedL2NNTest { void TearDown() override { FusedL2NNTest::TearDown(); } protected: + raft::handle_t handle; + cudaStream_t stream; + rmm::device_uvector> min1; static const int NumRepeats = 100; - raft::handle_t handle; - cudaStream_t stream; void generateGoldenResult() override {} }; diff --git a/cpp/test/label/merge_labels.cu b/cpp/test/label/merge_labels.cu index 28d8d59884..76e0a4295e 100644 --- a/cpp/test/label/merge_labels.cu +++ b/cpp/test/label/merge_labels.cu @@ -72,9 +72,10 @@ class MergeLabelsTest } protected: - MergeLabelsInputs params; raft::handle_t handle; cudaStream_t stream; + + MergeLabelsInputs params; rmm::device_uvector labels_a, labels_b, expected, R; rmm::device_scalar mask, m; }; diff --git a/cpp/test/linalg/add.cu b/cpp/test/linalg/add.cu index 50eea07b88..eea9df046b 100644 --- a/cpp/test/linalg/add.cu +++ b/cpp/test/linalg/add.cu @@ -53,14 +53,14 @@ class AddTest : public ::testing::TestWithParam> { } protected: + raft::handle_t handle; + cudaStream_t stream; + AddInputs params; rmm::device_uvector in1; rmm::device_uvector in2; rmm::device_uvector out_ref; rmm::device_uvector out; - - raft::handle_t handle; - cudaStream_t stream; }; const std::vector> inputsf = { diff --git a/cpp/test/linalg/binary_op.cu b/cpp/test/linalg/binary_op.cu index e282a49351..b60f04cd34 100644 --- a/cpp/test/linalg/binary_op.cu +++ b/cpp/test/linalg/binary_op.cu @@ -61,13 +61,14 @@ class BinaryOpTest } protected: + raft::handle_t handle; + cudaStream_t stream; + BinaryOpInputs params; rmm::device_uvector in1; rmm::device_uvector in2; rmm::device_uvector out_ref; rmm::device_uvector out; - raft::handle_t handle; - cudaStream_t stream; }; const std::vector> inputsf_i32 = { diff --git a/cpp/test/linalg/cholesky_r1.cu b/cpp/test/linalg/cholesky_r1.cu index 00db1715dc..262a1ad26c 100644 --- a/cpp/test/linalg/cholesky_r1.cu +++ b/cpp/test/linalg/cholesky_r1.cu @@ -105,9 +105,10 @@ class CholeskyR1Test : public ::testing::Test { } raft::handle_t handle; - cusolverDnHandle_t solver_handle; cudaStream_t stream; + cusolverDnHandle_t solver_handle; + int n_rows = 4; int Lwork; math_t G_host[16] = // clang-format off diff --git a/cpp/test/linalg/coalesced_reduction.cu b/cpp/test/linalg/coalesced_reduction.cu index 841cf0d9fe..f17a0f0f5d 100644 --- a/cpp/test/linalg/coalesced_reduction.cu +++ b/cpp/test/linalg/coalesced_reduction.cu @@ -77,12 +77,13 @@ class coalescedReductionTest } protected: + raft::handle_t handle; + cudaStream_t stream; + coalescedReductionInputs params; rmm::device_uvector data; rmm::device_uvector dots_exp; rmm::device_uvector dots_act; - raft::handle_t handle; - cudaStream_t stream; }; const std::vector> inputsf = { diff --git a/cpp/test/linalg/divide.cu b/cpp/test/linalg/divide.cu index 391a6f8b63..430c35f41b 100644 --- a/cpp/test/linalg/divide.cu +++ b/cpp/test/linalg/divide.cu @@ -66,12 +66,13 @@ class DivideTest } protected: + raft::handle_t handle; + cudaStream_t stream; + UnaryOpInputs params; rmm::device_uvector in; rmm::device_uvector out_ref; rmm::device_uvector out; - raft::handle_t handle; - cudaStream_t stream; }; const std::vector> inputsf = { diff --git a/cpp/test/linalg/eig.cu b/cpp/test/linalg/eig.cu index 74870a62bb..87d6c4faa6 100644 --- a/cpp/test/linalg/eig.cu +++ b/cpp/test/linalg/eig.cu @@ -100,6 +100,9 @@ class EigTest : public ::testing::TestWithParam> { } protected: + raft::handle_t handle; + cudaStream_t stream; + EigInputs params; rmm::device_uvector cov_matrix, eig_vectors, eig_vectors_jacobi, @@ -107,9 +110,6 @@ class EigTest : public ::testing::TestWithParam> { rmm::device_uvector cov_matrix_large, eig_vectors_large, eig_vectors_jacobi_large, eig_vals_large, eig_vals_jacobi_large; - - raft::handle_t handle; - cudaStream_t stream; }; const std::vector> inputsf2 = { diff --git a/cpp/test/linalg/eig_sel.cu b/cpp/test/linalg/eig_sel.cu index bd4c95b451..3c75654733 100644 --- a/cpp/test/linalg/eig_sel.cu +++ b/cpp/test/linalg/eig_sel.cu @@ -76,14 +76,15 @@ class EigSelTest : public ::testing::TestWithParam> { } protected: + raft::handle_t handle; + cudaStream_t stream; + EigSelInputs params; rmm::device_uvector cov_matrix; rmm::device_uvector eig_vectors; rmm::device_uvector eig_vectors_ref; rmm::device_uvector eig_vals; rmm::device_uvector eig_vals_ref; - raft::handle_t handle; - cudaStream_t stream; }; const std::vector> inputsf2 = { diff --git a/cpp/test/linalg/eltwise.cu b/cpp/test/linalg/eltwise.cu index 25ecb75f7d..65bd7e4427 100644 --- a/cpp/test/linalg/eltwise.cu +++ b/cpp/test/linalg/eltwise.cu @@ -80,10 +80,11 @@ class ScalarMultiplyTest } protected: - ScalarMultiplyInputs params; - rmm::device_uvector in, out_ref, out; raft::handle_t handle; cudaStream_t stream; + + ScalarMultiplyInputs params; + rmm::device_uvector in, out_ref, out; }; const std::vector> inputsf1 = { @@ -167,10 +168,11 @@ class EltwiseAddTest : public ::testing::TestWithParam> { } protected: - EltwiseAddInputs params; - rmm::device_uvector in1, in2, out_ref, out; raft::handle_t handle; cudaStream_t stream; + + EltwiseAddInputs params; + rmm::device_uvector in1, in2, out_ref, out; }; const std::vector> inputsf2 = { diff --git a/cpp/test/linalg/map.cu b/cpp/test/linalg/map.cu index a5677c0539..271ae13b2e 100644 --- a/cpp/test/linalg/map.cu +++ b/cpp/test/linalg/map.cu @@ -84,11 +84,12 @@ class MapTest } protected: + raft::handle_t handle; + cudaStream_t stream; + MapInputs params; rmm::device_uvector in1, in2, in3; rmm::device_uvector out_ref, out; - raft::handle_t handle; - cudaStream_t stream; }; const std::vector> inputsf_i32 = { diff --git a/cpp/test/linalg/map_then_reduce.cu b/cpp/test/linalg/map_then_reduce.cu index 84d47e8212..e77809def7 100644 --- a/cpp/test/linalg/map_then_reduce.cu +++ b/cpp/test/linalg/map_then_reduce.cu @@ -90,11 +90,12 @@ class MapReduceTest : public ::testing::TestWithParam> { } protected: + raft::handle_t handle; + cudaStream_t stream; + MapReduceInputs params; rmm::device_uvector in; rmm::device_uvector out_ref, out; - raft::handle_t handle; - cudaStream_t stream; }; const std::vector> inputsf = { @@ -168,9 +169,10 @@ class MapGenericReduceTest : public ::testing::Test { } protected: - int n = 1237; raft::handle_t handle; cudaStream_t stream; + + int n = 1237; rmm::device_uvector input; rmm::device_scalar output; }; diff --git a/cpp/test/linalg/matrix_vector_op.cu b/cpp/test/linalg/matrix_vector_op.cu index 3f029de743..28296ad7bd 100644 --- a/cpp/test/linalg/matrix_vector_op.cu +++ b/cpp/test/linalg/matrix_vector_op.cu @@ -92,10 +92,11 @@ class MatVecOpTest } protected: - MatVecOpInputs params; - rmm::device_uvector in, out, out_ref, vec1, vec2; raft::handle_t handle; cudaStream_t stream; + + MatVecOpInputs params; + rmm::device_uvector in, out, out_ref, vec1, vec2; }; const std::vector> inputsf_i32 = { diff --git a/cpp/test/linalg/multiply.cu b/cpp/test/linalg/multiply.cu index 7aedde71ef..d0772e538d 100644 --- a/cpp/test/linalg/multiply.cu +++ b/cpp/test/linalg/multiply.cu @@ -46,10 +46,11 @@ class MultiplyTest : public ::testing::TestWithParam> { } protected: - UnaryOpInputs params; - rmm::device_uvector in, out_ref, out; raft::handle_t handle; cudaStream_t stream; + + UnaryOpInputs params; + rmm::device_uvector in, out_ref, out; }; const std::vector> inputsf = { diff --git a/cpp/test/linalg/norm.cu b/cpp/test/linalg/norm.cu index d248ec6b77..94b703d15e 100644 --- a/cpp/test/linalg/norm.cu +++ b/cpp/test/linalg/norm.cu @@ -96,10 +96,11 @@ class RowNormTest : public ::testing::TestWithParam> { } protected: - NormInputs params; - rmm::device_uvector data, dots_exp, dots_act; raft::handle_t handle; cudaStream_t stream; + + NormInputs params; + rmm::device_uvector data, dots_exp, dots_act; }; ///// Column-wise norm test definitisons @@ -157,11 +158,11 @@ class ColNormTest : public ::testing::TestWithParam> { } protected: - NormInputs params; - rmm::device_uvector data, dots_exp, dots_act; - raft::handle_t handle; cudaStream_t stream; + + NormInputs params; + rmm::device_uvector data, dots_exp, dots_act; }; ///// Row- and column-wise tests diff --git a/cpp/test/linalg/reduce.cu b/cpp/test/linalg/reduce.cu index 304b4b9a68..cf7585dc23 100644 --- a/cpp/test/linalg/reduce.cu +++ b/cpp/test/linalg/reduce.cu @@ -86,12 +86,13 @@ class ReduceTest } protected: + raft::handle_t handle; + cudaStream_t stream; + ReduceInputs params; rmm::device_uvector data; rmm::device_uvector dots_exp, dots_act; int outlen; - raft::handle_t handle; - cudaStream_t stream; }; const std::vector> inputsff = { diff --git a/cpp/test/linalg/strided_reduction.cu b/cpp/test/linalg/strided_reduction.cu index f0bf5410eb..56632a59cc 100644 --- a/cpp/test/linalg/strided_reduction.cu +++ b/cpp/test/linalg/strided_reduction.cu @@ -64,10 +64,11 @@ class stridedReductionTest } protected: - stridedReductionInputs params; - rmm::device_uvector data, dots_exp, dots_act; raft::handle_t handle; cudaStream_t stream; + + stridedReductionInputs params; + rmm::device_uvector data, dots_exp, dots_act; }; const std::vector> inputsf = { diff --git a/cpp/test/linalg/subtract.cu b/cpp/test/linalg/subtract.cu index 945ce8bf88..df3686ee32 100644 --- a/cpp/test/linalg/subtract.cu +++ b/cpp/test/linalg/subtract.cu @@ -101,10 +101,11 @@ class SubtractTest : public ::testing::TestWithParam> { } protected: - SubtractInputs params; - rmm::device_uvector in1, in2, out_ref, out; raft::handle_t handle; cudaStream_t stream; + + SubtractInputs params; + rmm::device_uvector in1, in2, out_ref, out; }; const std::vector> inputsf2 = { diff --git a/cpp/test/linalg/svd.cu b/cpp/test/linalg/svd.cu index 3227bed603..cbd6df9c8f 100644 --- a/cpp/test/linalg/svd.cu +++ b/cpp/test/linalg/svd.cu @@ -87,11 +87,12 @@ class SvdTest : public ::testing::TestWithParam> { } protected: + raft::handle_t handle; + cudaStream_t stream; + SvdInputs params; rmm::device_uvector data, left_eig_vectors_qr, right_eig_vectors_trans_qr, sing_vals_qr, left_eig_vectors_ref, right_eig_vectors_ref, sing_vals_ref; - raft::handle_t handle; - cudaStream_t stream; }; const std::vector> inputsf2 = { diff --git a/cpp/test/linalg/transpose.cu b/cpp/test/linalg/transpose.cu index 5158891362..b3f7f5b126 100644 --- a/cpp/test/linalg/transpose.cu +++ b/cpp/test/linalg/transpose.cu @@ -64,10 +64,11 @@ class TransposeTest : public ::testing::TestWithParam> { } protected: - TranposeInputs params; - rmm::device_uvector data, data_trans, data_trans_ref; raft::handle_t handle; cudaStream_t stream; + + TranposeInputs params; + rmm::device_uvector data, data_trans, data_trans_ref; }; const std::vector> inputsf2 = { diff --git a/cpp/test/linalg/unary_op.cu b/cpp/test/linalg/unary_op.cu index 22f610b935..c3d10d70e7 100644 --- a/cpp/test/linalg/unary_op.cu +++ b/cpp/test/linalg/unary_op.cu @@ -74,11 +74,12 @@ class UnaryOpTest } protected: + raft::handle_t handle; + cudaStream_t stream; + UnaryOpInputs params; rmm::device_uvector in; rmm::device_uvector out_ref, out; - raft::handle_t handle; - cudaStream_t stream; }; template diff --git a/cpp/test/matrix/math.cu b/cpp/test/matrix/math.cu index 81d7f76344..84aa310076 100644 --- a/cpp/test/matrix/math.cu +++ b/cpp/test/matrix/math.cu @@ -179,13 +179,13 @@ class MathTest : public ::testing::TestWithParam> { } protected: + raft::handle_t handle; + cudaStream_t stream; + MathInputs params; rmm::device_uvector in_power, out_power_ref, in_sqrt, out_sqrt_ref, in_ratio, out_ratio_ref, in_sign_flip, out_sign_flip_ref, in_recip, in_recip_ref, out_recip, in_smallzero, out_smallzero, out_smallzero_ref; - - raft::handle_t handle; - cudaStream_t stream; }; const std::vector> inputsf = { diff --git a/cpp/test/matrix/matrix.cu b/cpp/test/matrix/matrix.cu index 3f8803a471..9dde1cca9a 100644 --- a/cpp/test/matrix/matrix.cu +++ b/cpp/test/matrix/matrix.cu @@ -63,10 +63,11 @@ class MatrixTest : public ::testing::TestWithParam> { } protected: - MatrixInputs params; - rmm::device_uvector in1, in2, in1_revr; raft::handle_t handle; cudaStream_t stream; + + MatrixInputs params; + rmm::device_uvector in1, in2, in1_revr; }; const std::vector> inputsf2 = {{0.000001f, 4, 4, 1234ULL}}; @@ -131,6 +132,9 @@ class MatrixCopyRowsTest : public ::testing::Test { } protected: + raft::handle_t handle; + cudaStream_t stream; + int n_rows = 10; int n_cols = 3; int n_selected = 5; @@ -140,8 +144,6 @@ class MatrixCopyRowsTest : public ::testing::Test { 17, 19, 20, 23, 24, 27, 29}; math_t output_exp_rowmajor[15] = {0, 1, 2, 9, 10, 11, 12, 13, 14, 21, 22, 23, 27, 28, 29}; - raft::handle_t handle; - cudaStream_t stream; rmm::device_uvector input; rmm::device_uvector output; rmm::device_uvector indices; diff --git a/cpp/test/random/rng.cu b/cpp/test/random/rng.cu index 2b4ee992c8..f0e0f6cb93 100644 --- a/cpp/test/random/rng.cu +++ b/cpp/test/random/rng.cu @@ -178,13 +178,13 @@ class RngTest : public ::testing::TestWithParam> { } protected: + raft::handle_t handle; + cudaStream_t stream; + RngInputs params; rmm::device_uvector data, stats; T h_stats[2]; // mean, var int num_sigma; - - raft::handle_t handle; - cudaStream_t stream; }; // The measured mean and standard deviation for each tested distribution are, @@ -444,10 +444,10 @@ class ScaledBernoulliTest : public ::testing::Test { delete[] h_data; } - rmm::device_uvector data; - raft::handle_t handle; cudaStream_t stream; + + rmm::device_uvector data; }; typedef ScaledBernoulliTest ScaledBernoulliTest1; @@ -477,10 +477,10 @@ class BernoulliTest : public ::testing::Test { delete[] h_data; } - rmm::device_uvector data; - raft::handle_t handle; cudaStream_t stream; + + rmm::device_uvector data; }; typedef BernoulliTest BernoulliTest1; @@ -545,13 +545,13 @@ class RngNormalTableTest } protected: + raft::handle_t handle; + cudaStream_t stream; + RngNormalTableInputs params; rmm::device_uvector data, stats, mu_vec; T h_stats[2]; // mean, var int num_sigma; - - raft::handle_t handle; - cudaStream_t stream; }; typedef RngNormalTableTest RngNormalTableTestF; diff --git a/cpp/test/random/rng_int.cu b/cpp/test/random/rng_int.cu index cf9da9e2ff..e51700fbb7 100644 --- a/cpp/test/random/rng_int.cu +++ b/cpp/test/random/rng_int.cu @@ -106,13 +106,13 @@ class RngTest : public ::testing::TestWithParam> { } protected: + raft::handle_t handle; + cudaStream_t stream; + RngInputs params; rmm::device_uvector data; rmm::device_uvector stats; float h_stats[2]; // mean, var - - raft::handle_t handle; - cudaStream_t stream; }; typedef RngTest RngTestU32; diff --git a/cpp/test/random/sample_without_replacement.cu b/cpp/test/random/sample_without_replacement.cu index 22f524c5ed..ecb4164616 100644 --- a/cpp/test/random/sample_without_replacement.cu +++ b/cpp/test/random/sample_without_replacement.cu @@ -71,13 +71,13 @@ class SWoRTest : public ::testing::TestWithParam> { } protected: + raft::handle_t handle; + cudaStream_t stream; + SWoRInputs params; rmm::device_uvector in, out, wts; rmm::device_uvector outIdx; std::vector h_outIdx; - - raft::handle_t handle; - cudaStream_t stream; }; typedef SWoRTest SWoRTestF; diff --git a/cpp/test/sparse/add.cu b/cpp/test/sparse/add.cu index 64519f5078..b9d4d18e98 100644 --- a/cpp/test/sparse/add.cu +++ b/cpp/test/sparse/add.cu @@ -118,14 +118,14 @@ class CSRAddTest } protected: + raft::handle_t handle; + cudaStream_t stream; + CSRAddInputs params; Index_ n_rows, nnz_a, nnz_b, nnz_result; rmm::device_uvector ind_a, ind_b, ind_verify, ind_result, ind_ptr_a, ind_ptr_b, ind_ptr_verify, ind_ptr_result; rmm::device_uvector values_a, values_b, values_verify, values_result; - - raft::handle_t handle; - cudaStream_t stream; }; using CSRAddTestF = CSRAddTest; diff --git a/cpp/test/sparse/convert_coo.cu b/cpp/test/sparse/convert_coo.cu index 339fe5ad7d..8bdd5b88c7 100644 --- a/cpp/test/sparse/convert_coo.cu +++ b/cpp/test/sparse/convert_coo.cu @@ -64,11 +64,11 @@ class CSRtoCOOTest : public ::testing::TestWithParam> { } protected: - CSRtoCOOInputs params; - rmm::device_uvector ex_scan, verify, result; - raft::handle_t handle; cudaStream_t stream; + + CSRtoCOOInputs params; + rmm::device_uvector ex_scan, verify, result; }; using CSRtoCOOTestI = CSRtoCOOTest; diff --git a/cpp/test/sparse/convert_csr.cu b/cpp/test/sparse/convert_csr.cu index f67104bcac..2f1ed99332 100644 --- a/cpp/test/sparse/convert_csr.cu +++ b/cpp/test/sparse/convert_csr.cu @@ -132,13 +132,13 @@ class CSRAdjGraphTest } protected: + raft::handle_t handle; + cudaStream_t stream; + CSRAdjGraphInputs params; Index_ nnz; rmm::device_uvector row_ind, result, verify; rmm::device_uvector adj; - - raft::handle_t handle; - cudaStream_t stream; }; using CSRAdjGraphTestI = CSRAdjGraphTest; diff --git a/cpp/test/sparse/csr_row_slice.cu b/cpp/test/sparse/csr_row_slice.cu index ff9ee22817..33893649bd 100644 --- a/cpp/test/sparse/csr_row_slice.cu +++ b/cpp/test/sparse/csr_row_slice.cu @@ -132,6 +132,9 @@ class CSRRowSliceTest } protected: + raft::handle_t handle; + cudaStream_t stream; + // input data rmm::device_uvector indptr, indices; rmm::device_uvector data; @@ -145,9 +148,6 @@ class CSRRowSliceTest rmm::device_uvector out_data_ref; CSRRowSliceInputs params; - - raft::handle_t handle; - cudaStream_t stream; }; const std::vector> inputs_i32_f = { diff --git a/cpp/test/sparse/csr_to_dense.cu b/cpp/test/sparse/csr_to_dense.cu index 5f5af00f6c..1a206c8499 100644 --- a/cpp/test/sparse/csr_to_dense.cu +++ b/cpp/test/sparse/csr_to_dense.cu @@ -105,6 +105,9 @@ class CSRToDenseTest } protected: + raft::handle_t raft_handle; + cudaStream_t stream; + cusparseHandle_t handle; // input data @@ -118,9 +121,6 @@ class CSRToDenseTest rmm::device_uvector out_ref; CSRToDenseInputs params; - - raft::handle_t raft_handle; - cudaStream_t stream; }; const std::vector> inputs_i32_f = { diff --git a/cpp/test/sparse/csr_transpose.cu b/cpp/test/sparse/csr_transpose.cu index ce042c7dc3..8983f10d2b 100644 --- a/cpp/test/sparse/csr_transpose.cu +++ b/cpp/test/sparse/csr_transpose.cu @@ -128,6 +128,9 @@ class CSRTransposeTest } protected: + raft::handle_t raft_handle; + cudaStream_t stream; + cusparseHandle_t handle; // input data @@ -143,9 +146,6 @@ class CSRTransposeTest rmm::device_uvector out_data_ref; CSRTransposeInputs params; - - cudaStream_t stream; - raft::handle_t raft_handle; }; const std::vector> inputs_i32_f = { diff --git a/cpp/test/sparse/knn_graph.cu b/cpp/test/sparse/knn_graph.cu index 67dc4fe36b..712f95018c 100644 --- a/cpp/test/sparse/knn_graph.cu +++ b/cpp/test/sparse/knn_graph.cu @@ -94,6 +94,9 @@ class KNNGraphTest void TearDown() override { delete out; } protected: + raft::handle_t handle; + cudaStream_t stream; + // input data raft::sparse::COO *out; @@ -102,9 +105,6 @@ class KNNGraphTest value_idx sum_h; KNNGraphInputs params; - - raft::handle_t handle; - cudaStream_t stream; }; const std::vector> knn_graph_inputs_fint = { diff --git a/cpp/test/sparse/linkage.cu b/cpp/test/sparse/linkage.cu index a4caaff11c..6d4af7f016 100644 --- a/cpp/test/sparse/linkage.cu +++ b/cpp/test/sparse/linkage.cu @@ -191,12 +191,12 @@ class LinkageTest : public ::testing::TestWithParam> { void SetUp() override { basicTest(); } protected: + raft::handle_t handle; + cudaStream_t stream; + LinkageInputs params; rmm::device_uvector labels, labels_ref; double score; - - raft::handle_t handle; - cudaStream_t stream; }; const std::vector> linkage_inputsf2 = { diff --git a/cpp/test/sparse/norm.cu b/cpp/test/sparse/norm.cu index 92aa9048b5..91b9bc6c54 100644 --- a/cpp/test/sparse/norm.cu +++ b/cpp/test/sparse/norm.cu @@ -78,12 +78,12 @@ class CSRRowNormalizeTest } protected: + raft::handle_t handle; + cudaStream_t stream; + CSRRowNormalizeInputs params; rmm::device_uvector ex_scan; rmm::device_uvector in_vals, result, verify; - - raft::handle_t handle; - cudaStream_t stream; }; using CSRRowNormalizeTestF = CSRRowNormalizeTest; diff --git a/cpp/test/sparse/row_op.cu b/cpp/test/sparse/row_op.cu index 9b24a971a0..8011d73a6e 100644 --- a/cpp/test/sparse/row_op.cu +++ b/cpp/test/sparse/row_op.cu @@ -78,13 +78,13 @@ class CSRRowOpTest } protected: + raft::handle_t handle; + cudaStream_t stream; + CSRRowOpInputs params; Index_ n_rows, nnz; rmm::device_uvector ex_scan; rmm::device_uvector result, verify; - - raft::handle_t handle; - cudaStream_t stream; }; using CSRRowOpTestF = CSRRowOpTest; diff --git a/cpp/test/sparse/symmetrize.cu b/cpp/test/sparse/symmetrize.cu index 5b3732a982..d50211f971 100644 --- a/cpp/test/sparse/symmetrize.cu +++ b/cpp/test/sparse/symmetrize.cu @@ -111,6 +111,9 @@ class SparseSymmetrizeTest : public ::testing::TestWithParam< } protected: + raft::handle_t handle; + cudaStream_t stream; + // input data rmm::device_uvector indptr, indices; rmm::device_uvector data; @@ -118,9 +121,6 @@ class SparseSymmetrizeTest : public ::testing::TestWithParam< value_idx sum_h; SparseSymmetrizeInputs params; - - raft::handle_t handle; - cudaStream_t stream; }; template diff --git a/cpp/test/spatial/haversine.cu b/cpp/test/spatial/haversine.cu index ea8e7fd9f3..e51bb227a1 100644 --- a/cpp/test/spatial/haversine.cu +++ b/cpp/test/spatial/haversine.cu @@ -90,6 +90,9 @@ class HaversineKNNTest : public ::testing::Test { void SetUp() override { basicTest(); } protected: + raft::handle_t handle; + cudaStream_t stream; + rmm::device_uvector d_train_inputs; int n = 6; @@ -102,9 +105,6 @@ class HaversineKNNTest : public ::testing::Test { rmm::device_uvector d_ref_I; rmm::device_uvector d_ref_D; - - raft::handle_t handle; - cudaStream_t stream; }; typedef HaversineKNNTest HaversineKNNTestF; diff --git a/cpp/test/spatial/knn.cu b/cpp/test/spatial/knn.cu index d2b98a1f6a..35a82b1e53 100644 --- a/cpp/test/spatial/knn.cu +++ b/cpp/test/spatial/knn.cu @@ -145,6 +145,9 @@ class KNNTest : public ::testing::TestWithParam { } private: + raft::handle_t handle; + cudaStream_t stream; + KNNInputs params_; int rows_; int cols_; @@ -157,9 +160,6 @@ class KNNTest : public ::testing::TestWithParam { rmm::device_uvector search_labels_; rmm::device_uvector actual_labels_; rmm::device_uvector expected_labels_; - - raft::handle_t handle; - cudaStream_t stream; }; const std::vector inputs = { diff --git a/cpp/test/spatial/selection.cu b/cpp/test/spatial/selection.cu index 791cf1fcb6..7742b9bd30 100644 --- a/cpp/test/spatial/selection.cu +++ b/cpp/test/spatial/selection.cu @@ -110,6 +110,9 @@ class SparseSelectionTest } protected: + raft::handle_t handle; + cudaStream_t stream; + int n_rows, n_cols, k; // input data @@ -124,9 +127,6 @@ class SparseSelectionTest rmm::device_uvector out_dists_ref; SparseSelectionInputs params; - - raft::handle_t handle; - cudaStream_t stream; }; const std::vector> inputs_i32_f = { diff --git a/cpp/test/stats/mean.cu b/cpp/test/stats/mean.cu index de4a2e4507..9884202cc0 100644 --- a/cpp/test/stats/mean.cu +++ b/cpp/test/stats/mean.cu @@ -65,12 +65,12 @@ class MeanTest : public ::testing::TestWithParam> { } protected: + raft::handle_t handle; + cudaStream_t stream; + MeanInputs params; int rows, cols; rmm::device_uvector data, mean_act; - - raft::handle_t handle; - cudaStream_t stream; }; // Note: For 1024 samples, 256 experiments, a mean of 1.0 with stddev=1.0, the diff --git a/cpp/test/stats/mean_center.cu b/cpp/test/stats/mean_center.cu index 13eb3546b5..9845663df9 100644 --- a/cpp/test/stats/mean_center.cu +++ b/cpp/test/stats/mean_center.cu @@ -70,12 +70,12 @@ class MeanCenterTest } protected: + raft::handle_t handle; + cudaStream_t stream; + MeanCenterInputs params; int rows, cols; rmm::device_uvector data, meanVec, out, out_ref; - - raft::handle_t handle; - cudaStream_t stream; }; const std::vector> inputsf_i32 = { diff --git a/cpp/test/stats/stddev.cu b/cpp/test/stats/stddev.cu index 99720cdbef..8c42b70c07 100644 --- a/cpp/test/stats/stddev.cu +++ b/cpp/test/stats/stddev.cu @@ -81,12 +81,12 @@ class StdDevTest : public ::testing::TestWithParam> { } protected: + raft::handle_t handle; + cudaStream_t stream; + StdDevInputs params; int rows, cols; rmm::device_uvector data, mean_act, stddev_act, vars_act; - - raft::handle_t handle; - cudaStream_t stream; }; const std::vector> inputsf = { diff --git a/cpp/test/stats/sum.cu b/cpp/test/stats/sum.cu index 6bfd1f3a30..f5b341cb0e 100644 --- a/cpp/test/stats/sum.cu +++ b/cpp/test/stats/sum.cu @@ -62,12 +62,12 @@ class SumTest : public ::testing::TestWithParam> { } protected: + raft::handle_t handle; + cudaStream_t stream; + SumInputs params; int rows, cols; rmm::device_uvector data, sum_act; - - raft::handle_t handle; - cudaStream_t stream; }; const std::vector> inputsf = {{0.05f, 1024, 32, 1234ULL},