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 "zeropad/zeropad.hpp"
26
27namespace zeropad {
28
29void check_correctness(const settings_t &s) {
30 for_(const auto &i_dt : s.dt)
31 for (const auto &i_tag : s.tag) {
32 const prb_t prb(s.prb_dims, i_dt, i_tag);
33 std::stringstream ss;
34 ss << prb;
35 const std::string cpp_pstr = ss.str();
36 const char *pstr = cpp_pstr.c_str();
37 BENCHDNN_PRINT(1, "run: %s\n", pstr);
38
39 res_t res {};
40 doit(&prb, &res);
41
42 parse_result(res, pstr);
43
44 if (is_bench_mode(PERF)) {
45 perf_report_t pr(&prb, s.perf_template);
46 pr.report(&res, pstr);
47 }
48 }
49}
50
51int bench(int argc, char **argv) {
52 driver_name = "zeropad";
53 using namespace parser;
54 static settings_t s;
55 static const settings_t def {};
56 for (; argc > 0; --argc, ++argv) {
57 const bool parsed_options = parse_bench_settings(argv[0])
58 || parse_batch(bench, argv[0])
59 || parse_dt(s.dt, def.dt, argv[0])
60 || parse_tag(s.tag, def.tag, argv[0])
61 || parse_perf_template(s.perf_template, s.perf_template_def,
62 s.perf_template_csv(), argv[0])
63 || parse_reset(s, argv[0]) || parse_help(argv[0]);
64 if (!parsed_options) {
65 catch_unknown_options(argv[0]);
66
67 parse_prb_dims(s.prb_dims, argv[0]);
68 check_correctness(s);
69 }
70 }
71
72 return parse_last_argument();
73}
74} // namespace zeropad
75