1 #ifndef CAFFE2_OPERATORS_ACTIVATION_OPS_MIOPEN_H_ 2 #define CAFFE2_OPERATORS_ACTIVATION_OPS_MIOPEN_H_ 4 #include "caffe2/core/hip/context_gpu.h" 5 #include "caffe2/core/hip/miopen_wrapper.h" 6 #include "caffe2/core/operator.h" 7 #include "caffe2/core/tensor.h" 8 #include "caffe2/core/types.h" 14 USE_OPERATOR_FUNCTIONS(HIPContext);
18 miopen_wrapper_(&context_) {
19 MIOPEN_ENFORCE(miopenCreateTensorDescriptor(&data_desc_));
20 MIOPEN_ENFORCE(miopenCreateActivationDescriptor(&act_desc_));
24 MIOPEN_ENFORCE(miopenDestroyTensorDescriptor(data_desc_));
25 MIOPEN_ENFORCE(miopenDestroyActivationDescriptor(act_desc_));
30 miopenTensorDescriptor_t data_desc_;
31 miopenActivationDescriptor_t act_desc_;
32 vector<int64_t> mio_dims_;
36 template <miopenActivationMode_t kMIOPENActivationMode>
39 USE_OPERATOR_FUNCTIONS(HIPContext);
43 MIOPEN_ENFORCE(miopenSetActivationDescriptor(
44 act_desc_, kMIOPENActivationMode, 1.0, 1.0, 1.0));
47 bool RunOnDevice()
override {
52 bool DoRunWithType() {
53 const auto& X =
Input(0);
57 Y->template mutable_data<T>();
61 if (X.sizes() != mio_dims_) {
62 VLOG(1) <<
"Setting descriptors.";
63 mio_dims_ = X.sizes().vec();
64 int C = 1, H = 1, W = 1;
73 C = X.size() / X.dim32(0);
75 MIOPEN_ENFORCE(miopenSet4dTensorDescriptor(
78 MIOPEN_ENFORCE(miopenActivationForward(
79 this->miopen_wrapper_.inline_miopen_handle(),
86 Y->template mutable_data<T>()));
91 template <miopenActivationMode_t kMIOPENActivationMode>
94 USE_OPERATOR_FUNCTIONS(HIPContext);
98 MIOPEN_ENFORCE(miopenSetActivationDescriptor(
99 act_desc_, kMIOPENActivationMode, 1.0, 1.0, 1.0));
102 bool RunOnDevice()
override {
106 template <
typename T>
107 bool DoRunWithType() {
108 const auto& Y =
Input(0);
109 const auto& dY =
Input(1);
110 auto* dX = Output(0);
113 dX->template mutable_data<T>();
117 if (Y.sizes() != mio_dims_) {
118 VLOG(1) <<
"Setting descriptors.";
119 mio_dims_ = Y.sizes().vec();
120 int C = 1, H = 1, W = 1;
129 C = Y.size() / Y.dim32(0);
131 MIOPEN_ENFORCE(miopenSet4dTensorDescriptor(
134 MIOPEN_ENFORCE(miopenActivationBackward(
135 this->miopen_wrapper_.inline_miopen_handle(),
139 Y.template data<T>(),
141 dY.template data<T>(),
143 Y.template data<T>(),
146 dX->template mutable_data<T>()));
153 #endif // CAFFE2_OPERATORS_ACTIVATION_OPS_MIOPEN_H_ miopenTypeWrapper is a wrapper class that allows us to refer to the miopen type in a template functio...
MIOPENWrapper is a class that wraps the miopen handles and miopen workspaces.
Workspace is a class that holds all the related objects created during runtime: (1) all blobs...
const Tensor & Input(int idx, DeviceType type=HIPContext::GetDeviceType())
Retrieve a non-owning reference to the input at position 'idx' for this operator. ...
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...