kern.cuh 2.5 KB
Newer Older
1 2 3 4
/**
 * \file dnn/src/cuda/conv_bias/chanwise/kern.cuh
 * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
 *
5
 * Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 */
#pragma once

#include "src/cuda/utils.cuh"

#include <cuda_runtime.h>
#include <stdint.h>

#if MEGDNN_CC_HOST
#include "src/cuda/conv_bias/helper.h"
#endif

namespace megdnn {
namespace cuda {
namespace conv_bias {
namespace chanwise {

struct Param {
M
Megvii Engine Team 已提交
28 29
    uint32_t batch, src_chl, src_h, src_w, chl_mul, flt_h, flt_w, out_h, out_w, pad_h,
            pad_w, stride_h, stride_w, dilation_h, dilation_w;
30
    bool is_compute_deafult;
31
#if MEGDNN_CC_HOST
32 33
    static Param from_fwd_args(
            const BiasForwardSizeArgs& args, bool is_compute_deafult_ = true) {
34 35 36 37 38 39 40 41 42 43 44 45 46
#define U(v) static_cast<uint32_t>(v)
        auto&& src = args.src_layout->shape;
        auto&& dst = args.dst_layout->shape;
        auto&& fm = args.filter_meta;
        size_t c_pos, hw_pos;
        if (fm.format == param::Convolution::Format::NCHW) {
            c_pos = 1;
            hw_pos = 2;
        } else {
            c_pos = 3;
            hw_pos = 1;
        }
        return {
47 48 49 50 51 52
                U(src[0]),           U(src[c_pos]),     U(src[hw_pos]),
                U(src[hw_pos + 1]),  U(fm.ocpg),        U(fm.spatial[0]),
                U(fm.spatial[1]),    U(dst[hw_pos]),    U(dst[hw_pos + 1]),
                U(fm.padding[0]),    U(fm.padding[1]),  U(fm.stride[0]),
                U(fm.stride[1]),     U(fm.dilation[0]), U(fm.dilation[1]),
                is_compute_deafult_,
53 54 55 56 57 58 59
        };
#undef U
    }
#endif
};

template <typename T>
M
Megvii Engine Team 已提交
60 61
void run_fwd(
        T* dst, const T* src, const T* flt, const Param& param, cudaStream_t stream);
62 63

template <typename T>
M
Megvii Engine Team 已提交
64 65
void run_fwd_small(
        T* dst, const T* src, const T* flt, const Param& param, cudaStream_t stream);
66

67 68 69 70
template <typename T>
void run_fwd_depthwise_large_filter(
        T* dst, const T* src, const T* flt, const Param& param, cudaStream_t stream);

71
// implemented in fwd_8x8x32.cu
M
Megvii Engine Team 已提交
72 73 74
void run_fwd_8x8x32(
        int32_t* dst, const int8_t* src, const int8_t* flt, const Param& param,
        cudaStream_t stream);
75 76 77 78 79 80 81

}  // namespace chanwise
}  // namespace conv_bias
}  // namespace cuda
}  // namespace megdnn

// vim: ft=cpp syntax=cpp.doxygen