Skip to content

Commit

Permalink
Decouple test and pairwise distance code
Browse files Browse the repository at this point in the history
A change in the pairwise_distance code will not trigger a rebuild of all
the tests any more.

pairwise_test                                                                                                               0.5 seconds
build.ninja                                                                                                                 4.0 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/russel_rao_double_double_double_int.cu.o          7.3 seconds
akeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/hellinger_expanded_double_double_double_int.cu.o    7.3 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/correlation_double_double_double_int.cu.o         8.2 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/l1_double_double_double_int.cu.o                  8.2 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/l2_unexpanded_double_double_double_int.cu.o       8.3 seconds
akeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/hamming_unexpanded_double_double_double_int.cu.o    8.6 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/l_inf_double_double_double_int.cu.o               9.6 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/russel_rao_float_float_float_int.cu.o            10.0 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/hellinger_expanded_float_float_float_int.cu.o    11.9 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/l1_float_float_float_int.cu.o                    12.2 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/hamming_unexpanded_float_float_float_int.cu.o    13.6 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/l2_unexpanded_float_float_float_int.cu.o         13.7 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/l_inf_float_float_float_int.cu.o                 13.7 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/correlation_float_float_float_int.cu.o           13.9 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/canberra_double_double_double_int.cu.o           14.9 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/canberra_float_float_float_int.cu.o              19.9 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/lp_unexpanded_float_float_float_int.cu.o         22.8 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/l2_expanded_double_double_double_int.cu.o        26.3 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/cosine_double_double_double_int.cu.o             31.4 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/jensen_shannon_float_float_float_int.cu.o        31.5 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/inner_product_double_double_double_int.cu.o      34.6 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/inner_product_float_float_float_int.cu.o         35.5 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/kl_divergence_float_float_float_int.cu.o         36.9 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/kernels/polynomial_kernel_double_int.cu.o        39.1 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/kernels/gram_matrix_base_double.cu.o             39.4 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/kernels/tanh_kernel_double.cu.o                  39.8 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/kernels/tanh_kernel_float.cu.o                   42.4 seconds
CMakeFiles/pairwise_test.dir/test/distance/dist_inner_product.cu.o                                                         42.7 seconds
CMakeFiles/pairwise_test.dir/test/distance/dist_cos.cu.o                                                                   42.8 seconds
CMakeFiles/pairwise_test.dir/test/distance/dist_l2_sqrt_exp.cu.o                                                           42.9 seconds
CMakeFiles/pairwise_test.dir/test/distance/dist_l2_exp.cu.o                                                                43.0 seconds
CMakeFiles/pairwise_test.dir/test/distance/dist_lp_unexp.cu.o                                                              43.4 seconds
CMakeFiles/pairwise_test.dir/test/distance/dist_l1.cu.o                                                                    43.5 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/jensen_shannon_double_double_double_int.cu.o     43.7 seconds
CMakeFiles/pairwise_test.dir/test/distance/dist_l2_unexp.cu.o                                                              43.7 seconds
CMakeFiles/pairwise_test.dir/test/distance/dist_russell_rao.cu.o                                                           43.8 seconds
CMakeFiles/pairwise_test.dir/test/distance/dist_canberra.cu.o                                                              43.9 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/kernels/polynomial_kernel_float_int.cu.o         44.2 seconds
CMakeFiles/pairwise_test.dir/test/distance/dist_l_inf.cu.o                                                                 44.2 seconds
CMakeFiles/pairwise_test.dir/test/distance/dist_hamming.cu.o                                                               44.4 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/kernels/gram_matrix_base_float.cu.o              44.5 seconds
CMakeFiles/pairwise_test.dir/test/distance/dist_jensen_shannon.cu.o                                                        44.6 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/kl_divergence_double_double_double_int.cu.o      44.9 seconds
CMakeFiles/pairwise_test.dir/test/distance/dist_correlation.cu.o                                                           44.9 seconds
CMakeFiles/pairwise_test.dir/test/distance/dist_kl_divergence.cu.o                                                         45.0 seconds
CMakeFiles/pairwise_test.dir/test/distance/dist_hellinger.cu.o                                                             45.3 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/l2_expanded_float_float_float_int.cu.o           45.4 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/pairwise_distance.cu.o                                                  56.0 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/cosine_float_float_float_int.cu.o                57.2 seconds
CMakeFiles/pairwise_test.dir/test/distance/gram.cu.o                                                                       57.5 seconds
CMakeFiles/pairwise_test.dir/src/distance/distance/specializations/detail/lp_unexpanded_double_double_double_int.cu.o      70.1 seconds
CMakeFiles/pairwise_test.dir/test/distance/dist_adj.cu.o                                                                  116.8 seconds
  • Loading branch information
