1 /*******************************************************************************
2 * Copyright 2019-2021 Intel Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *******************************************************************************/
16
17 #include <stdio.h>
18 #include <stdlib.h>
19
20 #include <sstream>
21
22 #include "dnnl_common.hpp"
23 #include "dnnl_memory.hpp"
24 #include "parser.hpp"
25
26 #include "concat/concat.hpp"
27
28 namespace concat {
29
check_correctness(const settings_t & s)30 void check_correctness(const settings_t &s) {
31 for_(const auto &i_sdt : s.sdt)
32 for_(const auto &i_ddt : s.ddt)
33 for_(const auto &i_stag_ : s.stag)
34 for_(const auto &i_dtag : s.dtag)
35 for_(const auto &i_axis : s.axis)
36 for (const auto &i_scratchpad_mode : s.scratchpad_mode) {
37 // if dst is omitted by dtag = tag::undef, omit ddt as well
38 auto ddt = i_dtag == tag::undef ? dnnl_data_type_undef : i_ddt;
39
40 // broadcast tag if needed
41 auto i_stag = i_stag_;
42 if (i_stag.size() == 1) {
43 const auto val = i_stag_[0];
44 i_stag.assign(s.sdims.size(), val);
45 }
46
47 if (s.sdims.size() != i_stag.size()) // want 1:1 match of sdims and tag
48 SAFE_V(FAIL);
49
50 attr_t attr;
51 attr.insert(i_scratchpad_mode);
52
53 const prb_t prb(s.sdims, i_sdt, ddt, i_stag, i_dtag, i_axis, attr);
54 std::stringstream ss;
55 ss << prb;
56 const std::string cpp_pstr = ss.str();
57 const char *pstr = cpp_pstr.c_str();
58 BENCHDNN_PRINT(1, "run: %s\n", pstr);
59
60 res_t res {};
61 int status = doit(&prb, &res);
62
63 bool want_perf_report = false;
64 parse_result(res, want_perf_report, status, pstr);
65
66 if (want_perf_report && is_bench_mode(PERF)) {
67 perf_report_t pr(s.perf_template);
68 pr.report(&prb, &res, pstr);
69 }
70
71 benchdnn_stat.tests++;
72 }
73 }
74
bench(int argc,char ** argv)75 int bench(int argc, char **argv) {
76 driver_name = "concat";
77 using namespace parser;
78 static settings_t s;
79 static const settings_t def {};
80 for (; argc > 0; --argc, ++argv) {
81 const bool parsed_options = parse_bench_settings(argv[0])
82 || parse_batch(bench, argv[0])
83 || parse_dt(s.sdt, def.sdt, argv[0], "sdt")
84 || parse_dt(s.ddt, def.ddt, argv[0], "ddt")
85 || parse_multi_tag(s.stag, def.stag, argv[0])
86 || parse_tag(s.dtag, def.dtag, argv[0], "dtag")
87 || parse_axis(s.axis, def.axis, argv[0])
88 || parse_attr_scratchpad_mode(
89 s.scratchpad_mode, def.scratchpad_mode, argv[0])
90 || parse_perf_template(s.perf_template, s.perf_template_def,
91 s.perf_template_csv, argv[0])
92 || parse_reset(s, argv[0]);
93 if (!parsed_options) {
94 catch_unknown_options(argv[0]);
95
96 parse_multi_dims(s.sdims, argv[0]);
97
98 check_correctness(s);
99 }
100 }
101
102 return parse_last_argument();
103 }
104
105 } // namespace concat
106