harmonize-python 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- harmonize/__init__.py +65 -0
- harmonize/__main__.py +39 -0
- harmonize/adapt.py +105 -0
- harmonize/array.py +588 -0
- harmonize/atomics.py +206 -0
- harmonize/codegen.py +409 -0
- harmonize/config.py +220 -0
- harmonize/cpp/async/future.h +64 -0
- harmonize/cpp/async/mod.h +9 -0
- harmonize/cpp/async/promise.h +747 -0
- harmonize/cpp/harmonize.h +4 -0
- harmonize/cpp/mem/mod.h +14 -0
- harmonize/cpp/mem/work.h +168 -0
- harmonize/cpp/preamble/adapt.h +162 -0
- harmonize/cpp/preamble/mod.h +133 -0
- harmonize/cpp/program/async.h +2923 -0
- harmonize/cpp/program/event.h +560 -0
- harmonize/cpp/program/mod.h +84 -0
- harmonize/cpp/sync/barrier.h +704 -0
- harmonize/cpp/sync/mod.h +9 -0
- harmonize/cpp/util/cli.h +510 -0
- harmonize/cpp/util/host.h +287 -0
- harmonize/cpp/util/iter.h +565 -0
- harmonize/cpp/util/mem.h +1050 -0
- harmonize/cpp/util/mod.h +148 -0
- harmonize/diagnostics.py +487 -0
- harmonize/errors.py +12 -0
- harmonize/logging.py +51 -0
- harmonize/pointer.py +108 -0
- harmonize/prim.py +59 -0
- harmonize/printing.py +104 -0
- harmonize/python/__init__.py +48 -0
- harmonize/runtime.py +1501 -0
- harmonize/templates.py +369 -0
- harmonize/timing.py +10 -0
- harmonize/types.py +16 -0
- harmonize_python-0.1.0.dist-info/METADATA +161 -0
- harmonize_python-0.1.0.dist-info/RECORD +40 -0
- harmonize_python-0.1.0.dist-info/WHEEL +4 -0
- harmonize_python-0.1.0.dist-info/licenses/LICENSE +29 -0
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
#ifndef HARMONIZE_PROGRAM_EVENT
|
|
5
|
+
#define HARMONIZE_PROGRAM_EVENT
|
|
6
|
+
|
|
7
|
+
#include "../async/mod.h"
|
|
8
|
+
#include "../mem/mod.h"
|
|
9
|
+
|
|
10
|
+
//! This macro is currently unused and partially implemented. When finished, it will
|
|
11
|
+
//! operate like the `MEMBER_SWITCH` macro, but for internal templates.
|
|
12
|
+
#define TEMPLATE_MEMBER_SWITCH(NAME,DEFAULT_TYPE) \
|
|
13
|
+
template<class PROG,class DEFAULT> static auto NAME##Lookup (int) -> DEFAULT; \
|
|
14
|
+
template<class PROG,class DEFAULT> static auto NAME##Lookup (bool) -> typename Specializer<typename PROG::NAME>::Type; \
|
|
15
|
+
typedef decltype(NAME##Lookup<PROGRAM_SPEC,DEFAULT_TYPE>(true)) NAME;
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
//! This macro inserts code that detects whether or not an internal type is defined by
|
|
19
|
+
//! the type `PROGRAM_SPEC` (the parameter name used to refer to a program specification)
|
|
20
|
+
//! and either defines an internal type that duplicates the internal type of `PROGRAM_SPEC`
|
|
21
|
+
//! or defines an internal type based off of a default.
|
|
22
|
+
#define MEMBER_SWITCH(NAME,DEFAULT_TYPE) \
|
|
23
|
+
template<class PROG,class DEFAULT> static auto NAME##Lookup (int) -> DEFAULT; \
|
|
24
|
+
template<class PROG,class DEFAULT> static auto NAME##Lookup (bool) -> typename PROG::NAME; \
|
|
25
|
+
typedef decltype(NAME##Lookup<PROGRAM_SPEC,DEFAULT_TYPE>(true)) NAME;
|
|
26
|
+
|
|
27
|
+
//! This macro behaves the same as `MEMBER_SWITCH`, but for internal static constants,
|
|
28
|
+
//! rather than for types
|
|
29
|
+
#define CONST_SWITCH(TYPE,NAME,DEFAULT_VAL) \
|
|
30
|
+
template<class PROG,TYPE DEFAULT> static auto NAME##Lookup (int) -> std::integral_constant<TYPE, DEFAULT>; \
|
|
31
|
+
template<class PROG,TYPE DEFAULT> static auto NAME##Lookup (bool) -> std::integral_constant<TYPE, PROG::NAME>; \
|
|
32
|
+
static const size_t NAME = decltype(NAME##Lookup<PROGRAM_SPEC,DEFAULT_VAL>(true))::value;
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
template<typename PROGRAM_SPEC>
|
|
38
|
+
class EventProgram
|
|
39
|
+
{
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
public:
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
typedef EventProgram<PROGRAM_SPEC> ProgramType;
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
template<class TYPE,class DEFAULT>
|
|
49
|
+
static auto ThreadStateLookup (int) -> DEFAULT;
|
|
50
|
+
|
|
51
|
+
template<class TYPE,class DEFAULT>
|
|
52
|
+
static auto ThreadStateLookup (double) -> typename TYPE::ThreadState;
|
|
53
|
+
/*
|
|
54
|
+
struct AdrTypeDefault { typedef unsigned int AdrType; };
|
|
55
|
+
template<class TYPE> using AdrTypeCheck = typename TYPE::AdrType;
|
|
56
|
+
typedef typename type_or<AdrTypeDefault,AdrTypeCheck,PROGRAM_SPEC>::AdrType AdrType;
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
MEMBER_SWITCH( AdrType,unsigned int)
|
|
60
|
+
MEMBER_SWITCH( OpSet, OpUnion<>)
|
|
61
|
+
MEMBER_SWITCH(DeviceState, VoidState)
|
|
62
|
+
MEMBER_SWITCH( GroupState, VoidState)
|
|
63
|
+
|
|
64
|
+
typedef decltype(ThreadStateLookup<PROGRAM_SPEC,VoidState>(1.0)) ThreadState;
|
|
65
|
+
|
|
66
|
+
typedef PromiseUnion<OpSet> PromiseUnionType;
|
|
67
|
+
|
|
68
|
+
template<typename TYPE>
|
|
69
|
+
struct Lookup { typedef typename PromiseUnionType::template Lookup<TYPE>::type type; };
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
CONST_SWITCH(size_t,GROUP_SIZE,adapt::WARP_SIZE)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
static const size_t WORK_GROUP_SIZE = GROUP_SIZE;
|
|
76
|
+
|
|
77
|
+
/*
|
|
78
|
+
// A set of halting condition flags
|
|
79
|
+
*/
|
|
80
|
+
static const unsigned int BAD_FUNC_ID_FLAG = 0x00000001;
|
|
81
|
+
static const unsigned int EARLY_HALT_FLAG = 0x40000000;
|
|
82
|
+
static const unsigned int COMPLETION_FLAG = 0x80000000;
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
/*
|
|
86
|
+
// The number of async functions present in the program.
|
|
87
|
+
*/
|
|
88
|
+
static const unsigned char FN_ID_COUNT = PromiseUnionType::Info::COUNT;
|
|
89
|
+
|
|
90
|
+
/*
|
|
91
|
+
// This struct represents the entire set of data structures that must be stored in thread
|
|
92
|
+
// memory to track te state of the program defined by the developer as well as the state of
|
|
93
|
+
// the context which is driving exection.
|
|
94
|
+
*/
|
|
95
|
+
struct ThreadContext {
|
|
96
|
+
|
|
97
|
+
unsigned int thread_id;
|
|
98
|
+
unsigned int rand_state;
|
|
99
|
+
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
/*
|
|
105
|
+
// This struct represents the entire set of data structures that must be stored in group
|
|
106
|
+
// memory to track te state of the program defined by the developer as well as the state of
|
|
107
|
+
// the context which is driving exection.
|
|
108
|
+
*/
|
|
109
|
+
struct GroupContext {
|
|
110
|
+
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
struct Status {
|
|
115
|
+
unsigned int checkout;
|
|
116
|
+
unsigned int flip_count;
|
|
117
|
+
unsigned int flags;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/*
|
|
121
|
+
// This struct represents the entire set of data structures that must be stored in main
|
|
122
|
+
// memory to track the state of the program defined by the developer as well as the state
|
|
123
|
+
// of the context which is driving execution.
|
|
124
|
+
*/
|
|
125
|
+
struct DeviceContext {
|
|
126
|
+
|
|
127
|
+
typedef ProgramType ParentProgramType;
|
|
128
|
+
|
|
129
|
+
Status *status;
|
|
130
|
+
unsigned int load_margin;
|
|
131
|
+
util::iter::IOBuffer<PromiseUnionType,AdrType> *event_io[PromiseUnionType::Info::COUNT];
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
/*
|
|
135
|
+
// Instances wrap around their program scope's DeviceContext. These differ from a program's
|
|
136
|
+
// DeviceContext object in that they perform automatic deallocation as soon as they drop
|
|
137
|
+
// out of scope.
|
|
138
|
+
*/
|
|
139
|
+
struct Instance {
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
util::host::DevBuf<Status> status;
|
|
143
|
+
util::host::DevObj<util::iter::IOBuffer<PromiseUnionType>> event_io[PromiseUnionType::Info::COUNT];
|
|
144
|
+
DeviceState device_state;
|
|
145
|
+
|
|
146
|
+
__host__ Instance (size_t io_size, DeviceState gs)
|
|
147
|
+
: device_state(gs)
|
|
148
|
+
{
|
|
149
|
+
|
|
150
|
+
for( unsigned int i=0; i<PromiseUnionType::Info::COUNT; i++){
|
|
151
|
+
event_io[i] = util::host::DevObj<util::iter::IOBuffer<PromiseUnionType>>(io_size);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
Status host_status{0u,0u,0u};
|
|
155
|
+
status << host_status;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
__host__ DeviceContext to_context(){
|
|
159
|
+
|
|
160
|
+
DeviceContext result;
|
|
161
|
+
|
|
162
|
+
result.status = status;
|
|
163
|
+
for( unsigned int i=0; i<PromiseUnionType::Info::COUNT; i++){
|
|
164
|
+
result.event_io[i] = event_io[i];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return result;
|
|
168
|
+
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
__host__ bool complete(){
|
|
172
|
+
|
|
173
|
+
bool complete = true;
|
|
174
|
+
for( unsigned int i=0; i<PromiseUnionType::Info::COUNT; i++){
|
|
175
|
+
event_io[i].pull_data();
|
|
176
|
+
check_error();
|
|
177
|
+
size_t item_count = event_io[i].host_copy().input_iter.limit;
|
|
178
|
+
if( item_count != 0 ){
|
|
179
|
+
//printf("Item count of %zu at %d\n",item_count,i);
|
|
180
|
+
complete = false;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// printf("\nitem count: %zu\n",item_count);
|
|
184
|
+
/*/
|
|
185
|
+
PromiseUnionType *host_array = new PromiseUnionType[item_count];
|
|
186
|
+
util::host::auto_throw(adapt::GPUrtMemcpy(
|
|
187
|
+
host_array,
|
|
188
|
+
event_io[i].host_copy().input_pointer(),
|
|
189
|
+
sizeof(PromiseUnionType)*item_count,
|
|
190
|
+
adapt::GPUrtMemcpyDeviceToHost
|
|
191
|
+
));
|
|
192
|
+
for(size_t i=0; i<item_count; i++) {
|
|
193
|
+
char * data = (char*) (host_array + i);
|
|
194
|
+
for(size_t j=0; j<sizeof(PromiseUnionType); j++) {
|
|
195
|
+
printf("%02hhx",data[j]);
|
|
196
|
+
}
|
|
197
|
+
printf(",\n");
|
|
198
|
+
}
|
|
199
|
+
printf("------\n");
|
|
200
|
+
delete[] host_array;
|
|
201
|
+
//*/
|
|
202
|
+
}
|
|
203
|
+
return complete;
|
|
204
|
+
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
__host__ void clear_flags(){
|
|
208
|
+
unsigned int value = 0;
|
|
209
|
+
unsigned int zero = 0;
|
|
210
|
+
util::host::auto_throw(adapt::GPUrtMemcpy(
|
|
211
|
+
&value,
|
|
212
|
+
&((Status*)status)->flags,
|
|
213
|
+
sizeof(unsigned int),
|
|
214
|
+
adapt::GPUrtMemcpyDeviceToHost
|
|
215
|
+
));
|
|
216
|
+
util::host::auto_throw(adapt::GPUrtMemcpy(
|
|
217
|
+
&((Status*)status)->flags,
|
|
218
|
+
&zero,
|
|
219
|
+
sizeof(unsigned int),
|
|
220
|
+
adapt::GPUrtMemcpyHostToDevice
|
|
221
|
+
));
|
|
222
|
+
util::host::auto_throw(adapt::GPUrtMemcpy(
|
|
223
|
+
&value,
|
|
224
|
+
&((Status*)status)->flags,
|
|
225
|
+
sizeof(unsigned int),
|
|
226
|
+
adapt::GPUrtMemcpyDeviceToHost
|
|
227
|
+
));
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
protected:
|
|
234
|
+
public:
|
|
235
|
+
|
|
236
|
+
DeviceContext & _dev_ctx;
|
|
237
|
+
GroupContext & _grp_ctx;
|
|
238
|
+
ThreadContext & _thd_ctx;
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
DeviceState & device;
|
|
242
|
+
GroupState & group;
|
|
243
|
+
ThreadState & thread;
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
__device__
|
|
247
|
+
EventProgram<PROGRAM_SPEC>
|
|
248
|
+
(
|
|
249
|
+
DeviceContext & d_c,
|
|
250
|
+
GroupContext & g_c,
|
|
251
|
+
ThreadContext & t_c,
|
|
252
|
+
|
|
253
|
+
DeviceState & d,
|
|
254
|
+
GroupState & g,
|
|
255
|
+
ThreadState & t
|
|
256
|
+
)
|
|
257
|
+
: _dev_ctx(d_c)
|
|
258
|
+
, _grp_ctx(g_c)
|
|
259
|
+
, _thd_ctx(t_c)
|
|
260
|
+
, device (d)
|
|
261
|
+
, group (g)
|
|
262
|
+
, thread (t)
|
|
263
|
+
{}
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
protected:
|
|
268
|
+
|
|
269
|
+
/*
|
|
270
|
+
// Initializes the shared state of a work group, which is stored as a ctx_shared struct. This
|
|
271
|
+
// is mainly done by initializing handles to the arena, pool, and stack, setting the current
|
|
272
|
+
// level to null, setting the stash iterator to null, and zeroing the stash.
|
|
273
|
+
*/
|
|
274
|
+
__device__ void init_group(){ }
|
|
275
|
+
|
|
276
|
+
/*
|
|
277
|
+
// Initializes the local state of a thread, which is just the device id of the thread and the
|
|
278
|
+
// state used by the thread to generate random numbers for stochastic choices needed to manage
|
|
279
|
+
// the runtime state.
|
|
280
|
+
*/
|
|
281
|
+
__device__ void init_thread(){
|
|
282
|
+
|
|
283
|
+
_thd_ctx.thread_id = (blockIdx.x * blockDim.x) + threadIdx.x;
|
|
284
|
+
_thd_ctx.rand_state = _thd_ctx.thread_id;
|
|
285
|
+
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
/*
|
|
290
|
+
// Sets the bits in the status_flags field of the stack according to the given flag bits.
|
|
291
|
+
*/
|
|
292
|
+
__device__ void set_flags(unsigned int flag_bits){
|
|
293
|
+
|
|
294
|
+
atomicOr(&_dev_ctx.status->flags,flag_bits);
|
|
295
|
+
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
/*
|
|
300
|
+
// Unsets the bits in the status_flags field of the stack according to the given flag bits.
|
|
301
|
+
*/
|
|
302
|
+
__device__ void unset_flags(unsigned int flag_bits){
|
|
303
|
+
|
|
304
|
+
atomicAnd(&_dev_ctx.status->_flags,~flag_bits);
|
|
305
|
+
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
__device__ bool any_flags_set() {
|
|
309
|
+
return (atomicAdd(&_dev_ctx.status->flags,0) != 0);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
static void check_error(){
|
|
314
|
+
|
|
315
|
+
adapt::GPUrtError_t status = adapt::GPUrtGetLastError();
|
|
316
|
+
|
|
317
|
+
if(status != adapt::GPUrtSuccess){
|
|
318
|
+
const char* err_str = adapt::GPUrtGetErrorString(status);
|
|
319
|
+
printf("ERROR: \"%s\"\n",err_str);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
template<typename TYPE>
|
|
327
|
+
__device__ void async_call_cast(int depth_delta, Promise<TYPE> param_value){
|
|
328
|
+
AdrType promise_index = 0;
|
|
329
|
+
AdrType io_index = static_cast<AdrType>(Lookup<TYPE>::type::DISC);
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
/*
|
|
333
|
+
printf("Event io at index %d is at %p with buffers at %p and %p\n",
|
|
334
|
+
io_index,
|
|
335
|
+
_dev_ctx.event_io[io_index],
|
|
336
|
+
_dev_ctx.event_io[io_index]->data_a,
|
|
337
|
+
_dev_ctx.event_io[io_index]->data_b
|
|
338
|
+
);
|
|
339
|
+
//*/
|
|
340
|
+
|
|
341
|
+
// Investigate push_idx
|
|
342
|
+
|
|
343
|
+
if( _dev_ctx.event_io[io_index]->push_index(promise_index) ){
|
|
344
|
+
//printf("{%d : -> %d}\n",io_index,promise_index);
|
|
345
|
+
/*/
|
|
346
|
+
printf("\n(");
|
|
347
|
+
char *data = (char*) ¶m_value;
|
|
348
|
+
for(size_t i=0; i<sizeof(param_value); i++){
|
|
349
|
+
printf("%02hhx",data[i]);
|
|
350
|
+
}
|
|
351
|
+
printf(")\n");
|
|
352
|
+
//*/
|
|
353
|
+
_dev_ctx.event_io[io_index]->output_pointer()[promise_index].template cast<TYPE>() = param_value;
|
|
354
|
+
//printf("\n\nDoing an async call!\n\n");
|
|
355
|
+
} else {
|
|
356
|
+
printf("\n\nRan out of space!\n\n");
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
template<typename TYPE>
|
|
362
|
+
__device__ void immediate_call_cast(Promise<TYPE> param_value){
|
|
363
|
+
PromiseUnionType promise;
|
|
364
|
+
promise.template cast<TYPE>() = param_value;
|
|
365
|
+
promise.template rigid_eval<ProgramType,TYPE>(*this);
|
|
366
|
+
//promise_eval<ProgramType,FUNC_ID>(param_value);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
public:
|
|
371
|
+
|
|
372
|
+
__device__ void init_program() {
|
|
373
|
+
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/*
|
|
377
|
+
// The workhorse of the program. This function executes until either a halting condition
|
|
378
|
+
// is encountered or a maximum number of processing cycles has occured. This makes sure
|
|
379
|
+
// that long-running programs don't time out on the GPU. In practice, cycle_count may have
|
|
380
|
+
// to be tuned to the average cycle execution time for a given application. This could
|
|
381
|
+
// potentially be automated using an exponential backoff heuristic.
|
|
382
|
+
*/
|
|
383
|
+
__device__ void exec(unsigned int chunk_size){
|
|
384
|
+
|
|
385
|
+
/* Initialize per-warp resources */
|
|
386
|
+
init_group();
|
|
387
|
+
|
|
388
|
+
/* Initialize per-thread resources */
|
|
389
|
+
init_thread();
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
if (threadIdx.x==0) {
|
|
393
|
+
for (unsigned int i=0; i < PromiseUnionType::Info::COUNT; i++) {
|
|
394
|
+
if ( !_dev_ctx.event_io[i]->input_empty() ) {
|
|
395
|
+
int in_v = _dev_ctx.event_io[i]->input_iter.value;
|
|
396
|
+
int in_l = _dev_ctx.event_io[i]->input_iter.limit;
|
|
397
|
+
int out_v = _dev_ctx.event_io[i]->output_iter.value;
|
|
398
|
+
int out_l = _dev_ctx.event_io[i]->output_iter.limit;
|
|
399
|
+
//printf("IO_BUFFER[%d] : (%d,%d) -> (%d,%d)\n",i,in_v,in_l,out_v,out_l);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
PROGRAM_SPEC::initialize(*this);
|
|
405
|
+
|
|
406
|
+
__shared__ util::iter::ArrayIter<PromiseUnionType,util::iter::AtomicIter,unsigned int> group_work;
|
|
407
|
+
__shared__ bool done;
|
|
408
|
+
__shared__ bool early_halt;
|
|
409
|
+
__shared__ OpDisc func_id;
|
|
410
|
+
|
|
411
|
+
__syncthreads();
|
|
412
|
+
if( threadIdx.x == 0 ){
|
|
413
|
+
early_halt = false;
|
|
414
|
+
group_work.reset(NULL,util::iter::Iter<unsigned int>(0,0));
|
|
415
|
+
}
|
|
416
|
+
__syncthreads();
|
|
417
|
+
|
|
418
|
+
/* The execution loop. */
|
|
419
|
+
unsigned int loop_lim = 0xFFFFF;
|
|
420
|
+
unsigned int loop_count = 0;
|
|
421
|
+
while(!early_halt){
|
|
422
|
+
__syncthreads();
|
|
423
|
+
if( threadIdx.x == 0 ) {
|
|
424
|
+
done = true;
|
|
425
|
+
|
|
426
|
+
if( any_flags_set() ){
|
|
427
|
+
early_halt = true;
|
|
428
|
+
printf("(Need to stop. Flags are %d)\n",_dev_ctx.status->flags);
|
|
429
|
+
} else {
|
|
430
|
+
for(unsigned int i=0; i < PromiseUnionType::Info::COUNT; i++){
|
|
431
|
+
if( !_dev_ctx.event_io[i]->input_empty() ){
|
|
432
|
+
done = false;
|
|
433
|
+
func_id = static_cast<OpDisc>(i);
|
|
434
|
+
group_work = _dev_ctx.event_io[i]->pull_span(chunk_size*GROUP_SIZE);
|
|
435
|
+
if (!group_work.done()){
|
|
436
|
+
break;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
__syncthreads();
|
|
445
|
+
if( done ){
|
|
446
|
+
__shared__ bool should_make_work;
|
|
447
|
+
__syncthreads();
|
|
448
|
+
if( threadIdx.x == 0 ) {
|
|
449
|
+
should_make_work = !early_halt;
|
|
450
|
+
}
|
|
451
|
+
__syncthreads();
|
|
452
|
+
while(should_make_work){
|
|
453
|
+
if( threadIdx.x == 0 ) {
|
|
454
|
+
for(int i=0; i<PromiseUnionType::Info::COUNT; i++){
|
|
455
|
+
int load = atomicAdd(&(_dev_ctx.event_io[i]->output_iter.value),0u);
|
|
456
|
+
if(load >= (_dev_ctx.event_io[i]->output_iter.limit / 2) ){
|
|
457
|
+
//printf("(Hit load margin!)\n");
|
|
458
|
+
should_make_work = false;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
if(should_make_work){
|
|
463
|
+
if( threadIdx.x == 0 ) {
|
|
464
|
+
rc_printf("(Making work!)\n");
|
|
465
|
+
}
|
|
466
|
+
should_make_work = PROGRAM_SPEC::make_work(*this);
|
|
467
|
+
if( (threadIdx.x == 0) && !should_make_work) {
|
|
468
|
+
rc_printf("(No more work. Halting...)\n");
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
break;
|
|
473
|
+
} else {
|
|
474
|
+
util::iter::ArrayIter<PromiseUnionType,util::iter::Iter,unsigned int> thread_work;
|
|
475
|
+
thread_work = group_work.leap(chunk_size);
|
|
476
|
+
PromiseUnionType promise;
|
|
477
|
+
while( thread_work.step_val(promise) ){
|
|
478
|
+
promise.template loose_eval<ProgramType>(*this,func_id);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
if(loop_count < loop_lim){
|
|
482
|
+
loop_count++;
|
|
483
|
+
} else {
|
|
484
|
+
rc_printf("(Loop count %d exceeds loop limit %d. Halting...)\n",loop_count, loop_lim);
|
|
485
|
+
break;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
__syncthreads();
|
|
492
|
+
|
|
493
|
+
PROGRAM_SPEC::finalize(*this);
|
|
494
|
+
|
|
495
|
+
__threadfence();
|
|
496
|
+
__syncthreads();
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
if( threadIdx.x == 0 ){
|
|
501
|
+
__threadfence();
|
|
502
|
+
unsigned int checkout_index = atomicAdd_system(&_dev_ctx.status->checkout,1);
|
|
503
|
+
__threadfence_system();
|
|
504
|
+
if( checkout_index == (gridDim.x - 1) ){
|
|
505
|
+
__threadfence_system();
|
|
506
|
+
atomicExch_system(&_dev_ctx.status->checkout,0);
|
|
507
|
+
__threadfence_system();
|
|
508
|
+
for(unsigned int i=0; i < PromiseUnionType::Info::COUNT; i++){
|
|
509
|
+
_dev_ctx.event_io[i]->flip();
|
|
510
|
+
__threadfence_system();
|
|
511
|
+
}
|
|
512
|
+
atomicAdd_system(&_dev_ctx.status->flip_count,1u);
|
|
513
|
+
__threadfence_system();
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
template<typename TYPE,typename... ARGS>
|
|
521
|
+
__device__ void async(ARGS... args){
|
|
522
|
+
async_call_cast<TYPE>(0,Promise<TYPE>(args...));
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
template<typename TYPE>
|
|
526
|
+
__device__ void async_call(Promise<TYPE> promise){
|
|
527
|
+
async_call_cast<TYPE>(0,promise);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
template<typename TYPE,typename... ARGS>
|
|
531
|
+
__device__ void sync(ARGS... args){
|
|
532
|
+
immediate_call_cast<TYPE>(Promise<TYPE>(args...));
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
template<typename TYPE>
|
|
536
|
+
__device__ void sync_call(Promise<TYPE> promise){
|
|
537
|
+
immediate_call_cast<TYPE>(0,promise);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
template<typename TYPE>
|
|
541
|
+
__device__ float load_fraction()
|
|
542
|
+
{
|
|
543
|
+
return _dev_ctx.event_io[Lookup<TYPE>::type::DISC]->output_fill_fraction_sync();
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
__device__ void halt_early() {
|
|
547
|
+
set_flags(EARLY_HALT_FLAG);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
};
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
#undef MEMBER_SWITCH
|
|
555
|
+
#undef CONST_SWITCH
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
#endif
|
|
559
|
+
|
|
560
|
+
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
#ifndef HARMONIZE_PROGRAM
|
|
5
|
+
#define HARMONIZE_PROGRAM
|
|
6
|
+
|
|
7
|
+
// The set of available program types
|
|
8
|
+
#include "async.h"
|
|
9
|
+
#include "event.h"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
/*
|
|
14
|
+
// These functions are here just to trampoline into the actual main functions for a given program.
|
|
15
|
+
// This additonal layer of calls is present to allow for linking to these calls as device functions.
|
|
16
|
+
*/
|
|
17
|
+
template<typename ProgType>
|
|
18
|
+
__device__ void _inner_dev_init(typename ProgType::DeviceContext& _dev_ctx, typename ProgType::DeviceState& device) {
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
__shared__ typename ProgType::GroupContext _grp_ctx;
|
|
22
|
+
__shared__ typename ProgType::GroupState group;
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
typename ProgType::ThreadContext _thd_ctx;
|
|
26
|
+
typename ProgType::ThreadState thread;
|
|
27
|
+
|
|
28
|
+
ProgType prog(_dev_ctx,_grp_ctx,_thd_ctx,device,group,thread);
|
|
29
|
+
|
|
30
|
+
prog.init_program();
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
template<typename ProgType>
|
|
36
|
+
__device__ void _inner_dev_exec(typename ProgType::DeviceContext& _dev_ctx, typename ProgType::DeviceState& device, size_t cycle_count) {
|
|
37
|
+
|
|
38
|
+
__shared__ typename ProgType::GroupContext _grp_ctx;
|
|
39
|
+
__shared__ typename ProgType::GroupState group;
|
|
40
|
+
|
|
41
|
+
typename ProgType::ThreadContext _thd_ctx;
|
|
42
|
+
typename ProgType::ThreadState thread;
|
|
43
|
+
|
|
44
|
+
ProgType prog(_dev_ctx,_grp_ctx,_thd_ctx,device,group,thread);
|
|
45
|
+
|
|
46
|
+
if (threadIdx.x == 0) {
|
|
47
|
+
//printf("(ctx%p)",&prog._dev_ctx);
|
|
48
|
+
//printf("(sta%p -> %p)",&prog.device,prog.device);
|
|
49
|
+
//printf("(pre%p)",((void**)&prog.device)[-1]);
|
|
50
|
+
//printf("(gtx%p)",(&prog._grp_ctx));
|
|
51
|
+
}
|
|
52
|
+
prog.exec(cycle_count);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
/*
|
|
58
|
+
// These functions are here just to trampoline into the device trampoline functions for a given program.
|
|
59
|
+
// This is done because structs/classes may not have global member functions.
|
|
60
|
+
*/
|
|
61
|
+
template<typename ProgType>
|
|
62
|
+
__global__ void _dev_init(typename ProgType::DeviceContext _dev_ctx, typename ProgType::DeviceState device) {
|
|
63
|
+
_inner_dev_init<ProgType>(_dev_ctx, device);
|
|
64
|
+
}
|
|
65
|
+
template<typename ProgType>
|
|
66
|
+
__global__ void _dev_exec(typename ProgType::DeviceContext _dev_ctx, typename ProgType::DeviceState device, size_t cycle_count) {
|
|
67
|
+
_inner_dev_exec<ProgType>(_dev_ctx, device,cycle_count);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
//! These functions unwrap an instance into its device context and passes it to the responsible
|
|
72
|
+
//! kernel.
|
|
73
|
+
template<typename ProgType>
|
|
74
|
+
__host__ void init(typename ProgType::Instance& instance,size_t group_count) {
|
|
75
|
+
_dev_init<ProgType><<<group_count,ProgType::WORK_GROUP_SIZE>>>(instance.to_context(),instance.device_state);
|
|
76
|
+
}
|
|
77
|
+
template<typename ProgType>
|
|
78
|
+
__host__ void exec(typename ProgType::Instance& instance,size_t group_count, size_t cycle_count) {
|
|
79
|
+
_dev_exec<ProgType><<<group_count,ProgType::WORK_GROUP_SIZE>>>(instance.to_context(),instance.device_state,cycle_count);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
#endif
|
|
84
|
+
|