summaryrefslogtreecommitdiff
path: root/kernels/compiler_workgroup_broadcast.cl
blob: 118cc9ef1ddcb82b64f040e09da9268c56089d1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
 * Workgroup broadcast 1D functions
 */

kernel void compiler_workgroup_broadcast_1D_int(global int *src,
                                                global int *dst,
                                                uint wg_local_x,
                                                uint wg_local_y,
                                                uint wg_local_z)
{
  uint offset = 0;
  uint index = offset + get_global_id(0);

  int val = src[index];
  int broadcast_val = work_group_broadcast(val,
                                            wg_local_x);
  dst[index] = broadcast_val;
}
#if 0
kernel void compiler_workgroup_broadcast_1D_long(global long *src,
                                                global long *dst,
                                                uint wg_local_x,
                                                uint wg_local_y,
                                                uint wg_local_z)
{
  uint offset = 0;
  uint index = offset + get_global_id(0);

  long val = src[index];
  long broadcast_val = work_group_broadcast(val,
                                            wg_local_x);
  dst[index] = broadcast_val;
}
#endif
/*
 * Workgroup broadcast 2D functions
 */
kernel void compiler_workgroup_broadcast_2D_int(global int *src,
                                                global int *dst,
                                                uint wg_local_x,
                                                uint wg_local_y,
                                                uint wg_local_z)
{
  uint lsize = get_local_size(0) * get_local_size(1);
  uint offset = get_group_id(0) * lsize +
      get_group_id(1) * get_num_groups(0) * lsize;
  uint index = offset + get_local_id(0) +
      get_local_id(1) * get_local_size(0);

  int val = src[index];
  int broadcast_val = work_group_broadcast(val,
                                            wg_local_x,
                                            wg_local_y);
  dst[index] = broadcast_val;
}
#if 0
kernel void compiler_workgroup_broadcast_2D_long(global long *src,
                                                global long *dst,
                                                uint wg_local_x,
                                                uint wg_local_y,
                                                uint wg_local_z)
{
  uint lsize = get_local_size(0) * get_local_size(1);
  uint offset = get_group_id(0) * lsize +
      get_group_id(1) * get_num_groups(0) * lsize;
  uint index = offset + get_local_id(0) +
      get_local_id(1) * get_local_size(0);

  long val = src[index];
  long broadcast_val = work_group_broadcast(val,
                                            wg_local_x,
                                            wg_local_y);
  dst[index] = broadcast_val;
}
#endif
/*
 * Workgroup broadcast 3D functions
 */
kernel void compiler_workgroup_broadcast_3D_int(global int *src,
                                                global int *dst,
                                                uint wg_local_x,
                                                uint wg_local_y,
                                                uint wg_local_z)
{
  uint lsize = get_local_size(0) * get_local_size(1) * get_local_size(2);
  uint offset = get_group_id(0) * lsize +
      get_group_id(1) * get_num_groups(0) * lsize +
      get_group_id(2) * get_num_groups(1) * get_num_groups(0) * lsize;
  uint index = offset + get_local_id(0) +
      get_local_id(1) * get_local_size(0) +
      get_local_id(2) * get_local_size(1) * get_local_size(0);

  int val = src[index];
  int broadcast_val = work_group_broadcast(val,
                                            wg_local_x,
                                            wg_local_y,
                                            wg_local_z);
  dst[index] = broadcast_val;
}
#if 0
kernel void compiler_workgroup_broadcast_3D_long(global long *src,
                                                global long *dst,
                                                uint wg_local_x,
                                                uint wg_local_y,
                                                uint wg_local_z)
{
  uint lsize = get_local_size(0) * get_local_size(1) * get_local_size(2);
  uint offset = get_group_id(0) * lsize +
      get_group_id(1) * get_num_groups(0) * lsize +
      get_group_id(2) * get_num_groups(0) * get_num_groups(1) * lsize;
  uint index = offset + get_local_id(0) +
      get_local_id(1) * get_local_size(0) +
      get_local_id(2) * get_local_size(1) * get_local_size(0);

  long val = src[index];
  long broadcast_val = work_group_broadcast(val,
                                            wg_local_x,
                                            wg_local_y,
                                            wg_local_z);
  dst[index] = broadcast_val;
}
#endif