示例#1
0
/* Get first platform that matches a string.
 */
cl_platform_id get_platform(const char *platform_string)
{
	cl_platform_id *platforms = NULL;
	cl_platform_id platform;
	int i;
	int num;
	char *name;
	int len;

	num = get_platforms(&platforms);
	if (num < 1)
		return NULL;
	
	platform = NULL;
	name = NULL;
	len = 0;
    for (i = 0; i < num; i++)
    {	
		get_platform_info(platforms[i], CL_PLATFORM_NAME, &name, &len);

		if (strstr(name, platform_string))
        {
			platform = platforms[i];
			break;
        }
    }

	if (name != NULL)
		free(name);
	
	if (platforms != NULL)
		free(platforms);
	
	return platform;
}
示例#2
0
文件: main.cpp 项目: Vdimir/cuda-lab
void cl_initilize() {
	cl_int errcode;

	cl_platform_id platform[10];
	get_platforms(platform);

	cl_device_id devices[10];
	int platform_index = 0;
	get_devices(platform[platform_index], devices);

	int device_index = 0;
	show_device_info(devices[device_index]);

	context = clCreateContext(NULL, 1, &devices[device_index], NULL, NULL, &errcode);
	checkError(clCreateContext);

	queue = clCreateCommandQueue (context, devices[device_index], CL_QUEUE_PROFILING_ENABLE, &errcode); // третий параметр - свойства
	checkError(clCreateCommandQueue);

	char* source = "\n\
			  __kernel void sum(__global const uchar *src, __global uchar *trg, int m, int n)\n\
			  {\n\
			    int  i = get_global_id(0);\n\
			    int  j = get_global_id(1);\n\
 	            int SIdx = (i*n + (n-1 - j)) ;\n\
		    	int DIdx = (j*m + i) ;\n\
				if (i > m) return;\
				if (j > n) return;\
            	for (int c = 0; c < 3; c++)\n\
   		            trg[DIdx*3+c] = src[SIdx*3+c];\n\
			  }";