Elffuss BraidHub

kikocis/kleidiai public

main · 2.1 KiBRawPermalink
1//
2// SPDX-FileCopyrightText: Copyright 2024-2026 Arm Limited and/or its affiliates <open-source-office@arm.com>
3//
4// SPDX-License-Identifier: Apache-2.0
5//
6
7#pragma once
8
9#include <cstdint>
10#include <iostream>
11#include <string_view>
12#include <type_traits>
13
14#include "test/common/int2.hpp"
15#include "test/common/int4.hpp"
16
17#define KAI_LOGE(...) kai::test::detail::log("ERROR", __VA_ARGS__)
18
19namespace kai::test::detail {
20
21/// Prints the specified value to standard error.
22///
23/// @tparam T Data type.
24///
25/// @param[in] value Value to be printed out.
26template <typename T>
27void write_log_content(T&& value) {
28 using TT = std::decay_t<decltype(value)>;
29
30 if constexpr (std::is_same_v<TT, uint8_t>) {
31 std::cerr << static_cast<uint32_t>(value);
32 } else if constexpr (std::is_same_v<TT, int8_t>) {
33 std::cerr << static_cast<int32_t>(value);
34 } else if constexpr (std::is_same_v<TT, UInt4>) {
35 std::cerr << static_cast<int32_t>(value);
36 } else if constexpr (std::is_same_v<TT, Int4>) {
37 std::cerr << static_cast<int32_t>(value);
38 } else if constexpr (std::is_same_v<TT, Int2>) {
39 std::cerr << static_cast<int32_t>(value);
40 } else if constexpr (std::is_same_v<TT, UInt2>) {
41 std::cerr << static_cast<int32_t>(value);
42 } else {
43 std::cerr << value;
44 }
45}
46
47/// Prints the specified values to standard error.
48///
49/// @tparam T Data type of the first value.
50/// @tparam Ts Data types of the subsequent values.
51///
52/// @param[in] value First value to be printed out.
53/// @param[in] others Subsequent values to be printed out.
54template <typename T, typename... Ts>
55void write_log_content(T&& value, Ts&&... others) {
56 write_log_content(std::forward<T>(value));
57 write_log_content(std::forward<Ts>(others)...);
58}
59
60/// Prints the log to standard error.
61///
62/// @tparam Ts Data types of values to be printed out.
63///
64/// @param[in] level Severity level.
65/// @param[in] args Values to be printed out.
66template <typename... Ts>
67void log(std::string_view level, Ts&&... args) {
68 std::cerr << level << " | ";
69 write_log_content(std::forward<Ts>(args)...);
70 std::cerr << "\n";
71}
72
73} // namespace kai::test::detail