Grok 12.0.1
print.h
Go to the documentation of this file.
1// Copyright 2022 Google LLC
2// SPDX-License-Identifier: Apache-2.0
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#ifndef HWY_PRINT_H_
17#define HWY_PRINT_H_
18
19// Helpers for printing vector lanes.
20
21#include <stddef.h>
22#include <stdio.h>
23
24#include "hwy/base.h"
25#include "hwy/highway_export.h"
26
27namespace hwy {
28
29namespace detail {
30
31// For implementing value comparisons etc. as type-erased functions to reduce
32// template bloat.
33struct TypeInfo {
34 size_t sizeof_t;
37 bool is_bf16;
38};
39
40template <typename T>
42 TypeInfo info;
43 info.sizeof_t = sizeof(T);
44 info.is_float = IsFloat<T>();
45 info.is_signed = IsSigned<T>();
46 info.is_bf16 = IsSame<T, bfloat16_t>();
47 return info;
48}
49
50HWY_DLLEXPORT void TypeName(const TypeInfo& info, size_t N, char* string100);
51HWY_DLLEXPORT void ToString(const TypeInfo& info, const void* ptr,
52 char* string100);
53
54HWY_DLLEXPORT void PrintArray(const TypeInfo& info, const char* caption,
55 const void* array_void, size_t N,
56 size_t lane_u = 0, size_t max_lanes = 7);
57
58} // namespace detail
59
60template <typename T>
61HWY_NOINLINE void PrintValue(T value) {
62 char str[100];
63 detail::ToString(hwy::detail::MakeTypeInfo<T>(), &value, str);
64 fprintf(stderr, "%s,", str);
65}
66
67template <typename T>
68HWY_NOINLINE void PrintArray(const T* value, size_t count) {
69 detail::PrintArray(hwy::detail::MakeTypeInfo<T>(), "", value, count, 0,
70 count);
71}
72
73} // namespace hwy
74
75#endif // HWY_PRINT_H_
#define HWY_NOINLINE
Definition base.h:103
#define HWY_INLINE
Definition base.h:101
#define HWY_DLLEXPORT
Definition highway_export.h:13
HWY_DLLEXPORT void TypeName(const TypeInfo &info, size_t N, char *string100)
HWY_DLLEXPORT void PrintArray(const TypeInfo &info, const char *caption, const void *array_void, size_t N, size_t lane_u=0, size_t max_lanes=7)
HWY_DLLEXPORT void ToString(const TypeInfo &info, const void *ptr, char *string100)
HWY_INLINE TypeInfo MakeTypeInfo()
Definition print.h:41
Definition abort.h:8
HWY_NOINLINE void PrintArray(const T *value, size_t count)
Definition print.h:68
HWY_NOINLINE void PrintValue(T value)
Definition print.h:61
Definition print.h:33
bool is_bf16
Definition print.h:37
bool is_float
Definition print.h:35
bool is_signed
Definition print.h:36
size_t sizeof_t
Definition print.h:34