Mercurial > hg > GearsTemplate
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/cuda.c Thu Jan 16 15:12:06 2020 +0900 @@ -0,0 +1,95 @@ +#include <stdio.h> +#include <sys/time.h> +#include <string.h> +#include <stdlib.h> + +// includes, project +#include <driver_types.h> +#include <cuda_runtime.h> +#include <cuda.h> +#include "helper_cuda.h" +#include "pthread.h" + +#include "context.h" + +/* +struct Context { + int next; + struct Worker* worker; + struct TaskManager* taskManager; + int codeNum; + void (**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; + struct Context* task; + struct Queue* tasks; + int num_exec; + CUmodule module; + CUfunction function; + union Data **data; + + // multi dimension parameter + int iterate; + struct Iterator* iterator; +}; + +struct CUDAWorker { + CUdevice device; + CUcontext cuCtx; + pthread_t thread; + struct Context* context; + int id; + struct Queue* tasks; + int runFlag; + int next; + int numStream; + CUstream *stream; +} CUDAWorker; + +struct LoopCounter { + int i; +} LoopCounter; + +struct Array { + int size; + int index; + int prefix; + int* array; +} Array; +*/ + +void cudaInit(struct CUDAWorker *cudaWorker,int phase, int deviceNum) { + // initialize and load kernel + cudaWorker->numStream = 1; // number of stream + // cudaWorker->stream = NEWN(cudaWorker->numStream, CUstream ); + if (phase==0) + checkCudaErrors(cuInit(0)); + if (phase==0) + checkCudaErrors(cuDeviceGet(&cudaWorker->device, deviceNum)); + if (phase==0) + checkCudaErrors(cuCtxCreate(&cudaWorker->cuCtx, CU_CTX_SCHED_SPIN, cudaWorker->device)); + // if (cudaWorker->num_stream) { + // for (int i=0;i<cudaWorker->num_stream;i++) + // checkCudaErrors(cuStreamCreate(&cudaWorker->stream[i],0)); + // } + printf("cuda Init: Done\n"); +} + +void cudaLoadFunction(struct Context* context, char* filename, char* function) { + checkCudaErrors(cuModuleLoad(&context->module, filename)); + checkCudaErrors(cuModuleGetFunction(&context->function, context->module, function)); +} + +void cudaShutdown(struct CUDAWorker *worker) { + // for (int i=0;i<worker->num_stream;i++) + // checkCudaErrors(cuStreamDestroy(worker->stream[i])); + checkCudaErrors(cuCtxDestroy(worker->cuCtx)); +}