PDA

View Full Version : opencl build error..!!



phoebe0105
05-14-2010, 07:55 AM
I face to opencl program build error.
This erro is "CL_BUILD_PROGRAM_FAILURE".
I read the document of opencl 1.0.43 provide by KHRONOS.

"CL_BUILD_PROGRAM_FAILURE if there is a failure to build the program executable.
This error will be returned if clBuildProgram does not return until the build has
completed."

But I don't know why this error is occured. Before I builded to command window, it isn't occured any error.
I builded to mfc, however, it is occured cl_build_program_failure error.

Is my soruce code wrong or miss anything??

santtt
05-14-2010, 09:06 AM
Are you sure your openCL kernel it's OK? Try commenting the code of the kernel and seeing if compile. If it happens, there is a kernel code error, with CL_PROGRAM_BUILD_STATUS flag in clGetProgramBuildInfo you can check where is the problem.

phoebe0105
05-14-2010, 09:21 AM
Are you sure your openCL kernel it's OK? Try commenting the code of the kernel and seeing if compile. If it happens, there is a kernel code error, with CL_PROGRAM_BUILD_STATUS flag in clGetProgramBuildInfo you can check where is the problem.

I attempt "clGetProgramBuildInfo()" before, and I got this information.
:160: error: expected identifier or '('

santtt
05-14-2010, 09:30 AM
It seems that you have an kernel code error, i suggest you that read de code in the line that appear in the error and look for an error in the neighborhood.

phoebe0105
05-14-2010, 10:05 AM
It seems that you have an kernel code error, i suggest you that read de code in the line that appear in the error and look for an error in the neighborhood.

When I build the same opencl kernel source in command(with c), it never occured error.
But now, I build with mfc, it is occured error. (opencl kernel source is same!!)
Therefore I don't understand in this situation.. :?:

santtt
05-14-2010, 06:35 PM
Do you have multiples kernels on the opencl kernel file? If that, try to make a file with only one kernel.

phoebe0105
05-16-2010, 08:45 AM
Do you have multiples kernels on the opencl kernel file? If that, try to make a file with only one kernel.

No I don't have multiples kernels on the opencl kernel file..
It has only one kernel.

I want to complie opencl from mfc project. Is it a problem??

santtt
05-16-2010, 08:52 AM
sorry, mfc? what is that?

phoebe0105
05-16-2010, 09:16 AM
sorry, mfc? what is that?

MFC is Microsoft Foundation Class Library in windows.

The Microsoft Foundation Class Library (also Microsoft Foundation Classes or MFC) is a library that wraps portions of the Windows API in C++ classes, including functionality that enables them to use a default application framework.
Classes are defined for many of the handle-managed Windows objects and also for predefined windows and common controls.

david.garcia
05-18-2010, 04:45 AM
I suggest doing as santtt says and looking around line 160 to see what is wrong with the kernel source that is producing error: expected identifier or '('

Maybe the kernel code is not exactly what you think and that's why it's producing an error now. MFC should have nothing to do with the error you are seeing.

santtt
05-20-2010, 02:15 PM
I got an error like yours and the answer was casting types. Cast everything you see and compile again!

sumeetsen
08-20-2010, 12:28 AM
Hi, even I am facing the same problem which is being discussed. So in order to debug i removed all other lines of the code except two. But still i am getting the same errors.

:16: error: expected identifier or '('
}様様様様様様様
^

I am using Visual Studio and the kernel code is as follows:

__kernel void hypothesis_opencl(__global uchar *Edges,
__global uchar *Depth,
__global uchar *Filtered,
__global float *weights_table,
__global float *dist_table,
int height,
int width,
int fltr_radius,
float search_limit)

{
int x = (int)get_global_id(0);

Filtered[x] = Depth[x];

}

the host code

#include "yuv_reader.h"
#include "hypothesis_opencl.h"
#include "pugixml.hpp"
#include "config.h"


