Skip to content

Commit bff4392

Browse files
dmitry-gorokhovluweizhou2016
authored andcommitted
[FORK][FEATURE] Migrate legacy post ops and zero points on runtime data pointers
ONEDNN 3.2 migration squashed commits: - fix depthwise nwc conv - Fix deconv 3D post OPs segment fault issue. (#130) - fix in avx2 conv+fakequant post ops +nxc last channel wrong result (#128) - Luwei/fix deconv 3d postops bug (#136) -- Fix the deconv fused with depthwise issue in cpuFuncTests -- Switch to use jit_uni_depthwise_injector API. -- Fix potential conflicts in registers and YMM. -- Update with optimization. - fix legacyOps with stock src_zero_point in jit_avx512_core_amx - Fix incorrect offset to rsp - Preserve bf16emu scratch register when conflict with legacy post ops - fix per-OC legacyPostOps for jit_avx512_dw_conv_fwd_kernel_bf16 - Fix segment fault caused by dest scale. ONEDNN 3.5 migration squshed commmits: [FIX][FORK][FEATURE] Introduced Depthwise and Quantization post ops
1 parent 293f8c0 commit bff4392

File tree

92 files changed

+1656
-939
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+1656
-939
lines changed

include/oneapi/dnnl/dnnl.h

+9-19
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "oneapi/dnnl/dnnl_config.h"
2525
#include "oneapi/dnnl/dnnl_types.h"
2626
#include "oneapi/dnnl/dnnl_version.h"
27+
#include <stdbool.h>
2728

2829
#ifdef __cplusplus
2930
extern "C" {
@@ -476,23 +477,14 @@ dnnl_status_t DNNL_API dnnl_primitive_attr_set_zero_points(
476477
dnnl_primitive_attr_t attr, int arg, int mask, int ndims,
477478
const dnnl_dims_t group_dims, dnnl_data_type_t data_type);
478479

479-
dnnl_status_t DNNL_API dnnl_primitive_attr_get_output_compensations(
480-
const_dnnl_primitive_attr_t attr, int *count, int *mask, const int32_t **compensations);
481-
482480
dnnl_status_t DNNL_API dnnl_primitive_attr_set_output_compensations(
483-
dnnl_primitive_attr_t attr, int count, int mask, const int32_t *compensations);
484-
485-
dnnl_status_t DNNL_API dnnl_primitive_attr_get_input_zero_points(
486-
const_dnnl_primitive_attr_t attr, int *count, int *mask, const uint8_t **zero_points);
481+
dnnl_primitive_attr_t attr, int count, int mask);
487482

488483
dnnl_status_t DNNL_API dnnl_primitive_attr_set_input_zero_points(
489-
dnnl_primitive_attr_t attr, int count, int mask, const uint8_t *zero_points);
490-
491-
dnnl_status_t DNNL_API dnnl_primitive_attr_get_weights_zero_points(
492-
const_dnnl_primitive_attr_t attr, int *count, int *mask, const float **zero_points);
484+
dnnl_primitive_attr_t attr, int count, int mask);
493485

494486
dnnl_status_t DNNL_API dnnl_primitive_attr_set_weights_zero_points(
495-
dnnl_primitive_attr_t attr, int count, int mask, const float *zero_points);
487+
dnnl_primitive_attr_t attr, int count, int mask);
496488

497489
/// Returns primitive attributes post-ops.
498490
///
@@ -700,8 +692,7 @@ dnnl_status_t DNNL_API dnnl_post_ops_get_params_dw(
700692
///
701693
/// The kind of this post operation is #dnnl_convolution.
702694
dnnl_status_t DNNL_API dnnl_post_ops_append_dw_conv(
703-
dnnl_post_ops_t post_ops, int in_h, int in_w, int ker_h, int ker_w, int str_h, int str_w, dnnl_data_type_t in_dt,
704-
const float* weights_data, const float* biases_data);
695+
dnnl_post_ops_t post_ops, int in_h, int in_w, int ker_h, int ker_w, int str_h, int str_w, dnnl_data_type_t in_dt);
705696

706697
/// Appends a binary post-op.
707698
///
@@ -783,14 +774,13 @@ dnnl_status_t DNNL_API dnnl_post_ops_get_params_prelu(
783774
const_dnnl_post_ops_t post_ops, int index, int *mask);
784775

785776
dnnl_status_t DNNL_API dnnl_post_ops_append_depthwise(
786-
dnnl_post_ops_t post_ops, dnnl_alg_kind_t alg,
787-
const float* weights_data, const float* biases_data);
777+
dnnl_post_ops_t post_ops, dnnl_alg_kind_t alg, size_t offset_size, const size_t* offset);
788778

789779
dnnl_status_t DNNL_API dnnl_post_ops_append_quantization(
790780
dnnl_post_ops_t post_ops, dnnl_alg_kind_t alg,
791-
const void* crop_low, const void* crop_high,
792-
const void* input_scale, const void* input_shift,
793-
const void* output_scale, const void* output_shift);
781+
size_t per_channel_size, const bool* per_channel,
782+
size_t all_default_size, const bool* all_default,
783+
size_t offset_size, const size_t* offset);
794784

