Mercurial > hg > Members > Moririn
view src/parallel_execution/context.h @ 375:ad44fdb11433
Fix compile error but not work
author | Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 18 Jul 2017 16:13:11 +0900 |
parents | fb50cf8aa615 |
children | 2744cb933ebc |
line wrap: on
line source
/* Context definition for llrb example */ #ifndef CONTEXT_H #define CONTEXT_H #include <stdlib.h> #include <pthread.h> #ifdef USE_CUDAWorker #include <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) ({\ struct Meta* meta = (struct Meta*)context->heap;\ meta->type = D_##dseg;\ meta->size = 1;\ context->heap += sizeof(struct Meta);\ context->data[D_##dseg] = context->heap; context->heap += sizeof(struct dseg); (struct dseg *)context->data[D_##dseg]; }) #define ALLOC_DATA_TYPE(context, dseg, t) ({\ struct Meta* meta = (struct Meta*)context->heap;\ meta->type = D_##t;\ meta->size = 1;\ context->heap += sizeof(struct Meta);\ context->data[D_##dseg] = context->heap; context->heap += sizeof(struct t); (struct t *)context->data[D_##dseg]; }) #define ALLOCATE(context, t) ({ \ struct Meta* meta = (struct Meta*)context->heap;\ context->heap += sizeof(struct Meta);\ union Data* data = context->heap; \ context->heap += sizeof(struct t); \ meta->type = D_##t; \ meta->size = 1; \ data; }) #define ALLOC(context, t) (&ALLOCATE(context, t)->t) #define ALLOC_ARRAY(context, dseg, len) ({\ struct Meta* meta = (struct Meta*)context->heap;\ context->heap += sizeof(struct Meta);\ union Data* data = context->heap; \ context->heap += sizeof(struct dseg *)*len; \ meta->type = D_##dseg; \ meta->size = len; \ data; }) #define ALLOCATE_DATA_GEAR(context, t) ({ \ union Data* data = ALLOCATE(context, t); \ struct Meta* meta = GET_META(data); \ meta->wait = createSingleLinkedQueue(context); \ data; }) #define GET_META(dseg) ((struct Meta*)(((void*)dseg) - sizeof(struct Meta))) #define GET_TYPE(dseg) (GET_META(dseg)->type) #define GET_SIZE(dseg) (GET_META(dseg)->size) #define GET_WAIT_LIST(dseg) (GET_META(dseg)->wait) #define Gearef(context, t) (&(context)->data[D_##t]->t) // (struct 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*); void* heapStart; void* heap; long heapLimit; int dataNum; int idgCount; //number of waiting dataGear int idg; int maxIdg; int odg; int maxOdg; int workerId; #ifdef USE_CUDAWorker int num_exec; CUmodule module; CUfunction function; #endif union Data **data; /* multi dimension parameter */ int iterate; struct Iterator* iterator; }; union Data { struct Meta { enum DataType type; long size; struct Queue* wait; // tasks waiting this dataGear } meta; struct Context Context; struct Time { union Data* time; enum Code start; enum Code end; enum Code next; } Time; struct TimeImpl { double time; } TimeImpl; struct LoopCounter { int i; } LoopCounter; struct TaskManager { #ifdef USE_CUDA_MAIN_THREAD volatile #endif union Data* taskManager; enum Code spawn; // start NEW context on the worker enum Code spawnTasks; // start NEW contexts on the worker enum Code shutdown; enum Code next; enum Code next1; enum Code task; struct Context* context; struct Context** contexts; union Data* data; int worker; int cpu; int gpu; int io; int maxCPU; } TaskManager; struct TaskManagerImpl { int numWorker; int sendWorkerIndex; pthread_mutex_t mutex; struct Queue* activeQueue; struct Queue* taskQueue; struct Worker** workers; struct LoopCounter* loopCounter; } TaskManagerImpl; struct Worker { union Data* worker; enum Code taskReceive; enum Code shutdown; enum Code next; struct Queue* tasks; struct TaskManager* taskManager; } Worker; struct CPUWorker { pthread_t thread; pthread_mutex_t mutex; pthread_cond_t cond; struct Context* context; int id; } CPUWorker; #ifdef USE_CUDAWorker struct CUDAWorker { CUdevice device; CUcontext cuCtx; pthread_t thread; struct Context* context; int id; struct Queue* tasks; int runFlag; enum Code next; int num_stream; CUstream *stream; } CUDAWorker; #else struct CUDAWorker { } CUDAWorker; #endif struct Main { enum Code code; enum Code next; struct Queue* args; } Main; // Queue Interface 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; struct SingleLinkedQueue { struct Element* top; struct Element* last; } SingleLinkedQueue; struct SynchronizedQueue { struct Element* top; struct Element* last; } SynchronizedQueue; // Stack Interface struct Stack { union Data* stack; union Data* data; union Data* data1; enum Code whenEmpty; enum Code clear; enum Code push; enum Code pop; enum Code pop2; enum Code isEmpty; enum Code get; enum Code get2; enum Code next; } Stack; // Stack implementations struct SingleLinkedStack { struct Element* top; } SingleLinkedStack; struct ArrayStack { int size; int limit; struct Element* array; } ArrayStack; // Stack implementation end struct Element { union Data* data; struct Element* next; } Element; struct Array { int size; int index; int prefix; int* array; } Array; struct Tree { union Data* tree; struct Node* node; enum Code put; enum Code get; enum Code remove; enum Code clear; enum Code next; } Tree; struct RedBlackTree { struct Node* root; struct Node* current; // reading node of original tree struct Node* previous; // parent of reading node of original tree struct Node* newNode; // writing node of new tree struct Node* parent; struct Node* grandparent; struct Stack* nodeStack; int result; } RedBlackTree; struct RotateTree { enum Code next; struct RedBlackTree* traverse; struct Tree* tree; } RotateTree; struct Node { int key; // comparable data segment union Data* value; struct Node* left; struct Node* right; // need to balancing enum Color { Red, Black, } color; } Node; struct Semaphore { union Data* semaphore; enum Code p; enum Code v; enum Code next; } Semaphore; struct SemaphoreImpl { int value; pthread_mutex_t mutex; pthread_cond_t cond; } SemaphoreImpl; struct Allocate { enum Code next; long size; } Allocate; struct Integer { int value; } Integer; struct SortArray {//そもそもこれは必要なのか? struct SortArray *sortArray; struct Integer **array;//Array arrayじゃできない? int loop_counter; int loop_counter2; int loop_counter3; int sort_finish; enum Code make_array; enum Code print; enum Code bitonic_sort; enum Code kernel; enum Code kernel2; enum Code swap; } SortArray; struct Iterator { union Data* iterator; struct Context* task; enum Code exec; enum Code barrier; enum Code whenWait; enum Code next; } Iterator; struct OneDimIterator { int x; int count; struct LoopCounter *loopCounter; } OneDimIterator; }; // 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 void initContext(struct Context* context); #endif