1 | /******************************************************************************* |
2 | * Copyright 2020-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 "prelu/prelu.hpp" |
26 | |
27 | namespace prelu { |
28 | |
29 | void check_correctness(const settings_t &s) { |
30 | for_(const auto &i_dir : s.dir) |
31 | for_(const auto &i_sdt : s.sdt) |
32 | for_(const auto &i_stag : s.stag) |
33 | for_(const auto &i_scratchpad_mode : s.scratchpad_mode) |
34 | for_(const auto &i_ctx_init : s.ctx_init) |
35 | for (const auto &i_ctx_exe : s.ctx_exe) { |
36 | // Expect exactly two inputs for problem dimensions. |
37 | static constexpr int n_inputs = 2; |
38 | if (s.prb_vdims.n_inputs() != n_inputs) { |
39 | BENCHDNN_PRINT(0, "%s\n" , |
40 | "Error: input tensors were specified in wrong format. " |
41 | "Please use NxNxNxNxN:MxMxMxMxM as a problem description " |
42 | "format." ); |
43 | SAFE_V(FAIL); |
44 | } |
45 | if (i_sdt.size() != n_inputs) { |
46 | BENCHDNN_PRINT(0, "%s\n" , |
47 | "Error: input data types were specified in wrong format. " |
48 | "Please use --sdt=X:X format." ); |
49 | SAFE_V(FAIL); |
50 | } |
51 | if (i_stag.size() != n_inputs) { |
52 | BENCHDNN_PRINT(0, "%s\n" , |
53 | "Error: input format tags were specified in wrong format. " |
54 | "Please use --stag=X:X format." ); |
55 | SAFE_V(FAIL); |
56 | } |
57 | |
58 | auto attr = settings_t::get_attr(i_scratchpad_mode); |
59 | |
60 | const prb_t prb( |
61 | s.prb_vdims, i_dir, i_sdt, i_stag, attr, i_ctx_init, i_ctx_exe); |
62 | std::stringstream ss; |
63 | ss << prb; |
64 | const std::string cpp_pstr = ss.str(); |
65 | const char *pstr = cpp_pstr.c_str(); |
66 | BENCHDNN_PRINT(1, "run: %s\n" , pstr); |
67 | |
68 | res_t res {}; |
69 | doit(&prb, &res); |
70 | |
71 | parse_result(res, pstr); |
72 | |
73 | if (is_bench_mode(PERF)) { |
74 | perf_report_t pr(&prb, s.perf_template); |
75 | pr.report(&res, pstr); |
76 | } |
77 | } |
78 | } |
79 | |
80 | int bench(int argc, char **argv) { |
81 | driver_name = "prelu" ; |
82 | using namespace parser; |
83 | static settings_t s; |
84 | static const settings_t def {}; |
85 | for (; argc > 0; --argc, ++argv) { |
86 | const bool parsed_options = parse_bench_settings(argv[0]) |
87 | || parse_batch(bench, argv[0]) |
88 | || parse_dir(s.dir, def.dir, argv[0]) |
89 | || parse_multi_dt(s.sdt, def.sdt, argv[0]) |
90 | || parse_multi_tag(s.stag, def.stag, argv[0]) |
91 | || parse_attr_scratchpad_mode( |
92 | s.scratchpad_mode, def.scratchpad_mode, argv[0]) |
93 | || parse_ctx_init(s.ctx_init, def.ctx_init, argv[0]) |
94 | || parse_ctx_exe(s.ctx_exe, def.ctx_exe, argv[0]) |
95 | || parse_perf_template(s.perf_template, s.perf_template_def, |
96 | s.perf_template_csv(), argv[0]) |
97 | || parse_reset(s, argv[0]) || parse_help(argv[0]); |
98 | if (!parsed_options) { |
99 | catch_unknown_options(argv[0]); |
100 | |
101 | parse_prb_vdims(s.prb_vdims, argv[0]); |
102 | check_correctness(s); |
103 | } |
104 | } |
105 | |
106 | return parse_last_argument(); |
107 | } |
108 | } // namespace prelu |
109 | |