Reputation: 11
[Cudafy]
private static void LevenshteinGpu3(GThread thread, char[] source, char[] pattern, int firstDim, byte compareLength, byte[] dev_results)
{
int tid = thread.threadIdx.x + thread.blockIdx.x * thread.blockDim.x;
byte[,,] dev_levMatrix_1 = _gpu.Allocate<byte>(20, 20, 20);
for (byte j = 0; j <= compareLength; j++)
{
dev_levMatrix_1[tid, 0, j] = j;
dev_levMatrix_1[tid, j, 0] = j;
}
if (tid < firstDim)
{
for (int i = 1; i <= compareLength; i++)
{
for (int j = 1; j <= compareLength; j++)
{
int iMinusOne = i - 1;
int jMinusOne = j - 1;
if (tid + iMinusOne < source.Length && source[tid + iMinusOne] == pattern[jMinusOne])
{
dev_levMatrix_1[tid, i, j] = dev_levMatrix_1[tid, iMinusOne, jMinusOne];
}
else
{
byte x = dev_levMatrix_1[tid, iMinusOne, j];
if (x > dev_levMatrix_1[tid, i, jMinusOne])
x = dev_levMatrix_1[tid, i, jMinusOne];
if (x > dev_levMatrix_1[tid, iMinusOne, jMinusOne])
x = dev_levMatrix_1[tid, iMinusOne, jMinusOne];
dev_levMatrix_1[tid, i, j] = ++x;
}
}
}
dev_results[tid] = dev_levMatrix_1[tid, compareLength, compareLength];
}
}
I'm using code of Konrad-Ziarko on github. But when I put
byte[,,] dev_levMatrix_1 = _gpu.Allocate<byte>(20, 20, 20);
in the code and run. Cuda showed error 719.
But if I put dev_levMatrix_1
like below, it works:
private static void LevenshteinGpu3(GThread thread, char[] source, char[] pattern, dev_levMatrix_1, int firstDim, byte compareLength, byte[] dev_results)
Can I can put dev_levMatrix_1
in a function?
Upvotes: 1
Views: 513
Reputation: 11
Little late but...
You can't allocate GPU memory inside Cudafy decorated function. Allocation should happen before passing parameters to kernel. Inside kernel function you can create local variables and use them.
Also, you could find help faster asking questions at the source not somewhere else and mention source.
Upvotes: 1