Skip to content

Commit

Permalink
Reconciling primitives moved to RAFT (rapidsai#4583)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjnolet authored Oct 19, 2022
1 parent 7257cfc commit 6a7cf52
Show file tree
Hide file tree
Showing 106 changed files with 342 additions and 9,549 deletions.
6 changes: 2 additions & 4 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ option(BUILD_CUML_MG_TESTS "Build cuML multigpu algorithm tests" OFF)
option(BUILD_PRIMS_TESTS "Build ml-prim tests" ON)
option(BUILD_CUML_EXAMPLES "Build C++ API usage examples" ON)
option(BUILD_CUML_BENCH "Build cuML C++ benchmark tests" ON)
option(BUILD_CUML_PRIMS_BENCH "Build ml-prims C++ benchmark tests" ON)
option(BUILD_CUML_STD_COMMS "Build the standard NCCL+UCX Communicator" ON)
option(BUILD_CUML_MPI_COMMS "Build the MPI+NCCL Communicator (used for testing)" OFF)
option(CUDA_ENABLE_KERNEL_INFO "Enable kernel resource usage info" OFF)
Expand All @@ -80,7 +79,6 @@ message(VERBOSE "CUML_CPP: Building cuML multigpu algorithm tests: ${BUILD_CUML_
message(VERBOSE "CUML_CPP: Building ml-prims tests: ${BUILD_PRIMS_TESTS}")
message(VERBOSE "CUML_CPP: Building C++ API usage examples: ${BUILD_CUML_EXAMPLES}")
message(VERBOSE "CUML_CPP: Building cuML C++ benchmark tests: ${BUILD_CUML_BENCH}")
message(VERBOSE "CUML_CPP: Building ml-prims C++ benchmark tests: ${BUILD_CUML_PRIMS_BENCH}")
message(VERBOSE "CUML_CPP: Building the standard NCCL+UCX Communicator: ${BUILD_CUML_STD_COMMS}")
message(VERBOSE "CUML_CPP: Building the MPI+NCCL Communicator (used for testing): ${BUILD_CUML_MPI_COMMS}")
message(VERBOSE "CUML_CPP: Enabling detection of conda environment for dependencies: ${DETECT_CONDA_ENV}")
Expand Down Expand Up @@ -244,7 +242,7 @@ if(BUILD_CUML_TESTS OR BUILD_PRIMS_TESTS)
include(cmake/thirdparty/get_gtest.cmake)
endif()

if(BUILD_CUML_BENCH OR BUILD_CUML_PRIMS_BENCH)
if(BUILD_CUML_BENCH)
include(cmake/thirdparty/get_gbench.cmake)
endif()

Expand Down Expand Up @@ -692,7 +690,7 @@ rapids_export(BUILD cuml
##############################################################################
# - build benchmark executable -----------------------------------------------

if(BUILD_CUML_BENCH OR BUILD_CUML_PRIMS_BENCH)
if(BUILD_CUML_BENCH)
add_subdirectory(bench)
endif()

Expand Down
45 changes: 1 addition & 44 deletions cpp/bench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,47 +66,4 @@ if(BUILD_CUML_BENCH)
DESTINATION bin/benchmarks/libcuml
EXCLUDE_FROM_ALL
)
endif()

##############################################################################
# - build prims bench executable ----------------------------------------------

if(BUILD_CUML_PRIMS_BENCH)
# (please keep the filenames in alphabetical order)
add_executable(${PRIMS_BENCH_TARGET}
prims/gram_matrix.cu
prims/main.cpp)

target_compile_options(${PRIMS_BENCH_TARGET}
PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${CUML_CXX_FLAGS}>"
"$<$<COMPILE_LANGUAGE:CUDA>:${CUML_CUDA_FLAGS}>"
)

target_link_libraries(${PRIMS_BENCH_TARGET}
PUBLIC
cuml::${CUML_CPP_TARGET}
benchmark::benchmark
${TREELITE_LIBS}
raft::raft
raft::nn
raft::distance
)

target_include_directories(${PRIMS_BENCH_TARGET}
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../src_prims>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)

set_target_properties(
${PRIMS_BENCH_TARGET}
PROPERTIES INSTALL_RPATH "\$ORIGIN/../../../lib"
)

install(
TARGETS ${PRIMS_BENCH_TARGET}
COMPONENT testing
DESTINATION bin/benchmarks/libcuml_prims
EXCLUDE_FROM_ALL
)
endif()
endif()
138 changes: 0 additions & 138 deletions cpp/bench/prims/gram_matrix.cu

This file was deleted.

19 changes: 0 additions & 19 deletions cpp/bench/prims/main.cpp

This file was deleted.

20 changes: 12 additions & 8 deletions cpp/bench/sg/svc.cu
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
* limitations under the License.
*/

#if defined RAFT_DISTANCE_COMPILED
#include <raft/distance/specializations.cuh>
#endif

#include "benchmark.cuh"
#include <cmath>
#include <cuml/matrix/kernelparams.h>
#include <cuml/svm/svc.hpp>
#include <cuml/svm/svm_model.h>
#include <cuml/svm/svm_parameter.h>
#include <raft/distance/kernels.cuh>
#include <sstream>
#include <utility>

Expand All @@ -31,7 +35,7 @@ template <typename D>
struct SvcParams {
DatasetParams data;
BlobsParams blobs;
MLCommon::Matrix::KernelParams kernel;
raft::distance::kernels::KernelParams kernel;
ML::SVM::SvmParameter svm_param;
ML::SVM::SvmModel<D> model;
};
Expand Down Expand Up @@ -74,7 +78,7 @@ class SVC : public BlobsFixture<D, D> {
}

private:
MLCommon::Matrix::KernelParams kernel;
raft::distance::kernels::KernelParams kernel;
ML::SVM::SvmParameter svm_param;
ML::SVM::SvmModel<D> model;
};
Expand Down Expand Up @@ -102,11 +106,11 @@ std::vector<SvcParams<D>> getInputs()

std::vector<Triplets> rowcols = {{50000, 2, 2}, {2048, 100000, 2}, {50000, 1000, 2}};

std::vector<MLCommon::Matrix::KernelParams> kernels{
MLCommon::Matrix::KernelParams{MLCommon::Matrix::LINEAR, 3, 1, 0},
MLCommon::Matrix::KernelParams{MLCommon::Matrix::POLYNOMIAL, 3, 1, 0},
MLCommon::Matrix::KernelParams{MLCommon::Matrix::RBF, 3, 1, 0},
MLCommon::Matrix::KernelParams{MLCommon::Matrix::TANH, 3, 0.1, 0}};
std::vector<raft::distance::kernels::KernelParams> kernels{
raft::distance::kernels::KernelParams{raft::distance::kernels::LINEAR, 3, 1, 0},
raft::distance::kernels::KernelParams{raft::distance::kernels::POLYNOMIAL, 3, 1, 0},
raft::distance::kernels::KernelParams{raft::distance::kernels::RBF, 3, 1, 0},
raft::distance::kernels::KernelParams{raft::distance::kernels::TANH, 3, 0.1, 0}};

for (auto& rc : rowcols) {
p.data.nrows = rc.nrows;
Expand Down
20 changes: 12 additions & 8 deletions cpp/bench/sg/svr.cu
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
* limitations under the License.
*/

#if defined RAFT_DISTANCE_COMPILED
#include <raft/distance/specializations.cuh>
#endif

#include "benchmark.cuh"
#include <cmath>
#include <cuml/matrix/kernelparams.h>
#include <cuml/svm/svc.hpp>
#include <cuml/svm/svm_model.h>
#include <cuml/svm/svm_parameter.h>
#include <cuml/svm/svr.hpp>
#include <raft/distance/kernels.cuh>
#include <utility>

namespace ML {
Expand All @@ -31,7 +35,7 @@ template <typename D>
struct SvrParams {
DatasetParams data;
RegressionParams regression;
MLCommon::Matrix::KernelParams kernel;
raft::distance::kernels::KernelParams kernel;
ML::SVM::SvmParameter svm_param;
ML::SVM::SvmModel<D>* model;
};
Expand Down Expand Up @@ -73,7 +77,7 @@ class SVR : public RegressionFixture<D> {
}

private:
MLCommon::Matrix::KernelParams kernel;
raft::distance::kernels::KernelParams kernel;
ML::SVM::SvmParameter svm_param;
ML::SVM::SvmModel<D>* model;
};
Expand Down Expand Up @@ -104,11 +108,11 @@ std::vector<SvrParams<D>> getInputs()

std::vector<Triplets> rowcols = {{50000, 2, 2}, {1024, 10000, 10}, {3000, 200, 200}};

std::vector<MLCommon::Matrix::KernelParams> kernels{
MLCommon::Matrix::KernelParams{MLCommon::Matrix::LINEAR, 3, 1, 0},
MLCommon::Matrix::KernelParams{MLCommon::Matrix::POLYNOMIAL, 3, 1, 0},
MLCommon::Matrix::KernelParams{MLCommon::Matrix::RBF, 3, 1, 0},
MLCommon::Matrix::KernelParams{MLCommon::Matrix::TANH, 3, 0.1, 0}};
std::vector<raft::distance::kernels::KernelParams> kernels{
raft::distance::kernels::KernelParams{raft::distance::kernels::LINEAR, 3, 1, 0},
raft::distance::kernels::KernelParams{raft::distance::kernels::POLYNOMIAL, 3, 1, 0},
raft::distance::kernels::KernelParams{raft::distance::kernels::RBF, 3, 1, 0},
raft::distance::kernels::KernelParams{raft::distance::kernels::TANH, 3, 0.1, 0}};

for (auto& rc : rowcols) {
p.data.nrows = rc.nrows;
Expand Down
23 changes: 5 additions & 18 deletions cpp/include/cuml/matrix/kernelparams.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2021, NVIDIA CORPORATION.
* Copyright (c) 2019-2022, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,26 +16,13 @@

#pragma once

#include <raft/distance/distance_types.hpp>

namespace MLCommon {
namespace Matrix {

enum KernelType { LINEAR, POLYNOMIAL, RBF, TANH };

/**
* Parameters for kernel matrices.
* The following kernels are implemented:
* - LINEAR \f[ K(x_1,x_2) = <x_1,x_2>, \f] where \f$< , >\f$ is the dot product
* - POLYNOMIAL \f[ K(x_1, x_2) = (\gamma <x_1,x_2> + \mathrm{coef0})^\mathrm{degree} \f]
* - RBF \f[ K(x_1, x_2) = \exp(- \gamma |x_1-x_2|^2) \f]
* - TANH \f[ K(x_1, x_2) = \tanh(\gamma <x_1,x_2> + \mathrm{coef0}) \f]
*/
struct KernelParams {
// Kernel function parameters
KernelType kernel; //!< Type of the kernel function
int degree; //!< Degree of polynomial kernel (ignored by others)
double gamma; //!< multiplier in the
double coef0; //!< additive constant in poly and tanh kernels
};
using raft::distance::kernels::KernelParams;
using raft::distance::kernels::KernelType;

}; // end namespace Matrix
}; // end namespace MLCommon
Loading

0 comments on commit 6a7cf52

Please sign in to comment.