#include #include #include //RANDOM IS UNINTERPRETED //THIS ASSUMES THE PROGRAMMER HAS ALREADY RAN THE ORIGINAL OPENCL CODE AND IS NOT RESPONSIBLE FOR CHECKING CORRECT USAGE OF METHODS AS OF NOW $input int NUM_DEVICES; $input int MAX_NUM_DEVICES; $input int CL_DEVICE_MAX_WORK_GROUP_SIZE; $input int LOCAL; $assume 0 < NUM_DEVICES && NUM_DEVICES < MAX_NUM_DEVICES; $gbarrier gbarrier = $gbarrier_create($here, NUM_DEVICES); //struct goes here typedef struct { int device_id; int workgroup; int global_id; int local_id; //kernel variables }kernel; //kernel goes here void workfunc(size_t local, size_t global, kernel param) { for(int i = local * param.workgroup; i < local * param.workgroup + local; i++) { param.local_id = i % local; param.global_id = i; //printf("My workgroup id is %d, my global id is %d, my local id is %d\n", param.workgroup, param.global_id, param.local_id); func(param.workgroup, param.global_id, param.local_id, ); } } /* Note that the original lines were "__kernel void square( \n" \ " __global int* input, \n" \ " __global int* output, \n" \ " const unsigned int count) \n" \ Any parser must take note of and don't input \n, "", or \ as is __global int * input, __global int * output, int count; */ int main(int argc, char** argv) { //get the number from clGetDeviceIDs 3rd parameter $assert (LOCAL < CL_DEVICE_MAX_WORK_GROUP_SIZE); //variables from __kernel come here //from the code before //handle the definitions being put in different places //comes from clCreateBuffer //Possibly keep a list of variables, with a flag for whether they are init or not //Not init, malloc one from what is found in //output = clCreateBuffer(context, CL_MEM_WRITE_ONLY, sizeof(int) * count, NULL, NULL); //came from clEnqueueWriteBuffer rather than the start of code //Phase after this is the definitions int device_id[NUM_DEVICES]; //put device_ids for(int i = 0; i < NUM_DEVICES; i++) { device_id[i] = i; } //from clCreateContext, uses the device input //but there may be a loop, take it into account in the next example // //"Get" local size from clEnqueueNDRangeKernel, but is really an input //Creates an array of the struct according to clEnqueueNDRangeKernel //Have to split array into parts using local and global, and those are a workgroup //For now, assume local is 1, or else inputting the arrays will be odd, for now kernel param[global/local]; for(int i = 0; i < global/local; i++) { //Also picks the device to be used param[i].device_id = device_id[0]; //other parts of the struct } //spawns processes according to parameters in clEnqueueNDRangeKernel //spawns processes according to parameters in clEnqueueNDRangeKernel $proc procs[global/local]; for(int i = 0; i < global/local; i++) { param[i].workgroup = i; procs[i] = $spawn workfunc(local, global, param[i]); } for(int i = 0; i < global/local; i++) { $wait(procs[i]); } //$barrier barrier = $barrier_create($here, gbarrier, now[i].device_id); //$barrier_call(barrier); //$barrier_destroy(barrier); $gbarrier_destroy(gbarrier); //use the information from clEnqueueReadBuffer //may have to alter later return 0; }