comparison src/parallel_execution/context.h @ 101:8987cf13d5bb

Add Allocate macro
author innparusu
date Wed, 02 Mar 2016 19:23:00 +0900
parents d400948dbbab
children 64c98838a291
comparison
equal deleted inserted replaced
100:3d7ecced7e14 101:8987cf13d5bb
1 /* Context definition for llrb example */ 1 /* Context definition for llrb example */
2 #include <pthread.h> 2 #include <pthread.h>
3 #ifdef USE_CUDA
3 #include <cuda.h> 4 #include <cuda.h>
5 #endif
4 #include "stack.h" 6 #include "stack.h"
5 7
6 #define ALLOCATE_SIZE 20000000 8 #define ALLOCATE_SIZE 20000000
9 #define NEW(type) (type*)(calloc(1, sizeof(type)))
10 #define NEWN(n, type) (type*)(calloc(n, sizeof(type)))
11
12 #define ALLOC_DATA(context, dseg) ({ context->data[dseg] = context->heap; context->heap += sizeof(struct dseg); (struct dseg *)context->data[dseg]; })
13
14 #define ALLOC_DATA_TYPE(context, dseg, type) ({ context->data[dseg] = context->heap; context->heap += sizeof(struct type); (struct type *)context->data[dseg]; })
7 15
8 enum Code { 16 enum Code {
9 Code1, 17 Code1,
10 Code2, 18 Code2,
11 Code3, 19 Code3,
105 } loopCounter; 113 } loopCounter;
106 struct Worker { 114 struct Worker {
107 int num; 115 int num;
108 struct Context* contexts; 116 struct Context* contexts;
109 } worker; 117 } worker;
118 #ifdef USE_CUDA
110 struct CudaTask { 119 struct CudaTask {
111 CUdevice device; 120 CUdevice device;
112 CUcontext cuCtx; 121 CUcontext cuCtx;
113 CUfunction code; 122 CUfunction code;
114 CUdeviceptr* deviceptr; 123 CUdeviceptr* deviceptr;
115 CUstream stream; 124 CUstream stream;
116 } cudatask; 125 } cudatask;
126 #endif
117 struct Task { 127 struct Task {
118 enum Code code; 128 enum Code code;
119 int key; 129 int key;
120 } task; 130 } task;
121 struct Queue { 131 struct Queue {