1 /** 2 * Copyright 2019-2021 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef MINDSPORE_CCSRC_PLUGIN_DEVICE_GPU_KERNEL_CUDA_IMPL_CUDA_OPS_PAD_IMPL_CUH_ 18 #define MINDSPORE_CCSRC_PLUGIN_DEVICE_GPU_KERNEL_CUDA_IMPL_CUDA_OPS_PAD_IMPL_CUH_ 19 #include <cuda_runtime.h> 20 #include "plugin/device/gpu/kernel/cuda_impl/cuda_ops/cuda_common.h" 21 22 struct PadInfo { 23 int shape[8] = {0}; 24 int strides[8] = {0}; 25 int paddings[16] = {0}; 26 }; 27 28 template <typename T> 29 CUDA_LIB_EXPORT cudaError_t CalPad(const size_t size, const T *input, const int num, const int channels, 30 const int old_height, const int old_width, const int padded_height, 31 const int padded_width, const int pad_top, const int pad_left, float pad_value, 32 T *output, cudaStream_t cuda_stream); 33 template <typename T> 34 CUDA_LIB_EXPORT cudaError_t CalPadGrad(const size_t size, const T *dy, const int num, const int channels, 35 const int old_height, const int old_width, const int padded_height, 36 const int padded_width, const int pad_top, const int pad_left, T *dx, 37 cudaStream_t cuda_stream); 38 template <typename T> 39 CUDA_LIB_EXPORT cudaError_t CalPadNHWC(const size_t size, const T *input, const int num, const int old_height, 40 const int old_width, const int channels, const int padded_height, 41 const int padded_width, const int pad_top, const int pad_left, float pad_value, 42 T *output, cudaStream_t cuda_stream); 43 template <typename T> 44 CUDA_LIB_EXPORT cudaError_t CalPadGradNHWC(const size_t size, const T *input, const int num, const int old_height, 45 const int old_width, const int channels, const int padded_height, 46 const int padded_width, const int pad_top, const int pad_left, T *output, 47 cudaStream_t cuda_stream); 48 template <typename T> 49 CUDA_LIB_EXPORT cudaError_t CalPadGeneral(const T *input, T *output, const PadInfo &info, const int input_size, 50 const size_t input_rank, cudaStream_t cuda_stream); 51 template <typename T> 52 CUDA_LIB_EXPORT cudaError_t CalPad3d(const size_t size, const T *input, const int num, const int channels, 53 const int old_depth, const int old_height, const int old_width, 54 const int padded_depth, const int padded_height, const int padded_width, 55 const int pad_head, const int pad_top, const int pad_left, const float pad_value, 56 T *output, cudaStream_t cuda_stream); 57 template <typename T> 58 CUDA_LIB_EXPORT cudaError_t CalPadGrad3d(const size_t size, const T *dy, const int num, const int channels, 59 const int old_depth, const int old_height, const int old_width, 60 const int padded_depth, const int padded_height, const int padded_width, 61 const int pad_head, const int pad_top, const int pad_left, T *dx, 62 cudaStream_t cuda_stream); 63 template <typename T> 64 CUDA_LIB_EXPORT cudaError_t CalPadNDHWC(const size_t size, const T *input, const int num, const int old_depth, 65 const int old_height, const int old_width, const int channels, 66 const int padded_depth, const int padded_height, const int padded_width, 67 const int pad_head, const int pad_top, const int pad_left, 68 const float pad_value, T *output, cudaStream_t cuda_stream); 69 template <typename T> 70 CUDA_LIB_EXPORT cudaError_t CalPadGradNDHWC(const size_t size, const T *dy, const int num, const int old_depth, 71 const int old_height, const int old_width, const int channels, 72 const int padded_depth, const int padded_height, const int padded_width, 73 const int pad_head, const int pad_top, const int pad_left, T *dx, 74 cudaStream_t cuda_stream); 75 #endif // MINDSPORE_CCSRC_PLUGIN_DEVICE_GPU_KERNEL_CUDA_IMPL_CUDA_OPS_PAD_IMPL_CUH_ 76