Skip to content

Commit

Permalink
Merge pull request #6 from hgb-bin-proteomics/develop
Browse files Browse the repository at this point in the history
verbosity in Cuda Batched
  • Loading branch information
michabirklbauer authored Jul 24, 2023
2 parents 8aa8660 + 25afc39 commit 645a6a1
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 12 deletions.
4 changes: 2 additions & 2 deletions DataLoader/Compare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public static int Compare(int nrCandidates, int nrSpectra, int topN, Random r)
sValuesPtr, sIdxPtr,
csrRowoffsets.Length, csrIdx.Length,
spectraValues.Length, spectraIdx.Length,
topN, (float) 0.02, NORMALIZE, USE_GAUSSIAN);
topN, (float) 0.02, NORMALIZE, USE_GAUSSIAN, 0);

Marshal.Copy(resultCuda, resultArrayCuda, 0, spectraIdx.Length * topN);

Expand All @@ -132,7 +132,7 @@ public static int Compare(int nrCandidates, int nrSpectra, int topN, Random r)
sValuesPtr, sIdxPtr,
csrRowoffsets.Length, csrIdx.Length,
spectraValues.Length, spectraIdx.Length,
topN, (float) 0.02, NORMALIZE, USE_GAUSSIAN, BATCH_SIZE);
topN, (float) 0.02, NORMALIZE, USE_GAUSSIAN, BATCH_SIZE, 0);

Marshal.Copy(resultCudaB, resultArrayCudaB, 0, spectraIdx.Length * topN);

Expand Down
12 changes: 8 additions & 4 deletions DataLoader/Cuda.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ private static extern IntPtr findTopCandidatesCuda(IntPtr cR, IntPtr cI,
int cRL, int cNNZ,
int sVL, int sIL,
int n, float tolerance,
bool normalize, bool gaussianTol);
bool normalize, bool gaussianTol,
int verbose);

[DllImport(dllCuda, CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr findTopCandidatesCudaBatched(IntPtr cR, IntPtr cI,
Expand All @@ -21,7 +22,8 @@ private static extern IntPtr findTopCandidatesCudaBatched(IntPtr cR, IntPtr cI,
int sVL, int sIL,
int n, float tolerance,
bool normalize, bool gaussianTol,
int batchSize);
int batchSize,
int verbose);

[DllImport(dllCuda, CallingConvention = CallingConvention.Cdecl)]
private static extern int releaseMemoryCuda(IntPtr result);
Expand Down Expand Up @@ -108,7 +110,8 @@ public static int Cuda(int nrCandidates, int nrSpectra, int topN, Random r, bool
csrRowoffsets.Length, csrIdx.Length,
spectraValues.Length, spectraIdx.Length,
topN, (float) 0.02,
NORMALIZE, USE_GAUSSIAN);
NORMALIZE, USE_GAUSSIAN,
1000);

Marshal.Copy(result, resultArray, 0, spectraIdx.Length * topN);

Expand All @@ -127,7 +130,8 @@ public static int Cuda(int nrCandidates, int nrSpectra, int topN, Random r, bool
spectraValues.Length, spectraIdx.Length,
topN, (float) 0.02,
NORMALIZE, USE_GAUSSIAN,
BATCH_SIZE);
BATCH_SIZE,
1000);

Marshal.Copy(result, resultArray, 0, spectraIdx.Length * topN);

Expand Down
2 changes: 1 addition & 1 deletion DataLoader/DataLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static void Main(string[] args)
var status = Cuda(nrCandidates, nrSpectra, topN, r, false);
Console.WriteLine($"Cuda routine exited with status: {status}");
}
if (mode == "CudaB")
else if (mode == "CudaB")
{
var status = Cuda(nrCandidates, nrSpectra, topN, r, true);
Console.WriteLine($"Cuda routine exited with status: {status}");
Expand Down
3 changes: 2 additions & 1 deletion DataLoader/DeterministicCompare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public static int DeterministicCompare()
csrRowoffsets.Length, csrIdx.Length,
spectraValues.Length, spectraIdx.Length,
topN, (float) 0.0,
NORMALIZE, USE_GAUSSIAN, 2);
NORMALIZE, USE_GAUSSIAN, 2,
1000);

Marshal.Copy(resultCuda, resultArrayCuda, 0, spectraIdx.Length * topN);

