Застрял на том, почему мое ядро OpenCL не будет выполняться с определенными параметрами

StackOverflow https://stackoverflow.com/questions/4305133

  •  29-09-2019
  •  | 
  •  

Вопрос

У меня есть ядро OpenCL, которое я запускаю в JOCL, и оно проходит все мои тесты JUnit.Я портировал свой код на C ++, чтобы иметь возможность профилировать ядро в тех же условиях.Драйвер работает нормально во всех случаях, кроме одного.Он отлично работает в JOCL, поэтому я считаю, что что-то в моем коде на C ++ неправильно.Мой код приведен ниже, я проверил его до смерти.Если кто-нибудь может помочь мне определить, в чем проблема, я был бы признателен.

Код драйвера отлично работает с аргументами 1 и 2 как 8192, аргументом 3 как 512.Он также прекрасно работает с аргументами 1 и 2 как 512 и аргументом 3 как 8192.Аргумент 4 всегда равен 1, что переводит ядро в режим действительных чисел.Когда я устанавливаю для аргументов 1 и 2 значение 262144, а для аргумента 3 значение 16, он выполняется, никаких сообщений об ошибках не сообщается, никаких сбоев seg, но ядро в итоге не изменяет данные.Обратите внимание, что аргумент 1*3 во всех приведенных выше случаях равен 2^22.Я полагаю, что во всех случаях я выделяю одинаковое количество плавающих значений.Я в тупике.Я не могу заставить OpenCL сказать мне, что не так:(

void HelperFunctions::callKernel(int windowSize, int primitivesPerDataFrame, int nInFramesThisCall, int realOrComplex)
{
// OpenCL Vars
cl_platform_id platform;       // OpenCL platform
cl_device_id device;           // OpenCL device
cl_context gpuContext;         // OpenCL context
cl_command_queue commandQueue; // OpenCL command queue
cl_program clProgram;           // OpenCL program
cl_kernel clkernel;             // OpenCL kernel
void *dataHostBuffer;        // Host buffer
void *windowDataHostBuffer;        // Host buffer
cl_mem inData;   // OpenCL device buffer
cl_mem windowData;  // OpenCL device source buffer
size_t szKernelLength;        // Byte size of kernel code
cl_int errCode;                // Error code var

long gridX = 256;
long gridY = 16384;
long gridZ = 1;
size_t global_work_size[] = {gridX, gridY, gridZ};
size_t local_work_size[] = {gridX, 1, 1};
const char* cSourceCL = NULL;     // Buffer to hold source for compilation

// Allocate and initialize host arrays
dataHostBuffer = (void *)malloc(sizeof(cl_float) * primitivesPerDataFrame * nInFramesThisCall);
windowDataHostBuffer = (void *)malloc(sizeof(cl_float) * windowSize);

//Populate the data buffers
dataHostBuffer = generateRampData(primitivesPerDataFrame * nInFramesThisCall);

windowDataHostBuffer = blackman(windowSize);

//Get an OpenCL platform
errCode = clGetPlatformIDs(1, &platform, NULL);
cout << "Error Code: " << errCode << endl;

//Get the devices
errCode = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, NULL);
cout << "Error Code: " << errCode << endl;

//Create the context
gpuContext = clCreateContext(0, 1, &device, NULL, NULL, &errCode);
cout << "Error Code: " << errCode << endl;

// Create a command-queue
commandQueue = clCreateCommandQueue(gpuContext, device, 0, &errCode);

// Read the OpenCL kernel in from source file
cSourceCL = oclLoadProgSource("/home/djkasht/workspaceBlueprint/bp/bp-trunk/bundles/CopperShark/src/coppershark/dsp/blocks/opencl/dsp/window/Window.cl", "", &szKernelLength);

szKernelLength = strlen(cSourceCL);
// Create the program
clProgram = clCreateProgramWithSource(gpuContext, 1, (const char **)&cSourceCL, &szKernelLength, &errCode);
cout << "Error Code: " << errCode << endl;

// Build the program
errCode = clBuildProgram(clProgram, 0, NULL, NULL, NULL, NULL);
cout << "Error Code: " << errCode << endl;

size_t log_size = 1000000 * sizeof(char);
char build_log[log_size];
size_t len;
errCode = clGetProgramBuildInfo(clProgram, device, CL_PROGRAM_BUILD_LOG, log_size, build_log, &len);
cout << build_log << endl;

// Create the kernel
clkernel = clCreateKernel(clProgram, "window", &errCode);
cout << "Error Code: " << errCode << endl;

// Allocate the OpenCL buffer memory objects
inData = clCreateBuffer(gpuContext, CL_MEM_READ_WRITE, sizeof(cl_float) * primitivesPerDataFrame * nInFramesThisCall, NULL, &errCode);
cout << "Error Code: " << errCode << endl;
windowData = clCreateBuffer(gpuContext, CL_MEM_READ_ONLY, sizeof(cl_float) * windowSize, NULL, &errCode);
cout << "Error Code: " << errCode << endl;

// Set the Argument values
errCode = clSetKernelArg(clkernel, 0, sizeof(cl_mem), (void*)&inData);
cout << "Error Code: " << errCode << endl;
errCode = clSetKernelArg(clkernel, 1, sizeof(cl_mem), (void*)&windowData);
cout << "Error Code: " << errCode << endl;
errCode = clSetKernelArg(clkernel, 2, sizeof(cl_int), (void*)&windowSize);
cout << "Error Code: " << errCode << endl;
errCode = clSetKernelArg(clkernel, 3, sizeof(cl_int), (void*)&primitivesPerDataFrame);
cout << "Error Code: " << errCode << endl;
errCode = clSetKernelArg(clkernel, 4, sizeof(cl_int), (void*)&nInFramesThisCall);
cout << "Error Code: " << errCode << endl;
errCode = clSetKernelArg(clkernel, 5, sizeof(cl_int), (void*)&realOrComplex);
cout << "Error Code: " << errCode << endl;

// Asynchronous write of data to GPU device
errCode = clEnqueueWriteBuffer(commandQueue, inData, CL_FALSE, 0, sizeof(cl_float) * primitivesPerDataFrame * nInFramesThisCall, dataHostBuffer, 0, NULL, NULL);
cout << "Error Code: " << errCode << endl;

// Synchronous/blocking read of results, and check accumulated errors
errCode = clEnqueueWriteBuffer(commandQueue, windowData, CL_FALSE, 0, sizeof(cl_float) * windowSize, windowDataHostBuffer, 0, NULL, NULL);
cout << "Error Code: " << errCode << endl;

errCode = clEnqueueNDRangeKernel(commandQueue, clkernel, 3, NULL, &(global_work_size[0]), &(local_work_size[0]), 0, NULL, NULL);
cout << "Error Code: " << errCode << endl;

void* dataHostBuffer2 = (void *)malloc(sizeof(cl_float) * primitivesPerDataFrame * nInFramesThisCall);
errCode = clEnqueueReadBuffer(commandQueue, inData, CL_TRUE, 0, sizeof(cl_float) * primitivesPerDataFrame * nInFramesThisCall, dataHostBuffer2, 0, NULL, NULL);

}

Это было полезно?

Решение

ОБНОВЛЕНИЕ, я все понял!Проблема кроется в моем ядре.Я использую постоянную память.Мой java-код учитывает это и текстуально манипулирует кодом так, что если размер моего буфера для arg 2 > 16384, он изменяет константу __ на __global.Я должен был знать это, но я забыл...

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top