source: CIVL/examples/opencl/2.15/reduce_int_kernel.cvl@ bb03188

main test-branch
Last change on this file since bb03188 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

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

  • Property mode set to 100644
File size: 2.1 KB
Line 
1
2#ifndef GROUP_SIZE
3#define GROUP_SIZE (64)
4#endif
5
6#ifndef OPERATIONS
7#define OPERATIONS (1)
8#endif
9
10////////////////////////////////////////////////////////////////////////////////////////////////////
11
12#define LOAD_GLOBAL_I1(s, i) \
13 (( const int*)(s))[(size_t)(i)]
14
15#define STORE_GLOBAL_I1(s, i, v) \
16 (( int*)(s))[(size_t)(i)] = (v)
17
18////////////////////////////////////////////////////////////////////////////////////////////////////
19
20#define LOAD_LOCAL_I1(s, i) \
21 (( int*)(s))[(size_t)(i)]
22
23#define STORE_LOCAL_I1(s, i, v) \
24 (( int*)(s))[(size_t)(i)] = (v)
25
26#define ACCUM_LOCAL_I1(s, i, j) \
27{ \
28 int x = (( int*)(s))[(size_t)(i)]; \
29 int y = (( int*)(s))[(size_t)(j)]; \
30 (( int*)(s))[(size_t)(i)] = (x + y); \
31}
32////////////////////////////////////////////////////////////////////////////////////////////////////
33/*
34 __global int *output,
35 __global const int *input,
36 __local int *shared,
37 const unsigned int n
38*/
39void reduce(
40 int workgroup,
41 int cl_global_id,
42 int cl_local_id,
43 int *output,
44 const int *input,
45 int *shared,
46 const unsigned int n)
47{
48 const int zero = 0.0f;
49 const unsigned int group_id = workgroup;
50 const unsigned int group_size = GROUP_SIZE;
51 const unsigned int group_stride = 2 * group_size;
52 const size_t local_stride = group_stride * group_size;
53
54 unsigned int op = 0;
55 unsigned int last = OPERATIONS - 1;
56 for(op = 0; op < OPERATIONS; op++)
57 {
58 const unsigned int offset = (last - op);
59 const size_t local_id = cl_local_id + offset;
60
61 STORE_LOCAL_I1(shared, local_id, zero);
62
63 size_t i = group_id * group_stride + local_id;
64 while (i < n)
65 {
66 int a = LOAD_GLOBAL_I1(input, i);
67 int b = LOAD_GLOBAL_I1(input, i + group_size);
68 int s = LOAD_LOCAL_I1(shared, local_id);
69 STORE_LOCAL_I1(shared, local_id, (a + b + s));
70 i += local_stride;
71 }
72
73 #if (GROUP_SIZE >= 2)
74 if (local_id < 1) { ACCUM_LOCAL_I1(shared, local_id, local_id + 1); }
75 #endif
76 }
77
78
79
80 if (cl_local_id == 0)
81 {
82 int v = LOAD_LOCAL_I1(shared, 0);
83 STORE_GLOBAL_I1(output, group_id, v);
84 }
85}
86
Note: See TracBrowser for help on using the repository browser.