// Main function
// ************************************************** *******************
int main(int argc, char **argv)
{
...
...
...

// Get platforms
cl_uint nPlatform = 0;
clGetPlatformIDs(0, NULL, &nPlatform);
cl_platform_id* plInfos = (cl_platform_id*)malloc(nPlatform * sizeof(cl_platform_id));
clGetPlatformIDs(nPlatform, plInfos, NULL);

// Get device
cl_context GPUContext;
for (cl_uint i = 0; i < nPlatform; i++)
{
cl_uint nDev = 0;
clGetDeviceIDs(plInfos[i], CL_DEVICE_TYPE_GPU, 0, 0, &nDev);
cl_device_id* GPUDevices = (cl_device_id*)malloc(nDev * sizeof(cl_device_id));
clGetDeviceIDs(plInfos[i], CL_DEVICE_TYPE_GPU, nDev, GPUDevices, 0);

// Create a context to run OpenCL on our CUDA-enabled NVIDIA GPU
cl_int errNum;
GPUContext = clCreateContext(NULL, nDev, GPUDevices, 0, 0, &errNum);
if(errNum != CL_SUCCESS)
{
std::cout << "ERROR: OpenCL::clCreateContext" << std::endl;
return -1;
}
}


// Get the list of GPU devices associated with this context
size_t ParmDataBytes;
clGetContextInfo(GPUContext, CL_CONTEXT_DEVICES, 0, NULL, &ParmDataBytes);
cl_device_id* GPUDevices = (cl_device_id*)malloc(ParmDataBytes);

clGetContextInfo(GPUContext, CL_CONTEXT_DEVICES, ParmDataBytes, GPUDevices, NULL);

// Create a command-queue on the first GPU device
cl_command_queue GPUCommandQueue = clCreateCommandQueue(GPUContext, GPUDevices[0], 0, NULL);

// Read OpenCL code from file
size_t sourceLength = 0;
char* sourceCL = readTextFile((char*)filenameCL.c_str(), &sourceLength);

if(sourceCL == NULL || sourceLength<10)
{
std::cout << "ERROR::main::readTextFile: Cannot open " << filenameCL << " file" << std::endl;
return -2;
}

cl_int errNum;

// Create OpenCL program with source code
cl_program OpenCLProgram = clCreateProgramWithSource( GPUContext,
1,
(const char **)&sourceCL,
&sourceLength,
&errNum);
delete[] sourceCL;

if(errNum != CL_SUCCESS)
{
std::cout << "ERROR::main::clCreateProgramWithSource: Unable to create opencl program" << std::endl;
return -1;
}

// Build the program (OpenCL JIT compilation)
retVal = clBuildProgram(OpenCLProgram, 1, GPUDevices, NULL, NULL, NULL);
//if(retVal != CL_SUCCESS)
//{
// std::cout << "ERROR::main::clBuildProgram: " << retVal << std::endl;
// return -1;
//}

size_t paramValueSize = 1024 * 1024,
param_value_size_ret;
char *paramValue;
paramValue = (char*)calloc(paramValueSize, sizeof(char));
retVal = clGetProgramBuildInfo( OpenCLProgram,
GPUDevices[0],
CL_PROGRAM_BUILD_LOG,
paramValueSize,
paramValue,
&param_value_size_ret);

fprintf(errLog, paramValue);
fclose(errLog);

// Create a handle to the compiled OpenCL function (Kernel)
cl_kernel openCLKernel = clCreateKernel( OpenCLProgram,
"hypothesis_opencl",
&errNum);
//if(errNum != CL_SUCCESS)
//{
// std::cout << "ERROR::main::clCreateKernel: " << errNum << std::endl;
// return -1;
//}

// Set kernel arguments
LocalBuffer buffLoc;
GPUBuffer buffGPU;
initLocalBuffer(&buffLoc, w, h);
initGPUBuffer(&buffGPU, GPUContext, w, h, searchLimit, radius);

// Fill local buffer with appropriate values
// pre-calculation of color & distance weights
init_color_SAD(buffLoc.weightTable, sigmaColor, MAXDIFF);
init_distance(buffLoc.distTable, sigmaDistance, radius);


// Loop till the end of video file
while((CIYuv_depth.readOneFrame(pf_read_depth, frameno)) == true)
{
CIYuv_col.readOneFrame(pf_read_col, frameno);

std::cout << "Processing frmne no. " << frameno << "\n";

// Set the YUV image format to 444
CIYuv_col444.setData444_inIYUV(&CIYuv_col);

int i = 0,
j = h * w,
k = h * w * 2;

// Initialize with some interesting data
// Copy Y U V data to the local buffer
for(int r = 0; r < h; r++)
{
for(int c = 0; c < w; c++)
{
buffLoc.frameCol[i] = CIYuv_col444.Y[r][c];
buffLoc.frameCol[j++] = CIYuv_col444.U[r][c];
buffLoc.frameCol[k++] = CIYuv_col444.V[r][c];

buffLoc.frameDepth[i++] = CIYuv_depth.Y[r][c];
}
}

// Copy the output in CPU memory TO GPU memory
//clEnqueueWriteBuffer(GPUCommandQueue, GPUVector1, CL_TRUE, 0,
//sizeof(int) * CIYuv_col.getSizeInByte(), HostVector1, 0, NULL, NULL);

// Copy the output in CPU memory TO GPU memory
fillGPUBuffer( GPUCommandQueue,
&CIYuv_col,
&CIYuv_depth,
&buffGPU,
&buffLoc );

initKernel( openCLKernel,
&CIYuv_col,
&CIYuv_depth,
&buffGPU);


// Launch the Kernel on the GPU
size_t workSize[2] = {w, h}; // two dimensional Range

clEnqueueNDRangeKernel( GPUCommandQueue,
openCLKernel,
2,
NULL,
workSize,
NULL,
0,
NULL,
NULL);

// Copy the output in GPU memory back to CPU memory
clEnqueueReadBuffer( GPUCommandQueue,
buffGPU.frameFilteredDepth,
CL_TRUE,
0,
sizeof(uchar) * (w * h),
buffLoc.frameFilteredDepth,
0,
NULL,
NULL);

...
...
...

// Increment the frame index
frameno ++;

}

_getch();
return 0;
}


