| 1 | #include <civlc.h>
|
|---|
| 2 | #include <stdio.h>
|
|---|
| 3 | #include "setup/openCL.cvl"
|
|---|
| 4 |
|
|---|
| 5 | //this is the kernel that gets loaded into the program
|
|---|
| 6 | // Simple compute kernel which computes the square of an input array
|
|---|
| 7 | //CIVL can't turn a string into a function at this time
|
|---|
| 8 |
|
|---|
| 9 | //const char *KernelSource = "__kernel void square( __global float* input, __global float* output, const unsigned int count){ int i = get_global_id(0); if(i < count) output[i] = input[i] * input[i];}";
|
|---|
| 10 |
|
|---|
| 11 | // Simple compute kernel which computes the square of an input array
|
|---|
| 12 | //
|
|---|
| 13 | const char *KernelSource = "\n" \
|
|---|
| 14 | "__kernel void square( \n" \
|
|---|
| 15 | " __global float* input, \n" \
|
|---|
| 16 | " __global float* output, \n" \
|
|---|
| 17 | " const unsigned int count) \n" \
|
|---|
| 18 | "{ \n" \
|
|---|
| 19 | " int i = get_global_id(0); \n" \
|
|---|
| 20 | " if(i < count) \n" \
|
|---|
| 21 | " output[i] = input[i] * input[i]; \n" \
|
|---|
| 22 | "} \n" \
|
|---|
| 23 | "\n";
|
|---|
| 24 | /*
|
|---|
| 25 | void square(float* input, float* output, const unsigned int count)
|
|---|
| 26 | {
|
|---|
| 27 | int i = get_global_id(0);
|
|---|
| 28 | if (i < count)
|
|---|
| 29 | {
|
|---|
| 30 | output[i] = input[i] * input[i];
|
|---|
| 31 | }
|
|---|
| 32 | }
|
|---|
| 33 | */
|
|---|
| 34 | void main()
|
|---|
| 35 | {
|
|---|
| 36 | int err;
|
|---|
| 37 | int num_entries = 3;
|
|---|
| 38 |
|
|---|
| 39 | cl_device_id device_id;
|
|---|
| 40 | cl_context context;
|
|---|
| 41 | cl_command_queue commands;
|
|---|
| 42 | cl_program program;
|
|---|
| 43 | cl_kernel kernel;
|
|---|
| 44 |
|
|---|
| 45 | //assumes you have hardware that works, does not check that part
|
|---|
| 46 | //fills the device_id with device ids, returns CL_SUCCESS if it works
|
|---|
| 47 | err = clGetDeviceIDs(NULL,
|
|---|
| 48 | CL_DEVICE_TYPE_GPU,
|
|---|
| 49 | num_entries,
|
|---|
| 50 | &device_id,
|
|---|
| 51 | NULL);
|
|---|
| 52 | printf("devices is %d", device_id[0]);
|
|---|
| 53 | $assert (err == CL_SUCCESS);
|
|---|
| 54 |
|
|---|
| 55 | //Returns a context, which has device information
|
|---|
| 56 | context = clCreateContext(0, 1, &device_id, NULL, NULL, &err);
|
|---|
| 57 | $assert (context != NULL);
|
|---|
| 58 |
|
|---|
| 59 | commands = clCreateCommandQueue(context, device_id, 0, &err);
|
|---|
| 60 | $assert (commands != NULL);
|
|---|
| 61 |
|
|---|
| 62 | program = clCreateProgramWithSource(context, 1, (const char **) & KernelSource, NULL, &err);
|
|---|
| 63 | $assert (program != NULL);
|
|---|
| 64 |
|
|---|
| 65 | //err = clBuildProgram(program, 0, NULL, NULL, NULL, NULL);
|
|---|
| 66 | }
|
|---|