Changes between Version 8 and Version 9 of OpenCLTransformation


Ignore:
Timestamp:
07/11/14 09:47:19 (12 years ago)
Author:
fuufusuu
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • OpenCLTransformation

    v8 v9  
    99This 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
    1010{{{
    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;
     11int 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
    1616  }
     17  return CL_SUCCESS;
     18}
    1719}}}
    1820
    1921kernel = clCreateKernel(program, "square", &err);
    2022
    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.
     23Creates the kernel using data from the program, and the name of the function. In the transformation it chooses which function to use.
     24
     25{{{
     26cl_kernel clCreateKernel(args * argument)
     27{
     28  cl_kernel kernel;
     29  kernel.arguments = argument;
     30 
     31  return kernel;
     32}
     33}}}
     34
     35args is a struct containing all of the variables that will be passed into a kernel, for example
     36{{{
     37typedef struct
     38{
     39  //Variables for kernels
     40 
     41  float * input;
     42  float * output;
     43  int count;
     44 
     45}args;
     46}}}
    2247
    2348input = clCreateBuffer(context,  CL_MEM_READ_ONLY,  sizeof(float) * count, NULL, NULL);
     
    4166clSetKernelArg sets arguments for an array of each device in the kernel.
    4267{{{
    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;
    5473}}}
    5574
     
    6685
    6786{{{
     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];
    6891  $proc procs[global/local];
    6992  for(int i = 0; i < global/local; i++)
    7093  {
     94    param[i] = kernel;
    7195    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]);
    7497  }
    7598 
     99  //this part here is the new clFinish(commands);
    76100  for(int i = 0; i < global/local; i++)
    77101  {
    78102    $wait(procs[i]);
    79103  }
     104 
     105  return CL_SUCCESS;
     106}
    80107}}}
    81108