forked from flexflow/FlexFlow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ops.h
170 lines (150 loc) · 4.11 KB
/
ops.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/* Copyright 2017 Stanford, NVIDIA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LEGION_CNN_OPS_H_
#define _LEGION_CNN_OPS_H_
//#define DISABLE_COMPUTATION
#include "legion.h"
#include <cudnn.h>
#include <cuda_runtime.h>
#include <curand.h>
#include <cublas_v2.h>
#include <unistd.h>
using namespace Legion;
template<typename FT, int N, typename T = coord_t> using AccessorRO = FieldAccessor<READ_ONLY,FT,N,T,Realm::AffineAccessor<FT,N,T> >;
template<typename FT, int N, typename T = coord_t> using AccessorRW = FieldAccessor<READ_WRITE,FT,N,T,Realm::AffineAccessor<FT,N,T> >;
template<typename FT, int N, typename T = coord_t> using AccessorWO = FieldAccessor<WRITE_ONLY,FT,N,T,Realm::AffineAccessor<FT,N,T> >;
#define MAX_NUM_INPUTS 6
#define MAX_NUM_OUTPUTS 6
#define MAX_NUM_LOCALS 3
#define MAX_NUM_WORKERS 16
#define MAX_NUM_PARTS 16
#define MAX_DIM 4
#define MAX_FILENAME 200
enum TaskIDs {
TOP_LEVEL_TASK_ID,
CUDNN_INIT_TASK_ID,
IMAGE_INIT_TASK_ID,
LABEL_INIT_TASK_ID,
LOAD_IMAGES_TASK_ID,
NORMALIZE_IMAGES_TASK_ID,
CONV2D_INIT_TASK_ID,
CONV2D_INIT_PARA_TASK_ID,
CONV2D_FWD_TASK_ID,
CONV2D_BWD_TASK_ID,
CONV2D_UPD_TASK_ID,
POOL2D_INIT_TASK_ID,
POOL2D_FWD_TASK_ID,
POOL2D_BWD_TASK_ID,
LINEAR_INIT_TASK_ID,
LINEAR_INIT_PARA_TASK_ID,
LINEAR_FWD_TASK_ID,
LINEAR_BWD_TASK_ID,
LINEAR_BWD2_TASK_ID,
LINEAR_UPD_TASK_ID,
FLAT_INIT_TASK_ID,
FLAT_FWD_TASK_ID,
FLAT_BWD_TASK_ID,
SOFTMAX_INIT_TASK_ID,
SOFTMAX_FWD_TASK_ID,
SOFTMAX_BWD_TASK_ID,
CONCAT_INIT_TASK_ID,
CONCAT_FWD_TASK_ID,
CONCAT_BWD_TASK_ID,
// RNN Task IDs
LSTM_INIT_TASK_ID,
LSTM_FWD_TASK_ID,
LSTM_BWD_TASK_ID,
RNN_LINEAR_INIT_TASK_ID,
RNN_LINEAR_FWD_TASK_ID,
RNN_LINEAR_BWD_TASK_ID,
RNN_LINEAR_BWD2_TASK_ID,
EMBED_INIT_TASK_ID,
EMBED_FWD_TASK_ID,
EMBED_BWD_TASK_ID,
RNN_SOFTMAXDP_INIT_TASK_ID,
RNN_SOFTMAXDP_FWD_TASK_ID,
RNN_SOFTMAXDP_BWD_TASK_ID,
PARAMS_INIT_TASK_ID,
PARAMS_UPD_TASK_ID,
WORD_INIT_TASK_ID, //DUMMY_TASK_ID: To be removed
ZERO_1D_INIT_TASK_ID,
ZERO_2D_INIT_TASK_ID,
ZERO_3D_INIT_TASK_ID,
// Dummy task ID
DUMMY_TASK_ID,
};
enum Pool2DType {
POOL2D_MAX,
POOL2D_AVG,
};
enum FieldIDs {
FID_DATA,
};
struct DnnHandle {
#ifndef DISABLE_COMPUTATION
cudnnHandle_t dnn;
cublasHandle_t blas;
#endif
void *workSpace;
size_t workSpaceSize;
};
struct Tensor {
// Tensor(int _numDim, int* _dim, LogicalRegion lr, LogicalPartition lp)
// {
// numDim = _numDim;
// for (int i = 0; i < numDim; i++)
// dim[i] = _dim[i];
// region = lr;
// partition = lp;
// }
int numDim, adim[MAX_DIM], pdim[MAX_DIM];
LogicalRegion region, region_grad;
LogicalPartition partition, partition_grad;
};
struct TensorWithGrad {
//int dim[MAX_DIM];
LogicalRegion region, region_grad;
LogicalPartition partition, partition_grad;
};
class OpMeta {
public:
OpMeta(DnnHandle _handle) : handle(_handle) {};
public:
DnnHandle handle;
};
// Empty base class
class CnnModel;
class DataLoader;
class Op {
public:
Op(Tensor input);
Op(int num, Tensor* inputs);
virtual void init(const CnnModel&) = 0;
virtual void forward(const CnnModel&) = 0;
virtual void backward(const CnnModel&) = 0;
virtual void update(const CnnModel&) = 0;
public:
Tensor output;
//Op* pre_ops[MAX_NUM_INPUTS];
Tensor inputs[MAX_NUM_INPUTS];
LogicalPartition input_lps[MAX_NUM_INPUTS];
TensorWithGrad locals[MAX_NUM_LOCALS];
OpMeta* meta[MAX_NUM_WORKERS];
//std::vector<LogicalRegion> inputs, grads;
};
DnnHandle init_cudnn(const Task *task,
const std::vector<PhysicalRegion> ®ions,
Context ctx, Runtime *runtime);
#endif // _LEGION_OPS_H_