MLCommon Namespace#

Warning

Primarily internal API: it may change or disappear without notice and has no stability, deprecation, backward-compatibility, or input-validation guarantees. Callers must validate inputs and satisfy all memory, stream, and lifetime preconditions. Prefer the supported Python API.

namespace MLCommon#
class TimerCPU#
#include <Timer.h>
namespace Datasets#
namespace Boston#

Variables

const std::vector<float> boston#
static const int n_samples = 506#
static const int n_features = 13#
namespace BreastCancer#

Variables

const std::vector<float> breast_cancer#
static const int n_samples = 569#
static const int n_features = 30#
namespace Diabetes#

Variables

const std::vector<float> diabetes#
static const int n_samples = 442#
static const int n_features = 10#
namespace Digits#

Variables

const std::vector<float> digits#
static const std::vector<float> distances#
static const std::vector<long> indices#
static const std::vector<float> Y#
static const std::vector<float> VAL_vector#
static const std::vector<int> ROW_vector#
static const std::vector<int> COL_vector#
static const int n_samples = 1797#
static const int n_features = 64#
namespace LinAlg#
namespace opg#

Functions

void eigDC(
const raft::handle_t &h,
float *eigenValues,
float *eigenVectors,
std::vector<Matrix::Data<float>*> &inParts,
Matrix::PartDescriptor &desc,
int myRank,
cudaStream_t stream
)#

Multi-GPU version of Eigen decomposition. This function works for symmetric matrices only. Whole input matrix is gathered at rank 0 and Eigen decomposition is carried out sequentially.

Parameters:
  • h – cuML handle object.

  • eigenValues[out] Output N Eigen values.

  • eigenVectors[out] Output N Eigen vectors of size N x 1.

  • inParts[in] Input symmetric matrix of size N x N.

  • desc[in] Descriptor of input matrix.

  • myRank[in] MPI rank of the process.

  • stream[in] CUDA stream.

void eigDC(
const raft::handle_t &h,
double *eigenValues,
double *eigenVectors,
std::vector<Matrix::Data<double>*> &inParts,
Matrix::PartDescriptor &desc,
int myRank,
cudaStream_t stream
)#
void eigJacobi(
const raft::handle_t &h,
float *eigenValues,
float *eigenVectors,
std::vector<Matrix::Data<float>*> &inParts,
Matrix::PartDescriptor &desc,
int myRank,
cudaStream_t stream
)#
void eigJacobi(
const raft::handle_t &h,
double *eigenValues,
double *eigenVectors,
std::vector<Matrix::Data<double>*> &inParts,
Matrix::PartDescriptor &desc,
int myRank,
cudaStream_t stream
)#
void gemm(
const raft::handle_t &h,
std::vector<Matrix::Data<float>*> &outZParts,
Matrix::PartDescriptor &outZDesc,
std::vector<Matrix::Data<float>*> &inXParts,
Matrix::PartDescriptor &inXDesc,
std::vector<Matrix::Data<float>*> &inYParts,
Matrix::PartDescriptor &inYDesc,
int myRank,
cudaStream_t stream
)#

A multi gpu generalized matrix multiplication function. This function performs Z = X * Y The X and Y matrix are distributed in blocks on different ranks. First Y matrix is duplicated at each rank. It is multiplied with blocks of X local to the rank.

Parameters:
  • h – cuML handle object.

  • outZParts[out] Result of the multiplication with size M x N. Distributed across ranks according to inXDesc/outZDesc descriptor.

  • outZDesc[out] Descriptor for outZParts matrix. It has to be same as inXDesc.

  • inXParts[in] Input matrix X with dimensions M x K. Distributed across ranks according to inXDesc descriptor.

  • inXDesc[in] Descriptor for X matrix.

  • inYParts[in] Input matrix Y with dimensions K x N. Distributed across ranks according to inYDesc descriptor.

  • inYDesc[in] Descriptor for Y matrix.

  • myRank[in] Rank of calling process.

  • stream[in] cuda stream on which work is launched.

void gemm(
const raft::handle_t &h,
std::vector<Matrix::Data<double>*> &outZParts,
Matrix::PartDescriptor &outZDesc,
std::vector<Matrix::Data<double>*> &inXParts,
Matrix::PartDescriptor &inXDesc,
std::vector<Matrix::Data<double>*> &inYParts,
Matrix::PartDescriptor &inYDesc,
int myRank,
cudaStream_t stream
)#
void lstsqEig(
const raft::handle_t &handle,
const std::vector<Matrix::Data<float>*> &A,
const Matrix::PartDescriptor &ADesc,
const std::vector<Matrix::Data<float>*> &b,
float *w,
cudaStream_t *streams,
int n_streams
)#

