cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

tumanovalex
Journeyman III

Error at loading of an kernel code

Prompt how correctly to load kernel source codes into the device, please? My code gives an error -11 (CL_BUILD_PROGRAM_FAILURE). Source codes I apply http://slil.ru/28390701.

0 Likes
7 Replies
genaganna
Journeyman III

Originally posted by: tumanovalex Prompt how correctly to load kernel source codes into the device, please? My code gives an error -11 (CL_BUILD_PROGRAM_FAILURE). Source codes I apply http://slil.ru/28390701.

 

Tumanovalex,

       Kernel code might have syntax/semantic errors. Could you please use clGetProgramBuildInfo to get build log info  with CL_PROGRAM_BUILD_LOG parameter?

0 Likes
genaganna
Journeyman III

Originally posted by: tumanovalex Prompt how correctly to load kernel source codes into the device, please? My code gives an error -11 (CL_BUILD_PROGRAM_FAILURE). Source codes I apply http://slil.ru/28390701.

 

Tumanovalex,

               filesize variable getting 0 value while reading file.  Make sure that  MyOpenCL.cl file read properly or not.

0 Likes

I'm sorry

hfile = fopen("MyOpenCL.cl", "r"); if(!hfile) { printf("Error file!\n"); _getch(); exit(1); } fseek(hfile, 0, SEEK_END); filesize = ftell(hfile); fseek(hfile, 0, SEEK_SET);

0 Likes

clGetProgramBuildInfo(cpProgram, devices[0], CL_PROGRAM_BUILD_LOG, nchar, plname, NULL) return empty string, clGetProgramInfo(cpProgram, CL_PROGRAM_SOURCE, nchar, plname, NULL) return "==" instead of an source code. Look, please, my project. Clearly that I have incorrectly caused clCreateProgramWithSource and how correctly to make it in my case, I do not know.

0 Likes

Tumanovalex,

 See attached code. I added ICD code also. It seems you are using still beta4.  You can find latest SDK at http://developer.amd.com/gpu/ATIStreamSDK/Pages/default.aspx

