summaryrefslogtreecommitdiff
path: root/backend/src/libocl/src/ocl_enqueue.cl
blob: 1ae43aa414fd4e4ebde8d67ba7cf927746fe3b80 (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/*
 * Copyright © 2012 - 2014 Intel Corporation
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 *
 */
#include "ocl_types.h"
#include "ocl_enqueue.h"
#include "ocl_workitem.h"
#include "ocl_atom.h"

queue_t get_default_queue(void)
{
  queue_t queue;
  return queue; //return NULL queue
}

ndrange_t __gen_ocl_set_ndrange_info(__private struct ndrange_info_t *info);
__private struct ndrange_info_t* __gen_ocl_get_ndrange_info(ndrange_t info);
__global int* __gen_ocl_get_enqueue_info_addr(void);

int __enqueue_kernel_basic(queue_t q, int flag, ndrange_t ndrange, BLOCK_TYPE block)
{
  int i;
  __private struct Block_literal *literal = (__private struct Block_literal *)block;
  __private uchar *data = (__private uchar *)block;
  int size = literal->descriptor->size;
  literal->descriptor->reserved = 0;
  __global int* start_addr = __gen_ocl_get_enqueue_info_addr();
  int offset = atomic_add(start_addr, size + sizeof(struct ndrange_info_t));
  __global uchar* addr = (__global uchar*)start_addr + offset + sizeof(int);
#if __clang_major__*10 + __clang_minor__ >= 50
  __private struct ndrange_info_t *info = to_private(&ndrange);
#else
  __private struct ndrange_info_t *info = __gen_ocl_get_ndrange_info(ndrange);
#endif
  *((__global struct ndrange_info_t *)addr) = *info;
  addr += sizeof(*info);

  for(i=0; i< size; i++) {
    addr[i] = data[i];
  }
  return 0;
}

int __enqueue_kernel_basic_events(queue_t q, int flag, ndrange_t ndrange,
                                uint num_events_in_wait_list, const EVENT_TYPE event_wait_list,
                                EVENT_TYPE event_ret, BLOCK_TYPE block)
{
  return __enqueue_kernel_basic(q, flag, ndrange, block);
}

int __gen_enqueue_kernel_slm(queue_t q, int flag, ndrange_t ndrange, BLOCK_TYPE block, int count, __private int* slm_sizes)
{
  int i;
  __private struct Block_literal* literal = (__private struct Block_literal *)block;
  __private uchar* data = (__private uchar *)block;
  int size = literal->descriptor->size;
  int slm_size = count * sizeof(int);
  literal->descriptor->reserved = slm_size;
  __global int* start_addr = __gen_ocl_get_enqueue_info_addr();
  int offset = atomic_add(start_addr, size + sizeof(struct ndrange_info_t) + slm_size);
  __global uchar* addr = (__global uchar*)start_addr + offset + sizeof(int);
#if __clang_major__*10 + __clang_minor__ >= 50
  __private struct ndrange_info_t *info = to_private(&ndrange);
#else
  __private struct ndrange_info_t *info = __gen_ocl_get_ndrange_info(ndrange);
#endif

  *((__global struct ndrange_info_t *)addr) = *info;
  addr += sizeof(*info);

  for(i=0; i < size; i++) {
    addr[i] = data[i];
  }

  addr += size;
  for(i=0; i < count; i++) {
    ((__global int *)addr)[i] = slm_sizes[i];
  }
  return 0;
}

clk_event_t create_user_event(void)
{
  clk_event_t e;
  return e;
}

void retain_event(clk_event_t event)
{
  return;
}

void release_event(clk_event_t event)
{
  return;
}

void set_user_event_status(clk_event_t event, int status)
{
  return;
}

bool is_valid_event(clk_event_t event)
{
  return 1;
}

uint __get_kernel_work_group_size_impl(BLOCK_TYPE block)
{
  return 256;
}

uint __get_kernel_preferred_work_group_multiple_impl(BLOCK_TYPE block)
{
  return 16;
}

void capture_event_profiling_info(clk_event_t event, int name, global void *value)
{
  //fake profiing data
  ((__global ulong *)value)[0] = 0x3000;
  ((__global ulong *)value)[1] = 0x6000;
}

#if __clang_major__*10 + __clang_minor__ >= 50
#define RET_INFO  return info;
#else
#define RET_INFO  return __gen_ocl_set_ndrange_info(&info);
#endif

OVERLOADABLE ndrange_t ndrange_1D(size_t global_work_size)
{
  struct ndrange_info_t info;
  info.type = 0x1;
  info.global_work_size[0] = global_work_size;
  RET_INFO;
}

OVERLOADABLE ndrange_t ndrange_1D(size_t global_work_size, size_t local_work_size)
{
  struct ndrange_info_t info;
  info.type = 0x2;
  info.global_work_size[0] = global_work_size;
  info.local_work_size[0] = local_work_size;
  RET_INFO;
}


OVERLOADABLE ndrange_t ndrange_1D(size_t global_work_offset, size_t global_work_size, size_t local_work_size)
{
  struct ndrange_info_t info;
  info.type = 0x3;
  info.global_work_size[0] = global_work_size;
  info.local_work_size[0] = local_work_size;
  info.global_work_offset[0] = global_work_offset;
  RET_INFO;
}

OVERLOADABLE ndrange_t ndrange_2D(const size_t global_work_size[2])
{
  struct ndrange_info_t info;
  info.type = 0x11;
  info.global_work_size[0] = global_work_size[0];
  info.global_work_size[1] = global_work_size[1];
  RET_INFO;
}

OVERLOADABLE ndrange_t ndrange_2D(const size_t global_work_size[2], const size_t local_work_size[2])
{
  struct ndrange_info_t info;
  info.type = 0x12;
  info.global_work_size[0] = global_work_size[0];
  info.global_work_size[1] = global_work_size[1];
  info.local_work_size[0] = local_work_size[0];
  info.local_work_size[1] = local_work_size[1];
  RET_INFO;
}


OVERLOADABLE ndrange_t ndrange_2D(const size_t global_work_offset[2], const size_t global_work_size[2], const size_t local_work_size[2])
{
  struct ndrange_info_t info;
  info.type = 0x13;
  info.global_work_size[0] = global_work_size[0];
  info.global_work_size[1] = global_work_size[1];
  info.local_work_size[0] = local_work_size[0];
  info.local_work_size[1] = local_work_size[1];
  info.global_work_offset[0] = global_work_offset[0];
  info.global_work_offset[1] = global_work_offset[1];
  RET_INFO;
}

OVERLOADABLE ndrange_t ndrange_3D(const size_t global_work_size[3])
{
  struct ndrange_info_t info;
  info.type = 0x21;
  info.global_work_size[0] = global_work_size[0];
  info.global_work_size[1] = global_work_size[1];
  info.global_work_size[2] = global_work_size[2];
  RET_INFO;
}

OVERLOADABLE ndrange_t ndrange_3D(const size_t global_work_size[3], const size_t local_work_size[3])
{
  struct ndrange_info_t info;
  info.type = 0x22;
  info.global_work_size[0] = global_work_size[0];
  info.global_work_size[1] = global_work_size[1];
  info.global_work_size[2] = global_work_size[2];
  info.local_work_size[0] = local_work_size[0];
  info.local_work_size[1] = local_work_size[1];
  info.local_work_size[2] = local_work_size[2];
  RET_INFO;
}

OVERLOADABLE ndrange_t ndrange_3D(const size_t global_work_offset[3], const size_t global_work_size[3], const size_t local_work_size[3])
{
  struct ndrange_info_t info;
  info.type = 0x23;
  info.global_work_size[0] = global_work_size[0];
  info.global_work_size[1] = global_work_size[1];
  info.global_work_size[2] = global_work_size[2];
  info.local_work_size[0] = local_work_size[0];
  info.local_work_size[1] = local_work_size[1];
  info.local_work_size[2] = local_work_size[2];
  info.global_work_offset[0] = global_work_offset[0];
  info.global_work_offset[1] = global_work_offset[1];
  info.global_work_offset[2] = global_work_offset[2];
  RET_INFO;
}

int enqueue_marker (queue_t queue, uint num_events_in_wait_list, const clk_event_t *event_wait_list, clk_event_t *event_ret)
{
  return 0;
}