-
Notifications
You must be signed in to change notification settings - Fork 242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rnn Relu refactoring #2541
base: develop
Are you sure you want to change the base?
Rnn Relu refactoring #2541
Changes from 27 commits
13da580
c3d8ab4
263c278
f247d7d
7bb3be5
3c889de
cf96713
c2bfee2
cdce2f5
b114b9b
12e4a43
d2a166b
f0d1d0a
e8de935
ee524b6
5cc2e09
7ca8c32
25dc932
e9f20d5
8ebdcf4
c1ac5af
92cc941
1745012
d795893
b93c0d3
87329c6
7ae3116
15a891f
ac66ac0
6f25e7d
a145ecb
ade5f3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,12 @@ | |
|
||
namespace miopen { | ||
|
||
enum rnn_direction | ||
{ | ||
Forward = 0, | ||
Backward = 1 | ||
}; | ||
|
||
#if MIOPEN_BACKEND_HIP | ||
inline void RNNProfilingBegin(const miopen::Handle& handle, | ||
miopen::HipEventPtr& start, | ||
|
@@ -121,6 +127,151 @@ void LSTMBackwardHiddenStateUpdate(const Handle& handle, | |
std::size_t dhidden_offset, | ||
std::size_t f_offset_pre); | ||
|
||
struct RNNWeightOffsets | ||
{ | ||
|
||
public: | ||
int input_offset(int layer) const; | ||
int hidden_offset(int layer) const; | ||
int bias_off(); | ||
int bias_off(int layer) const; | ||
|
||
private: | ||
int first_layer_offset() const; | ||
}; | ||
|
||
struct ReluWeightOffsets : public RNNWeightOffsets | ||
{ | ||
public: | ||
ReluWeightOffsets(int input_vector_sz, | ||
int hidden_vec_sz, | ||
int layers_cnt, | ||
int bias_mode, | ||
int bi, | ||
int nHiddenTensorsPerLayer) | ||
: weight_stride(hidden_vec_sz * bi * nHiddenTensorsPerLayer), | ||
in_vec_sz(input_vector_sz), | ||
h_vec_sz(hidden_vec_sz), | ||
num_layers(layers_cnt), | ||
bi_scale(bi), | ||
bias_count(bias_mode) | ||
{ | ||
} | ||
|
||
int input_weight_offset(int layer) const | ||
{ | ||
return layer == 0 ? 0 | ||
: first_layer_offset() + | ||
(h_vec_sz + h_vec_sz * bi_scale) * weight_stride * (layer - 1); | ||
} | ||
|
||
int hidden_weight_offset(int layer, int reverse = 0) const | ||
{ | ||
return layer == 0 ? input_weight_offset(layer) + in_vec_sz * weight_stride + | ||
reverse * h_vec_sz * h_vec_sz | ||
: input_weight_offset(layer) + bi_scale * h_vec_sz * weight_stride + | ||
reverse * h_vec_sz * h_vec_sz; | ||
} | ||
|
||
size_t bias_stride() const { return static_cast<size_t>(h_vec_sz) * bi_scale; } | ||
|
||
int bias_off() const | ||
{ | ||
return first_layer_offset() + | ||
(h_vec_sz * bi_scale + h_vec_sz) * (num_layers - 1) * weight_stride; | ||
} | ||
|
||
int bias_off(int layer_id) const { return bias_off() + bias_count * layer_id * weight_stride; } | ||
int weight_stride; | ||
|
||
private: | ||
const int in_vec_sz, h_vec_sz; | ||
|
||
public: | ||
const int num_layers; | ||
const int bi_scale = 1; | ||
const int bias_count = 0; | ||
|
||
int first_layer_offset() const { return (in_vec_sz + h_vec_sz) * weight_stride; } | ||
}; | ||
|
||
struct RNNOffsets | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is this class used and why is there no definition of its methods? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not fixed |
||
{ | ||
size_t layer_offset(int layer_id) const; | ||
|
||
size_t layer_stride() const; | ||
|
||
int gemm_write_size() const; | ||
|
||
size_t gemm_write_stride() const; | ||
|
||
size_t gemm_write_offset(int layer_id, int batch_id = 0, int reverse = 0) const; | ||
|
||
size_t hidden_offset(int layer_id, int batch_id = 0, int reverse = 0) const; | ||
}; | ||
|
||
struct ReluReserveBufferOffsets : public RNNOffsets | ||
{ | ||
struct RBuffHelper | ||
{ | ||
int element, save_point, batch; | ||
size_t layer, table; | ||
}; | ||
|
||
private: | ||
auto Reserve_Buffer_strides(int save_point_sz, int batches_per_l, int layers_cnt) const | ||
{ | ||
const auto element_st = 1; | ||
const auto save_point_st = element_st * save_point_sz; | ||
const auto batch_st = save_point_st; | ||
const auto layer_st = static_cast<size_t>(batch_st) * batches_per_l; | ||
const auto table_st = layers_cnt * layer_st; | ||
|
||
return RBuffHelper{element_st, save_point_st, batch_st, layer_st, table_st}; | ||
} | ||
|
||
public: | ||
ReluReserveBufferOffsets(int hidden_vec_size, int layers_cnt, int batches_per_l, int bi_scale, int workspace_scale) | ||
: hidden_size(hidden_vec_size), | ||
batches_per_layer(batches_per_l), | ||
save_point_size(hidden_vec_size * bi_scale * workspace_scale), | ||
layers(layers_cnt), | ||
strides(Reserve_Buffer_strides(save_point_size, batches_per_l, layers_cnt)) | ||
{ | ||
} | ||
|
||
size_t layer_offset(int layer_id) const | ||
{ | ||
return static_cast<size_t>(layer_id) * strides.layer; | ||
} | ||
|
||
size_t layer_stride() const { return strides.layer; } | ||
|
||
int gemm_write_size() const { return strides.save_point; } | ||
|
||
size_t gemm_write_stride() const { return strides.batch; } | ||
|
||
size_t gemm_write_offset(int layer_id, int batch_id, int reverse) const | ||
{ | ||
return layer_offset(layer_id) + static_cast<size_t>(gemm_write_stride()) * batch_id + | ||
(size_t)reverse * hidden_size; | ||
} | ||
|
||
size_t hidden_offset(int layer_id, int batch_id, int reverse) const | ||
{ | ||
return strides.table + gemm_write_offset(layer_id, batch_id, reverse); | ||
} | ||
|
||
private: | ||
const int hidden_size; | ||
|
||
public: | ||
const int batches_per_layer; | ||
const int save_point_size; | ||
const int layers; | ||
const RBuffHelper strides; | ||
}; | ||
|
||
struct RNNTensorPaddingConverter | ||
{ | ||
static void ConvertTensorData(const Handle& handle, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's mostly a question for @atamazov - do we use
enum class
or have plans to switch toenum class
everywhere?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's prefer enum class. But switching to it everywhere is impossible IIRC.