miopen.h 6.8 KB
Newer Older
Y
Y_Xuan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/* Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.

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. */

#pragma once
#include <glog/logging.h>

#include <miopen/miopen.h>
19
#include <miopen/version.h>
Y
Y_Xuan 已提交
20
#include <mutex>  // NOLINT
21
#include "paddle/pten/backends/dynload/miopen.h"
22

Y
Y_Xuan 已提交
23 24 25 26 27 28
namespace paddle {
namespace platform {
namespace dynload {

extern bool HasCUDNN();

29 30 31
#define PLATFORM_DECLARE_DYNAMIC_LOAD_MIOPEN_WRAP(__name)     \
  using DynLoad__##__name = pten::dynload::DynLoad__##__name; \
  extern DynLoad__##__name __name
Y
Y_Xuan 已提交
32 33 34 35 36

/**
 * include all needed miopen functions in HPPL
 **/
#define MIOPEN_DNN_ROUTINE_EACH(__macro)                  \
37
  __macro(miopenGetVersion);                              \
F
furnace 已提交
38
  __macro(miopenOpTensor);                                \
Y
Y_Xuan 已提交
39 40 41 42 43 44 45 46 47 48
  __macro(miopenSet4dTensorDescriptor);                   \
  __macro(miopenSetTensorDescriptor);                     \
  __macro(miopenInitConvolutionNdDescriptor);             \
  __macro(miopenFindConvolutionForwardAlgorithm);         \
  __macro(miopenGetConvolutionNdForwardOutputDim);        \
  __macro(miopenFindConvolutionBackwardDataAlgorithm);    \
  __macro(miopenFindConvolutionBackwardWeightsAlgorithm); \
  __macro(miopenGetTensorDescriptor);                     \
  __macro(miopenCreateTensorDescriptor);                  \
  __macro(miopenDestroyTensorDescriptor);                 \
49
  __macro(miopenGetTensorDescriptorSize);                 \
Y
Y_Xuan 已提交
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
  __macro(miopenSet2dPoolingDescriptor);                  \
  __macro(miopenGet2dPoolingDescriptor);                  \
  __macro(miopenGetPoolingNdForwardOutputDim);            \
  __macro(miopenCreateConvolutionDescriptor);             \
  __macro(miopenCreatePoolingDescriptor);                 \
  __macro(miopenDestroyPoolingDescriptor);                \
  __macro(miopenPoolingGetWorkSpaceSize);                 \
  __macro(miopenPoolingGetWorkSpaceSizeV2);               \
  __macro(miopenSetNdPoolingDescriptor);                  \
  __macro(miopenInitConvolutionDescriptor);               \
  __macro(miopenDestroyConvolutionDescriptor);            \
  __macro(miopenGetConvolutionNdDescriptor);              \
  __macro(miopenDeriveBNTensorDescriptor);                \
  __macro(miopenCreate);                                  \
  __macro(miopenDestroy);                                 \
  __macro(miopenSetStream);                               \
  __macro(miopenActivationForward);                       \
  __macro(miopenActivationBackward);                      \
  __macro(miopenConvolutionBackwardWeights);              \
  __macro(miopenConvolutionForward);                      \
R
ronnywang 已提交
70
  __macro(miopenConvolutionForwardBias);                  \
Y
Y_Xuan 已提交
71 72 73 74 75 76 77
  __macro(miopenConvolutionBackwardBias);                 \
  __macro(miopenConvolutionForwardGetWorkSpaceSize);      \
  __macro(miopenConvolutionBackwardDataGetWorkSpaceSize); \
  __macro(miopenTransformTensor);                         \
  __macro(miopenPoolingForward);                          \
  __macro(miopenPoolingBackward);                         \
  __macro(miopenSoftmaxBackward);                         \
78
  __macro(miopenSoftmaxBackward_V2);                      \
Y
Y_Xuan 已提交
79
  __macro(miopenSoftmaxForward);                          \
80
  __macro(miopenSoftmaxForward_V2);                       \
Y
Y_Xuan 已提交
81
  __macro(miopenCreateDropoutDescriptor);                 \
82 83
  __macro(miopenDestroyDropoutDescriptor);                \
  __macro(miopenRestoreDropoutDescriptor);                \
Y
Y_Xuan 已提交
84 85 86
  __macro(miopenDropoutGetStatesSize);                    \
  __macro(miopenSetDropoutDescriptor);                    \
  __macro(miopenCreateRNNDescriptor);                     \
87
  __macro(miopenDestroyRNNDescriptor);                    \
Y
Y_Xuan 已提交
88
  __macro(miopenSetRNNDescriptor);                        \
R
ronnywang 已提交
89
  __macro(miopenSetRNNDescriptor_V2);                     \
Y
Y_Xuan 已提交
90 91 92 93 94 95 96
  __macro(miopenGetRNNParamsSize);                        \
  __macro(miopenGetRNNWorkspaceSize);                     \
  __macro(miopenGetRNNTrainingReserveSize);               \
  __macro(miopenRNNForwardTraining);                      \
  __macro(miopenRNNBackwardData);                         \
  __macro(miopenRNNBackwardWeights);                      \
  __macro(miopenRNNForwardInference);                     \
97
  __macro(miopenGetTensorNumBytes);
Y
Y_Xuan 已提交
98

99
MIOPEN_DNN_ROUTINE_EACH(PLATFORM_DECLARE_DYNAMIC_LOAD_MIOPEN_WRAP)
Y
Y_Xuan 已提交
100 101 102

#define MIOPEN_DNN_ROUTINE_EACH_R2(__macro) \
  __macro(miopenConvolutionBackwardData);
103
MIOPEN_DNN_ROUTINE_EACH_R2(PLATFORM_DECLARE_DYNAMIC_LOAD_MIOPEN_WRAP)
Y
Y_Xuan 已提交
104 105 106 107

// APIs available after R3:
#define MIOPEN_DNN_ROUTINE_EACH_AFTER_R3(__macro) \
  __macro(miopenConvolutionBackwardWeightsGetWorkSpaceSize);
108
MIOPEN_DNN_ROUTINE_EACH_AFTER_R3(PLATFORM_DECLARE_DYNAMIC_LOAD_MIOPEN_WRAP)
Y
Y_Xuan 已提交
109 110 111 112 113 114

// APIs available after R4:
#define MIOPEN_DNN_ROUTINE_EACH_AFTER_R4(__macro)    \
  __macro(miopenBatchNormalizationForwardTraining);  \
  __macro(miopenBatchNormalizationForwardInference); \
  __macro(miopenBatchNormalizationBackward);
115
MIOPEN_DNN_ROUTINE_EACH_AFTER_R4(PLATFORM_DECLARE_DYNAMIC_LOAD_MIOPEN_WRAP)
Y
Y_Xuan 已提交
116 117 118 119 120 121 122

// APIs in R5
#define MIOPEN_DNN_ROUTINE_EACH_R5(__macro)  \
  __macro(miopenCreateActivationDescriptor); \
  __macro(miopenSetActivationDescriptor);    \
  __macro(miopenGetActivationDescriptor);    \
  __macro(miopenDestroyActivationDescriptor);
123
MIOPEN_DNN_ROUTINE_EACH_R5(PLATFORM_DECLARE_DYNAMIC_LOAD_MIOPEN_WRAP)
Y
Y_Xuan 已提交
124 125 126 127

// APIs in R6
#define MIOPEN_DNN_ROUTINE_EACH_R6(__macro) \
/*__macro(miopenSetRNNDescriptor_v6);*/
128
MIOPEN_DNN_ROUTINE_EACH_R6(PLATFORM_DECLARE_DYNAMIC_LOAD_MIOPEN_WRAP)
Y
Y_Xuan 已提交
129 130 131 132 133 134 135 136 137

#define MIOPEN_DNN_ROUTINE_EACH_R7(__macro) \
  __macro(miopenSetConvolutionGroupCount);  \
  __macro(miopenCreateCTCLossDescriptor);   \
  __macro(miopenDestroyCTCLossDescriptor);  \
  __macro(miopenGetCTCLossDescriptor);      \
  __macro(miopenSetCTCLossDescriptor);      \
  __macro(miopenGetCTCLossWorkspaceSize);   \
  __macro(miopenCTCLoss);
138
MIOPEN_DNN_ROUTINE_EACH_R7(PLATFORM_DECLARE_DYNAMIC_LOAD_MIOPEN_WRAP)
Y
Y_Xuan 已提交
139 140 141 142 143 144 145

#define MIOPEN_DNN_ROUTINE_EACH_AFTER_R7(__macro)                    \
/*__macro(cudnnGetBatchNormalizationForwardTrainingExWorkspaceSize); \
__macro(cudnnBatchNormalizationForwardTrainingEx);                   \
__macro(cudnnGetBatchNormalizationBackwardExWorkspaceSize);          \
__macro(cudnnBatchNormalizationBackwardEx);                          \
__macro(cudnnGetBatchNormalizationTrainingExReserveSpaceSize);*/
146
MIOPEN_DNN_ROUTINE_EACH_AFTER_R7(PLATFORM_DECLARE_DYNAMIC_LOAD_MIOPEN_WRAP)
Y
Y_Xuan 已提交
147 148 149
}  // namespace dynload
}  // namespace platform
}  // namespace paddle