35 var candidateValues =
new int[] { 1, 4, 0, 1, 2, 3, 1, 2, 3, 1, 4, 0, 1, 2, 3, 4};
36 var candidatesIdx =
new int[] { 0, 2, 6, 9, 11 };
37 var csrRowoffsets =
new int[] { 0, 2, 6, 9, 11, 16 };
38 var csrIdx =
new int[] { 1, 4, 0, 1, 2, 3, 1, 2, 3, 1, 4, 0, 1, 2, 3, 4 };
41 var spectraValues =
new int[] { 1, 2, 0, 1, 2, 4 };
42 var spectraIdx =
new int[] { 0, 2 };
48 var sw = Stopwatch.StartNew();
51 var cValuesLoc = GCHandle.Alloc(candidateValues, GCHandleType.Pinned);
52 var cIdxLoc = GCHandle.Alloc(candidatesIdx, GCHandleType.Pinned);
53 var csrRowoffsetsLoc = GCHandle.Alloc(csrRowoffsets, GCHandleType.Pinned);
54 var csrIdxLoc = GCHandle.Alloc(csrIdx, GCHandleType.Pinned);
55 var sValuesLoc = GCHandle.Alloc(spectraValues, GCHandleType.Pinned);
56 var sIdxLoc = GCHandle.Alloc(spectraIdx, GCHandleType.Pinned);
57 var resultArrayEigen =
new int[spectraIdx.Length * topN];
58 var resultArrayCuda =
new int[spectraIdx.Length * topN];
62 IntPtr cValuesPtr = cValuesLoc.AddrOfPinnedObject();
63 IntPtr cIdxPtr = cIdxLoc.AddrOfPinnedObject();
64 IntPtr csrRowoffsetsPtr = csrRowoffsetsLoc.AddrOfPinnedObject();
65 IntPtr csrIdxPtr = csrIdxLoc.AddrOfPinnedObject();
66 IntPtr sValuesPtr = sValuesLoc.AddrOfPinnedObject();
67 IntPtr sIdxPtr = sIdxLoc.AddrOfPinnedObject();
77 IntPtr resultCuda = findTopCandidatesCudaBatched(csrRowoffsetsPtr, csrIdxPtr,
79 csrRowoffsets.Length, csrIdx.Length,
80 spectraValues.Length, spectraIdx.Length,
82 NORMALIZE, USE_GAUSSIAN, 2,
85 Marshal.Copy(resultCuda, resultArrayCuda, 0, spectraIdx.Length * topN);
87 memStat = releaseMemoryCuda(resultCuda);
91 Console.WriteLine(
"Something went wrong:");
92 Console.WriteLine(ex.ToString());
96 if (cValuesLoc.IsAllocated) { cValuesLoc.Free(); }
97 if (cIdxLoc.IsAllocated) { cIdxLoc.Free(); }
98 if (csrRowoffsetsLoc.IsAllocated) { csrRowoffsetsLoc.Free(); }
99 if (csrIdxLoc.IsAllocated) { csrIdxLoc.Free(); }
100 if (sValuesLoc.IsAllocated) { sValuesLoc.Free(); }
101 if (sIdxLoc.IsAllocated) { sIdxLoc.Free(); }
107 for (
int i = 0; i < spectraIdx.Length * topN; i++)
109 Console.WriteLine($
"Eigen: {resultArrayEigen[i]}");
111 for (
int i = 0; i < spectraIdx.Length * topN; i++)
113 Console.WriteLine($
"CUDA: {resultArrayCuda[i]}");
116 Console.WriteLine($
"MemStat: {memStat}");
117 Console.WriteLine(
"Time for candidate search (SpMV):");
118 Console.WriteLine(sw.Elapsed.TotalSeconds.ToString());
122 GC.WaitForPendingFinalizers();