我對本地內存有問題,具體是保存值。這是加載到程序中的所有內核。OpenCL本地工作本地內存
__kernel void initData(int bitSample, int transmitorCount ,int bufferLen, __global short *sequence)
{
__local int constData[2];
__local short mask[(15 * 1023)];
constData[0] = bitSample;
constData[1] = bufferLen;
for (int i = 0; i < transmitorCount * 1023; i++) {
mask[i] = sequence[i];
}
printf("startPlace: %u \t Resutl: %i = %i\n", transmitorCount, constData[0], constData[1]);
barrier(CLK_LOCAL_MEM_FENCE);
}
__kernel void correlation(__global short *inBuffer, __global int *outBuffer, __local int *constData)
{
uint startPlace = get_global_id(0);
uint sequence = get_global_id(1);
outBuffer[0] = inBuffer[0];
printf("startPlace: %i Sequence: %i\t Resutl: %i = %i\n", startPlace, sequence, constData[0], constData[1]);
}
程序正在工作並保存本地內存。初始化調用是:
size_t globaId[3] = { 1, 0, 0 };
ret = clEnqueueNDRangeKernel(gpuControlData->cmdQueue, gpuControlData->initKernel, 1, NULL, globaId, NULL, 0, NULL, NULL);
但是,當我啓動相關內核時,保存的值僅在本地啓動。第二次和下一次啓動是錯誤的數據。我嘗試在每次啓動之前初始化本地內存,但它不起作用。創建命令隊列是:
while(true){
ret = clSetKernelArg(gpuControlData->corelationKernel, 0, sizeof(cl_mem), (void *) &inBuffer);
ret = clSetKernelArg(gpuControlData->corelationKernel, 1, sizeof(cl_mem), (void *)&outBuffer);
ret = clSetKernelArg(gpuControlData->corelationKernel, 2, sizeof(cl_int) * 2, NULL);
size_t globaId[3] = { 3, 2, 0 };
ret = clEnqueueNDRangeKernel(gpuControlData->maskCorrelQueue, gpuControlData->corelationKernel, 2, NULL, globaId, NULL, 0, NULL, NULL);
}
一個運行的結果是:
startPlace: 2 Resutl: 100 = 150000
startPlace: 0 Sequence: 0 Resutl: 100 = 150000
startPlace: 1 Sequence: 0 Resutl: 100 = 150000
startPlace: 2 Sequence: 0 Resutl: 100 = 150000
startPlace: 0 Sequence: 1 Resutl: 100 = 150000
startPlace: 1 Sequence: 1 Resutl: 100 = 150000
startPlace: 2 Sequence: 1 Resutl: 100 = 150000
oneIteration
startPlace: 0 Sequence: 0 Resutl: 1056562655 = 1058300571
startPlace: 1 Sequence: 0 Resutl: 1056562655 = 1058300571
startPlace: 2 Sequence: 0 Resutl: 1056562655 = 1058300571
startPlace: 0 Sequence: 1 Resutl: 1056562655 = 1058300571
startPlace: 1 Sequence: 1 Resutl: 1056562655 = 1058300571
startPlace: 2 Sequence: 1 Resutl: 1056562655 = 1058300571
所以我需要一些幫助,或者例如如何在同一本地數據循環中運行的內核?
感謝您的幫助。
如果我的記憶服務,本地存儲器中的數據不保留在波前。我想我不知道你想做什麼。 – BlueWanderer
我想比較數據。一個數據被定義,靜態和第二個數據被改變。所以我想將常量數據保存到本地內存以加快訪問速度。每次迭代我都有機會進入緩衝區。 –
@StepanRydlo工作組中的所有線程都可以將數據從全局內存收集到本地內存,並且它們可以同時進行。所以你可以讓單個內核同時進行初始化和關聯。在開始關聯之前,您需要與屏障命令同步。 –