diff --git a/dali/c_api/c_api.cc b/dali/c_api/c_api.cc index 13eabadadbb..3e97ad92b9e 100644 --- a/dali/c_api/c_api.cc +++ b/dali/c_api/c_api.cc @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "dali/c_api.h" // NOLINT [build/include] - #include #include #include @@ -34,6 +32,8 @@ #include "dali/pipeline/data/copy_to_external.h" #include "dali/pipeline/operator/checkpointing/checkpoint.h" +#include "dali/c_api.h" // NOLINT [build/include] + using dali::AccessOrder; using dali::CPUBackend; using dali::GPUBackend; diff --git a/dali/pipeline/data/types.h b/dali/pipeline/data/types.h index cad79254b3d..2fb19bddfd7 100644 --- a/dali/pipeline/data/types.h +++ b/dali/pipeline/data/types.h @@ -28,6 +28,7 @@ #include #include #include +#include "dali/core/dali_data_type.h" #include "dali/core/util.h" #include "dali/core/common.h" #include "dali/core/spinlock.h" @@ -87,212 +88,18 @@ inline Copier GetCopier() { } // namespace detail -/** - * @brief Enum identifiers for the different data types that - * the pipeline can output. - * - * IMPORTANT: This enum is used for serialization of DALI Pipeline. Therefore, any change made to - * this enum must retain backward compatibility. If the backward compatibility is broken - * (e.g. values of enumerations are shuffled), the already serialized pipelines - * around the globe will stop working correctly. - */ -enum DALIDataType : int { - DALI_NO_TYPE = -1, - DALI_UINT8 = 0, - DALI_UINT16 = 1, - DALI_UINT32 = 2, - DALI_UINT64 = 3, - DALI_INT8 = 4, - DALI_INT16 = 5, - DALI_INT32 = 6, - DALI_INT64 = 7, - DALI_FLOAT16 = 8, - DALI_FLOAT = 9, - DALI_FLOAT64 = 10, - DALI_BOOL = 11, - DALI_STRING = 12, - DALI_BOOL_VEC = 13, - DALI_INT_VEC = 14, - DALI_STRING_VEC = 15, - DALI_FLOAT_VEC = 16, -#ifdef DALI_BUILD_PROTO3 - DALI_TF_FEATURE = 17, - DALI_TF_FEATURE_VEC = 18, - DALI_TF_FEATURE_DICT = 19, -#endif // DALI_BUILD_PROTO3 - DALI_IMAGE_TYPE = 20, - DALI_DATA_TYPE = 21, - DALI_INTERP_TYPE = 22, - DALI_TENSOR_LAYOUT = 23, - DALI_PYTHON_OBJECT = 24, - DALI_TENSOR_LAYOUT_VEC = 25, - DALI_DATA_TYPE_VEC = 26, - DALI_NUM_BUILTIN_TYPES, - DALI_CUSTOM_TYPE_START = 1001 -}; - -inline const char *GetBuiltinTypeName(DALIDataType t) { - switch (t) { - case DALI_NO_TYPE: - return ""; - break; - case DALI_UINT8: - return "uint8"; - break; - case DALI_UINT16: - return "uint16"; - break; - case DALI_UINT32: - return "uint32"; - break; - case DALI_UINT64: - return "uint64"; - break; - case DALI_INT8: - return "int8"; - break; - case DALI_INT16: - return "int16"; - break; - case DALI_INT32: - return "int32"; - break; - case DALI_INT64: - return "int64"; - break; - case DALI_FLOAT16: - return "float16"; - break; - case DALI_FLOAT: - return "float"; - break; - case DALI_FLOAT64: - return "double"; - break; - case DALI_BOOL: - return "bool"; - break; - case DALI_STRING: - return "string"; - break; - case DALI_BOOL_VEC: - return "list of bool"; - break; - case DALI_INT_VEC: - return "list of int"; - break; - case DALI_STRING_VEC: - return "list of string"; - break; - case DALI_FLOAT_VEC: - return "list of float"; - break; -#ifdef DALI_BUILD_PROTO3 - case DALI_TF_FEATURE: - return "TFUtil::Feature"; - break; - case DALI_TF_FEATURE_VEC: - return "list of TFUtil::Feature"; - break; - case DALI_TF_FEATURE_DICT: - return "dictionary of TFUtil::Feature"; - break; -#endif // DALI_BUILD_PROTO3 - case DALI_IMAGE_TYPE: - return "DALIImageType"; - break; - case DALI_DATA_TYPE: - return "DALIDataType"; - break; - case DALI_INTERP_TYPE: - return "DALIInterpType"; - break; - case DALI_TENSOR_LAYOUT: - return "TensorLayout"; - break; - case DALI_PYTHON_OBJECT: - return "Python object"; - break; - case DALI_TENSOR_LAYOUT_VEC: - return "list of TensorLayout"; - break; - case DALI_DATA_TYPE_VEC: - return "list of DALIDataType"; - default: - return nullptr; - } -} +using DALIDataType = daliDataType_t; inline std::string to_string(DALIDataType dtype); inline std::ostream &operator<<(std::ostream &, DALIDataType dtype); -constexpr bool IsFloatingPoint(DALIDataType type) { - switch (type) { - case DALI_FLOAT16: - case DALI_FLOAT: - case DALI_FLOAT64: - return true; - default: - return false; - } -} - -constexpr bool IsIntegral(DALIDataType type) { - switch (type) { - case DALI_BOOL: - case DALI_UINT8: - case DALI_UINT16: - case DALI_UINT32: - case DALI_UINT64: - case DALI_INT8: - case DALI_INT16: - case DALI_INT32: - case DALI_INT64: - return true; - default: - return false; - } -} - -constexpr bool IsSigned(DALIDataType type) { - switch (type) { - case DALI_FLOAT16: - case DALI_FLOAT: - case DALI_FLOAT64: - case DALI_INT8: - case DALI_INT16: - case DALI_INT32: - case DALI_INT64: - return true; - default: - return false; - } -} +constexpr auto GetBuiltinTypeName = daliDataTypeName; +constexpr auto IsFloatingPoint = daliDataTypeIsFloatingPoint; +constexpr auto IsIntegral = daliDataTypeIsIntegral; +constexpr auto IsSigned = daliDataTypeIsSigned; +constexpr auto IsUnsigned = daliDataTypeIsUnsigned; +constexpr auto IsEnum = daliDataTypeIsEnum; -constexpr bool IsUnsigned(DALIDataType type) { - switch (type) { - case DALI_BOOL: - case DALI_UINT8: - case DALI_UINT16: - case DALI_UINT32: - case DALI_UINT64: - return true; - default: - return false; - } -} - - -constexpr bool IsEnum(DALIDataType type) { - switch (type) { - case DALI_DATA_TYPE: - case DALI_IMAGE_TYPE: - case DALI_INTERP_TYPE: - return true; - default: - return false; - } -} template struct id2type_helper; diff --git a/include/dali/c_api.h b/include/dali/c_api.h index 56d62d8c463..d1ded2d2ac2 100644 --- a/include/dali/c_api.h +++ b/include/dali/c_api.h @@ -18,6 +18,7 @@ #include #include #include "dali/core/api_helper.h" +#include "dali/core/dali_data_type.h" // Trick to bypass gcc4.9 old ABI name mangling used by TF #ifdef __cplusplus @@ -43,21 +44,7 @@ typedef enum { DALI_BACKEND_MIXED = 2 } dali_backend_t; -typedef enum { - DALI_NO_TYPE = -1, - DALI_UINT8 = 0, - DALI_UINT16 = 1, - DALI_UINT32 = 2, - DALI_UINT64 = 3, - DALI_INT8 = 4, - DALI_INT16 = 5, - DALI_INT32 = 6, - DALI_INT64 = 7, - DALI_FLOAT16 = 8, - DALI_FLOAT = 9, - DALI_FLOAT64 = 10, - DALI_BOOL = 11, -} dali_data_type_t; +typedef daliDataType_t dali_data_type_t; typedef enum { DALI_EXEC_IS_PIPELINED = 1, diff --git a/include/dali/core/dali_data_type.h b/include/dali/core/dali_data_type.h new file mode 100644 index 00000000000..9b2b5b03472 --- /dev/null +++ b/include/dali/core/dali_data_type.h @@ -0,0 +1,248 @@ +// Copyright (c) 2017-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef DALI_CORE_DALI_DATA_TYPE_H_ +#define DALI_CORE_DALI_DATA_TYPE_H_ + +#ifdef __cplusplus +#define DALI_CONSTEXPR constexpr + +#include +#include + +using daliBool = std::conditional_t; + +extern "C" { +#else +#define DALI_CONSTEXPR inline +#include +#include + +typedef uint8_t daliBool; +#endif + +/** + * @brief Enum identifiers for the different data types that + * the pipeline can output. + * + * IMPORTANT: This enum is used for serialization of DALI Pipeline. Therefore, any change made to + * this enum must retain backward compatibility. If the backward compatibility is broken + * (e.g. values of enumerations are shuffled), the already serialized pipelines + * around the globe will stop working correctly. + */ +typedef enum _DALIDataType { + DALI_NO_TYPE = -1, + DALI_UINT8 = 0, + DALI_UINT16 = 1, + DALI_UINT32 = 2, + DALI_UINT64 = 3, + DALI_INT8 = 4, + DALI_INT16 = 5, + DALI_INT32 = 6, + DALI_INT64 = 7, + DALI_FLOAT16 = 8, + DALI_FLOAT = 9, + DALI_FLOAT64 = 10, + DALI_BOOL = 11, + DALI_STRING = 12, + DALI_BOOL_VEC = 13, + DALI_INT_VEC = 14, + DALI_STRING_VEC = 15, + DALI_FLOAT_VEC = 16, + DALI_TF_FEATURE = 17, + DALI_TF_FEATURE_VEC = 18, + DALI_TF_FEATURE_DICT = 19, + DALI_IMAGE_TYPE = 20, + DALI_DATA_TYPE = 21, + DALI_INTERP_TYPE = 22, + DALI_TENSOR_LAYOUT = 23, + DALI_PYTHON_OBJECT = 24, + DALI_TENSOR_LAYOUT_VEC = 25, + DALI_DATA_TYPE_VEC = 26, + DALI_NUM_BUILTIN_TYPES, + DALI_CUSTOM_TYPE_START = 1001, + DALI_DATA_TYPE_FORCE_INT32 = 0x7fffffff +} daliDataType_t; + +/** Returns a display name of a DALI built-in type. + * + * @return A pointer to a string constant containing the name or NULL if the type is unknown. + */ +inline const char *daliDataTypeName(daliDataType_t t) { + switch (t) { + case DALI_NO_TYPE: + return ""; + break; + case DALI_UINT8: + return "uint8"; + break; + case DALI_UINT16: + return "uint16"; + break; + case DALI_UINT32: + return "uint32"; + break; + case DALI_UINT64: + return "uint64"; + break; + case DALI_INT8: + return "int8"; + break; + case DALI_INT16: + return "int16"; + break; + case DALI_INT32: + return "int32"; + break; + case DALI_INT64: + return "int64"; + break; + case DALI_FLOAT16: + return "float16"; + break; + case DALI_FLOAT: + return "float"; + break; + case DALI_FLOAT64: + return "double"; + break; + case DALI_BOOL: + return "bool"; + break; + case DALI_STRING: + return "string"; + break; + case DALI_BOOL_VEC: + return "list of bool"; + break; + case DALI_INT_VEC: + return "list of int"; + break; + case DALI_STRING_VEC: + return "list of string"; + break; + case DALI_FLOAT_VEC: + return "list of float"; + break; + case DALI_TF_FEATURE: + return "TFUtil::Feature"; + break; + case DALI_TF_FEATURE_VEC: + return "list of TFUtil::Feature"; + break; + case DALI_TF_FEATURE_DICT: + return "dictionary of TFUtil::Feature"; + break; + case DALI_IMAGE_TYPE: + return "DALIImageType"; + break; + case DALI_DATA_TYPE: + return "DALIDataType"; + break; + case DALI_INTERP_TYPE: + return "DALIInterpType"; + break; + case DALI_TENSOR_LAYOUT: + return "TensorLayout"; + break; + case DALI_PYTHON_OBJECT: + return "Python object"; + break; + case DALI_TENSOR_LAYOUT_VEC: + return "list of TensorLayout"; + break; + case DALI_DATA_TYPE_VEC: + return "list of DALIDataType"; + default: + return 0; + } +} + +/** Returns `true` if the `type` is a floating point type. */ +DALI_CONSTEXPR bool daliDataTypeIsFloatingPoint(daliDataType_t type) { + switch (type) { + case DALI_FLOAT16: + case DALI_FLOAT: + case DALI_FLOAT64: + return true; + default: + return false; + } +} + +/** Returns `true` if the `type` is an integral type. */ +DALI_CONSTEXPR bool daliDataTypeIsIntegral(daliDataType_t type) { + switch (type) { + case DALI_BOOL: + case DALI_UINT8: + case DALI_UINT16: + case DALI_UINT32: + case DALI_UINT64: + case DALI_INT8: + case DALI_INT16: + case DALI_INT32: + case DALI_INT64: + return true; + default: + return false; + } +} + +/** Returns `true` if the `type` has a sign (includes floating point types). */ +DALI_CONSTEXPR bool daliDataTypeIsSigned(daliDataType_t type) { + switch (type) { + case DALI_FLOAT16: + case DALI_FLOAT: + case DALI_FLOAT64: + case DALI_INT8: + case DALI_INT16: + case DALI_INT32: + case DALI_INT64: + return true; + default: + return false; + } +} + +/** Returns `true` if the `type` is an unsigned integer (includes boolean). */ +DALI_CONSTEXPR bool daliDataTypeIsUnsigned(daliDataType_t type) { + switch (type) { + case DALI_BOOL: + case DALI_UINT8: + case DALI_UINT16: + case DALI_UINT32: + case DALI_UINT64: + return true; + default: + return false; + } +} + +/** Returns `true` if the `type` is an enumerated type. */ +DALI_CONSTEXPR bool daliDataTypeIsEnum(daliDataType_t type) { + switch (type) { + case DALI_DATA_TYPE: + case DALI_IMAGE_TYPE: + case DALI_INTERP_TYPE: + return true; + default: + return false; + } +} + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // DALI_CORE_DALI_DATA_TYPE_H_ diff --git a/plugins/video/pkg_src/src/decoder/video_decoder_mixed.cc b/plugins/video/pkg_src/src/decoder/video_decoder_mixed.cc index 02d3bbb6761..b49ccdc9824 100644 --- a/plugins/video/pkg_src/src/decoder/video_decoder_mixed.cc +++ b/plugins/video/pkg_src/src/decoder/video_decoder_mixed.cc @@ -63,7 +63,7 @@ bool VideoDecoderMixed::SetupImpl(std::vector &output_desc, } output_desc.resize(1); output_desc[0].shape = sh; - output_desc[0].type = dali::DALI_UINT8; + output_desc[0].type = DALI_UINT8; return true; } diff --git a/plugins/video/pkg_src/src/decoder/video_decoder_mixed.h b/plugins/video/pkg_src/src/decoder/video_decoder_mixed.h index 0da6ea4f1c6..2a4e6990db9 100644 --- a/plugins/video/pkg_src/src/decoder/video_decoder_mixed.h +++ b/plugins/video/pkg_src/src/decoder/video_decoder_mixed.h @@ -39,7 +39,7 @@ class VideoDecoderMixed : public dali::Operator { void ValidateInput(const dali::Workspace &ws) { const auto &input = ws.Input(0); - DALI_ENFORCE(input.type() == dali::DALI_UINT8, + DALI_ENFORCE(input.type() == DALI_UINT8, "Type of the input buffer must be uint8."); DALI_ENFORCE(input.sample_dim() == 1, "Input buffer must be 1-dimensional.");