Changes between Version 8 and Version 9 of OpenCLTransformation
- Timestamp:
- 07/11/14 09:47:19 (12 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
OpenCLTransformation
v8 v9 9 9 This only takes up the 3rd and 4th parameter, the 3rd for the number of devices, but also uses the name of the pointer in the 4th place. Note that the part for picking a device actually comes from clCreateCommandQueue, and if multiple devices are not used then the device at index 0 is used 10 10 {{{ 11 int device_id[NUM_DEVICES];12 //put device_ids 13 for (int i = 0; i < NUM_DEVICES; i++)14 {15 device_id[i] = i;11 int clGetDeviceIDs(int numEntries, cl_device_id * devices) 12 { 13 for (int i=0; i<numEntries; i++) { 14 devices[i].id = i; 15 // exactly equivalent to: (devices+i)->id = i 16 16 } 17 return CL_SUCCESS; 18 } 17 19 }}} 18 20 19 21 kernel = clCreateKernel(program, "square", &err); 20 22 21 Creates the kernel using data from the program, and the name of the function. In the transformation it chooses which function to use. Currently unimplemented. 23 Creates the kernel using data from the program, and the name of the function. In the transformation it chooses which function to use. 24 25 {{{ 26 cl_kernel clCreateKernel(args * argument) 27 { 28 cl_kernel kernel; 29 kernel.arguments = argument; 30 31 return kernel; 32 } 33 }}} 34 35 args is a struct containing all of the variables that will be passed into a kernel, for example 36 {{{ 37 typedef struct 38 { 39 //Variables for kernels 40 41 float * input; 42 float * output; 43 int count; 44 45 }args; 46 }}} 22 47 23 48 input = clCreateBuffer(context, CL_MEM_READ_ONLY, sizeof(float) * count, NULL, NULL); … … 41 66 clSetKernelArg sets arguments for an array of each device in the kernel. 42 67 {{{ 43 $assert(global%local == 0); 44 kernel param[global/local]; 45 for(int i = 0; i < global/local; i++) 46 { 47 //Also picks the device to be used 48 param[i].device_id = device_id[0]; 49 //other parts of the struct 50 param[i].input = input; 51 param[i].output = output; 52 param[i].count = count; 53 } 68 ((args*)kernel.arguments)->input = input; 69 70 ((args*)kernel.arguments)->output = output; 71 72 ((args*)kernel.arguments)->count = count; 54 73 }}} 55 74 … … 66 85 67 86 {{{ 87 int clEnqueueNDRangeKernel(cl_command_queue commands, cl_kernel kernel, int global, int local) 88 { 89 $assert(global % local == 0); 90 cl_kernel param[global/local]; 68 91 $proc procs[global/local]; 69 92 for(int i = 0; i < global/local; i++) 70 93 { 94 param[i] = kernel; 71 95 param[i].workgroup = i; 72 //procs[i] = $spawn square(param[i].global_id, param[i].input, param[i].output, param[i].count); 73 procs[i] = $spawn worksquare(local, global, param[i]); 96 procs[i] = $spawn workfunc(local, global, param[i]); 74 97 } 75 98 99 //this part here is the new clFinish(commands); 76 100 for(int i = 0; i < global/local; i++) 77 101 { 78 102 $wait(procs[i]); 79 103 } 104 105 return CL_SUCCESS; 106 } 80 107 }}} 81 108
