annotate TaskManager/Cuda/CudaScheduler.h @ 1925:cd5bbd8ec5d6 draft

fix CudaScheduler
author Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
date Fri, 31 Jan 2014 05:56:23 +0900
parents 14f9fc88872c
children 4eefec26e3e2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1908
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #ifndef INCLUDE_CUDA_SCHEDULER
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #define INCLUDE_CUDA_SCHEDULER
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #include "MainScheduler.h"
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 #include "FifoDmaManager.h"
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 #include "CudaThreads.h"
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 #include "HTask.h"
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 #include "TaskManager.h"
1915
effb5653fd5c update cuda, yet running
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1908
diff changeset
9 #include <cuda.h>
1908
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 extern TaskObject cuda_task_list[MAX_TASK_OBJECT];
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 class CudaScheduler : public MainScheduler {
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 public:
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 typedef struct cudabuffer {
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 int allcate_size;
1924
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1923
diff changeset
17 int in_size;
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1923
diff changeset
18 int out_size;
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1923
diff changeset
19 CUdeviceptr* memin;
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1923
diff changeset
20 CUdeviceptr* memout;
1908
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 CUevent* event;
1924
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1923
diff changeset
22 CUstream stream;
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1923
diff changeset
23 } CudaBuffer, *CudaBufferPtr;
1908
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 CudaScheduler();
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 virtual ~CudaScheduler();
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 void init_gpu();
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 void wait_for_event(CUevent* event, CudaBufferPtr m, TaskListPtr taskList, int cur);
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 void run();
1924
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1923
diff changeset
29
1908
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 // platform platform;
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 // platform は OpenCL が複数のメーカーの GPU に対応してるから必要
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 // Cuda の場合、NVIDIA だけなので必要ない?
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 CUdevice device;
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 unsigned int ret_num_platforms; // たぶん要らない
1925
cd5bbd8ec5d6 fix CudaScheduler
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1924
diff changeset
35 int ret_num_devices;
1908
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 CUcontext context;
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 // command_queue command_queue;
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 // Cuda には command_queue に相当するものはない
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 // Closest approximation would be the CUDA Stream mechanism. らしい...
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 int ret;
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 memaddr reply;
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 // cl_kernel に相当
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 // 変数名は function にすべきか kernel にすべきか
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 // とりあえず、kernel で
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 CUfunction kernel[2];
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 CUevent kernel_event[2];
1924
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1923
diff changeset
47 CudaBuffer* cudabuffer;
1925
cd5bbd8ec5d6 fix CudaScheduler
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1924
diff changeset
48 HTask::htask_flag flag[2];
1908
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
1925
cd5bbd8ec5d6 fix CudaScheduler
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1924
diff changeset
50 private:
1908
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 int load_kernel(int cmd);
1925
cd5bbd8ec5d6 fix CudaScheduler
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1924
diff changeset
52 CUdeviceptr createBuffer(CudaBufferPtr cudabuffer, CUdeviceptr* mem, int i, size_t size, int* error);
1908
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 void initCudaBuffer(CudaBufferPtr m);
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 void destroyCudaBuffer(CudaBufferPtr m);
1925
cd5bbd8ec5d6 fix CudaScheduler
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1924
diff changeset
55 void CudaTaskError(CudaBufferPtr cudabuffer, int cur, TaskListPtr taskList, int ret);
1908
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 };
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 #define CudaSchedRegister(str, filename, functionname) \
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 cuda_register_task(str, filename, functionname);
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 #endif