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 | #include <string.h> |
20 | |
21 | #include <sstream> |
22 | |
23 | #include "dnnl_common.hpp" |
24 | #include "utils/parser.hpp" |
25 | |
26 | #include "resampling/resampling.hpp" |
27 | |
28 | namespace resampling { |
29 | |
30 | void check_correctness(const settings_t &s) { |
31 | for_(const auto &i_dir : s.dir) |
32 | for_(const auto &i_sdt : s.sdt) |
33 | for_(const auto &i_ddt : s.ddt) |
34 | for_(const auto &i_tag : s.tag) |
35 | for_(const auto &i_alg : s.alg) |
36 | for_(const auto &i_post_ops : s.post_ops) |
37 | for_(const auto &i_mb : s.mb) |
38 | for_(const auto &i_scratchpad_mode : s.scratchpad_mode) |
39 | for_(const auto &i_ctx_init : s.ctx_init) |
40 | for (const auto &i_ctx_exe : s.ctx_exe) { |
41 | auto attr = settings_t::get_attr(i_post_ops, i_scratchpad_mode); |
42 | |
43 | const prb_t prb(s.desc, i_dir, i_sdt, i_ddt, i_tag, i_alg, attr, |
44 | i_ctx_init, i_ctx_exe, i_mb); |
45 | std::stringstream ss; |
46 | ss << prb; |
47 | const std::string cpp_pstr = ss.str(); |
48 | const char *pstr = cpp_pstr.c_str(); |
49 | BENCHDNN_PRINT(1, "run: %s\n" , pstr); |
50 | |
51 | res_t res {}; |
52 | doit(&prb, &res); |
53 | |
54 | parse_result(res, pstr); |
55 | |
56 | if (is_bench_mode(PERF)) { |
57 | perf_report_t pr(&prb, s.perf_template); |
58 | pr.report(&res, pstr); |
59 | } |
60 | } |
61 | } |
62 | |
63 | int bench(int argc, char **argv) { |
64 | driver_name = "resampling" ; |
65 | using namespace parser; |
66 | static settings_t s; |
67 | static const settings_t def {}; |
68 | for (; argc > 0; --argc, ++argv) { |
69 | const bool parsed_options = parse_bench_settings(argv[0]) |
70 | || parse_batch(bench, argv[0]) |
71 | || parse_dir(s.dir, def.dir, argv[0]) |
72 | || parse_dt(s.sdt, def.sdt, argv[0], "sdt" ) |
73 | || parse_dt(s.ddt, def.ddt, argv[0], "ddt" ) |
74 | || parse_tag(s.tag, def.tag, argv[0]) |
75 | || parse_alg(s.alg, def.alg, str2alg, argv[0]) |
76 | || parse_mb(s.mb, def.mb, argv[0]) |
77 | || parse_attr_post_ops(s.post_ops, argv[0]) |
78 | || parse_attr_scratchpad_mode( |
79 | s.scratchpad_mode, def.scratchpad_mode, argv[0]) |
80 | || parse_ctx_init(s.ctx_init, def.ctx_init, argv[0]) |
81 | || parse_ctx_exe(s.ctx_exe, def.ctx_exe, argv[0]) |
82 | || parse_perf_template(s.perf_template, s.perf_template_def, |
83 | s.perf_template_csv(), argv[0]) |
84 | || parse_reset(s, argv[0]) || parse_help(argv[0]); |
85 | if (!parsed_options) { |
86 | catch_unknown_options(argv[0]); |
87 | |
88 | SAFE(str2desc(&s.desc, argv[0]), CRIT); |
89 | check_correctness(s); |
90 | } |
91 | } |
92 | |
93 | return parse_last_argument(); |
94 | } |
95 | |
96 | } // namespace resampling |
97 | |