#define CONTEXT_H #include <stdlib.h> #include <pthread.h> #ifdef USE_CUDAWorker #include <cuda.h> #include <driver_types.h> #include <cuda_runtime.h> #include “helper_cuda.h” #endif
#define ALLOCATE_SIZE 20000000 #define NEW(type) (type*)(calloc(1, sizeof(type))) #define NEWN(n, type) (type*)(calloc(n, sizeof(type)))
#define ALLOC_DATA(context, dseg) ({
Meta* meta = (Meta*)context->heap;
meta->type = D_##dseg;
meta->size = sizeof(dseg);
meta->len = 1;
context->heap += sizeof(Meta);
meta->data = context->heap;
*context->metaData = meta;
context->metaData++;
context->data[D_##dseg] = context->heap; context->heap += sizeof(dseg); (dseg *)context->data[D_##dseg]; })
#define ALLOC_DATA_TYPE(context, dseg, t) ({
Meta* meta = (Meta*)context->heap;
meta->type = D_##t;
meta->size = sizeof(t);
meta->len = 1;
context->heap += sizeof(Meta);
meta->data = context->heap;
*context->metaData = meta;
context->metaData++;
context->data[D_##dseg] = context->heap; context->heap += sizeof(t); (t *)context->data[D_##dseg]; })
#define ALLOCATE(context, t) ({
Meta* meta = (Meta*)context->heap;
context->heap += sizeof(Meta);
union Data* data = context->heap;
context->heap += sizeof(t);
meta->type = D_##t;
meta->size = sizeof(t);
meta->len = 1;
meta->data = data;
*context->metaData = meta;
context->metaData++;
data; })
#define ALLOCATE_ARRAY(context, t, length) ({
Meta* meta = (Meta*)context->heap;
context->heap += sizeof(Meta);
union Data* data = context->heap;
context->heap += sizeof(t)*length;
meta->type = D_##t;
meta->size = sizeof(t)*length;
meta->len = length;
meta->data = data;
*context->metaData = meta;
context->metaData++;
data; })
#define ALLOCATE_PTR_ARRAY(context, dseg, length) ({
Meta* meta = (Meta*)context->heap;
context->heap += sizeof(Meta);
union Data* data = context->heap;
context->heap += sizeof(dseg *)*length;
meta->type = D_##dseg;
meta->size = sizeof(dseg *)*length;
meta->len = length;
meta->data = data;
*context->metaData = meta;
context->metaData++;
data; })
#define ALLOCATE_DATA_GEAR(context, t) ({
union Data* data = ALLOCATE(context, t);
Meta* meta = GET_META(data);
meta->wait = createSynchronizedQueue(context);
data; })
#define ALLOC(context, t) (&ALLOCATE(context, t)->t) #define NALLOC(t) (&ALLOCATE(context, t)->t)
#define GET_META(dseg) ((Meta*)(((void*)dseg) - sizeof(Meta))) #define GET_TYPE(dseg) (GET_META(dseg)->type) #define GET_SIZE(dseg) (GET_META(dseg)->size) #define GET_LEN(dseg) (GET_META(dseg)->len) #define GET_WAIT_LIST(dseg) (GET_META(dseg)->wait) #define GET_PREV_META(dseg) ((Meta*)(((void*)dseg) - (sizeof(Meta) * 2)))
#define Gearef(context, t) (&(context)->data[D_##t]->t)
// (SingleLinkedStack *)context->data[D_Stack]->Stack.stack->Stack.stack
#define GearImpl(context, intf, name) (Gearef(context, intf)->name->intf.name)
#include “c/enumCode.h”
enum Relational { EQ, GT, LT, };
#include “c/enumData.h” struct Context { enum Code next; struct Worker* worker; struct TaskManager* taskManager; int codeNum; __code (*code) (struct Context); union Data **data; struct Meta **metaDataStart; struct Meta metaData; void heapStart; void heap; long heapLimit; int dataNum;
// task parameter
int idgCount; //number of waiting dataGear
int idg;
int maxIdg;
int odg;
int maxOdg;
int gpu; // GPU task
struct Context* task;
struct Element* taskList;
#ifdef USE_CUDAWorker int num_exec; CUmodule module; CUfunction function; #endif /* multi dimension parameter / int iterate; struct Iterator iterator; };
typedef int Int; #ifndef USE_CUDAWorker typedef unsigned long long CUdeviceptr; #endif union Data { ///home/anatofuz/src/firefly/hg/Gears/Gears/src/parallel_execution/../parallel_execution/Atomic.h #ifndef ATOMIC_STRUCT struct Atomic { union Data* atomic; union Data** ptr; union Data* oldData; union Data* newData; enum Code checkAndSet; enum Code next; enum Code fail; } Atomic; #define ATOMIC_STRUCT #else struct Atomic; #endif ///home/anatofuz/src/firefly/hg/Gears/Gears/src/parallel_execution/../parallel_execution/plautogen/impl/AtomicReference.h #ifndef ATOMICREFERENCE_STRUCT struct AtomicReference { } AtomicReference; #define ATOMICREFERENCE_STRUCT #else struct AtomicReference; #endif ///home/anatofuz/src/firefly/hg/Gears/Gears/src/parallel_execution/../parallel_execution/plautogen/interface/CPUWorker.h #ifndef CPUWORKER_STRUCT struct CPUWorker { pthread_mutex_t mutex; pthread_cond_t cond; struct Context* context; int id; int loopCounter; } CPUWorker; #define CPUWORKER_STRUCT #else struct CPUWorker; #endif ///home/anatofuz/src/firefly/hg/Gears/Gears/src/parallel_execution/../parallel_execution/plautogen/interface/Element.h #ifndef ELEMENT_STRUCT struct Element { union Data* data; struct Element* next; } Element; #define ELEMENT_STRUCT #else struct Element; #endif ///home/anatofuz/src/firefly/hg/Gears/Gears/src/parallel_execution/../parallel_execution/plautogen/interface/Integer.h #ifndef INTEGER_STRUCT struct Integer { int value; } Integer; #define INTEGER_STRUCT #else struct Integer; #endif ///home/anatofuz/src/firefly/hg/Gears/Gears/src/parallel_execution/../parallel_execution/Iterator.h #ifndef ITERATOR_STRUCT struct Iterator { union Data* iterator; struct Context* task; int numGPU; enum Code exec; enum Code barrier; enum Code whenWait; enum Code next; } Iterator; #define ITERATOR_STRUCT #else struct Iterator; #endif ///home/anatofuz/src/firefly/hg/Gears/Gears/src/parallel_execution/../parallel_execution/plautogen/interface/LoopCounter.h #ifndef LOOPCOUNTER_STRUCT struct LoopCounter { int i; } LoopCounter; #define LOOPCOUNTER_STRUCT #else struct LoopCounter; #endif ///home/anatofuz/src/firefly/hg/Gears/Gears/src/parallel_execution/../parallel_execution/plautogen/interface/Meta.h #ifndef META_STRUCT struct Meta { enum DataType type; long size; long len; union Data* data; struct Queue* wait; // tasks waiting this dataGear; } Meta; #define META_STRUCT #else struct Meta; #endif ///home/anatofuz/src/firefly/hg/Gears/Gears/src/parallel_execution/../parallel_execution/Queue.h #ifndef QUEUE_STRUCT struct Queue { union Data* queue; union Data* data; enum Code whenEmpty; enum Code clear; enum Code put; enum Code take; enum Code isEmpty; enum Code next; } Queue; #define QUEUE_STRUCT #else struct Queue; #endif ///home/anatofuz/src/firefly/hg/Gears/Gears/src/parallel_execution/../parallel_execution/plautogen/impl/SynchronizedQueue.h #ifndef SYNCHRONIZEDQUEUE_STRUCT struct SynchronizedQueue { struct Element* top; struct Element* last; struct Atomic* atomic; } SynchronizedQueue; #define SYNCHRONIZEDQUEUE_STRUCT #else struct SynchronizedQueue; #endif ///home/anatofuz/src/firefly/hg/Gears/Gears/src/parallel_execution/../parallel_execution/interface/StackGenerics.h #ifndef STACKGENERICS_STRUCT struct StackGenerics { union Data* stack; TYPED_GENERICS_StackGenerics_T * data; TYPED_GENERICS_StackGenerics_T * data1; enum Code clear; enum Code push; enum Code pop; enum Code pop2; enum Code isEmpty; enum Code get; enum Code get2; enum Code next; enum Code whenEmpty; } StackGenerics; #define STACKGENERICS_STRUCT #else struct StackGenerics; #endif ///home/anatofuz/src/firefly/hg/Gears/Gears/src/parallel_execution/../parallel_execution/impl/StackGenericsImpl.h #ifndef STACKGENERICSIMPL_STRUCT struct StackGenericsImpl { enum Code next; } StackGenericsImpl; #define STACKGENERICSIMPL_STRUCT #else struct StackGenericsImpl; #endif ///home/anatofuz/src/firefly/hg/Gears/Gears/src/parallel_execution/../parallel_execution/TaskManager.h #ifndef TASKMANAGER_STRUCT struct TaskManager { union Data* taskManager; struct Context* task; union Data* taskManagerImpl; struct Element* taskList; enum Code spawn; enum Code spawnTasks; enum Code setWaitTask; enum Code shutdown; enum Code incrementTaskCount; enum Code decrementTaskCount; enum Code next; enum Code next1; } TaskManager; #define TASKMANAGER_STRUCT #else struct TaskManager; #endif ///home/anatofuz/src/firefly/hg/Gears/Gears/src/parallel_execution/../parallel_execution/plautogen/impl/TaskManagerImpl.h #ifndef TASKMANAGERIMPL_STRUCT struct TaskManagerImpl { int numWorker; int sendCPUWorkerIndex; int sendGPUWorkerIndex; int taskCount; pthread_mutex_t mutex; struct Queue* activeQueue; struct Worker** workers; struct Element* taskList; int loopCounter; int cpu; int gpu; int io; int maxCPU; enum Code next; } TaskManagerImpl; #define TASKMANAGERIMPL_STRUCT #else struct TaskManagerImpl; #endif ///home/anatofuz/src/firefly/hg/Gears/Gears/src/parallel_execution/../parallel_execution/Worker.h #ifndef WORKER_STRUCT struct Worker { union Data* worker; struct Queue* tasks; struct Context* task; pthread_t thread; struct TaskManager* taskManager; enum Code taskReceive; enum Code shutdown; enum Code next; } Worker; #define WORKER_STRUCT #else struct Worker; #endif struct Context Context; }; // union Data end this is necessary for context generator typedef union Data Data; #include “c/typedefData.h”
#include “c/extern.h”
extern __code start_code(struct Context* context); extern __code exit_code(struct Context* context); extern __code meta(struct Context* context, enum Code next); //extern __code par_meta(struct Context* context, enum Code spawns, enum Code next); extern __code parGotoMeta(struct Context* context, enum Code next); extern void initContext(struct Context* context);
#endif Filehandle STDOUT reopened as $fd only for input at generate_context.pl line 145. Filehandle STDOUT reopened as $cx only for input at generate_context.pl line 159.
|
|
|
|
|
|
AtomicTはわりとしょっぱいバグ
|
|