performs MNMG Least squares calculation.

void lstsqEig(
const raft::handle_t &handle,
const std::vector<Matrix::Data<double>*> &A,
const Matrix::PartDescriptor &ADesc,
const std::vector<Matrix::Data<double>*> &b,
double *w,
cudaStream_t *streams,
int n_streams
)#
void meanSquaredError(
double *out,
const Matrix::Data<double> &in1,
const Matrix::PartDescriptor &in1Desc,
const Matrix::Data<double> &in2,
const Matrix::PartDescriptor &in2Desc,
const raft::comms::comms_t &comm,
cudaStream_t stream,
int root = 0,
bool broadcastResult = true
)#

multi-gpu mean squared error

Parameters:
  • out[out] the output data (device pointer)

  • in1[in] the first input data

  • in1Desc[in] descriptor for the first input data

  • in2[in] the second input data

  • in2Desc[in] descriptor for the second input data

  • comm[in] the communicator object

  • stream[in] cuda stream where to launch work

  • root[in] worker ID which is supposed to be considered as root

  • broadcastResult[in] if false, only root process will have the result, else all ranks

void meanSquaredError(
float *out,
const Matrix::Data<float> &in1,
const Matrix::PartDescriptor &in1Desc,
const Matrix::Data<float> &in2,
const Matrix::PartDescriptor &in2Desc,
const raft::comms::comms_t &comm,
cudaStream_t stream,
int root = 0,
bool broadcastResult = true
)#
void mm_aTa(
const raft::handle_t &handle,
Matrix::Data<double> &out,
const std::vector<Matrix::Data<double>*> &in1,
const Matrix::PartDescriptor &in1Desc,
cudaStream_t *streams,
int n_streams
)#

performs MNMG A^T x A calculation.

Parameters:
  • handle[in] cuML handle object

  • out[out] resulting A^T x A matrix

  • in1[in] input data

  • in1Desc[in] MNMG description of the input

  • streams[in] cuda streams

  • n_streams[in] number of streams

void mm_aTa(
const raft::handle_t &handle,
Matrix::Data<float> &out,
const std::vector<Matrix::Data<float>*> &in1,
const Matrix::PartDescriptor &in1Desc,
cudaStream_t *streams,
int n_streams
)#
void mv_aTb(
const raft::handle_t &handle,
Matrix::Data<double> &out,
const std::vector<Matrix::Data<double>*> &A,
const Matrix::PartDescriptor &ADesc,
const std::vector<Matrix::Data<double>*> &b,
cudaStream_t *streams,
int n_streams
)#

performs MNMG A^T x b calculation.

Parameters:
  • handle[in] cuML handle object

  • out[out] resulting A^T x b matrix

  • A[in] input data matrix

  • ADesc[in] MNMG description of A

  • b[in] input vector

  • streams[in] cuda streams

  • n_streams[in] number of streams

void mv_aTb(
const raft::handle_t &handle,
Matrix::Data<float> &out,
const std::vector<Matrix::Data<float>*> &A,
const Matrix::PartDescriptor &ADesc,
const std::vector<Matrix::Data<float>*> &b,
cudaStream_t *streams,
int n_streams
)#
void colNorm2(
const raft::handle_t &handle,
Matrix::Data<double> &out,
const std::vector<Matrix::Data<double>*> &in,
const Matrix::PartDescriptor &inDesc,
cudaStream_t *streams,
int n_streams
)#

performs MNMG Least squares calculation.

void colNorm2(
const raft::handle_t &handle,
Matrix::Data<float> &out,
const std::vector<Matrix::Data<float>*> &in,
const Matrix::PartDescriptor &inDesc,
cudaStream_t *streams,
int n_streams
)#
void colNorm2NoSeq(
const raft::handle_t &handle,
Matrix::Data<double> &out,
const std::vector<Matrix::Data<double>*> &in,
const Matrix::PartDescriptor &inDesc,
cudaStream_t *streams,
int n_streams
)#
void colNorm2NoSeq(
const raft::handle_t &handle,
Matrix::Data<float> &out,
const std::vector<Matrix::Data<float>*> &in,
const Matrix::PartDescriptor &inDesc,
cudaStream_t *streams,
int n_streams
)#
void svdEig(
const raft::handle_t &handle,
const std::vector<Matrix::Data<float>*> &A,
const Matrix::PartDescriptor &ADesc,
std::vector<Matrix::Data<float>*> &U,
float *S,
float *V,
cudaStream_t *streams,
int n_streams
)#

