27 #ifndef LBANN_UTILS_DNN_LIB_MIOPEN_HPP 28 #define LBANN_UTILS_DNN_LIB_MIOPEN_HPP 32 #ifdef LBANN_HAS_MIOPEN 34 #include <miopen/miopen.h> 37 #define CHECK_MIOPEN_NODEBUG(miopen_call) \ 39 const miopenStatus_t status_CHECK_MIOPEN = (miopen_call); \ 40 if (status_CHECK_MIOPEN != miopenStatusSuccess) { \ 41 LBANN_ERROR("MIOpen error (", \ 42 miopenGetErrorString(status_CHECK_MIOPEN), \ 46 #define CHECK_MIOPEN_DEBUG(miopen_call) \ 48 LBANN_ROCM_CHECK_LAST_ERROR(true); \ 49 CHECK_MIOPEN_NODEBUG(miopen_call); \ 52 #define CHECK_MIOPEN(miopen_call) CHECK_MIOPEN_DEBUG(miopen_call) 54 #define CHECK_MIOPEN(miopen_call) CHECK_MIOPEN_NODEBUG(miopen_call) 55 #endif // #ifdef LBANN_DEBUG 57 #define CHECK_MIOPEN_DTOR(miopen_call) \ 59 CHECK_MIOPEN(miopen_call); \ 61 catch (std::exception const& e) { \ 62 std::cerr << "Caught exception:\n\n what(): " << e.what() \ 63 << "\n\nCalling std::terminate() now." << std::endl; \ 67 std::cerr << "Caught something that isn't an std::exception.\n\n" \ 68 << "Calling std::terminate() now." << std::endl; \ 79 using dnnHandle_t = miopenHandle_t;
80 using dnnDataType_t = miopenDataType_t;
81 using dnnTensorDescriptor_t = miopenTensorDescriptor_t;
82 using dnnFilterDescriptor_t = miopenTensorDescriptor_t;
83 using dnnTensorFormat_t = miopenTensorLayout_t;
84 using dnnDropoutDescriptor_t = miopenDropoutDescriptor_t;
85 using dnnRNGType_t = miopenRNGType_t;
86 using dnnRNNDescriptor_t = miopenRNNDescriptor_t;
87 using dnnRNNAlgo_t = miopenRNNAlgo_t;
88 using dnnRNNMode_t = miopenRNNMode_t;
89 using dnnRNNBiasMode_t = miopenRNNBiasMode_t;
90 using dnnDirectionMode_t = miopenRNNDirectionMode_t;
91 using dnnRNNInputMode_t = miopenRNNInputMode_t;
92 using dnnMathType_t = int;
93 using dnnRNNDataDescriptor_t = int;
94 using dnnRNNDataLayout_t = int;
95 using dnnConvolutionDescriptor_t = miopenConvolutionDescriptor_t;
96 using dnnConvolutionMode_t = miopenConvolutionMode_t;
97 using dnnActivationDescriptor_t = miopenActivationDescriptor_t;
98 using dnnActivationMode_t = miopenActivationMode_t;
99 using dnnNanPropagation_t = miopenNanPropagation_t;
100 using dnnPoolingDescriptor_t = miopenPoolingDescriptor_t;
101 using dnnPoolingMode_t = miopenPoolingMode_t;
102 using dnnLRNDescriptor_t = miopenLRNDescriptor_t;
103 using dnnLRNMode_t = miopenLRNMode_t;
104 using dnnConvolutionFwdAlgo_t = miopenConvFwdAlgorithm_t;
105 using dnnConvolutionBwdDataAlgo_t = miopenConvBwdDataAlgorithm_t;
106 using dnnConvolutionBwdFilterAlgo_t = miopenConvBwdWeightsAlgorithm_t;
108 constexpr dnnConvolutionMode_t DNN_CROSS_CORRELATION = miopenConvolution;
109 constexpr dnnNanPropagation_t DNN_PROPAGATE_NAN = MIOPEN_PROPAGATE_NAN;
110 constexpr dnnMathType_t DNN_DEFAULT_MATH = 0;
111 constexpr dnnTensorFormat_t DNN_TENSOR_NCHW = miopenTensorNCHW;
112 constexpr dnnRNGType_t DNN_RNG_PSEUDO_XORWOW = MIOPEN_RNG_PSEUDO_XORWOW;
113 constexpr dnnLRNMode_t DNN_LRN_CROSS_CHANNEL = miopenLRNCrossChannel;
114 constexpr dnnMathType_t DNN_TENSOR_OP_MATH_ALLOW_CONVERSION =
123 inline miopenConvFwdAlgorithm_t to_miopen(
fwd_conv_alg a)
127 return miopenConvolutionFwdAlgoImplicitGEMM;
129 return miopenConvolutionFwdAlgoGEMM;
131 return miopenConvolutionFwdAlgoDirect;
133 return miopenConvolutionFwdAlgoFFT;
135 return miopenConvolutionFwdAlgoWinograd;
137 LBANN_ERROR(
"Invalid forward convolution algorithm requested.");
143 inline fwd_conv_alg from_miopen(miopenConvFwdAlgorithm_t a)
146 case miopenConvolutionFwdAlgoGEMM:
148 case miopenConvolutionFwdAlgoImplicitGEMM:
150 case miopenConvolutionFwdAlgoDirect:
152 case miopenConvolutionFwdAlgoFFT:
154 case miopenConvolutionFwdAlgoWinograd:
157 std::ostringstream err;
158 err <<
"miopenConvFwdAlgorithm_t " << a <<
" is not supported by LBANN.";
169 return miopenConvolutionBwdDataAlgoGEMM;
171 return miopenConvolutionBwdDataAlgoDirect;
173 return miopenConvolutionBwdDataAlgoFFT;
175 return miopenConvolutionBwdDataAlgoWinograd;
177 return miopenConvolutionBwdDataAlgoWinograd;
179 return miopenConvolutionBwdDataAlgoImplicitGEMM;
181 LBANN_ERROR(
"Invalid backward convolution algorithm requested.");
190 case miopenConvolutionBwdDataAlgoGEMM:
192 case miopenConvolutionBwdDataAlgoDirect:
194 case miopenConvolutionBwdDataAlgoFFT:
196 case miopenConvolutionBwdDataAlgoWinograd:
198 case miopenConvolutionBwdDataAlgoImplicitGEMM:
201 std::ostringstream err;
202 err <<
"miopenConvBwdDataAlgorithm_t " << a
203 <<
" is not supported by LBANN.";
215 return miopenConvolutionBwdWeightsAlgoGEMM;
217 return miopenConvolutionBwdWeightsAlgoDirect;
219 return miopenConvolutionBwdWeightsAlgoWinograd;
221 return miopenConvolutionBwdWeightsAlgoImplicitGEMM;
223 LBANN_ERROR(
"Invalid backward convolution filter requested.");
232 case miopenConvolutionBwdWeightsAlgoGEMM:
234 case miopenConvolutionBwdWeightsAlgoDirect:
236 case miopenConvolutionBwdWeightsAlgoWinograd:
238 case miopenConvolutionBwdWeightsAlgoImplicitGEMM:
241 std::ostringstream err;
242 err <<
"miopenConvBwdWeightsAlgorithm_t " << a
243 <<
" is not supported by LBANN.";
254 return miopenPoolingMax;
255 #ifdef LBANN_DETERMINISTIC 257 LBANN_WARNING(
"Deterministic max pooling mode not supported in MIOpen");
259 return miopenPoolingMax;
261 return miopenPoolingMax;
262 #endif // LBANN_DETERMINISTIC 264 return miopenPoolingAverageInclusive;
266 return miopenPoolingAverage;
269 LBANN_WARNING(
"Deterministic max pooling mode not supported in MIOpen");
271 return miopenPoolingMax;
280 case miopenPoolingMax:
282 case miopenPoolingAverageInclusive:
284 case miopenPoolingAverage:
296 return MIOPEN_SOFTMAX_MODE_INSTANCE;
298 return MIOPEN_SOFTMAX_MODE_CHANNEL;
306 inline miopenSoftmaxAlgorithm_t to_miopen(
softmax_alg alg)
310 return MIOPEN_SOFTMAX_FAST;
312 return MIOPEN_SOFTMAX_ACCURATE;
314 return MIOPEN_SOFTMAX_LOG;
316 LBANN_ERROR(
"Invalid softmax algorithm requested.");
323 #endif // LBANN_HAS_MIOPEN 324 #endif // LBANN_UTILS_DNN_LIB_MIOPEN_HPP
bwd_data_conv_alg
Which backward convolution algorithm to use.
bwd_filter_conv_alg
Which backward convolution filter algorithm to use.
softmax_alg
Internal LBANN names for supported softmax algorithms.
pooling_mode
Which pooling mode to use.
fwd_conv_alg
Which forward convolution algorithm to use.
#define LBANN_WARNING(...)
softmax_mode
Which tensor dimensions to apply softmax over.