Skip to content

Commit 0bcd6ac

Browse files
committed
common: attributes: remove defined() method as obsolete
1 parent 45ab072 commit 0bcd6ac

10 files changed

+32
-57
lines changed

src/common/primitive_attr.cpp

+5-24
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,6 @@ bool primitive_attr_t::defined(dnnl_primitive_attr::skip_mask_t mask) const {
186186
#define CHECK_ARG(x) ok = ok && (x)
187187
#define CHECK_MASK(mask_name, mask_field) \
188188
CHECK_ARG(IMPLICATION((bool)(~mask & (mask_name)), (mask_field).defined()))
189-
CHECK_MASK(smask_t::scales, scales_);
190-
CHECK_MASK(smask_t::zero_points, zero_points_);
191-
CHECK_MASK(smask_t::post_ops, post_ops_);
192189
CHECK_MASK(smask_t::rnn_data_qparams, rnn_data_qparams_);
193190
CHECK_MASK(smask_t::rnn_weights_qparams, rnn_weights_qparams_);
194191
CHECK_MASK(smask_t::rnn_weights_projection_qparams,
@@ -200,6 +197,8 @@ bool primitive_attr_t::defined(dnnl_primitive_attr::skip_mask_t mask) const {
200197

201198
status_t post_ops_t::append_sum(
202199
float scale, int32_t zero_point, data_type_t dt) {
200+
if (is_runtime_value(scale)) return invalid_arguments;
201+
203202
entry_.emplace_back();
204203
auto &e = entry_.back();
205204
e.kind = primitive_kind::sum;
@@ -213,6 +212,9 @@ status_t post_ops_t::append_eltwise(
213212
float scale, alg_kind_t alg, float alpha, float beta) {
214213
if (!math::is_eltwise_ok(data_type::f32, alg, alpha, beta))
215214
return invalid_arguments;
215+
if (is_runtime_value(scale)) return invalid_arguments;
216+
if (is_runtime_value(alpha)) return invalid_arguments;
217+
if (is_runtime_value(beta)) return invalid_arguments;
216218

217219
entry_.emplace_back();
218220
auto &e = entry_.back();
@@ -310,27 +312,6 @@ status_t post_ops_t::append_prelu(int mask) {
310312
return success;
311313
}
312314

313-
bool post_ops_t::defined() const {
314-
for (int idx = 0; idx < len(); ++idx) {
315-
auto kind = entry_[idx].kind;
316-
if (kind == primitive_kind::sum) {
317-
if (is_runtime_value(entry_[idx].sum.scale)) return false;
318-
} else if (kind == primitive_kind::eltwise) {
319-
const auto &e = entry_[idx].eltwise;
320-
if (is_runtime_value(e.scale) || is_runtime_value(e.alpha)
321-
|| is_runtime_value(e.beta))
322-
return false;
323-
} else if (utils::one_of(kind, primitive_kind::binary,
324-
primitive_kind::prelu,
325-
primitive_kind::convolution)) {
326-
// binary is always defined
327-
} else {
328-
assert(!"unreachable");
329-
}
330-
}
331-
return true;
332-
}
333-
334315
status_t post_ops_t::set_default_formats(const memory_desc_t *dst_md) {
335316
for (int idx = 0; idx < len(); ++idx) {
336317
if (!contain(primitive_kind::binary, idx)) continue;

src/common/primitive_attr.hpp

-9
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,6 @@ struct runtime_scales_t : public c_compatible {
225225
bool has_default_groups() const { return 0 == ndims_; }
226226
bool has_default_data_type() const { return data_type_ == data_type::f32; }
227227

228-
bool defined() const { return has_default_values(); }
229-
230-
void reset() { *this = default_runtime_scale(); }
231-
232228
// TODO: replace with `-1` to remove `is_set_`.
233229
// Hide `mask_` under `private:` to force interface usage.
234230
int mask_ = 0;
@@ -318,8 +314,6 @@ struct arg_scales_t : public c_compatible {
318314
return status::success;
319315
}
320316

321-
bool defined() const { return has_default_values(); }
322-
323317
status_t copy_from(const arg_scales_t &other) {
324318
for (auto it = other.scales_.begin(); it != other.scales_.end(); ++it) {
325319
// Find an entry that can match the arguments without constructing a
@@ -387,7 +381,6 @@ struct zero_points_t : public c_compatible {
387381

388382
// arg-specific checks
389383
bool common(int arg) const { return get_mask(arg) == 0; }
390-
bool defined(int arg) const { return has_default_values(arg); }
391384
bool has_default_values(int arg) const {
392385
return is_set(arg) == false && has_default_data_type(arg);
393386
}
@@ -399,7 +392,6 @@ struct zero_points_t : public c_compatible {
399392
}
400393
// same checks but for all supported arguments at once
401394
bool common() const { return check_all(&zero_points_t::common); }
402-
bool defined() const { return has_default_values(); }
403395
bool has_default_values() const {
404396
return check_all(&zero_points_t::has_default_values);
405397
}
@@ -743,7 +735,6 @@ struct dnnl_post_ops : public dnnl::impl::c_compatible {
743735
return dst_dt;
744736
}
745737

746-
bool defined() const;
747738
int len() const { return (int)entry_.size(); }
748739
bool has_default_values(
749740
const std::vector<dnnl::impl::primitive_kind_t> &skip_pk

src/common/primitive_desc.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,19 @@ struct primitive_desc_t : public c_compatible {
152152
using types::is_zero_md;
153153
if (arg & DNNL_ARG_ATTR_ZERO_POINTS) {
154154
int zp_arg = arg & ~DNNL_ARG_ATTR_ZERO_POINTS;
155-
if (!attr()->zero_points_.defined(zp_arg))
155+
if (!attr()->zero_points_.has_default_values(zp_arg))
156156
return arg_usage_t::input;
157157
}
158158
if (arg & DNNL_ARG_ATTR_SCALES) {
159159
int scale_arg = arg & ~DNNL_ARG_ATTR_SCALES;
160-
if (!attr()->scales_.get(scale_arg).defined())
160+
if (!attr()->scales_.get(scale_arg).has_default_values())
161161
return arg_usage_t::input;
162162
}
163163
if ((arg == (DNNL_ARG_ATTR_SCALES | DNNL_ARG_SRC_0))
164-
&& !attr()->scales_.get(DNNL_ARG_SRC_0).defined())
164+
&& !attr()->scales_.get(DNNL_ARG_SRC_0).has_default_values())
165165
return arg_usage_t::input;
166166
if ((arg == (DNNL_ARG_ATTR_SCALES | DNNL_ARG_SRC_1))
167-
&& !attr()->scales_.get(DNNL_ARG_SRC_1).defined())
167+
&& !attr()->scales_.get(DNNL_ARG_SRC_1).has_default_values())
168168
return arg_usage_t::input;
169169
if (arg == DNNL_ARG_SCRATCHPAD && !is_zero_md(scratchpad_md()))
170170
return arg_usage_t::output;

src/cpu/aarch64/jit_uni_binary.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ status_t jit_uni_binary_t::pd_t::init(engine_t *engine) {
140140
po, src0_md_, get_supported_postops_bcast_strategies());
141141
conf_.op_type = get_op_type(src0_md_);
142142
assert(conf_.op_type != op_t::none);
143-
conf_.do_scale_src0 = !attr()->scales_.get(DNNL_ARG_SRC_0).defined()
144-
|| !attr()->scales_.get(DNNL_ARG_SRC_0).has_default_values();
145-
conf_.do_scale_src1 = !attr()->scales_.get(DNNL_ARG_SRC_1).defined()
146-
|| !attr()->scales_.get(DNNL_ARG_SRC_1).has_default_values();
143+
conf_.do_scale_src0
144+
= !attr()->scales_.get(DNNL_ARG_SRC_0).has_default_values();
145+
conf_.do_scale_src1
146+
= !attr()->scales_.get(DNNL_ARG_SRC_1).has_default_values();
147147
const auto sum_idx = po.find(primitive_kind::sum);
148148
conf_.do_sum = sum_idx != -1 && po.entry_[sum_idx].sum.scale != 0.f;
149149
conf_.with_eltwise = po.find(primitive_kind::eltwise) != -1;

src/cpu/cpu_primitive.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
#define DEFINE_ZERO_POINTS_BUFFER(zero_points_ptr, mem_arg) \
6767
int32_t CONCAT2(default_zero_point_, mem_arg) = 0; \
6868
const int32_t *zero_points_ptr \
69-
= pd()->attr()->zero_points_.defined(mem_arg) \
69+
= pd()->attr()->zero_points_.has_default_values(mem_arg) \
7070
? &CONCAT2(default_zero_point_, mem_arg) \
7171
: CTX_IN_MEM( \
7272
const int32_t *, DNNL_ARG_ATTR_ZERO_POINTS | mem_arg); \

src/cpu/x64/jit_uni_binary.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,10 @@ status_t jit_uni_binary_t::pd_t::init(engine_t *engine) {
172172
conf_.is_f16 = conf_.dst_type == f16;
173173
conf_.op_type = get_op_type(src0_md_);
174174
assert(conf_.op_type != op_t::none);
175-
conf_.do_scale_src0 = !attr()->scales_.get(DNNL_ARG_SRC_0).defined()
176-
|| !attr()->scales_.get(DNNL_ARG_SRC_0).has_default_values();
177-
conf_.do_scale_src1 = !attr()->scales_.get(DNNL_ARG_SRC_1).defined()
178-
|| !attr()->scales_.get(DNNL_ARG_SRC_1).has_default_values();
175+
conf_.do_scale_src0
176+
= !attr()->scales_.get(DNNL_ARG_SRC_0).has_default_values();
177+
conf_.do_scale_src1
178+
= !attr()->scales_.get(DNNL_ARG_SRC_1).has_default_values();
179179
const auto sum_idx = po.find(primitive_kind::sum);
180180
conf_.do_sum = sum_idx != -1 && po.entry_[sum_idx].sum.scale != 0.f;
181181
conf_.with_eltwise = po.find(primitive_kind::eltwise) != -1;

src/gpu/generic/sycl/ref_layer_normalizations.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ status_t ref_layer_normalization_fwd_t::pd_t::init_conf() {
4040
conf_.wk_size = memory_desc_wrapper(src_md(0)).nelems();
4141
conf_.block_size = 16;
4242

43-
conf_.rt_scaling = !attr()->scales_.defined();
43+
conf_.rt_scaling = !attr()->scales_.has_default_values();
4444
conf_.src_def = attr()->scales_.get(DNNL_ARG_SRC).has_default_values();
4545
conf_.dst_def = attr()->scales_.get(DNNL_ARG_DST).has_default_values();
4646

src/gpu/intel/jit/ir/post_ops.hpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,13 @@ struct zero_points_config_t {
6262
DNNL_ARG_WEIGHTS))
6363
, do_dst_compensation(pd
6464
&& !pd->attr()->zero_points_.has_default_values(DNNL_ARG_DST))
65-
, is_runtime_src_zero_points(
66-
pd && !pd->attr()->zero_points_.defined(DNNL_ARG_SRC))
67-
, is_runtime_wei_zero_points(
68-
pd && !pd->attr()->zero_points_.defined(DNNL_ARG_WEIGHTS))
69-
, is_runtime_dst_zero_points(
70-
pd && !pd->attr()->zero_points_.defined(DNNL_ARG_DST))
65+
, is_runtime_src_zero_points(pd
66+
&& !pd->attr()->zero_points_.has_default_values(DNNL_ARG_SRC))
67+
, is_runtime_wei_zero_points(pd
68+
&& !pd->attr()->zero_points_.has_default_values(
69+
DNNL_ARG_WEIGHTS))
70+
, is_runtime_dst_zero_points(pd
71+
&& !pd->attr()->zero_points_.has_default_values(DNNL_ARG_DST))
7172
, is_common_src_zero_point(
7273
pd && pd->attr()->zero_points_.common(DNNL_ARG_SRC))
7374
, is_common_wei_zero_point(

src/gpu/intel/primitive_conf.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,12 @@ struct attr_info_t {
167167
attr_info.dst_zpoints_data_type = zp.get_data_type(DNNL_ARG_DST);
168168

169169
attr_info.with_per_ic_src_zpoints = attr_info.with_src_zpoints
170-
&& !zp.defined(DNNL_ARG_SRC) && !zp.common(DNNL_ARG_SRC);
170+
&& !zp.has_default_values(DNNL_ARG_SRC)
171+
&& !zp.common(DNNL_ARG_SRC);
171172

172173
attr_info.with_per_oc_dst_zpoints = attr_info.with_dst_zpoints
173-
&& !zp.defined(DNNL_ARG_DST) && !zp.common(DNNL_ARG_DST);
174+
&& !zp.has_default_values(DNNL_ARG_DST)
175+
&& !zp.common(DNNL_ARG_DST);
174176

175177
attr_info.initialized = true;
176178
return attr_info;

src/gpu/nvidia/cudnn_binary.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ status_t cudnn_binary_t::execute(const exec_ctx_t &ctx) const {
3535
nvidia::stream_t *cuda_stream
3636
= utils::downcast<nvidia::stream_t *>(ctx.stream());
3737

38-
if (!pd()->attr()->scales_.get(DNNL_ARG_SRC_0).defined())
38+
if (!pd()->attr()->scales_.get(DNNL_ARG_SRC_0).has_default_values())
3939
CHECK(stream_utils::copy_input_arg_to_host(ctx, cuda_stream,
4040
&host_scales_[0], DNNL_ARG_ATTR_SCALES | DNNL_ARG_SRC_0,
4141
sizeof(float)));
42-
if (!pd()->attr()->scales_.get(DNNL_ARG_SRC_1).defined())
42+
if (!pd()->attr()->scales_.get(DNNL_ARG_SRC_1).has_default_values())
4343
CHECK(stream_utils::copy_input_arg_to_host(ctx, cuda_stream,
4444
&host_scales_[1], DNNL_ARG_ATTR_SCALES | DNNL_ARG_SRC_1,
4545
sizeof(float)));

0 commit comments

Comments
 (0)