1 | /******************************************************************************* |
2 | * Copyright 2019-2022 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 "utils/parser.hpp" |
24 | |
25 | #include "concat/concat.hpp" |
26 | |
27 | namespace concat { |
28 | |
29 | void check_correctness(const settings_t &s) { |
30 | for_(const auto &i_sdt : s.sdt) |
31 | for_(const auto &i_ddt : s.ddt) |
32 | for_(const auto &i_stag : s.stag) |
33 | for_(const auto &i_dtag : s.dtag) |
34 | for_(const auto &i_axis : s.axis) |
35 | for_(const auto &i_scales : s.scales) |
36 | for_(const auto &i_scratchpad_mode : s.scratchpad_mode) |
37 | for_(const auto &i_ctx_init : s.ctx_init) |
38 | for (const auto &i_ctx_exe : s.ctx_exe) { |
39 | const int n_stags = static_cast<int>(i_stag.size()); |
40 | const int n_inputs = s.prb_vdims.n_inputs(); |
41 | if (n_stags != n_inputs && n_stags != 1) { |
42 | BENCHDNN_PRINT(0, |
43 | "ERROR: Expected number of stag arguments is `1` or `%d`, " |
44 | "provided `%d`.\n" , |
45 | n_inputs, n_stags); |
46 | SAFE_V(FAIL); |
47 | } |
48 | |
49 | auto attr = settings_t::get_attr(i_scales, i_scratchpad_mode); |
50 | |
51 | const prb_t prb(s.prb_vdims, i_sdt, i_ddt, i_stag, i_dtag, i_axis, attr, |
52 | i_ctx_init, i_ctx_exe); |
53 | std::stringstream ss; |
54 | ss << prb; |
55 | const std::string cpp_pstr = ss.str(); |
56 | const char *pstr = cpp_pstr.c_str(); |
57 | BENCHDNN_PRINT(1, "run: %s\n" , pstr); |
58 | |
59 | res_t res {}; |
60 | doit(&prb, &res); |
61 | |
62 | parse_result(res, pstr); |
63 | |
64 | if (is_bench_mode(PERF)) { |
65 | perf_report_t pr(&prb, s.perf_template); |
66 | pr.report(&res, pstr); |
67 | } |
68 | } |
69 | } |
70 | |
71 | int bench(int argc, char **argv) { |
72 | driver_name = "concat" ; |
73 | using namespace parser; |
74 | static settings_t s; |
75 | static const settings_t def {}; |
76 | for (; argc > 0; --argc, ++argv) { |
77 | const bool parsed_options = parse_bench_settings(argv[0]) |
78 | || parse_batch(bench, argv[0]) |
79 | || parse_dt(s.sdt, def.sdt, argv[0], "sdt" ) |
80 | || parse_dt(s.ddt, def.ddt, argv[0], "ddt" ) |
81 | || parse_multi_tag(s.stag, def.stag, argv[0]) |
82 | || parse_tag(s.dtag, def.dtag, argv[0], "dtag" ) |
83 | || parse_axis(s.axis, def.axis, argv[0]) |
84 | || parse_attr_scales(s.scales, argv[0]) |
85 | || parse_attr_scratchpad_mode( |
86 | s.scratchpad_mode, def.scratchpad_mode, argv[0]) |
87 | || parse_ctx_init(s.ctx_init, def.ctx_init, argv[0]) |
88 | || parse_ctx_exe(s.ctx_exe, def.ctx_exe, argv[0]) |
89 | || parse_perf_template(s.perf_template, s.perf_template_def, |
90 | s.perf_template_csv(), argv[0]) |
91 | || parse_reset(s, argv[0]) || parse_help(argv[0]); |
92 | if (!parsed_options) { |
93 | catch_unknown_options(argv[0]); |
94 | |
95 | parse_prb_vdims(s.prb_vdims, argv[0], 1); |
96 | |
97 | check_correctness(s); |
98 | } |
99 | } |
100 | |
101 | return parse_last_argument(); |
102 | } |
103 | |
104 | } // namespace concat |
105 | |