ahendriksen committed Mar 14, 2023
1 parent fe9d1bb commit f1db5a1
Showing 1 changed file with 63 additions and 10 deletions.
73 changes: 63 additions & 10 deletions cpp/test/distance/distance_base.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,23 @@

#include "../test_utils.cuh"
#include <gtest/gtest.h>
#include <raft/common/nvtx.hpp>
#include <raft/core/mdarray.hpp>
#include <raft/core/operators.hpp>
#include <raft/distance/distance.cuh>
#include <raft/util/cuda_utils.cuh>
#include <raft/util/cudart_utils.hpp>
#include <raft/common/nvtx.hpp> // common::nvtx::range

#include <raft/core/device_resources.hpp> // raft::device_resources
#include <raft/core/operators.hpp> // raft::sqrt
#include <raft/distance/distance_types.hpp> // raft::distance::DistanceType
#include <raft/random/rng.cuh>
#include <rmm/device_uvector.hpp> // rmm::device_uvector

// When the distance library is precompiled, include only the raft_runtime
// headers. This way, a small change in one of the kernel internals does not
// trigger a rebuild of the test files (it of course still triggers a rebuild of
// the raft specializations)
#if defined RAFT_DISTANCE_COMPILED
#include <raft/distance/specializations.cuh>
#include <raft_runtime/distance/pairwise_distance.hpp>
#else
#include <raft/distance/distance.cuh>
#endif
#include <raft/random/rng.cuh>

namespace raft {
namespace distance {
Expand Down Expand Up @@ -409,6 +416,25 @@ template <typename DataType>
return os;
}

// TODO: Remove when mdspan-based raft::runtime::distance::pairwise_distance is
// implemented.
//
// Context:
// https://github.com/rapidsai/raft/issues/1338
template <typename layout>
constexpr bool layout_to_row_major();

template <>
constexpr bool layout_to_row_major<layout_c_contiguous>()
{
return true;
}
template <>
constexpr bool layout_to_row_major<layout_f_contiguous>()
{
return false;
}

template <raft::distance::DistanceType distanceType, typename DataType, typename layout>
void distanceLauncher(raft::device_resources const& handle,
DataType* x,
Expand All @@ -422,12 +448,23 @@ void distanceLauncher(raft::device_resources const& handle,
DataType threshold,
DataType metric_arg = 2.0f)
{
#if defined RAFT_DISTANCE_COMPILED
// TODO: Implement and use mdspan-based
// raft::runtime::distance::pairwise_distance here.
//
// Context:
// https://github.com/rapidsai/raft/issues/1338
bool row_major = layout_to_row_major<layout>();
raft::runtime::distance::pairwise_distance(
handle, x, y, dist, m, n, k, distanceType, row_major, metric_arg);
#else
auto x_v = make_device_matrix_view<DataType, int, layout>(x, m, k);
auto y_v = make_device_matrix_view<DataType, int, layout>(y, n, k);
auto dist_v = make_device_matrix_view<DataType, int, layout>(dist, m, n);

raft::distance::distance<distanceType, DataType, DataType, DataType, layout>(
handle, x_v, y_v, dist_v, metric_arg);
#endif
}

template <raft::distance::DistanceType distanceType, typename DataType>
Expand Down Expand Up @@ -523,9 +560,25 @@ class BigMatrixDistanceTest : public ::testing::Test {
auto testInfo = testing::UnitTest::GetInstance()->current_test_info();
common::nvtx::range fun_scope("test::%s/%s", testInfo->test_suite_name(), testInfo->name());

void pairwise_distance(raft::device_resources const& handle,
float* x,
float* y,
float* dists,
int m,
int n,
int k,
raft::distance::DistanceType metric,
bool isRowMajor,
float metric_arg);
bool row_major = true;
float metric_arg = 0.0f;
#if defined RAFT_DISTANCE_COMPILED
raft::runtime::distance::pairwise_distance(
handle, x.data(), x.data(), dist.data(), m, n, k, distanceType, row_major, metric_arg);
#else
raft::distance::distance<distanceType, float, float, float>(
handle, x.data(), x.data(), dist.data(), m, n, k, true, 0.0f);

handle, x.data(), x.data(), dist.data(), m, n, k, row_major, metric_arg);
#endif
RAFT_CUDA_TRY(cudaStreamSynchronize(handle.get_stream()));
}

Expand Down

0 comments on commit f1db5a1

Please sign in to comment.