performs MNMG Least squares calculation.

void svdEig(
const raft::handle_t &handle,
const std::vector<Matrix::Data<double>*> &A,
const Matrix::PartDescriptor &ADesc,
std::vector<Matrix::Data<double>*> &U,
double *S,
double *V,
cudaStream_t *streams,
int n_streams
)#
namespace Matrix#

Typedefs

typedef Data<float> floatData_t#
typedef Data<double> doubleData_t#

Enums

enum Layout#

Describes the data layout

Values:

enumerator LayoutRowMajor#

row major layout

enumerator LayoutColMajor#

column major layout

Functions

std::ostream &operator<<(
std::ostream &os,
const PartDescriptor &desc
)#

Print matrix descriptor in human readable form

bool operator==(const PartDescriptor &a, const PartDescriptor &b)#

compare 2 descriptor objects

template<typename Type>
struct Data#
#include <data.hpp>

This is a helper wrapper around the multi-gpu data blocks owned by a worker. It’s design is NOT final. Its so written this way to get something concrete in a short span of time.

Todo:

add support for custom allocators

Public Functions

inline size_t numElements() const#

Return the number of elements of Type in ptr.

Public Members

Type *ptr = nullptr#

actual data block. This is just a linearly laid out buffer of all blocks owned by this worker

size_t totalSize = (size_t)0#

total size (in bytes) of this buffer. In future, this will be passed to the dealloc function underneath

struct RankSizePair#
#include <part_descriptor.hpp>

Public Members

size_t size#

Total number of rows

struct PartDescriptor#
#include <part_descriptor.hpp>

Public Functions

PartDescriptor(
size_t _M,
size_t _N,
const std::vector<RankSizePair*> &_partsToRanks,
int rank,
Layout _layout = LayoutColMajor
)#

For a given matrix and block-sizes construct the corresponding descriptor for it. This is useful when we are dealing with standard row/column-wise block-cyclic data distribution, as seen in other popular multi-node packages like magma etc.

Parameters:
  • _M – total number of rows of this matrix

  • _N – total number of columns

  • _partsToRanks – mapping of ranks to parts and sizes

  • rank – MPI rank of the process

  • _layout – data layout (row or column major)

inline int totalBlocks() const#

total number of blocks across all workers

int totalBlocksOwnedBy(int rank) const#

Count the total number of blocks owned by a given rank

std::vector<RankSizePair*> blocksOwnedBy(int rank) const#

Returns the vector of blocks (each identified by linearBLockIndex) owned by the given rank.

size_t totalElementsOwnedBy(int rank) const#

Count the total number of matrix elements owned by a given rank

Public Members

size_t M#

total number of rows

size_t N#

total number of columns

std::vector<RankSizePair*> partsToRanks#

mapping of each block (in col-major order) to the device that owns it

Friends

friend std::ostream &operator<<(
std::ostream &os,
const PartDescriptor &desc
)#

Print matrix descriptor in human readable form

friend bool operator==(
const PartDescriptor &a,
const PartDescriptor &b
)#

compare 2 descriptor objects

namespace opg#

Functions

