Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- nvcc text.cu -cubin
- __global__ void string_search(char** texts, int* lengths, char* symbol, int* matches, int symbolLength)
- {
- int localMatches = 0;
- int blockId = blockIdx.x + blockIdx.y * gridDim.x;
- int threadId = threadIdx.x + threadIdx.y * blockDim.x;
- int blockThreads = blockDim.x * blockDim.y;
- __shared__ int localMatchCounts[32];
- bool breaking = false;
- for(int i = 0; i < (lengths[blockId] - (symbolLength - 1)); i += blockThreads)
- {
- if(texts[blockId][i] == symbol[0])
- {
- for(int j = 1; j < symbolLength; j++)
- {
- if(texts[blockId][i + j] != symbol[j])
- {
- breaking = true;
- break;
- }
- }
- if (breaking) continue;
- localMatches++;
- }
- }
- localMatchCounts[threadId] = localMatches;
- __syncthreads();
- if(threadId == 0)
- {
- int sum = 0;
- for(int i = 0; i < 32; i++)
- {
- sum += localMatchCounts[i];
- }
- matches[blockId] = sum;
- }
- }
- localMatchCounts[threadId] = localMatches;
- localMatchCounts[threadId] = 5;
Add Comment
Please, Sign In to add comment