Mercurial > hg > GearsTemplate
changeset 576:c86da02a73bf
add Template.pm
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 25 Nov 2019 17:06:09 +0900 |
parents | 3e3158198cb5 |
children | f78ad1f89524 |
files | src/parallel_execution/lib/Gears/Context/Template.pm |
diffstat | 1 files changed, 171 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/lib/Gears/Context/Template.pm Mon Nov 25 17:06:09 2019 +0900 @@ -0,0 +1,171 @@ +package Gears::Context::Template; +use strict; +use warnings; + +sub emit_top_header { + my ($class, $out) = @_; +my $str = << 'EOFEOF'; +/* Context definition for llrb example */ +#ifndef CONTEXT_H +#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);\ + 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);\ + 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;\ + 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; \ + 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; \ + 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 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 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; + 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; + enum Code before; +}; + +typedef int Int; +#ifndef USE_CUDAWorker +typedef unsigned long long CUdeviceptr; +#endif +EOFEOF + print $out $str; +} + +sub emit_data_gears { + my ($class, $out, $dgs) = @_; + +print $out "union Data {\n"; +print $out $dgs; +print $out <<'EOF'; + struct Context Context; +}; // union Data end this is necessary for context generator +typedef union Data Data; +EOF +} + + +sub emit_last_header { + my($class, $out) = @_; + print $out <<'EOF'; +#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 +EOF +} + +1;