| 1 | #include "openCLshared.cvl"
|
|---|
| 2 | #include <stdio.h>
|
|---|
| 3 | #include <stdlib.h>
|
|---|
| 4 | #include <string.h>
|
|---|
| 5 |
|
|---|
| 6 | $input int NUM_DEVICES;
|
|---|
| 7 | $input int MAX_NUM_DEVICES;
|
|---|
| 8 | $assume 0 < NUM_DEVICES && NUM_DEVICES < MAX_NUM_DEVICES;
|
|---|
| 9 |
|
|---|
| 10 | $input int DATA_SIZE;
|
|---|
| 11 | $input int MAX_DATA_SIZE;
|
|---|
| 12 | $assume 0 < DATA_SIZE && DATA_SIZE < MAX_NUM_DEVICES;
|
|---|
| 13 |
|
|---|
| 14 | typedef struct
|
|---|
| 15 | {
|
|---|
| 16 | //which contains device info...
|
|---|
| 17 | cl_context context;
|
|---|
| 18 |
|
|---|
| 19 | //Variables for kernels
|
|---|
| 20 | int * input;
|
|---|
| 21 | int * output;
|
|---|
| 22 | const unsigned int count;
|
|---|
| 23 | }args;
|
|---|
| 24 |
|
|---|
| 25 | //kernel
|
|---|
| 26 | void square(int workgroup, int global_id, int local_id, int* input, int* output, const unsigned int count)
|
|---|
| 27 | {
|
|---|
| 28 | //int i = get_global_id(0);
|
|---|
| 29 | int i = global_id;
|
|---|
| 30 | if (i < count)
|
|---|
| 31 | {
|
|---|
| 32 | output[i] = input[i] * input[i];
|
|---|
| 33 | //printf("output[%d] is %d\n", i, output[i]);
|
|---|
| 34 | }
|
|---|
| 35 | }
|
|---|
| 36 | /*
|
|---|
| 37 | void workfunc(size_t local, size_t global, kernel param)
|
|---|
| 38 | {
|
|---|
| 39 | for(int i = local * param.workgroup; i < local * param.workgroup + local; i++)
|
|---|
| 40 | {
|
|---|
| 41 | param.local_id = i % local;
|
|---|
| 42 | param.global_id = i;
|
|---|
| 43 | //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);
|
|---|
| 44 | square(param.workgroup, param.global_id, param.local_id, param.input, param.output, param.count);
|
|---|
| 45 | }
|
|---|
| 46 | }
|
|---|
| 47 | */
|
|---|
| 48 | int main(int argc, char** argv)
|
|---|
| 49 | {
|
|---|
| 50 | args arguments;
|
|---|
| 51 |
|
|---|
| 52 | float data[DATA_SIZE]; // original data set given to device
|
|---|
| 53 | float results[DATA_SIZE]; // results returned from device
|
|---|
| 54 | unsigned int correct; // number of correct results returned
|
|---|
| 55 |
|
|---|
| 56 | size_t global; // global domain size for our calculation
|
|---|
| 57 | size_t local; // local domain size for our calculation
|
|---|
| 58 |
|
|---|
| 59 | cl_device_id device_id; // compute device id
|
|---|
| 60 | cl_context context; // compute context
|
|---|
| 61 | cl_command_queue commands; // compute command queue
|
|---|
| 62 | cl_program program; // compute program
|
|---|
| 63 | cl_kernel kernel; // compute kernel
|
|---|
| 64 |
|
|---|
| 65 | cl_mem input; // device memory used for the input array
|
|---|
| 66 | cl_mem output; // device memory used for the output array
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 | int err = clGetDeviceIDs(1, &device_id);
|
|---|
| 70 |
|
|---|
| 71 | //ignore clCreateContext for now, until we get an example that uses multiple ones
|
|---|
| 72 |
|
|---|
| 73 | //clCreateCommandQueue, could use context later
|
|---|
| 74 | commands = clCreateCommandQueue(device_id);
|
|---|
| 75 |
|
|---|
| 76 | //clCreateProgram is far different from the real version, this just stores parameters for the kernel
|
|---|
| 77 | //In order to make this clear, it is clCreateProgram and not something like clCreateProgramFromSource, which actually exists in openCL code
|
|---|
| 78 | //program = clCreateProgram(args);
|
|---|
| 79 |
|
|---|
| 80 | return 0;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|