template<bool rowMajor, bool bcastAlongRows>
void matrixVectorBinaryDivSkipZero(
std::vector<Matrix::Data<double>*> &data,
const Matrix::PartDescriptor &inDesc,
const Matrix::Data<double> &vec,
bool return_zero,
const raft::comms::comms_t &comm,
cudaStream_t *streams,
int n_streams
)#
template<bool rowMajor, bool bcastAlongRows>
void matrixVectorBinaryDivSkipZero(
std::vector<Matrix::Data<float>*> &data,
const Matrix::PartDescriptor &inDesc,
const Matrix::Data<float> &vec,
bool return_zero,
const raft::comms::comms_t &comm,
cudaStream_t *streams,
int n_streams
)#
template<bool rowMajor, bool bcastAlongRows>
void matrixVectorBinaryMult(
std::vector<Matrix::Data<double>*> &data,
const Matrix::PartDescriptor &inDesc,
const Matrix::Data<double> &vec,
const raft::comms::comms_t &comm,
cudaStream_t *streams,
int n_streams
)#
template<bool rowMajor, bool bcastAlongRows>
void matrixVectorBinaryMult(
std::vector<Matrix::Data<float>*> &data,
const Matrix::PartDescriptor &inDesc,
const Matrix::Data<float> &vec,
const raft::comms::comms_t &comm,
cudaStream_t *streams,
int n_streams
)#
void gatherPart(
const raft::handle_t &h,
float *gatheredPart,
std::vector<Matrix::Data<float>*> &parts,
Matrix::PartDescriptor &desc,
int partIndex,
int rootRank,
int myRank,
cudaStream_t stream
)#
void allGatherPart(
const raft::handle_t &h,
float *gatheredPart,
std::vector<Matrix::Data<float>*> &parts,
Matrix::PartDescriptor &desc,
int partIndex,
int myRank,
cudaStream_t stream
)#
void gather(
const raft::handle_t &h,
float *gatheredMatrix,
std::vector<Matrix::Data<float>*> &parts,
Matrix::PartDescriptor &desc,
int rootRank,
int myRank,
cudaStream_t stream
)#
void allGather(
const raft::handle_t &h,
float *gatheredMatrix,
std::vector<Matrix::Data<float>*> &parts,
Matrix::PartDescriptor &desc,
int myRank,
cudaStream_t stream
)#
void allocate(
const raft::handle_t &h,
std::vector<Matrix::Data<float>*> &parts,
Matrix::PartDescriptor &desc,
int myRank,
cudaStream_t stream
)#
void deallocate(
const raft::handle_t &h,
std::vector<Matrix::Data<float>*> &parts,
Matrix::PartDescriptor &desc,
int myRank,
cudaStream_t stream
)#
void randomize(
const raft::handle_t &h,
raft::random::Rng &r,
std::vector<Matrix::Data<float>*> &parts,
Matrix::PartDescriptor &desc,
int myRank,
cudaStream_t stream,
float low = -1.0f,
float high = 1.0f
)#
void reset(
const raft::handle_t &h,
std::vector<Matrix::Data<float>*> &parts,
Matrix::PartDescriptor &desc,
int myRank,
cudaStream_t stream
)#
void printRaw2D(
float *buffer,
int rows,
int cols,
bool isColMajor,
cudaStream_t stream
)#
void print(
const raft::handle_t &h,
std::vector<Matrix::Data<float>*> &parts,
Matrix::PartDescriptor &desc,
const char *matrixName,
int myRank,
cudaStream_t stream
)#
void gatherPart(
const raft::handle_t &h,
double *gatheredPart,
std::vector<Matrix::Data<double>*> &parts,
Matrix::PartDescriptor &desc,
int partIndex,
int rootRank,
int myRank,
cudaStream_t stream
)#
void allGatherPart(
const raft::handle_t &h,
double *gatheredPart,
std::vector<Matrix::Data<double>*> &parts,
Matrix::PartDescriptor &desc,
int partIndex,
int myRank,
cudaStream_t stream
)#
void gather(
const raft::handle_t &h,
double *gatheredMatrix,
std::vector<Matrix::Data<double>*> &parts,
Matrix::PartDescriptor &desc,
int rootRank,
int myRank,
cudaStream_t stream
)#
void allGather(
const raft::handle_t &h,
double *gatheredMatrix,
std::vector<Matrix::Data<double>*> &parts,
Matrix::PartDescriptor &desc,
int myRank,
cudaStream_t stream
)#
void allocate(
const raft::handle_t &h,
std::vector<Matrix::Data<double>*> &parts,
Matrix::PartDescriptor &desc,
int myRank,
cudaStream_t stream
)#
void deallocate(
const raft::handle_t &h,
std::vector<Matrix::Data<double>*> &parts,
Matrix::PartDescriptor &desc,
int myRank,
cudaStream_t stream
)#
void randomize(
const raft::handle_t &h,
raft::random::Rng &r,
std::vector<Matrix::Data<double>*> &parts,
Matrix::PartDescriptor &desc,
int myRank,
cudaStream_t stream,
double low = -1.0,
double high = 1.0
)#
void reset(
const raft::handle_t &h,
std::vector<Matrix::Data<double>*> &parts,
Matrix::PartDescriptor &desc,
int myRank,
cudaStream_t stream
)#
void printRaw2D(
double *buffer,
int rows,
int cols,
bool isColMajor,
cudaStream_t stream
)#
void print(
const raft::handle_t &h,
std::vector<Matrix::Data<double>*> &parts,
Matrix::PartDescriptor &desc,
const char *matrixName,
int myRank,
cudaStream_t stream
)#
namespace opg#

Functions