795785
dnnl_status_t DNNL_API dnnl_post_ops_append_binarization(
796786
dnnl_post_ops_t post_ops, dnnl_alg_kind_t alg, const float* weights_data, const float* output_mask);

include/oneapi/dnnl/dnnl.hpp

+20-65
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <memory>
3030
#include <string>
3131
#include <vector>
32+
#include <array>
3233
#include <unordered_map>
3334

3435
#include "oneapi/dnnl/dnnl.h"
@@ -148,6 +149,10 @@ struct primitive : public handle<dnnl_primitive_t> {
148149
layer_normalization = dnnl_layer_normalization,
149150
/// A group normalization primitive
150151
group_normalization = dnnl_group_normalization,
152+
153+
depthwise = dnnl_depthwise,
154+
quantization = dnnl_quantization,
155+
binarization = dnnl_binarization,
151156
};
152157

153158
using handle::handle;
@@ -168,7 +173,7 @@ struct primitive : public handle<dnnl_primitive_t> {
168173
const std::vector<uint8_t> &cache_blob);
169174

170175
/// Constructs a primitive from a primitive descriptor.
171-
///
176+
///src/common/deconvolution_pd.hpp
172177
/// @param pd Primitive descriptor.
173178
primitive(const primitive_desc &pd);
174179

@@ -3816,10 +3821,9 @@ struct post_ops : public handle<dnnl_post_ops_t> {
38163821
"could not append a binary post-op");
38173822
}
38183823

3819-
void append_dw_conv(int in_h, int in_w, int ker_h, int ker_w, int str_h, int str_w, dnnl_data_type_t in_dt,
3820-
const float* weights_data, const float* biases_data) {
3824+
void append_dw_conv(int in_h, int in_w, int ker_h, int ker_w, int str_h, int str_w, dnnl_data_type_t in_dt) {
38213825
error::wrap_c_api(dnnl_post_ops_append_dw_conv(get(),
3822-
in_h, in_w, ker_h, ker_w, str_h, str_w, in_dt, weights_data, biases_data),
3826+
in_h, in_w, ker_h, ker_w, str_h, str_w, in_dt),
38233827
"could not append dw conv");
38243828
}
38253829

@@ -3908,19 +3912,15 @@ struct post_ops : public handle<dnnl_post_ops_t> {
39083912
"could not get parameters of a binary post-op");
39093913
}
39103914