Can someone suggest me some solution to debug this error.

ibbles
08-20-2010, 03:51 AM
Hi, even I am facing the same problem which is being discussed. So in order to debug i removed all other lines of the code except two. But still i am getting the same errors.

:16: error: expected identifier or '('
}様様様様様様様
^

the host code


// Read OpenCL code from file
size_t sourceLength = 0;
char* sourceCL = readTextFile((char*)filenameCL.c_str(), &sourceLength);

if(sourceCL == NULL || sourceLength<10)
{
std::cout << "ERROR::main::readTextFile: Cannot open " << filenameCL << " file" << std::endl;
return -2;
}

cl_int errNum;
// Create OpenCL program with source code
cl_program OpenCLProgram = clCreateProgramWithSource( GPUContext, 1, (const char **)&sourceCL, &sourceLength, &errNum);

Can someone suggest me some solution to debug this error.

I looks like the string you are passing to the OpenCL compiler contains more than the actual file content. I suggest you carefully read the 'readTextFile' function and ensure that the value written to 'sourceLength' is correct. If you are on Windows, then pay particular attention to newline characters.

sumeetsen
08-24-2010, 03:08 AM
Thanks friend, you were correct.

thorne
02-07-2011, 09:55 AM
To solve the error CL_Build_program_Failure is because the build file is not loaded properly or the systems file is missing .For this you have go through the newer version of the document 1.0.44 provided by the KHRONOS.

There is definetly a problem with the configuration files.Once that is set up.The program will restart and them will b running fine.Try rebuilding the mfc ,if that doesnt work either ,there is a problem with the source code.