template<typename T>
void reduce_single_sum(
T *out,
const T *in,
const raft::comms::comms_t &comm,
cudaStream_t stream,
int root = 0
)#

sum-reduce single float numbers across workers

template<typename T>
void allreduce_single_sum(
T *out,
const T *in,
const raft::comms::comms_t &comm,
cudaStream_t stream
)#

all-reduce single float numbers across workers in Comm

namespace Stats#
namespace opg#

Functions

void cov(
const raft::handle_t &handle,
Matrix::Data<float> &covar,
const std::vector<Matrix::Data<float>*> &data,
const Matrix::PartDescriptor &dataDesc,
Matrix::Data<float> &mu,
bool sample,
cudaStream_t *streams,
int n_streams
)#

performs MNMG covariance calculation.

Parameters:
  • handle[in] cuML handle object

  • covar[out] resulting covariance matrix

  • data[in] the data that cov matrix is calculated for

  • dataDesc[in] MNMG description of the input data

  • mu[in] mean of every column in data

  • sample[in] whether to compute sample covariance

  • streams[in] cuda streams

  • n_streams[in] number of streams

void cov(
const raft::handle_t &handle,
Matrix::Data<double> &covar,
const std::vector<Matrix::Data<double>*> &data,
const Matrix::PartDescriptor &dataDesc,
Matrix::Data<double> &mu,
bool sample,
cudaStream_t *streams,
int n_streams
)#
void mean(
const raft::handle_t &handle,
Matrix::Data<float> &out,
const std::vector<Matrix::Data<float>*> &in,
const Matrix::PartDescriptor &inDesc,
cudaStream_t *streams,
int n_streams
)#

performs MNMG mean calculation.

Parameters:
  • handle[in] cuML handle object

  • out[out] mean of every column of the input

  • in[in] all the data partitions

  • inDesc[in] MNMG description of the input data

  • streams[in] cuda streams

  • n_streams[in] number of streams

void mean(
const raft::handle_t &handle,
Matrix::Data<double> &out,
const std::vector<Matrix::Data<double>*> &in,
const Matrix::PartDescriptor &inDesc,
cudaStream_t *streams,
int n_streams
)#
void mean_center(
const std::vector<Matrix::Data<double>*> &data,
const Matrix::PartDescriptor &dataDesc,
const Matrix::Data<double> &mu,
const raft::comms::comms_t &comm,
cudaStream_t *streams,
int n_streams
)#

performs MNMG mean subtraction calculation.

Parameters:
  • data[inout] the data that mean of every column is added

  • dataDesc[in] MNMG description of the input data

  • mu[in] mean of every column in data

  • comm[in] communicator

  • streams[in] cuda streams

  • n_streams[in] number of streams

void mean_center(
const std::vector<Matrix::Data<float>*> &data,
const Matrix::PartDescriptor &dataDesc,
const Matrix::Data<float> &mu,
const raft::comms::comms_t &comm,
cudaStream_t *streams,
int n_streams
)#
void mean_add(
const std::vector<Matrix::Data<double>*> &data,
const Matrix::PartDescriptor &dataDesc,
const Matrix::Data<double> &mu,
const raft::comms::comms_t &comm,
cudaStream_t *streams,
int n_streams
)#

performs MNMG mean add calculation.

Parameters:
  • data[inout] the data that mean of every column is added

  • dataDesc[in] MNMG description of the input data

  • mu[in] mean of every column in data

  • comm[in] communicator

  • streams[in] cuda streams

  • n_streams[in] number of streams

void mean_add(
const std::vector<Matrix::Data<float>*> &data,
const Matrix::PartDescriptor &dataDesc,
const Matrix::Data<float> &mu,
const raft::comms::comms_t &comm,
cudaStream_t *streams,
int n_streams
)#
void var(
const raft::handle_t &handle,
Matrix::Data<float> &out,
const std::vector<Matrix::Data<float>*> &in,
const Matrix::PartDescriptor &inDesc,
const float *mu,
cudaStream_t *streams,
int n_streams
)#

performs MNMG var calculation.

Parameters:
  • handle[in] cuML handle object

  • out[out] var of every column of the input

  • in[in] all the data partitions

  • inDesc[in] MNMG description of the input data

  • mu[in] mean of every column in data

  • streams[in] cuda streams

  • n_streams[in] number of streams

void var(
const raft::handle_t &handle,
Matrix::Data<double> &out,
const std::vector<Matrix::Data<double>*> &in,
const Matrix::PartDescriptor &inDesc,
const double *mu,
cudaStream_t *streams,
int n_streams
)#