1/*******************************************************************************
2* Copyright 2018-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 COMMON_VERBOSE_HPP
18#define COMMON_VERBOSE_HPP
19
20#include <cinttypes>
21#include <mutex>
22#include <stdio.h>
23
24#include "c_types_map.hpp"
25#include "oneapi/dnnl/dnnl_debug.h"
26#include "utils.hpp"
27#include "z_magic.hpp"
28
29namespace dnnl {
30namespace impl {
31
32struct verbose_t {
33 int level;
34};
35
36int get_verbose();
37bool get_verbose_timestamp();
38double get_msec();
39
40/// A container for primitive desc verbose string.
41struct primitive_desc_t;
42struct pd_info_t {
43 pd_info_t() = default;
44 pd_info_t(const pd_info_t &rhs)
45 : str_(rhs.str_), is_initialized_(rhs.is_initialized_) {}
46 pd_info_t &operator=(const pd_info_t &rhs) {
47 is_initialized_ = rhs.is_initialized_;
48 str_ = rhs.str_;
49 return *this;
50 }
51
52 const char *c_str() const { return str_.c_str(); }
53 bool is_initialized() const { return is_initialized_; }
54
55 void init(engine_t *engine, const primitive_desc_t *pd);
56
57private:
58 std::string str_;
59
60#if defined(DISABLE_VERBOSE)
61 bool is_initialized_ = true; // no verbose -> info is always ready
62#else
63 bool is_initialized_ = false;
64#endif
65
66 // Alas, `std::once_flag` cannot be manually set and/or copied (in terms of
67 // its state). Hence, when `pd_info_t` is copied the `initialization_flag_`
68 // is always reset. To avoid re-initialization we use an extra
69 // `is_initialized_` flag, that should be checked before calling `init()`.
70 std::once_flag initialization_flag_;
71};
72
73std::string md2fmt_str(const memory_desc_t *md);
74std::string md2dim_str(const memory_desc_t *md);
75
76} // namespace impl
77} // namespace dnnl
78
79#endif
80