Skip to content

Commit 86c1466

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 75def0b commit 86c1466

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

@@ -3810,10 +3815,9 @@ struct post_ops : public handle<dnnl_post_ops_t> {
38103815
"could not append a binary post-op");
38113816
}
38123817

3813-
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,
3814-
const float* weights_data, const float* biases_data) {
3818+
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) {
38153819
error::wrap_c_api(dnnl_post_ops_append_dw_conv(get(),
3816-
in_h, in_w, ker_h, ker_w, str_h, str_w, in_dt, weights_data, biases_data),
3820+
in_h, in_w, ker_h, ker_w, str_h, str_w, in_dt),
38173821
"could not append dw conv");
38183822
}
38193823

@@ -3902,19 +3906,15 @@ struct post_ops : public handle<dnnl_post_ops_t> {
39023906
"could not get parameters of a binary post-op");
39033907
}
39043908

3905-
void append_depthwise(algorithm alg, const float* weights_data,
3906-
const float* biases_data) {
3907-
error::wrap_c_api(dnnl_post_ops_append_depthwise(get(),
3908-
convert_to_c(alg), weights_data, biases_data),
3909+
void append_depthwise(algorithm alg, const std::array<size_t, 2>& offset) {
3910+
error::wrap_c_api(dnnl_post_ops_append_depthwise(get(), convert_to_c(alg), offset.size(), offset.data()),
39093911
"could not append depthwise");
39103912
}
39113913

3912-
void append_quantization(algorithm alg,
3913-
const void* crop_low, const void* crop_high,
3914-
const void* input_scale, const void* input_shift,
3915-
const void* output_scale, const void* output_shift) {
3916-
error::wrap_c_api(dnnl_post_ops_append_quantization(get(), convert_to_c(alg), crop_low, crop_high,
3917-
input_scale, input_shift, output_scale, output_shift),
3914+
void append_quantization(algorithm alg, const std::array<bool, 6>& per_channel, const std::array<bool, 6>& all_default,
3915+
const std::array<size_t, 6>& offset) {
3916+
error::wrap_c_api(dnnl_post_ops_append_quantization(get(), convert_to_c(alg), per_channel.size(), per_channel.data(),
3917+
all_default.size(), all_default.data(), offset.size(), offset.data()),
39183918
"could not append quantization");
39193919
}
39203920

@@ -4129,66 +4129,21 @@ struct primitive_attr : public handle<dnnl_primitive_attr_t> {
41294129
"could not set zero points primitive attribute");
41304130
}
41314131

4132-
void get_output_compensations(int &mask, std::vector<int32_t> &compensations) const
4132+
void set_output_compensations(dnnl_dim_t count, int mask)
41334133
{
4134-
int count, c_mask;
4135-
const int32_t *c_compensations;
4136-
error::wrap_c_api(dnnl_primitive_attr_get_output_compensations(get(),
4137-
&count, &c_mask, &c_compensations),
4138-
"could not get int output compensations");
4139-
compensations.resize(count);
4140-
4141-
mask = c_mask;
4142-
for (int c = 0; c < count; ++c)
4143-
compensations[c] = c_compensations[c];
4144-
}
4145-
4146-
void set_output_compensations(int mask, const std::vector<int32_t> &compensations)
4147-
{
4148-
error::wrap_c_api(dnnl_primitive_attr_set_output_compensations(get(),
4149-
(int)compensations.size(), mask, &compensations[0]),
4134+
error::wrap_c_api(dnnl_primitive_attr_set_output_compensations(get(), count, mask),
41504135
"could not set int output compensations");
41514136
}
41524137

4153-
void get_input_zero_points(int &mask, std::vector<uint8_t> &zero_points) const
4138+
void set_input_zero_points(dnnl_dim_t count, int mask)
41544139
{
4155-
int count, c_mask;
4156-
const uint8_t *c_zero_points;
4157-
error::wrap_c_api(dnnl_primitive_attr_get_input_zero_points(get(),
4158-
&count, &c_mask, &c_zero_points),
4159-
"could not get int input zero_points");
4160-
zero_points.resize(count);
4161-
4162-
mask = c_mask;
4163-
for (int c = 0; c < count; ++c)
4164-
zero_points[c] = c_zero_points[c];
4165-
}
4166-
4167-
void set_input_zero_points(int mask, const std::vector<uint8_t> &zero_points)
4168-
{
4169-
error::wrap_c_api(dnnl_primitive_attr_set_input_zero_points(get(),
4170-
(int)zero_points.size(), mask, &zero_points[0]),
4140+
error::wrap_c_api(dnnl_primitive_attr_set_input_zero_points(get(), count, mask),
41714141
"could not set int input zero_points");
41724142
}
41734143

4174-
void get_weights_zero_points(int &mask, std::vector<int8_t> &zero_points) const
4175-
{
4176-
int count, c_mask;
4177-
const float *c_zero_points;
4178-
error::wrap_c_api(dnnl_primitive_attr_get_weights_zero_points(get(),
4179-
&count, &c_mask, &c_zero_points),
4180-
"could not get int weights zero_points");
4181-
zero_points.resize(count);
4182-
4183-
mask = c_mask;
4184-
for (int c = 0; c < count; ++c)
4185-
zero_points[c] = c_zero_points[c];
4186-
}
4187-
4188-
void set_weights_zero_points(int mask, const std::vector<float> &zero_points)
4144+
void set_weights_zero_points(dnnl_dim_t count, int mask)
41894145
{
4190-
error::wrap_c_api(dnnl_primitive_attr_set_weights_zero_points(get(),
4191-
(int)zero_points.size(), mask, &zero_points[0]),
4146+
error::wrap_c_api(dnnl_primitive_attr_set_weights_zero_points(get(), count, mask),
41924147
"could not set int weights zero_points");
41934148
}
41944149

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)