source: CIVL/examples/translation/openclversion2.1/square.cvl@ 9e44c01

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since 9e44c01 was d508f18, checked in by Jacob Trieu <fuufusuu@…>, 12 years ago

Even more methods

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@1214 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 3.9 KB
Line 
1//Forget the program
2
3#include "openCLshared.cvl"
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7
8$input int NUM_DEVICES;
9$input int MAX_NUM_DEVICES;
10$assume 0 < NUM_DEVICES && NUM_DEVICES < MAX_NUM_DEVICES;
11
12$input int DATA_SIZE;
13$input int MAX_DATA_SIZE;
14$assume 0 < DATA_SIZE && DATA_SIZE < MAX_NUM_DEVICES;
15
16$input int LOCAL;
17
18typedef struct
19{
20 //Variables for kernels
21
22 int * input;
23 int * output;
24 const unsigned int count;
25
26}args;
27
28
29cl_kernel clCreateKernel(args * argument)
30{
31 cl_kernel kernel;
32 kernel.arguments = argument;
33
34 return kernel;
35}
36/*
37int clSetKernelArg(cl_kernel kernel, int index, size_t size, void * value)
38{
39 if (index == 0)
40 {
41 kernel.program.arguments.input = (int *)malloc(size);
42 }
43
44 return CL_SUCCESS;
45}
46*/
47int clEnqueueNDRangeKernel(cl_command_queue commands, cl_kernel kernel, int global, int local)
48{
49
50 return CL_SUCCESS;
51}
52
53//kernel
54void square(int workgroup, int global_id, int local_id, float* input, float* output, const unsigned int count)
55{
56 //int i = get_global_id(0);
57 int i = global_id;
58 if (i < count)
59 {
60 output[i] = input[i] * input[i];
61 //printf("output[%d] is %d\n", i, output[i]);
62 }
63}
64/*
65void workfunc(size_t local, size_t global, kernel param)
66{
67 for(int i = local * param.workgroup; i < local * param.workgroup + local; i++)
68 {
69 param.local_id = i % local;
70 param.global_id = i;
71 //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);
72 square(param.workgroup, param.global_id, param.local_id, param.input, param.output, param.count);
73 }
74}
75*/
76int main(int argc, char** argv)
77{
78 args * arguments;
79 arguments = (args*)malloc(sizeof(args));
80
81 float data[DATA_SIZE]; // original data set given to device
82 float results[DATA_SIZE]; // results returned from device
83 unsigned int correct; // number of correct results returned
84
85 size_t global; // global domain size for our calculation
86 size_t local; // local domain size for our calculation
87
88 cl_device_id device_id; // compute device id
89 cl_context context; // compute context
90 cl_command_queue commands; // compute command queue
91 //cl_program program; // compute program
92 cl_kernel kernel; // compute kernel
93
94
95 float * input; // device memory used for the input array
96 float * output; // device memory used for the output array
97
98 unsigned int count = DATA_SIZE;
99 for(int i = 0; i < count; i++)
100 {
101 data[i] = i;
102 }
103
104 int err = clGetDeviceIDs(1, &device_id);
105
106 //ignore clCreateContext for now, until we get an example that uses multiple ones
107
108 //clCreateCommandQueue, could use context later
109 commands = clCreateCommandQueue(device_id);
110
111 //clCreateProgram is far different from the real version, this just stores parameters for the kernel
112 //In order to make this clear, it is clCreateProgram and not something like clCreateProgramFromSource, which actually exists in openCL code
113 //program = clCreateProgram(arguments);
114
115 kernel = clCreateKernel(arguments);
116
117
118 //comes from clCreateBuffer
119 input = (float *) malloc(sizeof(float) * count);
120 output = (float *) malloc(sizeof(float) * count);
121
122
123
124 memcpy(input, data, sizeof(float) * count);
125
126 /*
127 err = 0;
128 err = clSetKernelArg(kernel, 0, sizeof(cl_mem), &input);
129 err = clSetKernelArg(kernel, 1, sizeof(cl_mem), &output);
130 err = clSetKernelArg(kernel, 2, sizeof(unsigned int), &count);
131 */
132
133
134 //came from clEnqueueWriteBuffer
135
136 //clGetKernelWorkGroupInfo
137 local = LOCAL;
138
139 global = count;
140 /*
141 commands holds the "order" of devices
142 kernel holds program, which holds variables
143 offset not implemented
144 */
145 //err = clEnqueueNDRangeKernel(commands, kernel, global, local);
146
147 free(input);
148 free(output);
149 free(arguments);
150 return 0;
151}
152
Note: See TracBrowser for help on using the repository browser.