Mercurial > hg > GearsTemplate
comparison src/cuda.c @ 590:9146d6017f18 default tip
hg mv parallel_execution/* ..
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 16 Jan 2020 15:12:06 +0900 |
parents | src/parallel_execution/cuda.c@d6983ce1015d |
children |
comparison
equal
deleted
inserted
replaced
589:a4cab67624f7 | 590:9146d6017f18 |
---|---|
1 #include <stdio.h> | |
2 #include <sys/time.h> | |
3 #include <string.h> | |
4 #include <stdlib.h> | |
5 | |
6 // includes, project | |
7 #include <driver_types.h> | |
8 #include <cuda_runtime.h> | |
9 #include <cuda.h> | |
10 #include "helper_cuda.h" | |
11 #include "pthread.h" | |
12 | |
13 #include "context.h" | |
14 | |
15 /* | |
16 struct Context { | |
17 int next; | |
18 struct Worker* worker; | |
19 struct TaskManager* taskManager; | |
20 int codeNum; | |
21 void (**code) (struct Context*); | |
22 void* heapStart; | |
23 void* heap; | |
24 long heapLimit; | |
25 int dataNum; | |
26 int idgCount; //number of waiting dataGear | |
27 int idg; | |
28 int maxIdg; | |
29 int odg; | |
30 int maxOdg; | |
31 int workerId; | |
32 struct Context* task; | |
33 struct Queue* tasks; | |
34 int num_exec; | |
35 CUmodule module; | |
36 CUfunction function; | |
37 union Data **data; | |
38 | |
39 // multi dimension parameter | |
40 int iterate; | |
41 struct Iterator* iterator; | |
42 }; | |
43 | |
44 struct CUDAWorker { | |
45 CUdevice device; | |
46 CUcontext cuCtx; | |
47 pthread_t thread; | |
48 struct Context* context; | |
49 int id; | |
50 struct Queue* tasks; | |
51 int runFlag; | |
52 int next; | |
53 int numStream; | |
54 CUstream *stream; | |
55 } CUDAWorker; | |
56 | |
57 struct LoopCounter { | |
58 int i; | |
59 } LoopCounter; | |
60 | |
61 struct Array { | |
62 int size; | |
63 int index; | |
64 int prefix; | |
65 int* array; | |
66 } Array; | |
67 */ | |
68 | |
69 void cudaInit(struct CUDAWorker *cudaWorker,int phase, int deviceNum) { | |
70 // initialize and load kernel | |
71 cudaWorker->numStream = 1; // number of stream | |
72 // cudaWorker->stream = NEWN(cudaWorker->numStream, CUstream ); | |
73 if (phase==0) | |
74 checkCudaErrors(cuInit(0)); | |
75 if (phase==0) | |
76 checkCudaErrors(cuDeviceGet(&cudaWorker->device, deviceNum)); | |
77 if (phase==0) | |
78 checkCudaErrors(cuCtxCreate(&cudaWorker->cuCtx, CU_CTX_SCHED_SPIN, cudaWorker->device)); | |
79 // if (cudaWorker->num_stream) { | |
80 // for (int i=0;i<cudaWorker->num_stream;i++) | |
81 // checkCudaErrors(cuStreamCreate(&cudaWorker->stream[i],0)); | |
82 // } | |
83 printf("cuda Init: Done\n"); | |
84 } | |
85 | |
86 void cudaLoadFunction(struct Context* context, char* filename, char* function) { | |
87 checkCudaErrors(cuModuleLoad(&context->module, filename)); | |
88 checkCudaErrors(cuModuleGetFunction(&context->function, context->module, function)); | |
89 } | |
90 | |
91 void cudaShutdown(struct CUDAWorker *worker) { | |
92 // for (int i=0;i<worker->num_stream;i++) | |
93 // checkCudaErrors(cuStreamDestroy(worker->stream[i])); | |
94 checkCudaErrors(cuCtxDestroy(worker->cuCtx)); | |
95 } |