CandidateVectorSearch 1.7.2
Searching for peptide candidates using sparse matrix + matrix/vector multiplication.
Loading...
Searching...
No Matches
findTopCandidatesCudaInt.cpp File Reference
#include "pch.h"
#include <cuda_runtime_api.h>
#include <cusparse.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <numeric>
#include <algorithm>
#include <vector>

Go to the source code of this file.

Macros

#define METHOD_EXPORTS
 
#define EXPORT   __declspec(dllexport)
 
#define CHECK_CUDA(status)   { checkCuda(status, __LINE__); }
 
#define CHECK_CUSPARSE(status)   { checkCusparse(status, __LINE__); }
 

Functions

EXPORT int * findTopCandidatesCuda (int *csrRowoffsets, int *csrColIdx, int *spectraValues, int *spectraIdx, int csrRowoffsetsLength, int csrNNZ, int sVLength, int sILength, int n, float tolerance, bool normalize, bool gaussianTol, int verbose)
 A function that calculates the top n candidates for each spectrum (SpM*V) using f32 operations.
 
EXPORT int * findTopCandidatesCudaInt (int *csrRowoffsets, int *csrColIdx, int *spectraValues, int *spectraIdx, int csrRowoffsetsLength, int csrNNZ, int sVLength, int sILength, int n, float tolerance, bool normalize, bool gaussianTol, int verbose)
 A function that calculates the top n candidates for each spectrum (SpM*V) using i8 and 32 operations.
 
EXPORT int * findTopCandidatesCudaBatched (int *csrRowoffsets, int *csrColIdx, int *spectraValues, int *spectraIdx, int csrRowoffsetsLength, int csrNNZ, int sVLength, int sILength, int n, float tolerance, bool normalize, bool gaussianTol, int batchSize, int verbose)
 A function that calculates the top n candidates for each spectrum. Uses cusparseSpGEMM to calculate matrix product.
 
EXPORT int * findTopCandidatesCudaBatched2 (int *csrRowoffsets, int *csrColIdx, int *spectraValues, int *spectraIdx, int csrRowoffsetsLength, int csrNNZ, int sVLength, int sILength, int n, float tolerance, bool normalize, bool gaussianTol, int batchSize, int verbose)
 A function that calculates the top n candidates for each spectrum. Uses cusparseSpMM to calculate matrix product.
 
EXPORT int releaseMemoryCuda (int *result)
 Free memory after result has been marshalled.
 
float squared (float x)
 Returns the square for a given value x.
 
float normpdf (float x, float mu, float sigma)
 Returns the PDF for a given x for the normal distribution given by mu and sigma.
 
int getRowIdx (int *csrRowoffsets, int csrRowoffsetsLength, int colIdxPos)
 Gets the row index of a specific position in the csr_column_indices array.
 
int checkCuda (cudaError_t, int line)
 
int checkCusparse (cusparseStatus_t, int line)
 