Expand Down
2 changes: 2 additions & 0 deletions VectorSearch/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ float normpdf(float, float, float);
/// <param name="tolerance">Tolerance for peak matching (float).</param>
/// <param name="normalize">If candidate vectors should be normalized to sum(elements) = 1 (bool).</param>
/// <param name="gaussianTol">If spectrum peaks should be modelled as normal distributions or not (bool).</param>
/// <param name="verbose">Print info every (int) processed spectra.</param>
/// <returns>An integer array of length sILength * n containing the indexes of the top n candidates for each spectrum.</returns>
int* findTopCandidates(int* candidatesValues, int* candidatesIdx,
int* spectraValues, int* spectraIdx,
Expand Down Expand Up @@ -158,6 +159,7 @@ int* findTopCandidates(int* candidatesValues, int* candidatesIdx,
/// <param name="normalize">If candidate vectors should be normalized to sum(elements) = 1 (bool).</param>
/// <param name="gaussianTol">If spectrum peaks should be modelled as normal distributions or not (bool).</param>
/// <param name="batchSize">How many spectra (int) should be searched at once.</param>
/// <param name="verbose">Print info every (int) processed spectra.</param>
/// <returns>An integer array of length sILength * n containing the indexes of the top n candidates for each spectrum.</returns>
int* findTopCandidatesBatched(int* candidatesValues, int* candidatesIdx,
int* spectraValues, int* spectraIdx,
Expand Down
22 changes: 18 additions & 4 deletions VectorSearchCUDA/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

const int versionMajor = 1;
const int versionMinor = 3;
const int versionFix = 3;
const int versionFix = 4;

#define METHOD_EXPORTS
#ifdef METHOD_EXPORTS
Expand All @@ -31,14 +31,16 @@ extern "C" {
int, int,
int, int,
int, float,
bool, bool);
bool, bool,
int);

EXPORT int* findTopCandidatesCudaBatched(int*, int*,
int*, int*,
int, int,
int, int,
int, float,
bool, bool,
int,
int);

EXPORT int releaseMemoryCuda(int*);
Expand Down Expand Up @@ -86,13 +88,15 @@ int CHECK_CUSPARSE(cusparseStatus_t status)
/// <param name="tolerance">Tolerance for peak matching (float).</param>
/// <param name="normalize">If candidate vectors should be normalized to sum(elements) = 1 (bool).</param>
/// <param name="gaussianTol">If spectrum peaks should be modelled as normal distributions or not (bool).</param>
/// <param name="verbose">Print info every (int) processed spectra.</param>
/// <returns>An integer array of length sILength * n containing the indexes of the top n candidates for each spectrum.</returns>
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) {
bool normalize, bool gaussianTol,
int verbose) {

if (n >= csrRowoffsetsLength) {
throw std::invalid_argument("Cannot return more hits than number of candidates!");
Expand Down Expand Up @@ -201,6 +205,10 @@ int* findTopCandidatesCuda(int* csrRowoffsets, int* csrColIdx,
}

delete[] idx;

if (verbose != 0 && (i + 1) % verbose == 0) {
std::cout << "Searched " << i + 1 << " spectra in total..." << std::endl;
}
}

// device destroy descriptors
Expand Down Expand Up @@ -239,14 +247,16 @@ int* findTopCandidatesCuda(int* csrRowoffsets, int* csrColIdx,
/// <param name="normalize">If candidate vectors should be normalized to sum(elements) = 1 (bool).</param>
/// <param name="gaussianTol">If spectrum peaks should be modelled as normal distributions or not (bool).</param>
/// <param name="batchSize">How many spectra (int) should be searched at once.</param>
/// <param name="verbose">Print info every (int) processed spectra.</param>
/// <returns>An integer array of length sILength * n containing the indexes of the top n candidates for each spectrum.</returns>
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 batchSize,
int verbose) {

if (n >= csrRowoffsetsLength) {
throw std::invalid_argument("Cannot return more hits than number of candidates!");
Expand Down Expand Up @@ -462,6 +472,10 @@ int* findTopCandidatesCudaBatched(int* csrRowoffsets, int* csrColIdx,
CHECK_CUDA(cudaFree(dM_csrValues));
CHECK_CUDA(cudaFree(dspgemM_csrColIdx));
CHECK_CUDA(cudaFree(dspgemM_csrValues));

if (verbose != 0 && (i + batchSize) % verbose == 0) {
std::cout << "Searched " << i + batchSize << " spectra in total..." << std::endl;
}
}

// device destroy descriptors
Expand Down
Binary file modified dll/VectorSearch.dll
Binary file not shown.
Binary file modified dll/VectorSearchCUDA.dll
Binary file not shown.

0 comments on commit 645a6a1

Please sign in to comment.