source: CIVL/examples/translation/openclversion2.1/square.cvl@ 0c8fec8

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

file containing types done

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

  • Property mode set to 100644
File size: 2.1 KB
Line 
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//kernel
11void square(int workgroup, int global_id, int local_id, int* input, int* output, const unsigned int count)
12{
13 //int i = get_global_id(0);
14 int i = global_id;
15 if (i < count)
16 {
17 output[i] = input[i] * input[i];
18 //printf("output[%d] is %d\n", i, output[i]);
19 }
20}
21/*
22void workfunc(size_t local, size_t global, kernel param)
23{
24 for(int i = local * param.workgroup; i < local * param.workgroup + local; i++)
25 {
26 param.local_id = i % local;
27 param.global_id = i;
28 //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);
29 square(param.workgroup, param.global_id, param.local_id, param.input, param.output, param.count);
30 }
31}
32*/
33int main(int argc, char** argv)
34{
35 float data[DATA_SIZE]; // original data set given to device
36 float results[DATA_SIZE]; // results returned from device
37 unsigned int correct; // number of correct results returned
38
39 size_t global; // global domain size for our calculation
40 size_t local; // local domain size for our calculation
41
42 cl_device_id device_id; // compute device id
43 cl_context context; // compute context
44 cl_command_queue commands; // compute command queue
45 cl_program program; // compute program
46 cl_kernel kernel; // compute kernel
47
48 cl_mem input; // device memory used for the input array
49 cl_mem output; // device memory used for the output array
50
51
52 //replaces clGetDeviceIDs
53 device_id = (cl_device_id)malloc(sizeof(_cl_device_id));
54
55 //grab the number after * from input
56 devices->id = (int*)malloc(sizeof(int) * NUM_DEVICES);
57 for(int i = 0; i < NUM_DEVICES; i++)
58 {
59 devices->id[i] = i;
60 }
61
62 free(devices->id);
63 free(devices);
64
65 return 0;
66}
67
Note: See TracBrowser for help on using the repository browser.