-
Notifications
You must be signed in to change notification settings - Fork 8
/
queueInterface.cuh
370 lines (320 loc) · 10 KB
/
queueInterface.cuh
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
// Project Whippletree
// http://www.icg.tugraz.at/project/parallel
//
// Copyright (C) 2014 Institute for Computer Graphics and Vision,
// Graz University of Technology
//
// Author(s): Markus Steinberger - steinberger ( at ) icg.tugraz.at
// Michael Kenzel - kenzel ( at ) icg.tugraz.at
// Pedro Boechat - boechat ( at ) icg.tugraz.at
// Bernhard Kerbl - kerbl ( at ) icg.tugraz.at
// Mark Dokter - dokter ( at ) icg.tugraz.at
// Dieter Schmalstieg - schmalstieg ( at ) icg.tugraz.at
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#pragma once
#include <string>
template<bool TWarnings = true>
class Queue
{
public:
static const bool needTripleCall = false;
static const bool supportReuseInit = false;
static const int globalMaintainMinThreads = 0;
static int globalMaintainSharedMemory(int Threads) { return 0; }
static const int requiredShared = 0;
__inline__ __device__ void init()
{
if(TWarnings) printf("Warning: Queue does not implement init\n");
}
template<class PROCEDURE>
__inline__ __device__ bool enqueueInitial(typename PROCEDURE::ExpectedData data)
{
if(TWarnings) printf("Error: Queue does not implement enqueueInitial\n");
return false;
}
template<int threads, class PROCEDURE>
__inline__ __device__ bool enqueueInitial(typename PROCEDURE::ExpectedData* data)
{
if(TWarnings) printf("Error: Queue does not implement enqueueInitial<int,Proc>\n");
return false;
}
template<class PROCEDURE>
__inline__ __device__ bool enqueue(typename PROCEDURE::ExpectedData data)
{
if(TWarnings) printf("Error: Queue does not implement enqueue\n");
return false;
}
template<int threads, class PROCEDURE>
__inline__ __device__ bool enqueue(typename PROCEDURE::ExpectedData* data)
{
if(TWarnings) printf("Error: Queue does not implement enqueue<Threads>\n");
return false;
}
template<bool MultiProcedure>
__inline__ __device__ int dequeue(void*& data, int*& procId, int maxShared = -1)
{
if(TWarnings) printf("Error: Queue does not implement dequeue\n");
return 0;
}
template<bool MultiProcedure>
__inline__ __device__ int dequeueSelected(void*& data, int procId, int maxNum = -1)
{
if(TWarnings) printf("Error: Queue does not implement dequeueSelected\n");
return 0;
}
template<bool MultiProcedure>
__inline__ __device__ int dequeueStartRead(void*& data, int*& procId, int maxShared = -1)
{
if(TWarnings) printf("Error: Queue does not implement dequeuePointer\n");
return 0;
}
template<class PROCEDURE>
__inline__ __device__ int reserveRead(int maxNum = -1)
{
if(TWarnings) printf("Error: Queue does not implement reserveRead\n");
return 0;
}
template<class PROCEDURE>
__inline__ __device__ int startRead(void*& data, int num)
{
if(TWarnings) printf("Error: Queue does not implement startRead\n");
return -1;
}
template<class PROCEDURE>
__inline__ __device__ void finishRead(int id, int num)
{
if(TWarnings) printf("Error: Queue does not implement finishRead\n");
}
__inline__ __device__ void numEntries(int* counts)
{
if(TWarnings) printf("Error: Queue does not implement numEntries\n");
}
__inline__ __device__ void record()
{
if(TWarnings) printf("Error: Queue does not implement record\n");
}
__inline__ __device__ void reset()
{
if(TWarnings) printf("Error: Queue does not implement reset\n");
}
__inline__ __device__ void workerStart()
{ }
__inline__ __device__ void workerMaintain()
{ }
__inline__ __device__ void workerEnd()
{ }
__inline__ __device__ void globalMaintain()
{ }
static std::string name()
{
if(TWarnings)
return "UnnamedQueuing";
else
return "";
}
};
template<class ProcedureInfo, template<class /*PI*/> class RealQueue, template<class> class MatchMaker>
class QueueEnqueueWrapper : public RealQueue<ProcedureInfo>
{
public:
template<class PROCEDURE>
__inline__ __device__ bool enqueueInitial(typename PROCEDURE::ExpectedData data)
{
return RealQueue<ProcedureInfo>:: template enqueueInitial < typename MatchMaker<PROCEDURE>::Match>(data);
}
template<int threads, class PROCEDURE>
__inline__ __device__ bool enqueueInitial(typename PROCEDURE::ExpectedData *data)
{
return RealQueue<ProcedureInfo>:: template enqueueInitial < typename MatchMaker<PROCEDURE>::Match>(data);
}
template<class PROCEDURE>
__inline__ __device__ bool enqueue(typename PROCEDURE::ExpectedData data)
{
return RealQueue<ProcedureInfo>:: template enqueue < typename MatchMaker<PROCEDURE>::Match>(data);
}
template<int threads, class PROCEDURE>
__inline__ __device__ bool enqueue(typename PROCEDURE::ExpectedData* data)
{
return RealQueue<ProcedureInfo>:: template enqueue <threads, typename MatchMaker<PROCEDURE>::Match>(data);
}
};
template<class TAdditionalData>
class BasicQueue
{
public:
__inline__ __device__ void init()
{
printf("Warning: BasicQueue does not implement init\n");
}
template<class Data>
__inline__ __device__ bool enqueueInitial(Data data, TAdditionalData additionalData)
{
printf("Error: BasicQueue does not implement enqueueInitial\n");
return false;
}
template<int Threads, class Data>
__inline__ __device__ bool enqueueInitial(Data* data, TAdditionalData additionalData)
{
printf("Error: BasicQueue does not implement enqueueInitial\n");
return false;
}
template<class Data>
__inline__ __device__ bool enqueue(Data data, TAdditionalData additionalData)
{
printf("Error: BasicQueue does not implement enqueue\n");
return false;
}
template<int threads, class Data>
__inline__ __device__ bool enqueue(Data* data, TAdditionalData additionalData)
{
printf("Error: BasicQueue does not implement enqueue<Threads>\n");
return false;
}
__inline__ __device__ int dequeue(void* data, TAdditionalData* addtionalData, int maxnum)
{
printf("Error: BasicQueue does not implement dequeue\n");
return 0;
}
__inline__ __device__ int reserveRead(int maxnum, bool only_read_all = false)
{
printf("Error: BasicQueue does not implement reserveRead\n");
return 0;
}
__inline__ __device__ int startRead(void*& data, TAdditionalData* addtionalData, int pos, int num)
{
printf("Error: BasicQueue does not implement startRead\n");
return -1;
}
__inline__ __device__ void finishRead(int id, int num)
{
printf("Error: BasicQueue does not implement finishRead\n");
}
template<class SortInfo>
__inline__ __device__ bool sort( unsigned int threads)
{
printf("Error: BasicQueue does not implement sort\n");
return false;
}
static std::string name()
{
return "UnnamedBasicQueue";
}
};
template<>
class BasicQueue<void>
{
public:
__inline__ __device__ void init()
{
printf("Warning: BasicQueue does not implement init\n");
}
template<class Data>
__inline__ __device__ bool enqueueInitial(Data data)
{
printf("Error: BasicQueue does not implement enqueueInitial\n");
return false;
}
template<int threads, class Data>
__inline__ __device__ bool enqueueInitial(Data* data)
{
printf("Error: BasicQueue does not implement enqueueInitial*\n");
return false;
}
template<class Data>
__inline__ __device__ bool enqueue(Data data)
{
printf("Error: BasicQueue does not implement enqueue\n");
return false;
}
template<int threads, class Data>
__inline__ __device__ bool enqueue(Data* data)
{
printf("Error: BasicQueue does not implement enqueue<Threads>\n");
return false;
}
__inline__ __device__ int dequeue(void* data, int maxnum)
{
printf("Error: BasicQueue does not implement dequeue\n");
return 0;
}
__inline__ __device__ int reserveRead(int maxnum, bool only_read_all = false)
{
printf("Error: BasicQueue does not implement reserveRead\n");
return 0;
}
__inline__ __device__ int startRead(void*& data, int pos, int num)
{
printf("Error: BasicQueue does not implement startRead\n");
return -1;
}
__inline__ __device__ void finishRead(int id, int num)
{
printf("Error: Queue does not implement finishRead\n");
}
template<class SortInfo>
__inline__ __device__ bool sort( unsigned int threads)
{
printf("Error: BasicQueue does not implement sort\n");
return false;
}
static std::string name()
{
return "UnnamedBasicQueue";
}
};
typedef Queue<false> ZeroQueue;
template<class ProcInfo>
class IgnoreQueue : public ZeroQueue { };
template<class Q>
__global__ void initQueue(Q* q)
{
q->init();
}
template<unsigned int Size>
class Min16
{
public:
static const unsigned int Compute = Size;
};
#define _Min16Macro(Size) \
template<> \
class Min16<Size> \
{ \
public: \
static const unsigned int Compute = 16U; \
};
_Min16Macro(0U)
_Min16Macro(1U)
_Min16Macro(2U)
_Min16Macro(3U)
_Min16Macro(4U)
_Min16Macro(5U)
_Min16Macro(6U)
_Min16Macro(7U)
_Min16Macro(8U)
_Min16Macro(9U)
_Min16Macro(10U)
_Min16Macro(11U)
_Min16Macro(12U)
_Min16Macro(13U)
_Min16Macro(14U)
_Min16Macro(15U)
#undef _Min16Macro