caxieyou

can not build program with VS2010

Discussion created by caxieyou on Sep 6, 2011
Latest reply on Sep 8, 2011 by himanshu.gautam

ATI Mobility Radeon HD 5700 Series 1024MB

in line 156, the status is always -11

status = clBuildProgram(program, 1, devices, NULL, NULL, NULL);

 

I've tried on different desktop with ATI card, not working, any help?

// HelloWorldCL.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #if defined(__APPLE__)|| defined(MACOSX) #include <CL/cl.h> #else #include <CL/cl.h> #endif #define KERNEL(...)#__VA_ARGS__ const char* kernelSourceCode = KERNEL( __kernel void hellocl(__global unit *buffer) { size_t gidx = get_global_id(0); size_t gidy = get_global_id(1); size_t lidx = get_local_id(0); buffer[gidx + 4*gidy] = (1<<gidx | (0x10<<gidy)); } ); int _tmain(int argc, _TCHAR* argv[]) { printf("hello OpenGL\n"); cl_int status =0; size_t deviceListSize; /* ???????????AMD????????? */ cl_uint numPlatforms; cl_platform_id platform = NULL; status = clGetPlatformIDs(0, NULL, &numPlatforms); if(status != CL_SUCCESS) { printf("Error: Getting Platforms. \ (clGetPlatformIDs)\n "); return EXIT_FAILURE; } if(numPlatforms >0) { cl_platform_id* platforms = (cl_platform_id*)malloc(numPlatforms*sizeof(cl_platform_id)); status = clGetPlatformIDs(numPlatforms, platforms, NULL); if(status != CL_SUCCESS) { printf("Error: Getting Platform Ids.\ (clGetPlatformsIds)\n"); return -1; } for(unsigned int i=0; i < numPlatforms; ++i) { char pbuff[100]; status = clGetPlatformInfo( platforms[i], CL_PLATFORM_VENDOR, sizeof(pbuff), pbuff, NULL); platform = platforms[i]; if(!strcmp(pbuff, "Advanced Micro Devices, Inc.")) { break; } } delete platforms; } /* ?????????????????????NULL */ cl_context_properties cps[3] = { CL_CONTEXT_PLATFORM, (cl_context_properties) platform, 0 }; cl_context_properties* cprops = (NULL == platform) ? NULL : cps; /*????? */ cl_context context = clCreateContextFromType( cprops, CL_DEVICE_TYPE_CPU, NULL, NULL, &status ); if(status != CL_SUCCESS) { printf("Error: Creating Context.\ (clCreateContextFormType)\n "); return EXIT_FAILURE; } /* ??OpenCL?? */ //??????????? status = clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &deviceListSize); if(status != CL_SUCCESS) { printf("Error: Getting Context Info \ (device list size, clGetContextInfo)n"); return EXIT_FAILURE; } cl_device_id * devices = (cl_device_id *) malloc (deviceListSize); if(devices ==0) { printf("Error: No devices found.\n"); return EXIT_FAILURE; } //???????? status = clGetContextInfo( context, CL_CONTEXT_DEVICES, deviceListSize, devices, NULL); if(status != CL_SUCCESS) { printf("Error: Getting Context Info \ (device list, clGetContextInfo)\n"); return EXIT_FAILURE; } // ?????????CL program???CL???? size_t sourceSize[] = {strlen(kernelSourceCode)}; cl_program program = clCreateProgramWithSource( context, 1, &kernelSourceCode, sourceSize, &status); if(status != CL_SUCCESS) { printf("Error: Loading Binary into cl_program \ (clCreateProgramWithBinary)\n"); return EXIT_FAILURE; } // ??????????CL program. status = clBuildProgram(program, 1, devices, NULL, NULL, NULL); if(status != CL_SUCCESS) { printf("Error: Building Program \ (clBuildProgram)\n"); return EXIT_FAILURE; } //?????????????? cl_kernel kernel = clCreateKernel(program, "hellocl", &status); if(status != CL_SUCCESS) { printf("Error: Creating Kernel from program.\ (clCreateKernel)\n"); return EXIT_FAILURE; } //???? OpenCL command queue cl_command_queue commandQueue = clCreateCommandQueue(context, devices[0], 0, &status); if(status != CL_SUCCESS) { printf("Creating Command Queue.\ (clCreateCommandQueue)\n"); return EXIT_FAILURE; } //??OpenCL buffer?? unsigned int *outbuffer = new unsigned int[4*4]; memset(outbuffer, 0, 4*4*4); cl_mem outputBuffer = clCreateBuffer( context, CL_MEM_ALLOC_HOST_PTR, 4*4*4, NULL, &status); if(status != CL_SUCCESS) { printf("Error: clCreateBuffer \ (outputBuffer)\n"); return EXIT_FAILURE; } //???????????? status = clSetKernelArg(kernel, 0, sizeof(cl_mem), (void*)&outputBuffer); if(status != CL_SUCCESS) { printf("Error: Setting kernel argument.\ (output)\n"); return EXIT_FAILURE; } //???kernel??command queue size_t globalThreads[] = {4, 4}; size_t localThread[] = {2, 2}; status = clEnqueueNDRangeKernel( commandQueue, kernel, 2, NULL, globalThreads, localThread,0, NULL, NULL); if(status != CL_SUCCESS) { printf("Error: Enqueueing kernel \n"); return EXIT_FAILURE; } status = clEnqueueReadBuffer(commandQueue, outputBuffer, CL_TRUE, 0, 4*4*4, outbuffer, 0, NULL, NULL); if(status != CL_SUCCESS) { printf("Error: Read Buffer queue\n"); return EXIT_FAILURE; } printf("out: \n"); for(int i = 0; i < 16; i++) { printf("%x ", outbuffer[i]); if((i+1)%4 == 0) printf("\n"); } status = clReleaseKernel(kernel); status = clReleaseProgram(program); status = clReleaseMemObject(outputBuffer); status = clReleaseCommandQueue(commandQueue); free(devices); delete outbuffer; return 0; }

Outcomes