#include <conio.h> #include <stdio.h> #include <stdlib.h> #include <CL/cl.hpp> #include <windows.h> #define ndev 3 #define nchar 128 void geterror(char *errmes, int nres) { if(nres != CL_SUCCESS) { printf("\n"); printf(errmes); printf(" = %i\n", nres); _getch(); exit(1); } } char* getKernelSourceString(const char* clFileName, const char* prependStr, size_t* strSize) { // locals FILE* filePtr = NULL; size_t srcSize; //printf("FileName = %s, prependStr = %s", clFileName, prependStr); // open the OpenCL source code file #ifdef _WIN32 // Windows version if(fopen_s(&filePtr, clFileName, "rb") != 0) { printf("Failed to open file : %s \n", clFileName); return NULL; } #else // Linux version filePtr = fopen(clFileName, "rb"); if(filePtr == 0) { printf("Failed to open file : %s \n", clFileName); return NULL; } #endif size_t prependStrSize = 0; if(prependStr != NULL) prependStrSize = strlen(prependStr); // get the length of the source code fseek(filePtr, 0, SEEK_END); srcSize = ftell(filePtr); fseek(filePtr, 0, SEEK_SET); // allocate a buffer for the source code string and read it in char* str = (char *)malloc(srcSize + prependStrSize + 1); memcpy(str, prependStr, prependStrSize); fread((str) + prependStrSize, srcSize, 1, filePtr); // close the file and return the total length of the combined (prepend + source) string fclose(filePtr); if(strSize != NULL) { *strSize = srcSize + prependStrSize; } str[srcSize + prependStrSize] = '\0'; return str; } int main(int argc, char argv[]) { cl_uint max_cu, max_wi_dim; size_t max_wg_size, ndim[ndev], program_length = 256; cl_ulong max_dev_mem, max_dev_glmem, max_dev_locmem; cl_int npl; cl_uint i; cl_device_id devices[ndev]; char plname[nchar]; FILE *hfile; char *buf; long filesize; cl_int status = CL_SUCCESS; cl_device_type dType = CL_DEVICE_TYPE_CPU; /* * Have a look at the available platforms and pick either * the AMD one if available or a reasonable default. */ cl_uint numPlatforms; cl_platform_id platform = NULL; status = clGetPlatformIDs(0, NULL, &numPlatforms); geterror("Number error clGetPlatformIDs", status); if (0 < numPlatforms) { cl_platform_id* platforms = new cl_platform_id[numPlatforms]; status = clGetPlatformIDs(numPlatforms, platforms, NULL); geterror("Number error clGetPlatformIDs", status); for (unsigned i = 0; i < numPlatforms; ++i) { char pbuf[100]; status = clGetPlatformInfo(platforms, CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, NULL); geterror("Number error clGetPlatformIDs", status); platform = platforms; if (!strcmp(pbuf, "Advanced Micro Devices, Inc.")) { break; } } delete[] platforms; } /* * If we could find our platform, use it. Otherwise pass a NULL and get whatever the * implementation thinks we should be using. */ cl_context_properties cps[3] = { CL_CONTEXT_PLATFORM, (cl_context_properties)platform, 0 }; /* Use NULL for backward compatibility */ cl_context_properties* cprops = (NULL == platform) ? NULL : cps; printf("\n-------------- Device Info --------------------------------------\n"); npl = clGetDeviceIDs(platform, dType, ndev, devices, NULL); geterror("Number error clGetDeviceIDs", npl); npl = clGetDeviceInfo(devices[0], CL_DEVICE_NAME, nchar, plname, NULL); geterror("Number error clGetDeviceInfo CL_DEVICE_NAME", npl); printf("\nType OpenCL Device\t%s\n", plname); npl = clGetDeviceInfo(devices[0], CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(cl_uint), &max_cu, NULL); geterror("Number error clGetDeviceInfo CL_DEVICE_MAX_COMPUTE_UNIT", npl); printf("\nCL_DEVICE_MAX_COMPUTE_UNIT\t\t%i\n", max_cu); npl = clGetDeviceInfo(devices[0], CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, sizeof(cl_uint), &max_wi_dim, NULL); geterror("Number error clGetDeviceInfo CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS", npl); printf("\nCL_DEVICE_MAX_WORK_ITEM_DIMENTIONS\t%i\n", max_wi_dim); npl = clGetDeviceInfo(devices[0], CL_DEVICE_MAX_WORK_ITEM_SIZES, max_wi_dim*sizeof(size_t), ndim, NULL); geterror("Number error clGetDeviceInfo CL_DEVICE_MAX_WORK_ITEM_SIZES", npl); printf("\nCL_DEVICE_MAX_WORK_ITEM_SIZES\t\t"); for(i=0; i < max_wi_dim; i++) { printf("%i\t", ndim); } npl = clGetDeviceInfo(devices[0], CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(size_t), &max_wg_size, NULL); geterror("Number error clGetDeviceInfo CL_DEVICE_MAX_WORK_GROUP_SIZE", npl); printf("\n\nCL_DEVICE_MAX_WORK_GROUP_SIZE\t\t%i\n", max_wg_size); npl = clGetDeviceInfo(devices[0], CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof(unsigned long long), &max_dev_mem, NULL); geterror("Number error clGetDeviceInfo CL_DEVICE_MAX_MEM_ALLOC_SIZE", npl); printf("\nCL_DEVICE_MAX_MEM_ALLOC_SIZE\t\t%i\n", max_dev_mem); npl = clGetDeviceInfo(devices[0], CL_DEVICE_GLOBAL_MEM_SIZE, sizeof(unsigned long long), &max_dev_glmem, NULL); geterror("Number error clGetDeviceInfo CL_DEVICE_GLOBAL_MEM_SIZE", npl); printf("\nCL_DEVICE_GLOBAL_MEM_SIZE\t\t%i\n", max_dev_glmem); npl = clGetDeviceInfo(devices[0], CL_DEVICE_LOCAL_MEM_SIZE, sizeof(unsigned long long), &max_dev_locmem, NULL); geterror("Number error clGetDeviceInfo CL_DEVICE_LOCAL_MEM_SIZE", npl); printf("\nCL_DEVICE_LOCAL_MEM__SIZE\t\t%i\n", max_dev_locmem); printf("\n-------------- Get Context and Create Memory Buffer -------------------\n"); cl_context cxGPUContext = clCreateContextFromType(cprops, dType, NULL, NULL, &npl); geterror("Number error clCreateContextFromType", npl); cl_command_queue cqCommandQue = clCreateCommandQueue(cxGPUContext, devices[0], 0, &npl); geterror("Number error clCreateCommandQueue", npl); cl_mem cmDevSrcA = clCreateBuffer(cxGPUContext, CL_MEM_READ_ONLY, (size_t)max_dev_mem/4, NULL, &npl);//GPU geterror("Number error mem cmDevSrcA", npl); cl_mem cmDevSrcB = clCreateBuffer(cxGPUContext, CL_MEM_READ_ONLY, (size_t) max_dev_mem/4, NULL, &npl); geterror("Number error mem cmDevSrcB", npl); cl_mem cmDevDst = clCreateBuffer (cxGPUContext, CL_MEM_WRITE_ONLY, (size_t) max_dev_mem/4, NULL, &npl); geterror("Number error mem cmDevDst", npl); printf("\n-------------- Create Program With Source -------------------\n"); //if((hfile = fopen("MyOpenCL.cl", "r"))!=NULL) { // fseek(hfile, 0, SEEK_END); // filesize = ftell(hfile); // fseek(hfile, 0, SEEK_SET); //} //else { // printf("Can't read file\n"); // _getch(); // exit(1); //} //program_length = (size_t)filesize; //buf = (char*) malloc(filesize + sizeof(char)); //buf[filesize+ sizeof(char)] = '\0'; //fread(buf, sizeof(char), filesize, hfile); buf = getKernelSourceString("MyOpenCL.cl", "", &program_length); cl_program cpProgram = clCreateProgramWithSource(cxGPUContext, 1, (const char**)&buf, &program_length, &npl); geterror("Number error clCreateProgramWithSource", npl); npl = clBuildProgram(cpProgram, 0, NULL, NULL, NULL, NULL); if(npl != CL_SUCCESS) { if(npl == CL_BUILD_PROGRAM_FAILURE) { cl_int logStatus; char * buildLog = NULL; size_t buildLogSize = 0; logStatus = clGetProgramBuildInfo(cpProgram, devices[0], CL_PROGRAM_BUILD_LOG, buildLogSize, buildLog, &buildLogSize); geterror("Number error clCreateProgramWithSource", logStatus); buildLog = (char*)malloc(buildLogSize); if(buildLog == NULL) { printf("Failed to allocate host memory.(buildLog)"); return 1; } memset(buildLog, 0, buildLogSize); logStatus = clGetProgramBuildInfo(cpProgram, devices[0], CL_PROGRAM_BUILD_LOG, buildLogSize, buildLog, NULL); geterror("Number error clCreateProgramWithSource", logStatus); printf(" \n\t\t\tBUILD LOG\n"); printf(" ************************************************\n"); printf("%s \n", buildLog); printf(" ************************************************\n"); free(buildLog); } geterror("Number error clBuildProgram", npl); } printf("No error\n"); _getch(); return 0; } // end main

0 Likes

Thanks you huge for a code and explanatories to it!

0 Likes

The flag you were using in reading *.cl file was 'r' in fopen function, if you change that to 'rb' (read-only binary) then its should kernel file properly.

0 Likes