| 1 | #include <stdio.h>
|
|---|
| 2 | #include <stdlib.h>
|
|---|
| 3 | #include <string.h>
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 | $input int NUM_DEVICES;
|
|---|
| 7 | $input int MAX_NUM_DEVICES;
|
|---|
| 8 | $assume NUM_DEVICES < MAX_NUM_DEVICES;
|
|---|
| 9 | $gbarrier gbarrier = $gbarrier_create($here, NUM_DEVICES);
|
|---|
| 10 | //struct goes here
|
|---|
| 11 | typedef struct
|
|---|
| 12 | {
|
|---|
| 13 | int device_id;
|
|---|
| 14 | //other variables
|
|---|
| 15 | }process;
|
|---|
| 16 |
|
|---|
| 17 | //kernel goes here
|
|---|
| 18 |
|
|---|
| 19 | /*
|
|---|
| 20 | Note that the original lines were "__kernel void square( \n" \
|
|---|
| 21 | " __global float* input, \n" \
|
|---|
| 22 | " __global float* output, \n" \
|
|---|
| 23 | " const unsigned int count) \n" \
|
|---|
| 24 |
|
|---|
| 25 | Any parser must take note of and don't input \n, "", or \ as is
|
|---|
| 26 | __global float * input, __global float * output, int count;
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 | int main(int argc, char** argv)
|
|---|
| 31 | {
|
|---|
| 32 | //get the number from clGetDeviceIDs 3rd parameter
|
|---|
| 33 | //int num_devices = 1;
|
|---|
| 34 |
|
|---|
| 35 | //variables from __kernel come here
|
|---|
| 36 |
|
|---|
| 37 | //from the code before
|
|---|
| 38 |
|
|---|
| 39 | //comes from clCreateBuffer
|
|---|
| 40 |
|
|---|
| 41 | //Possibly keep a list of variables, with a flag for whether they are init or not
|
|---|
| 42 | //Not init, malloc one from what is found in
|
|---|
| 43 | //output = clCreateBuffer(context, CL_MEM_WRITE_ONLY, sizeof(float) * count, NULL, NULL);
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 | //came from clEnqueueWriteBuffer rather than the start of code
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 | //Phase after this is the definitions
|
|---|
| 50 | //put device_ids
|
|---|
| 51 | for(int i = 0; i < NUM_DEVICES; i++)
|
|---|
| 52 | {
|
|---|
| 53 | now[i].device_id = i;
|
|---|
| 54 | //other variables
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | //spawns processes according to devices, uses the struct for inputs
|
|---|
| 58 | $proc procs[NUM_DEVICES];
|
|---|
| 59 | for(int i = 0; i < NUM_DEVICES; i++)
|
|---|
| 60 | {
|
|---|
| 61 | procs[i] = $spawn //insert kernel function here
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | for(int i = 0; i < NUM_DEVICES; i++)
|
|---|
| 65 | {
|
|---|
| 66 | $wait(procs[i]);
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | //$barrier barrier = $barrier_create($here, gbarrier, now[i].device_id);
|
|---|
| 70 | //$barrier_call(barrier);
|
|---|
| 71 | //$barrier_destroy(barrier);
|
|---|
| 72 | //may use later, but not now
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 | $gbarrier_destroy(gbarrier);
|
|---|
| 77 |
|
|---|
| 78 | //use the information from clEnqueueReadBuffer
|
|---|
| 79 | //may have to alter later
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 | return 0;
|
|---|
| 83 | }
|
|---|