Skip to content

Commit

Permalink
conv code refactoring (pytorch#856)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: pytorch#856

To simplify D33523940, separate out code refactoring changes like removing deprecated interface, reducing code duplication

Reviewed By: jiyuanzFB

Differential Revision: D33533769

fbshipit-source-id: 00e26cd87102364c12c4abbae78cae149f6a3b30
  • Loading branch information
jspark1105 authored and facebook-github-bot committed Jan 13, 2022
1 parent 135412d commit 3fac636
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 1,533 deletions.
37 changes: 0 additions & 37 deletions include/fbgemm/Fbgemm.h
Original file line number Diff line number Diff line change
Expand Up @@ -1362,27 +1362,6 @@ FBGEMM_API void fbgemmPacked(
* Note: Currently threading is not supported. This function does
* nothing for thread_ids > 0, i.e., returns early.
*
* @param rowOffsetBuf nullptr if B uses symmetric quantization
*/

template <
typename packed_W,
typename outType,
typename processOutputType,
int SPATIAL_DIM = 2>
FBGEMM_API void fbgemmGroupwiseConv(
const conv_param_t<SPATIAL_DIM>& conv_param,
const std::uint8_t* activations,
std::int32_t a_zero_point,
std::int32_t* rowOffsetBuf,
packed_W& packed_weights,
outType* out,
std::int32_t* outBuffer,
const processOutputType& outProcess,
int thread_id,
int num_threads);

/**
* @param rowOffsetBuf nullptr if B uses symmetric quantization
* Note: Currently threading is not supported. This function does
* nothing for thread_ids > 0, i.e., returns early.
Expand Down Expand Up @@ -1414,22 +1393,6 @@ template <int SPATIAL_DIM = 2>
FBGEMM_API int rowOffsetBufferSizeGConv(
const conv_param_t<SPATIAL_DIM>& conv_param);

/**
* @brief Perform depthwise separable convolution
*/
template <
typename packingAMatrix,
typename packingBMatrix,
typename outT,
typename processOutputType>
void convDepthwiseSeparable(
const conv_param_t<>& conv_param_dw,
const conv_param_t<>& conv_param_1x1,
packingAMatrix& packdw,
packingBMatrix& packed_1x1,
outT* out,
const processOutputType& output);

/**
* @brief Is this depthwise convolution optimized?
*/
Expand Down
53 changes: 0 additions & 53 deletions include/fbgemm/FbgemmI8DepthwiseAvx2.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,59 +83,6 @@ FBGEMM_API void depthwise_2d_same_pad(
int thread_id = 0,
int num_threads = 1);

template <typename BIAS_TYPE = std::int32_t>
FBGEMM_API void depthwise_2d_same_pad(
int N,
int H,
int W,
int IC_OC,
int stride_h,
int stride_w,
std::int32_t A_zero_point,
const std::uint8_t* A,
std::int32_t B_zero_point,
const PackedDepthWiseConvMatrix& Bp,
float C_multiplier,
std::int32_t C_zero_point,
std::uint8_t* C,
const std::int32_t* col_offsets,
const BIAS_TYPE* bias,
bool fuse_relu = false,
float act_times_w_scale = 1.0f,
int thread_id = 0,
int num_threads = 1);

/**
* Depth-wise convolution that results in the same output feature size as the
* input feature. That is PAD_T = PAD_B = (R - 1) / 2 and PAD_L = PAD_R =
* (S - 1) / 2. This function also does requantization and uses per-channel
* quantization.
* @param col_offsets nullptr if col_offsets are folded into bias
* @param act_times_w_scale Only used if BIAS_TYPE is float, i.e., bias is
* unquantized.
*/
template <typename BIAS_TYPE = std::int32_t>
FBGEMM_API void depthwise_2d_per_channel_quantization_same_pad(
int N,
int H,
int W,
int IC_OC,
int stride_h,
int stride_w,
std::int32_t A_zero_point,
const std::uint8_t* A,
const std::int32_t* B_zero_point,
const PackedDepthWiseConvMatrix& Bp,
const float* C_multiplier,
std::int32_t C_zero_point,
std::uint8_t* C,
const std::int32_t* col_offsets,
const BIAS_TYPE* bias,
bool fuse_relu = false,
const float* act_times_w_scale = nullptr,
int thread_id = 0,
int num_threads = 1);

/**
* @param col_offsets nullptr if col_offsets are folded into bias
*/
Expand Down
47 changes: 17 additions & 30 deletions src/FbgemmI8Depthwise2DAvx2-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ template <
bool HAS_BIAS,
bool A_SYMMETRIC,
bool B_SYMMETRIC,
typename BIAS_TYPE,
QuantizationGranularity Q_GRAN>
QuantizationGranularity Q_GRAN,
typename BIAS_TYPE>
static ALWAYS_INLINE void depthwise_2d_(
int N,
int H,
Expand Down Expand Up @@ -185,8 +185,7 @@ static ALWAYS_INLINE void depthwise_2d_(
HAS_BIAS,
A_SYMMETRIC,
B_SYMMETRIC,
Q_GRAN,
BIAS_TYPE>(
Q_GRAN>(
H,
W,
IC,
Expand Down Expand Up @@ -216,8 +215,7 @@ static ALWAYS_INLINE void depthwise_2d_(
HAS_BIAS,
A_SYMMETRIC,
B_SYMMETRIC,
Q_GRAN,
BIAS_TYPE>(
Q_GRAN>(
H,
W,
IC,
Expand Down Expand Up @@ -247,8 +245,7 @@ static ALWAYS_INLINE void depthwise_2d_(
HAS_BIAS,
A_SYMMETRIC,
B_SYMMETRIC,
Q_GRAN,
BIAS_TYPE>(
Q_GRAN>(
H,
W,
IC,
Expand Down Expand Up @@ -292,8 +289,7 @@ static ALWAYS_INLINE void depthwise_2d_(
HAS_BIAS,
A_SYMMETRIC,
B_SYMMETRIC,
Q_GRAN,
BIAS_TYPE>(
Q_GRAN>(
H,
W,
IC,
Expand Down Expand Up @@ -341,8 +337,7 @@ static ALWAYS_INLINE void depthwise_2d_(
HAS_BIAS,
A_SYMMETRIC,
B_SYMMETRIC,
Q_GRAN,
BIAS_TYPE>(
Q_GRAN>(
H,
W,
IC,
Expand Down Expand Up @@ -373,8 +368,7 @@ static ALWAYS_INLINE void depthwise_2d_(
HAS_BIAS,
A_SYMMETRIC,
B_SYMMETRIC,
Q_GRAN,
BIAS_TYPE>(
Q_GRAN>(
H,
W,
IC,
Expand Down Expand Up @@ -406,8 +400,7 @@ static ALWAYS_INLINE void depthwise_2d_(
HAS_BIAS,
A_SYMMETRIC,
B_SYMMETRIC,
Q_GRAN,
BIAS_TYPE>(
Q_GRAN>(
H,
W,
IC,
Expand Down Expand Up @@ -437,8 +430,7 @@ static ALWAYS_INLINE void depthwise_2d_(
HAS_BIAS,
A_SYMMETRIC,
B_SYMMETRIC,
Q_GRAN,
BIAS_TYPE>(
Q_GRAN>(
H,
W,
IC,
Expand Down Expand Up @@ -468,8 +460,7 @@ static ALWAYS_INLINE void depthwise_2d_(
HAS_BIAS,
A_SYMMETRIC,
B_SYMMETRIC,
Q_GRAN,
BIAS_TYPE>(
Q_GRAN>(
H,
W,
IC,
Expand Down Expand Up @@ -502,8 +493,8 @@ template <
int S,
bool FUSE_RELU,
bool HAS_BIAS,
typename BIAS_TYPE,
QuantizationGranularity Q_GRAN>
QuantizationGranularity Q_GRAN,
typename BIAS_TYPE>
static void depthwise_2d_(
int N,
int H,
Expand Down Expand Up @@ -534,7 +525,6 @@ static void depthwise_2d_(
HAS_BIAS,
true /*A_symmetric*/,
true /*B_symmetric*/,
BIAS_TYPE,
Q_GRAN>(
N,
H,
Expand Down Expand Up @@ -563,7 +553,6 @@ static void depthwise_2d_(
HAS_BIAS,
true /*A_symmetric*/,
false /*B_symmetric*/,
BIAS_TYPE,
Q_GRAN>(
N,
H,
Expand Down Expand Up @@ -594,7 +583,6 @@ static void depthwise_2d_(
HAS_BIAS,
false /*A_symmetric*/,
true /*B_symmetric*/,
BIAS_TYPE,
Q_GRAN>(
N,
H,
Expand Down Expand Up @@ -623,7 +611,6 @@ static void depthwise_2d_(
HAS_BIAS,
false /*A_symmetric*/,
false /*B_symmetric*/,
BIAS_TYPE,
Q_GRAN>(
N,
H,
Expand Down Expand Up @@ -654,8 +641,8 @@ static void depthwise_2d_(
template <
int S,
bool FUSE_RELU,
typename BIAS_TYPE,
QuantizationGranularity Q_GRAN>
QuantizationGranularity Q_GRAN,
typename BIAS_TYPE>
static void depthwise_2d_(
int N,
int H,
Expand All @@ -677,7 +664,7 @@ static void depthwise_2d_(
int thread_id,
int num_threads) {
if (bias) {
depthwise_2d_<S, FUSE_RELU, true /*HAS_BIAS*/, BIAS_TYPE, Q_GRAN>(
depthwise_2d_<S, FUSE_RELU, true /*HAS_BIAS*/, Q_GRAN>(
N,
H,
W,
Expand All @@ -698,7 +685,7 @@ static void depthwise_2d_(
thread_id,
num_threads);
} else {
depthwise_2d_<S, FUSE_RELU, false /*HAS_BIAS*/, BIAS_TYPE, Q_GRAN>(
depthwise_2d_<S, FUSE_RELU, false /*HAS_BIAS*/, Q_GRAN>(
N,
H,
W,
Expand Down
Loading

0 comments on commit 3fac636

Please sign in to comment.