BOOL APIENTRY DllMain (HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
 

Variables

const int versionMajor = 1
 
const int versionMinor = 5
 
const int versionFix = 1
 
const int MASS_RANGE = 5000
 
const int MASS_MULTIPLIER = 100
 
const int ENCODING_SIZE = MASS_RANGE * MASS_MULTIPLIER
 
const float ROUNDING_ACCURACY = (float) INT8_MAX / 7.0f
 
const double ONE_OVER_SQRT_PI = 0.39894228040143267793994605993438
 

Macro Definition Documentation

◆ CHECK_CUDA

#define CHECK_CUDA (   status)    { checkCuda(status, __LINE__); }

Definition at line 23 of file findTopCandidatesCudaInt.cpp.

◆ CHECK_CUSPARSE

#define CHECK_CUSPARSE (   status)    { checkCusparse(status, __LINE__); }

Definition at line 24 of file findTopCandidatesCudaInt.cpp.

◆ EXPORT

#define EXPORT   __declspec(dllexport)

Definition at line 18 of file findTopCandidatesCudaInt.cpp.

◆ METHOD_EXPORTS

#define METHOD_EXPORTS

Definition at line 16 of file findTopCandidatesCudaInt.cpp.

Function Documentation

◆ checkCuda()

int checkCuda ( cudaError_t  status,
int  line 
)

Definition at line 77 of file findTopCandidatesCudaInt.cpp.

◆ checkCusparse()

int checkCusparse ( cusparseStatus_t  status,
int  line 
)

Definition at line 87 of file findTopCandidatesCudaInt.cpp.

◆ DllMain()

BOOL APIENTRY DllMain ( HMODULE  hModule,
DWORD  ul_reason_for_call,
LPVOID  lpReserved 
)

Definition at line 946 of file findTopCandidatesCudaInt.cpp.

◆ findTopCandidatesCuda()

int * findTopCandidatesCuda ( int *  csrRowoffsets,
int *  csrColIdx,
int *  spectraValues,
int *  spectraIdx,
int  csrRowoffsetsLength,
int  csrNNZ,
int  sVLength,
int  sILength,
int  n,
float  tolerance,
bool  normalize,
bool  gaussianTol,
int  verbose 
)

A function that calculates the top n candidates for each spectrum (SpM*V) using f32 operations.

Parameters
csrRowoffsetsRowoffsets (int array) of the CSR sparse matrix (L: rows + 1).
csrColIdxColumn indices (int array) of the CSR sparse matrix (L: NNZ).
spectraValuesAn integer array of peaks from experimental spectra flattened.
spectraIdxAn integer array that contains indices of where each spectrum starts in spectraValues.
csrRowoffsetsLengthLength (int) of csrRowoffsets (rows + 1).
csrNNZNumber of non-zero entries (int) in the CSR sparse matrix.
sVLengthLength (int) of spectraValues.
sILengthLength (int) of spectraIdx.
nHow many of the best hits should be returned (int).
toleranceTolerance for peak matching (float).
normalizeIf candidate vectors should be normalized to sum(elements) = 1 (bool).
gaussianTolIf spectrum peaks should be modelled as normal distributions or not (bool).
verbosePrint info every (int) processed spectra.
Returns
An integer array of length sILength * n containing the indexes of the top n candidates for each spectrum.
Parameters
csrRowoffsetsRowoffsets (int array) of the CSR sparse matrix (L: rows + 1).
csrColIdxColumn indices (int array) of the CSR sparse matrix (L: NNZ).
spectraValuesAn integer array of peaks from experimental spectra flattened.
spectraIdxAn integer array that contains indices of where each spectrum starts in spectraValues.
csrRowoffsetsLengthLength (int) of csrRowoffsets (rows + 1).
csrNNZNumber of non-zero entries (int) in the CSR sparse matrix.
sVLengthLength (int) of spectraValues.
sILengthLength (int) of spectraIdx.
nHow many of the best hits should be returned (int).
toleranceTolerance for peak matching (float).
normalizeIf candidate vectors should be normalized to sum(elements) = 1 (bool).
gaussianTolIf spectrum peaks should be modelled as normal distributions or not (bool).
verbosePrint info every (int) processed spectra.
Returns
An integer array of length sILength * n containing the indexes of the top n candidates for each spectrum.
Exceptions
std::invalid_argumentThrown if n is greater than cILength, cannot return more hits than number of candidates.

Definition at line 114 of file findTopCandidatesCudaInt.cpp.

◆ findTopCandidatesCudaBatched()

int * findTopCandidatesCudaBatched ( int *  csrRowoffsets,
int *  csrColIdx,
int *  spectraValues,
int *  spectraIdx,
int  csrRowoffsetsLength,
int  csrNNZ,
int  sVLength,
int  sILength,
int  n,
float  tolerance,
bool  normalize,
bool  gaussianTol,
int  batchSize,
int  verbose 
)

A function that calculates the top n candidates for each spectrum. Uses cusparseSpGEMM to calculate matrix product.

Parameters
csrRowoffsetsRowoffsets (int array) of the CSR sparse matrix (L: rows + 1).
csrColIdxColumn indices (int array) of the CSR sparse matrix (L: NNZ).
spectraValuesAn integer array of peaks from experimental spectra flattened.
spectraIdxAn integer array that contains indices of where each spectrum starts in spectraValues.
csrRowoffsetsLengthLength (int) of csrRowoffsets (rows + 1).
csrNNZNumber of non-zero entries (int) in the CSR sparse matrix.
sVLengthLength (int) of spectraValues.
sILengthLength (int) of spectraIdx.
nHow many of the best hits should be returned (int).
toleranceTolerance for peak matching (float).
normalizeIf candidate vectors should be normalized to sum(elements) = 1 (bool).
gaussianTolIf spectrum peaks should be modelled as normal distributions or not (bool).
batchSizeHow many spectra (int) should be searched at once.
verbosePrint info every (int) processed spectra.
Returns
An integer array of length sILength * n containing the indexes of the top n candidates for each spectrum.
Parameters
csrRowoffsetsRowoffsets (int array) of the CSR sparse matrix (L: rows + 1).
csrColIdxColumn indices (int array) of the CSR sparse matrix (L: NNZ).
spectraValuesAn integer array of peaks from experimental spectra flattened.
spectraIdxAn integer array that contains indices of where each spectrum starts in spectraValues.
csrRowoffsetsLengthLength (int) of csrRowoffsets (rows + 1).
csrNNZNumber of non-zero entries (int) in the CSR sparse matrix.
sVLengthLength (int) of spectraValues.
sILengthLength (int) of spectraIdx.
nHow many of the best hits should be returned (int).
toleranceTolerance for peak matching (float).
normalizeIf candidate vectors should be normalized to sum(elements) = 1 (bool).
gaussianTolIf spectrum peaks should be modelled as normal distributions or not (bool).
batchSizeHow many spectra (int) should be searched at once.
verbosePrint info every (int) processed spectra.
Returns
An integer array of length sILength * n containing the indexes of the top n candidates for each spectrum.
Exceptions
std::invalid_argumentThrown if n is greater than cILength, cannot return more hits than number of candidates.

Definition at line 435 of file findTopCandidatesCudaInt.cpp.

◆ findTopCandidatesCudaBatched2()

int * findTopCandidatesCudaBatched2 ( int *  csrRowoffsets,
int *  csrColIdx,
int *  spectraValues,
int *  spectraIdx,
int  csrRowoffsetsLength,
int  csrNNZ,
int  sVLength,
int  sILength,
int  n,
float  tolerance,
bool  normalize,
bool  gaussianTol,
int  batchSize,
int  verbose 
)

A function that calculates the top n candidates for each spectrum. Uses cusparseSpMM to calculate matrix product.

Parameters
csrRowoffsetsRowoffsets (int array) of the CSR sparse matrix (L: rows + 1).
csrColIdxColumn indices (int array) of the CSR sparse matrix (L: NNZ).
spectraValuesAn integer array of peaks from experimental spectra flattened.
spectraIdxAn integer array that contains indices of where each spectrum starts in spectraValues.
csrRowoffsetsLengthLength (int) of csrRowoffsets (rows + 1).
csrNNZNumber of non-zero entries (int) in the CSR sparse matrix.
sVLengthLength (int) of spectraValues.
sILengthLength (int) of spectraIdx.
nHow many of the best hits should be returned (int).
toleranceTolerance for peak matching (float).
normalizeIf candidate vectors should be normalized to sum(elements) = 1 (bool).
gaussianTolIf spectrum peaks should be modelled as normal distributions or not (bool).
batchSizeHow many spectra (int) should be searched at once.
verbosePrint info every (int) processed spectra.
Returns
An integer array of length sILength * n containing the indexes of the top n candidates for each spectrum.
Parameters
csrRowoffsetsRowoffsets (int array) of the CSR sparse matrix (L: rows + 1).
csrColIdxColumn indices (int array) of the CSR sparse matrix (L: NNZ).
spectraValuesAn integer array of peaks from experimental spectra flattened.
spectraIdxAn integer array that contains indices of where each spectrum starts in spectraValues.
csrRowoffsetsLengthLength (int) of csrRowoffsets (rows + 1).
csrNNZNumber of non-zero entries (int) in the CSR sparse matrix.
sVLengthLength (int) of spectraValues.
sILengthLength (int) of spectraIdx.
nHow many of the best hits should be returned (int).
toleranceTolerance for peak matching (float).
normalizeIf candidate vectors should be normalized to sum(elements) = 1 (bool).
gaussianTolIf spectrum peaks should be modelled as normal distributions or not (bool).
batchSizeHow many spectra (int) should be searched at once.
verbosePrint info every (int) processed spectra.
Returns
An integer array of length sILength * n containing the indexes of the top n candidates for each spectrum.
Exceptions
std::invalid_argumentThrown if n is greater than cILength, cannot return more hits than number of candidates.

Definition at line 710 of file findTopCandidatesCudaInt.cpp.

◆ findTopCandidatesCudaInt()

int * findTopCandidatesCudaInt ( int *  csrRowoffsets,
int *  csrColIdx,
int *  spectraValues,
int *  spectraIdx,
int  csrRowoffsetsLength,
int  csrNNZ,
int  sVLength,
int  sILength,
int  n,
float  tolerance,
bool  normalize,
bool  gaussianTol,
int  verbose 
)

A function that calculates the top n candidates for each spectrum (SpM*V) using i8 and 32 operations.

Parameters
csrRowoffsetsRowoffsets (int array) of the CSR sparse matrix (L: rows + 1).
csrColIdxColumn indices (int array) of the CSR sparse matrix (L: NNZ).
spectraValuesAn integer array of peaks from experimental spectra flattened.
spectraIdxAn integer array that contains indices of where each spectrum starts in spectraValues.
csrRowoffsetsLengthLength (int) of csrRowoffsets (rows + 1).
csrNNZNumber of non-zero entries (int) in the CSR sparse matrix.
sVLengthLength (int) of spectraValues.
sILengthLength (int) of spectraIdx.
nHow many of the best hits should be returned (int).
toleranceTolerance for peak matching (float).
normalizeIf candidate vectors should be normalized to sum(elements) = 1 (bool).
gaussianTolIf spectrum peaks should be modelled as normal distributions or not (bool).
verbosePrint info every (int) processed spectra.
Returns
An integer array of length sILength * n containing the indexes of the top n candidates for each spectrum.

Definition at line 272 of file findTopCandidatesCudaInt.cpp.

◆ getRowIdx()

int getRowIdx ( int *  csrRowoffsets,
int  csrRowoffsetsLength,
int  colIdxPos 
)

Gets the row index of a specific position in the csr_column_indices array.

Parameters
csrRowoffsetsThe csr_row_offsets array.
csrRowoffsetsLengthLength (int) of the csr_row_offsets array.
colIdxPosThe position (int) of the element in question of the csr_column_indices array.
Returns
Associated row index (int) or throws an error if the row index could not be found.
Parameters
csrRowoffsetsThe csr_row_offsets array.
csrRowoffsetsLengthLength (int) of the csr_row_offsets array.
colIdxPosThe position (int) of the element in question of the csr_column_indices array.
Returns
Associated row index (int) or throws an error if the row index could not be found.
Exceptions
std::logic_errorThrown if the row index could not be found.

Definition at line 934 of file findTopCandidatesCudaInt.cpp.

◆ normpdf()

float normpdf ( float  x,
float  mu,
float  sigma 
)

Returns the PDF for a given x for the normal distribution given by mu and sigma.

Parameters
xThe value for which the PDF should be calculated.
muThe mu of the normal distribution.
sigmaThe sigma of the normal distribution.
Returns
The PDF at x for the normal distribution given by mu and sigma. If sigma = 0 it returns 1.

Definition at line 920 of file findTopCandidatesCudaInt.cpp.

◆ releaseMemoryCuda()

int releaseMemoryCuda ( int *  result)

Free memory after result has been marshalled.

Parameters
resultThe result array.
Returns
0

Definition at line 898 of file findTopCandidatesCudaInt.cpp.

◆ squared()

float squared ( float  x)

Returns the square for a given value x.

Parameters
xThe value to be squared.
Returns
Square of x.

Definition at line 909 of file findTopCandidatesCudaInt.cpp.

Variable Documentation

◆ ENCODING_SIZE

const int ENCODING_SIZE = MASS_RANGE * MASS_MULTIPLIER

Definition at line 28 of file findTopCandidatesCudaInt.cpp.

◆ MASS_MULTIPLIER

const int MASS_MULTIPLIER = 100

Definition at line 27 of file findTopCandidatesCudaInt.cpp.

◆ MASS_RANGE

const int MASS_RANGE = 5000

Definition at line 26 of file findTopCandidatesCudaInt.cpp.

◆ ONE_OVER_SQRT_PI

const double ONE_OVER_SQRT_PI = 0.39894228040143267793994605993438

Definition at line 30 of file findTopCandidatesCudaInt.cpp.

◆ ROUNDING_ACCURACY

const float ROUNDING_ACCURACY = (float) INT8_MAX / 7.0f

Definition at line 29 of file findTopCandidatesCudaInt.cpp.

◆ versionFix

const int versionFix = 1

Definition at line 14 of file findTopCandidatesCudaInt.cpp.

◆ versionMajor

const int versionMajor = 1

Definition at line 12 of file findTopCandidatesCudaInt.cpp.

◆ versionMinor

const int versionMinor = 5

Definition at line 13 of file findTopCandidatesCudaInt.cpp.