3911-
void append_depthwise(algorithm alg, const float* weights_data,
3912-
const float* biases_data) {
3913-
error::wrap_c_api(dnnl_post_ops_append_depthwise(get(),
3914-
convert_to_c(alg), weights_data, biases_data),
3915+
void append_depthwise(algorithm alg, const std::array<size_t, 2>& offset) {
3916+
error::wrap_c_api(dnnl_post_ops_append_depthwise(get(), convert_to_c(alg), offset.size(), offset.data()),
39153917
"could not append depthwise");
39163918
}
39173919

3918-
void append_quantization(algorithm alg,
3919-
const void* crop_low, const void* crop_high,
3920-
const void* input_scale, const void* input_shift,
3921-
const void* output_scale, const void* output_shift) {
3922-
error::wrap_c_api(dnnl_post_ops_append_quantization(get(), convert_to_c(alg), crop_low, crop_high,
3923-
input_scale, input_shift, output_scale, output_shift),
3920+
void append_quantization(algorithm alg, const std::array<bool, 6>& per_channel, const std::array<bool, 6>& all_default,
3921+
const std::array<size_t, 6>& offset) {
3922+
error::wrap_c_api(dnnl_post_ops_append_quantization(get(), convert_to_c(alg), per_channel.size(), per_channel.data(),
3923+
all_default.size(), all_default.data(), offset.size(), offset.data()),
39243924
"could not append quantization");
39253925
}
39263926

@@ -4135,66 +4135,21 @@ struct primitive_attr : public handle<dnnl_primitive_attr_t> {
41354135
"could not set zero points primitive attribute");
41364136
}
41374137

4138-
void get_output_compensations(int &mask, std::vector<int32_t> &compensations) const
4138+
void set_output_compensations(dnnl_dim_t count, int mask)
41394139
{
4140-
int count, c_mask;
4141-
const int32_t *c_compensations;
4142-
error::wrap_c_api(dnnl_primitive_attr_get_output_compensations(get(),
4143-
&count, &c_mask, &c_compensations),
4144-
"could not get int output compensations");
4145-
compensations.resize(count);
4146-
4147-
mask = c_mask;
4148-
for (int c = 0; c < count; ++c)
4149-
compensations[c] = c_compensations[c];
4150-
}
4151-
4152-
void set_output_compensations(int mask, const std::vector<int32_t> &compensations)
4153-
{
4154-
error::wrap_c_api(dnnl_primitive_attr_set_output_compensations(get(),
4155-
(int)compensations.size(), mask, &compensations[0]),
4140+
error::wrap_c_api(dnnl_primitive_attr_set_output_compensations(get(), count, mask),
41564141
"could not set int output compensations");
41574142
}
41584143

4159-
void get_input_zero_points(int &mask, std::vector<uint8_t> &zero_points) const
4144+
void set_input_zero_points(dnnl_dim_t count, int mask)
41604145
{
4161-
int count, c_mask;
4162-
const uint8_t *c_zero_points;
4163-
error::wrap_c_api(dnnl_primitive_attr_get_input_zero_points(get(),
4164-
&count, &c_mask, &c_zero_points),
4165-
"could not get int input zero_points");
4166-
zero_points.resize(count);
4167-
4168-
mask = c_mask;
4169-
for (int c = 0; c < count; ++c)
4170-
zero_points[c] = c_zero_points[c];
4171-
}
4172-
4173-
void set_input_zero_points(int mask, const std::vector<uint8_t> &zero_points)
4174-
{
4175-
error::wrap_c_api(dnnl_primitive_attr_set_input_zero_points(get(),
4176-
(int)zero_points.size(), mask, &zero_points[0]),
4146+
error::wrap_c_api(dnnl_primitive_attr_set_input_zero_points(get(), count, mask),
41774147
"could not set int input zero_points");
41784148
}
41794149

4180-
void get_weights_zero_points(int &mask, std::vector<int8_t> &zero_points) const
4181-
{
4182-
int count, c_mask;
4183-
const float *c_zero_points;
4184-
error::wrap_c_api(dnnl_primitive_attr_get_weights_zero_points(get(),
4185-
&count, &c_mask, &c_zero_points),
4186-
"could not get int weights zero_points");
4187-
zero_points.resize(count);
4188-
4189-
mask = c_mask;
4190-
for (int c = 0; c < count; ++c)
4191-
zero_points[c] = c_zero_points[c];
4192-
}
4193-
4194-
void set_weights_zero_points(int mask, const std::vector<float> &zero_points)
4150+
void set_weights_zero_points(dnnl_dim_t count, int mask)
41954151
{
4196-
error::wrap_c_api(dnnl_primitive_attr_set_weights_zero_points(get(),
4197-
(int)zero_points.size(), mask, &zero_points[0]),
4152+
error::wrap_c_api(dnnl_primitive_attr_set_weights_zero_points(get(), count, mask),
41984153
"could not set int weights zero_points");
41994154
}
42004155

src/common/convolution_pd.hpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,8 @@ struct convolution_fwd_pd_t : public convolution_pd_t {
298298
}
299299

300300
int n_inputs() const override {
301-
// todo: [antonvor] uncomment when new behavior of dw convolution fusing from oneDNN 1.6 will be supported
302-
return 2 + with_bias() /* + attr_post_op_dw_inputs() */ + n_binary_po_inputs()
303-
+ n_prelu_po_inputs();
301+
return 2 + with_bias() + attr_post_op_dw_inputs() + n_binary_po_inputs()
302+
+ n_prelu_po_inputs() + n_depthwise_po_inputs() + n_quantization_po_inputs();
304303
}
305304

306305
int n_outputs() const override { return 1; }
@@ -330,8 +329,7 @@ struct convolution_fwd_pd_t : public convolution_pd_t {
330329
const auto &po = attr_.post_ops_;
331330
int conv = po.find(primitive_kind::convolution);
332331
if (conv == -1) return 0;
333-
return po.entry_[conv].depthwise_conv.bias_dt == data_type::undef ? 1
334-
: 2;
332+
return 2;
335333
}
336334
};
337335

@@ -379,7 +377,9 @@ struct convolution_bwd_data_pd_t : public convolution_pd_t {
379377
return &glob_zero_md;
380378
}
381379

382-
int n_inputs() const override { return 2 + with_bias(); }
380+
int n_inputs() const override {
381+
return 2 + with_bias() + n_depthwise_po_inputs() + n_quantization_po_inputs();
382+
}
383383
int n_outputs() const override { return 1; }
384384

385385
virtual bool support_bias() const { return false; }

src/common/deconvolution_pd.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ struct deconvolution_fwd_pd_t : public deconvolution_pd_t {
245245
}
246246

247247
int n_inputs() const override {
248-
return 2 + with_bias() + n_prelu_po_inputs() + n_binary_po_inputs();
248+
return 2 + with_bias() + n_prelu_po_inputs() + n_binary_po_inputs() + n_depthwise_po_inputs() + n_quantization_po_inputs();
249249
}
250250
int n_outputs() const override { return 1; }
251251

src/common/pooling_pd.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ struct pooling_fwd_pd_t : public pooling_pd_t {
215215
: &glob_zero_md;
216216
}
217217

218-
int n_inputs() const override { return 1 + n_binary_po_inputs(); }
218+
int n_inputs() const override { return 1 + n_binary_po_inputs() + n_depthwise_po_inputs() + n_quantization_po_inputs(); }
219219
int n_outputs() const override {
220220
return 1 + (!types::is_zero_md(workspace_md()));
221221
}

0 commit comments

Comments
 (0)