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 | #ifndef ZEROPAD_HPP |
18 | #define ZEROPAD_HPP |
19 | |
20 | #include "oneapi/dnnl/dnnl.h" |
21 | |
22 | #include "common.hpp" |
23 | #include "dnn_types.hpp" |
24 | #include "dnnl_common.hpp" |
25 | #include "utils/perf_report.hpp" |
26 | #include "utils/settings.hpp" |
27 | |
28 | namespace zeropad { |
29 | |
30 | struct settings_t : public base_settings_t { |
31 | settings_t() = default; |
32 | |
33 | // ctor to save certain fields from resetting |
34 | settings_t(const char *perf_template) : settings_t() { |
35 | this->perf_template = perf_template; |
36 | } |
37 | |
38 | prb_dims_t prb_dims; |
39 | |
40 | std::vector<dnnl_data_type_t> dt {dnnl_f32}; |
41 | std::vector<std::string> tag {tag::abx}; |
42 | |
43 | const char *perf_template_csv() const { |
44 | static const std::string args = "%dt%,%tag%" ; |
45 | return perf_template_csv_base(args); |
46 | } |
47 | |
48 | void reset() { *this = settings_t(perf_template); } |
49 | }; |
50 | |
51 | struct prb_t : public prb_dims_t { |
52 | prb_t(const prb_dims_t &prb_dims, dnnl_data_type_t dt, |
53 | const std::string &tag) |
54 | : prb_dims_t(prb_dims), dt(dt), tag(tag) {} |
55 | ~prb_t() {} |
56 | |
57 | dnnl_data_type_t dt; |
58 | std::string tag; |
59 | }; |
60 | std::ostream &operator<<(std::ostream &s, const prb_t &prb); |
61 | |
62 | struct perf_report_t : public base_perf_report_t { |
63 | perf_report_t(const prb_t *prb, const char *perf_template) |
64 | : base_perf_report_t(perf_template) |
65 | , p_(prb) |
66 | , tag_(normalize_tag(p_->tag, p_->ndims)) {} |
67 | |
68 | void dump_desc(std::ostream &s) const override { |
69 | s << static_cast<const prb_dims_t &>(*p_); |
70 | } |
71 | |
72 | void dump_desc_csv(std::ostream &s) const override { dump_desc(s); } |
73 | |
74 | const std::string *name() const override { return &p_->name; } |
75 | const dnnl_data_type_t *dt() const override { return &p_->dt; } |
76 | const std::string *tag() const override { return &tag_; } |
77 | |
78 | private: |
79 | const prb_t *p_; |
80 | std::string tag_; |
81 | }; |
82 | |
83 | int doit(const prb_t *prb, res_t *res); |
84 | int bench(int argc, char **argv); |
85 | |
86 | } // namespace zeropad |
87 | |
88 | #endif |
89 | |