Skip to content

Commit 95b1ab8

Browse files
committed
benchdnn: self: replace temporary "const char *" with "std::string"
Temporary "const char *" objects can disappear while getting to the parser internals. Moving strings to parse into a permanent container solves the problem.
1 parent 03bae07 commit 95b1ab8

File tree

1 file changed

+34
-28
lines changed

1 file changed

+34
-28
lines changed

tests/benchdnn/self/common.cpp

+34-28
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ static int check_attr() {
118118
{
119119
base_settings_t s;
120120
std::vector<attr_t::zero_points_t> &zp = s.zero_points;
121-
SELF_CHECK_EQ(parse_attributes(s, def,
122-
"--attr-zero-points=src:common:0+wei:per_oc+dst:"
123-
"common:-2,src:per_dim_1"),
124-
true);
121+
std::string content_to_parse(
122+
"--attr-zero-points=src:common:0+wei:per_oc+dst:common:-2,src:"
123+
"per_dim_1");
124+
SELF_CHECK_EQ(parse_attributes(s, def, content_to_parse.c_str()), true);
125125
SELF_CHECK_EQ(zp.size(), 2);
126126
const std::vector<dnnl_dim_t> def_g {};
127127
SELF_CHECK_ATTR_ZP(
@@ -138,11 +138,10 @@ static int check_attr() {
138138
{
139139
base_settings_t s;
140140
std::vector<attr_t::arg_scales_t> &sc = s.scales;
141+
std::string content_to_parse(
142+
"--attr-scales=src:common:1.5+wei:per_oc+src:common:0.5");
141143
// `src` scale is overridden with the latter value.
142-
SELF_CHECK_EQ(parse_attributes(s, def,
143-
"--attr-scales=src:common:1.5+wei:per_oc+src:"
144-
"common:0.5"),
145-
true);
144+
SELF_CHECK_EQ(parse_attributes(s, def, content_to_parse.c_str()), true);
146145
SELF_CHECK_EQ(sc.size(), 1);
147146
SELF_CHECK_EQ(sc[0].get(DNNL_ARG_SRC).policy, policy_t::COMMON);
148147
SELF_CHECK_EQ(sc[0].get(DNNL_ARG_SRC).scale, 0.5f);
@@ -153,9 +152,9 @@ static int check_attr() {
153152
{
154153
base_settings_t s;
155154
std::vector<attr_t::arg_scales_t> &sc = s.scales;
156-
SELF_CHECK_EQ(parse_attributes(s, def,
157-
"--attr-scales=src:common:2.5+src1:common:1.5"),
158-
true);
155+
std::string content_to_parse(
156+
"--attr-scales=src:common:2.5+src1:common:1.5");
157+
SELF_CHECK_EQ(parse_attributes(s, def, content_to_parse.c_str()), true);
159158
SELF_CHECK_EQ(sc.size(), 1);
160159
SELF_CHECK_EQ(sc[0].get(DNNL_ARG_SRC_0).policy, policy_t::COMMON);
161160
SELF_CHECK_EQ(sc[0].get(DNNL_ARG_SRC_0).scale, 2.5);
@@ -166,9 +165,8 @@ static int check_attr() {
166165
{
167166
base_settings_t s;
168167
std::vector<attr_t::zero_points_t> &zp = s.zero_points;
169-
SELF_CHECK_EQ(parse_attributes(
170-
s, def, "--attr-zero-points=wei:per_ocic:s8:2x1"),
171-
true);
168+
std::string content_to_parse("--attr-zero-points=wei:per_ocic:s8:2x1");
169+
SELF_CHECK_EQ(parse_attributes(s, def, content_to_parse.c_str()), true);
172170
SELF_CHECK_EQ(zp.size(), 1);
173171
std::vector<dnnl_dim_t> groups = {2, 1};
174172
SELF_CHECK_ATTR_ZP(zp[0], DNNL_ARG_WEIGHTS, policy_t::PER_OCIC, 0,
@@ -178,9 +176,9 @@ static int check_attr() {
178176
{
179177
base_settings_t s;
180178
std::vector<attr_t::arg_scales_t> &sc = s.scales;
181-
SELF_CHECK_EQ(parse_attributes(s, def,
182-
"--attr-scales=attr_post_op_dw_wei:common:2"),
183-
true);
179+
std::string content_to_parse(
180+
"--attr-scales=attr_post_op_dw_wei:common:2");
181+
SELF_CHECK_EQ(parse_attributes(s, def, content_to_parse.c_str()), true);
184182
SELF_CHECK_EQ(sc.size(), 1);
185183
const auto arg = DNNL_ARG_ATTR_POST_OP_DW | DNNL_ARG_WEIGHTS;
186184
SELF_CHECK_EQ(sc[0].get(arg).policy, policy_t::COMMON);
@@ -191,7 +189,8 @@ static int check_attr() {
191189
{
192190
base_settings_t s;
193191
std::vector<attr_t::post_ops_t> &po = s.post_ops;
194-
auto st = parse_attributes(s, def, "--attr-post-ops=dw:k3s1p1");
192+
std::string content_to_parse("--attr-post-ops=dw:k3s1p1");
193+
auto st = parse_attributes(s, def, content_to_parse.c_str());
195194
SELF_CHECK_EQ(st, true);
196195
SELF_CHECK_EQ(po[0].len(), 1);
197196
const auto &e = po[0].entry[0];
@@ -206,8 +205,9 @@ static int check_attr() {
206205
{
207206
base_settings_t s;
208207
std::vector<attr_t::post_ops_t> &po = s.post_ops;
209-
auto st = parse_attributes(
210-
s, def, "--attr-post-ops=relu:0.5+dw:k3s2p1:s8+linear:2:1");
208+
std::string content_to_parse(
209+
"--attr-post-ops=relu:0.5+dw:k3s2p1:s8+linear:2:1");
210+
auto st = parse_attributes(s, def, content_to_parse.c_str());
211211
SELF_CHECK_EQ(st, true);
212212
SELF_CHECK_EQ(po[0].len(), 3);
213213
auto &e = po[0].entry[0];
@@ -236,7 +236,8 @@ static int check_attr() {
236236
{
237237
base_settings_t s;
238238
std::vector<attr_t::fpmath_mode_t> &fm = s.fpmath_mode;
239-
auto st = parse_attributes(s, def, "--attr-fpmath=strict:true");
239+
std::string content_to_parse("--attr-fpmath=strict:true");
240+
auto st = parse_attributes(s, def, content_to_parse.c_str());
240241
SELF_CHECK_EQ(st, true);
241242
SELF_CHECK_EQ(fm[0].mode, dnnl_fpmath_mode_strict);
242243
SELF_CHECK_EQ(fm[0].apply_to_int, true);
@@ -245,7 +246,8 @@ static int check_attr() {
245246
{
246247
base_settings_t s;
247248
std::vector<attr_t::fpmath_mode_t> &fm = s.fpmath_mode;
248-
auto st = parse_attributes(s, def, "--attr-fpmath=bf16");
249+
std::string content_to_parse("--attr-fpmath=bf16");
250+
auto st = parse_attributes(s, def, content_to_parse.c_str());
249251
SELF_CHECK_EQ(st, true);
250252
SELF_CHECK_EQ(fm[0].mode, dnnl_fpmath_mode_bf16);
251253
SELF_CHECK_EQ(fm[0].apply_to_int, false);
@@ -257,7 +259,8 @@ static int check_attr() {
257259
std::vector<attr_t::fpmath_mode_t> &fm = s.fpmath_mode;
258260
def.fpmath_mode.emplace_back();
259261
def.fpmath_mode[0].set(dnnl_fpmath_mode_bf16, true);
260-
auto st = parse_attributes(s, def, "--attr-fpmath=");
262+
std::string content_to_parse("--attr-fpmath=");
263+
auto st = parse_attributes(s, def, content_to_parse.c_str());
261264
SELF_CHECK_EQ(st, true);
262265
SELF_CHECK_EQ(fm[0].mode, dnnl_fpmath_mode_bf16);
263266
SELF_CHECK_EQ(fm[0].apply_to_int, true);
@@ -268,7 +271,8 @@ static int check_attr() {
268271
{
269272
base_settings_t s;
270273
std::vector<attr_t::dropout_t> &d = s.dropout;
271-
auto st = parse_attributes(s, def, "--attr-dropout=0.5:12345:axb");
274+
std::string content_to_parse("--attr-dropout=0.5:12345:axb");
275+
auto st = parse_attributes(s, def, content_to_parse.c_str());
272276
SELF_CHECK_EQ(st, true);
273277
SELF_CHECK_EQ(d[0].p, 0.5f);
274278
SELF_CHECK_EQ(d[0].seed, 12345);
@@ -278,7 +282,8 @@ static int check_attr() {
278282
{
279283
base_settings_t s;
280284
std::vector<attr_t::dropout_t> &d = s.dropout;
281-
auto st = parse_attributes(s, def, "--attr-dropout=0.75");
285+
std::string content_to_parse("--attr-dropout=0.75");
286+
auto st = parse_attributes(s, def, content_to_parse.c_str());
282287
SELF_CHECK_EQ(st, true);
283288
SELF_CHECK_EQ(d[0].p, 0.75f);
284289
SELF_CHECK_EQ(d[0].seed, 0);
@@ -288,7 +293,8 @@ static int check_attr() {
288293
{
289294
base_settings_t s;
290295
std::vector<attr_t::dropout_t> &d = s.dropout;
291-
auto st = parse_attributes(s, def, "--attr-dropout=");
296+
std::string content_to_parse("--attr-dropout=");
297+
auto st = parse_attributes(s, def, content_to_parse.c_str());
292298
SELF_CHECK_EQ(st, true);
293299
SELF_CHECK_EQ(d[0].p, 0.f);
294300
SELF_CHECK_EQ(d[0].seed, 0);
@@ -298,8 +304,8 @@ static int check_attr() {
298304
{
299305
base_settings_t s;
300306
std::vector<attr_t::rounding_mode_t> &rm = s.rounding_mode;
301-
auto st = parse_attributes(
302-
s, def, "--attr-rounding-mode=dst:stochastic");
307+
std::string content_to_parse("--attr-rounding-mode=dst:stochastic");
308+
auto st = parse_attributes(s, def, content_to_parse.c_str());
303309
SELF_CHECK_EQ(st, true);
304310
SELF_CHECK_EQ(rm[0].get(DNNL_ARG_DST), dnnl_rounding_mode_stochastic);
305311
SELF_CHECK_EQ(rm[0].get(DNNL_ARG_SRC), dnnl_rounding_mode_environment);

0 commit comments

Comments
 (0)