From f6e2c00c309ca2dd05c80cf38f5deb645d110ed6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Zientkiewicz?= Date: Fri, 13 Dec 2024 13:26:27 +0100 Subject: [PATCH] Move operator<< and to_string for DALIDataType to the global namespace. (#5748) Fix ADL for operator<< in gcc>=12 and clang. Signed-off-by: Michal Zientkiewicz --- dali/pipeline/data/types.h | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/dali/pipeline/data/types.h b/dali/pipeline/data/types.h index 2fb19bddfd7..7a321648938 100644 --- a/dali/pipeline/data/types.h +++ b/dali/pipeline/data/types.h @@ -52,6 +52,9 @@ #define DALI_REGISTER_TYPE_IMPL(...) #endif +inline std::string to_string(daliDataType_t dtype); +inline std::ostream &operator<<(std::ostream &, daliDataType_t dtype); + namespace dali { class TensorLayout; @@ -90,9 +93,6 @@ inline Copier GetCopier() { using DALIDataType = daliDataType_t; -inline std::string to_string(DALIDataType dtype); -inline std::ostream &operator<<(std::ostream &, DALIDataType dtype); - constexpr auto GetBuiltinTypeName = daliDataTypeName; constexpr auto IsFloatingPoint = daliDataTypeIsFloatingPoint; constexpr auto IsIntegral = daliDataTypeIsIntegral; @@ -412,14 +412,6 @@ inline std::string_view TypeName(DALIDataType dtype) { return ""; } -inline std::string to_string(DALIDataType dtype) { - std::string_view name = TypeName(dtype); - if (name == "") - return "unknown type: " + std::to_string(static_cast(dtype)); - else - return std::string(name); -} - // Used to define a type for use in dali. Inserts the type into the // TypeTable w/ a unique id and creates a method to get the name of // the type as a string. This does not work for non-fundamental types, @@ -465,8 +457,22 @@ DALI_REGISTER_TYPE(std::vector, DALI_FLOAT_VEC); DALI_REGISTER_TYPE(std::vector, DALI_TENSOR_LAYOUT_VEC); DALI_REGISTER_TYPE(std::vector, DALI_DATA_TYPE_VEC); -inline std::ostream &operator<<(std::ostream &os, DALIDataType dtype) { - std::string_view name = TypeName(dtype); +#define DALI_INTEGRAL_TYPES uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t +#define DALI_NUMERIC_TYPES DALI_INTEGRAL_TYPES, float, double +#define DALI_NUMERIC_TYPES_FP16 DALI_NUMERIC_TYPES, float16 + +} // namespace dali + +inline std::string to_string(daliDataType_t dtype) { + std::string_view name = dali::TypeName(dtype); + if (name == "") + return "unknown type: " + std::to_string(static_cast(dtype)); + else + return std::string(name); +} + +inline std::ostream &operator<<(std::ostream &os, daliDataType_t dtype) { + std::string_view name = dali::TypeName(dtype); if (name == "") { // Use string concatenation so that the result is the same as in to_string, unaffected by // formatting & other settings in `os`. @@ -476,10 +482,5 @@ inline std::ostream &operator<<(std::ostream &os, DALIDataType dtype) { } } -#define DALI_INTEGRAL_TYPES uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t -#define DALI_NUMERIC_TYPES DALI_INTEGRAL_TYPES, float, double -#define DALI_NUMERIC_TYPES_FP16 DALI_NUMERIC_TYPES, float16 - -} // namespace dali #endif // DALI_PIPELINE_DATA_TYPES_H_