diff --git a/include/aidge/aidge.hpp b/include/aidge/aidge.hpp index d65a46378c01b070d998b72d5d2e272b7d8f7def..bf8bcbca0fc0fe079b2d359c50e5f94f1f515977 100644 --- a/include/aidge/aidge.hpp +++ b/include/aidge/aidge.hpp @@ -21,6 +21,8 @@ #include "aidge/backend/cpu/data/GetCPUPtr.h" #include "aidge/data/Data.hpp" +#include "aidge/data/DataFormat.hpp" +#include "aidge/data/DataType.hpp" #include "aidge/data/Tensor.hpp" #include "aidge/data/Database.hpp" #include "aidge/data/DataProvider.hpp" @@ -93,6 +95,7 @@ #include "aidge/utils/Random.hpp" #include "aidge/utils/Registrar.hpp" #include "aidge/utils/Types.h" +#include "aidge/utils/logger/EnumString.hpp" #include "aidge/utils/sys_info/CoreVersionInfo.hpp" #endif /* AIDGE_IMPORTS_H_ */ diff --git a/include/aidge/data/Data.hpp b/include/aidge/data/Data.hpp index 35df9c0e0bf24ee175fe27eb7c831fcae7a700e7..156e4d8c14510d52780b512a03d95c7c01d25e53 100644 --- a/include/aidge/data/Data.hpp +++ b/include/aidge/data/Data.hpp @@ -12,90 +12,11 @@ #ifndef AIDGE_DATA_H_ #define AIDGE_DATA_H_ -#include <cstdint> -#include <fmt/format.h> #include <string> -#include <tuple> -#include <array> -#include "aidge/data/half.hpp" -#include "aidge/utils/Attributes.hpp" #include "aidge/utils/ErrorHandling.hpp" namespace Aidge { -enum class DataType { - Float64, - Float32, - Float16, - BFloat16, - Binary, - Octo_Binary, - Ternary, - Int2, - Quad_Int2, - Int3, - Dual_Int3, - Int4, - Dual_Int4, - Int5, - Int6, - Int7, - Int8, - Int16, - Int32, - Int64, - UInt2, - Quad_UInt2, - UInt3, - Dual_UInt3, - UInt4, - Dual_UInt4, - UInt5, - UInt6, - UInt7, - UInt8, - UInt16, - UInt32, - UInt64, - Any -}; - -bool isDataTypeFloatingPoint(const DataType& type); -size_t getDataTypeBitWidth(const DataType& type); - -enum class DataFormat { - Default, - NCHW, - NHWC, - CHWN, - NCDHW, - NDHWC, - CDHWN, - Any -}; - -using DataFormatTranspose = std::array<size_t, 5>; -// Permutation arrays dict to obtain DataFormat (same order as DataFormat enum) -constexpr std::array<DataFormatTranspose, 7> DataFormatTransposeDict = {{ - // Important: in this array only, dimension index must start at 1, not 0! - // (0 is the default value) - {}, - {1, 2, 3, 4}, - {1, 3, 4, 2}, - {2, 3, 4, 1}, - {1, 2, 3, 4, 5}, - {1, 3, 4, 5, 2}, - {2, 3, 4, 5, 1} -}}; - -/** - * Get the DataFormatTranspose array to transpose data from src to dst DataFormat. - * @param src Source DataFormat - * @param dst Destination DataFormat - * @return DataFormatTranspose Permutation array to achieve a transposition - * from src to dst DataFormat. -*/ -DataFormatTranspose getDataFormatTranspose(const DataFormat& src, const DataFormat& dst); class Data { public: @@ -123,79 +44,4 @@ private: }; } -namespace { - -template <Aidge::DataType D> struct WeightInterleavingType { static const Aidge::DataType type; }; -template <> const Aidge::DataType WeightInterleavingType<Aidge::DataType::Int4>::type = Aidge::DataType::Dual_Int4; -template <> const Aidge::DataType WeightInterleavingType<Aidge::DataType::UInt4>::type = Aidge::DataType::Dual_UInt4; -template <> const Aidge::DataType WeightInterleavingType<Aidge::DataType::Int3>::type = Aidge::DataType::Dual_Int3; -template <> const Aidge::DataType WeightInterleavingType<Aidge::DataType::UInt3>::type = Aidge::DataType::Dual_UInt3; -template <> const Aidge::DataType WeightInterleavingType<Aidge::DataType::Int2>::type = Aidge::DataType::Quad_Int2; -template <> const Aidge::DataType WeightInterleavingType<Aidge::DataType::UInt2>::type = Aidge::DataType::Quad_UInt2; -template <> const Aidge::DataType WeightInterleavingType<Aidge::DataType::Binary>::type = Aidge::DataType::Octo_Binary; - - -template <typename T> struct NativeType { static const Aidge::DataType type; }; -template <> const Aidge::DataType NativeType<double>::type = Aidge::DataType::Float64; -template <> const Aidge::DataType NativeType<float>::type = Aidge::DataType::Float32; -template <> const Aidge::DataType NativeType<half_float::half>::type = Aidge::DataType::Float16; -template <> const Aidge::DataType NativeType<std::int8_t>::type = Aidge::DataType::Int8; -template <> const Aidge::DataType NativeType<std::int16_t>::type = Aidge::DataType::Int16; -template <> const Aidge::DataType NativeType<std::int32_t>::type = Aidge::DataType::Int32; -template <> const Aidge::DataType NativeType<std::int64_t>::type = Aidge::DataType::Int64; -template <> const Aidge::DataType NativeType<std::uint8_t>::type = Aidge::DataType::UInt8; -template <> const Aidge::DataType NativeType<std::uint16_t>::type = Aidge::DataType::UInt16; -template <> const Aidge::DataType NativeType<std::uint32_t>::type = Aidge::DataType::UInt32; -template <> const Aidge::DataType NativeType<std::uint64_t>::type = Aidge::DataType::UInt64; - -template <> -const char* const EnumStrings<Aidge::DataType>::data[] - = {"Float64", "Float32", "Float16", "BFloat16", "Binary", "Octo_Binary", "Ternary", - "Int2", "Quad_Int2", "Int3", "Dual_Int3", "Int4", "Dual_Int4", "Int5", "Int6", "Int7", "Int8", "Int16", - "Int32", "Int64", "UInt2", "Quad_UInt2", "UInt3", "Dual_UInt3", "UInt4", "Dual_UInt4", "UInt5", "UInt6", - "UInt7", "UInt8", "UInt16", "UInt32", "UInt64", "Any"}; - -template <> -const char* const EnumStrings<Aidge::DataFormat>::data[] - = {"Default", "NCHW", "NHWC", "CHWN", "NCDHW", "NDHWC", "CDHWN", "Any"}; - -template <Aidge::DataType D> struct cpptype { - using type = void; // Placeholder -}; -template <> struct cpptype<Aidge::DataType::Float16> { using type = half_float::half; }; -template <> struct cpptype<Aidge::DataType::Float32> { using type = float; }; -template <> struct cpptype<Aidge::DataType::Float64> { using type = double; }; -template <> struct cpptype<Aidge::DataType::Int4> { using type = std::int8_t; }; -template <> struct cpptype<Aidge::DataType::UInt4> { using type = std::int8_t; }; -template <> struct cpptype<Aidge::DataType::Int3> { using type = std::int8_t; }; -template <> struct cpptype<Aidge::DataType::UInt3> { using type = std::int8_t; }; -template <> struct cpptype<Aidge::DataType::Int2> { using type = std::int8_t; }; -template <> struct cpptype<Aidge::DataType::UInt2> { using type = std::int8_t; }; -template <> struct cpptype<Aidge::DataType::Dual_Int4> { using type = std::int8_t; }; -template <> struct cpptype<Aidge::DataType::Dual_UInt4> { using type = std::int8_t; }; -template <> struct cpptype<Aidge::DataType::Dual_Int3> { using type = std::int8_t; }; -template <> struct cpptype<Aidge::DataType::Dual_UInt3> { using type = std::int8_t; }; -template <> struct cpptype<Aidge::DataType::Quad_Int2> { using type = std::int8_t; }; -template <> struct cpptype<Aidge::DataType::Quad_UInt2> { using type = std::int8_t; }; -template <> struct cpptype<Aidge::DataType::Binary> { using type = std::int8_t; }; -template <> struct cpptype<Aidge::DataType::Octo_Binary> { using type = std::int8_t; }; -template <> struct cpptype<Aidge::DataType::Int8> { using type = std::int8_t; }; -template <> struct cpptype<Aidge::DataType::Int16> { using type = std::int16_t; }; -template <> struct cpptype<Aidge::DataType::Int32> { using type = std::int32_t; }; -template <> struct cpptype<Aidge::DataType::Int64> { using type = std::int64_t; }; -template <> struct cpptype<Aidge::DataType::UInt8> { using type = std::uint8_t; }; -template <> struct cpptype<Aidge::DataType::UInt16> { using type = std::uint16_t; }; -template <> struct cpptype<Aidge::DataType::UInt32> { using type = std::uint32_t; }; -template <> struct cpptype<Aidge::DataType::UInt64> { using type = std::uint64_t; }; - -template <Aidge::DataType D> using cpptype_t = typename cpptype<D>::type; - -} - - -namespace Aidge { -inline auto format_as(DataType dt) { return EnumStrings<Aidge::DataType>::data[static_cast<int>(dt)]; } -inline auto format_as(DataFormat df) { return EnumStrings<Aidge::DataFormat>::data[static_cast<int>(df)]; } -} - #endif /* AIDGE_DATA_H_ */ diff --git a/include/aidge/data/DataFormat.hpp b/include/aidge/data/DataFormat.hpp new file mode 100644 index 0000000000000000000000000000000000000000..1f018a497963938244ce113c6a00883bb2c0976c --- /dev/null +++ b/include/aidge/data/DataFormat.hpp @@ -0,0 +1,82 @@ +/******************************************************************************** + * Copyright (c) 2023 CEA-List + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + ********************************************************************************/ + +#ifndef AIDGE_CORE_DATA_DATAFORMAT_H_ +#define AIDGE_CORE_DATA_DATAFORMAT_H_ + +#include <array> +#include <cstddef> // std::size_t + +#include "aidge/utils/logger/EnumString.hpp" + +namespace Aidge { + +/** + * @brief Enumeration of supported tensor data layouts + * + * Represents different memory layout formats for multi-dimensional tensors: + * - N: Batch size + * - C: Channels + * - H: Height + * - W: Width + * - D: Depth (for 3D tensors) + */ +enum class DataFormat { + Default, ///< Default format, implementation dependent + NCHW, ///< 4D format: [batch][channel][height][width] + NHWC, ///< 4D format: [batch][height][width][channel] + CHWN, ///< 4D format: [channel][height][width][batch] + NCDHW, ///< 5D format: [batch][channel][depth][height][width] + NDHWC, ///< 5D format: [batch][depth][height][width][channel] + CDHWN, ///< 5D format: [channel][depth][height][width][batch] + Any ///< Unspecified format +}; + +using DataFormatTranspose = std::array<std::size_t, 5>; + +/** + * @brief Dictionary of transpose operations between different formats + * + * Contains permutation arrays to convert between different data formats. + * @warning In this array only, dimension index starts at 1 + * (0 is reserved as default value). + */ +constexpr std::array<DataFormatTranspose, 7> DataFormatTransposeDict = {{ + {}, // Default + {1, 2, 3, 4}, // NCHW + {1, 3, 4, 2}, // NHWC + {2, 3, 4, 1}, // CHWN + {1, 2, 3, 4, 5}, // NCDHW + {1, 3, 4, 5, 2}, // NDHWC + {2, 3, 4, 5, 1} // CDHWN +}}; + +/** + * @brief Get the permutation array for converting between data formats + * + * @param src Source data format + * @param dst Destination data format + * @return DataFormatTranspose Permutation array to achieve the format conversion + */ +DataFormatTranspose getDataFormatTranspose(const DataFormat& src, const DataFormat& dst); + + +namespace { +template <> +const char* const EnumStrings<DataFormat>::data[] + = {"Default", "NCHW", "NHWC", "CHWN", "NCDHW", "NDHWC", "CDHWN", "Any"}; +} + +inline auto format_as(DataFormat df) { return EnumStrings<DataFormat>::data[static_cast<int>(df)]; } + +} // namespace Aidge + +#endif /* AIDGE_CORE_DATA_DATAFORMAT_H_ */ diff --git a/include/aidge/data/DataType.hpp b/include/aidge/data/DataType.hpp new file mode 100644 index 0000000000000000000000000000000000000000..859dfcb2eac5b212f84666a7226c5b3318068478 --- /dev/null +++ b/include/aidge/data/DataType.hpp @@ -0,0 +1,187 @@ +/******************************************************************************** + * Copyright (c) 2023 CEA-List + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + ********************************************************************************/ + +#ifndef AIDGE_CORE_DATA_DATATYPE_H_ +#define AIDGE_CORE_DATA_DATATYPE_H_ + +#include <cstddef> // std::size_t +#include <cstdint> + +#include "aidge/data/half.hpp" +#include "aidge/utils/logger/EnumString.hpp" + +namespace Aidge { +/** + * @brief Enumeration of data types supported by the framework + * + * Represents the various data types that can be used for computation and storage. + * This includes standard types (floating point, integers), quantized types, + * and specialized formats for neural network operations. + */ +enum class DataType { + // Floating point types + Float64, ///< 64-bit floating point (double) + Float32, ///< 32-bit floating point (float) + Float16, ///< 16-bit floating point (half) + BFloat16, ///< 16-bit brain floating point + + // Quantized binary and ternary types + Binary, ///< 1-bit binary values + Octo_Binary,///< 8x1-bit interleaved binary + Ternary, ///< Ternary values (-1,0,1) + + // Quantized integer types (2-bit) + Int2, ///< 2-bit signed integer + Quad_Int2, ///< 4x2-bit interleaved signed integer + UInt2, ///< 2-bit unsigned integer + Quad_UInt2, ///< 4x2-bit interleaved unsigned integer + + // Quantized integer types (3-bit) + Int3, ///< 3-bit signed integer + Dual_Int3, ///< 2x3-bit interleaved signed integer + UInt3, ///< 3-bit unsigned integer + Dual_UInt3, ///< 2x3-bit interleaved unsigned integer + + // Quantized integer types (4-bit) + Int4, ///< 4-bit signed integer + Dual_Int4, ///< 2x4-bit interleaved signed integer + UInt4, ///< 4-bit unsigned integer + Dual_UInt4, ///< 2x4-bit interleaved unsigned integer + + // Standard integer types + Int5, ///< 5-bit signed integer + Int6, ///< 6-bit signed integer + Int7, ///< 7-bit signed integer + Int8, ///< 8-bit signed integer + Int16, ///< 16-bit signed integer + Int32, ///< 32-bit signed integer + Int64, ///< 64-bit signed integer + + UInt5, ///< 5-bit unsigned integer + UInt6, ///< 6-bit unsigned integer + UInt7, ///< 7-bit unsigned integer + UInt8, ///< 8-bit unsigned integer + UInt16, ///< 16-bit unsigned integer + UInt32, ///< 32-bit unsigned integer + UInt64, ///< 64-bit unsigned integer + + Any ///< Unspecified type +}; + +namespace { + +template <> +const char* const EnumStrings<DataType>::data[] + = {"Float64", "Float32", "Float16", "BFloat16", "Binary", "Octo_Binary", + "Ternary", "Int2", "Quad_Int2", "UInt2", "Quad_UInt2", "Int3", + "Dual_Int3", "UInt3", "Dual_UInt3", "Int4", "Dual_Int4", "UInt4", + "Dual_UInt4", "Int5", "Int6", "Int7", "Int8", "Int16", "Int32", "Int64", + "UInt5", "UInt6", "UInt7", "UInt8", "UInt16", "UInt32", "UInt64", "Any"}; + + +// Type trait for mapping C++ types to Aidge DataType +template<typename T> +struct NativeType { + static constexpr DataType value = DataType::Any; +}; +// Helper variable template +template<typename T> +constexpr DataType NativeType_v = NativeType<T>::value; +// Specializations for native types +template<> struct NativeType<double> { static constexpr DataType value = Aidge::DataType::Float64; }; +template<> struct NativeType<float> { static constexpr DataType value = Aidge::DataType::Float32; }; +template<> struct NativeType<half_float::half> { static constexpr DataType value = Aidge::DataType::Float16; }; +template<> struct NativeType<std::int8_t> { static constexpr DataType value = Aidge::DataType::Int8; }; +template<> struct NativeType<std::int16_t> { static constexpr DataType value = Aidge::DataType::Int16; }; +template<> struct NativeType<std::int32_t> { static constexpr DataType value = Aidge::DataType::Int32; }; +template<> struct NativeType<std::int64_t> { static constexpr DataType value = Aidge::DataType::Int64; }; +template<> struct NativeType<std::uint8_t> { static constexpr DataType value = Aidge::DataType::UInt8; }; +template<> struct NativeType<std::uint16_t> { static constexpr DataType value = Aidge::DataType::UInt16; }; +template<> struct NativeType<std::uint32_t> { static constexpr DataType value = Aidge::DataType::UInt32; }; +template<> struct NativeType<std::uint64_t> { static constexpr DataType value = Aidge::DataType::UInt64; }; + + +// Type trait for mapping Aidge DataType to C++ types +template <DataType D> +struct cpptype { + using type = void; // Placeholder +}; +// Helper alias template +template <DataType D> +using cpptype_t = typename cpptype<D>::type; +// Specializations for data types +template <> struct cpptype<DataType::Float16> { using type = half_float::half; }; +template <> struct cpptype<DataType::Float32> { using type = float; }; +template <> struct cpptype<DataType::Float64> { using type = double; }; +template <> struct cpptype<DataType::Int4> { using type = std::int8_t; }; +template <> struct cpptype<DataType::UInt4> { using type = std::int8_t; }; +template <> struct cpptype<DataType::Int3> { using type = std::int8_t; }; +template <> struct cpptype<DataType::UInt3> { using type = std::int8_t; }; +template <> struct cpptype<DataType::Int2> { using type = std::int8_t; }; +template <> struct cpptype<DataType::UInt2> { using type = std::int8_t; }; +template <> struct cpptype<DataType::Dual_Int4> { using type = std::int8_t; }; +template <> struct cpptype<DataType::Dual_UInt4> { using type = std::int8_t; }; +template <> struct cpptype<DataType::Dual_Int3> { using type = std::int8_t; }; +template <> struct cpptype<DataType::Dual_UInt3> { using type = std::int8_t; }; +template <> struct cpptype<DataType::Quad_Int2> { using type = std::int8_t; }; +template <> struct cpptype<DataType::Quad_UInt2> { using type = std::int8_t; }; +template <> struct cpptype<DataType::Binary> { using type = std::int8_t; }; +template <> struct cpptype<DataType::Octo_Binary> { using type = std::int8_t; }; +template <> struct cpptype<DataType::Int8> { using type = std::int8_t; }; +template <> struct cpptype<DataType::Int16> { using type = std::int16_t; }; +template <> struct cpptype<DataType::Int32> { using type = std::int32_t; }; +template <> struct cpptype<DataType::Int64> { using type = std::int64_t; }; +template <> struct cpptype<DataType::UInt8> { using type = std::uint8_t; }; +template <> struct cpptype<DataType::UInt16> { using type = std::uint16_t; }; +template <> struct cpptype<DataType::UInt32> { using type = std::uint32_t; }; +template <> struct cpptype<DataType::UInt64> { using type = std::uint64_t; }; + + +// Type trait for mapping DataType to their interleaved variants +template<DataType D> +struct WeightInterleavedType { + static const DataType value = DataType::Any; +}; +// Helper varible template +template<DataType D> +constexpr DataType WeightInterleavedType_v = WeightInterleavedType<D>::value; +// Specializations for interleaved types +template<> struct WeightInterleavedType<DataType::Int4> { static constexpr DataType value = DataType::Dual_Int4; }; +template<> struct WeightInterleavedType<DataType::UInt4> { static constexpr DataType value = DataType::Dual_UInt4; }; +template<> struct WeightInterleavedType<DataType::Int3> { static constexpr DataType value = DataType::Dual_Int3; }; +template<> struct WeightInterleavedType<DataType::UInt3> { static constexpr DataType value = DataType::Dual_UInt3; }; +template<> struct WeightInterleavedType<DataType::Int2> { static constexpr DataType value = DataType::Quad_Int2; }; +template<> struct WeightInterleavedType<DataType::UInt2> { static constexpr DataType value = DataType::Quad_UInt2; }; +template<> struct WeightInterleavedType<DataType::Binary> { static constexpr DataType value = DataType::Octo_Binary; }; + +} + +/** + * @brief Check if a data type is floating point + * @param type The type to check + * @return true if the type is floating point, false otherwise + */ +constexpr bool isFloatingPoint(const DataType& type) noexcept { + return type == DataType::Float64 || + type == DataType::Float32 || + type == DataType::Float16 || + type == DataType::BFloat16; +} + +std::size_t getDataTypeBitWidth(const DataType& type); + +inline auto format_as(DataType dt) { + return EnumStrings<DataType>::data[static_cast<int>(dt)]; +} + +} // namespace Aidge + +#endif /* AIDGE_CORE_DATA_DATATYPE_H_ */ diff --git a/include/aidge/utils/Attributes.hpp b/include/aidge/utils/Attributes.hpp index f73de2ea31681a60c85229102a9b2ebbce4d3c3e..e25485fe059ddbf2d5eb72e3aa1c79457633a467 100644 --- a/include/aidge/utils/Attributes.hpp +++ b/include/aidge/utils/Attributes.hpp @@ -26,14 +26,6 @@ namespace py = pybind11; #endif -namespace { -// This is the type that will hold all the strings. Each enumerate type will -// declare its own specialization. -template <typename T> struct EnumStrings { - static const char* const data[]; -}; -} - namespace Aidge { template<class T, std::size_t N> constexpr std::size_t size(T (&)[N]) { return N; } diff --git a/include/aidge/utils/Log.hpp b/include/aidge/utils/Log.hpp index 8c576fc811dcfb74168e752b0b7dc87ad2c1a482..91619b15be572d77b83e339a3aac92b4576600ce 100644 --- a/include/aidge/utils/Log.hpp +++ b/include/aidge/utils/Log.hpp @@ -22,7 +22,7 @@ #include <pybind11/pybind11.h> #endif -#include "aidge/utils/Attributes.hpp" +#include "aidge/utils/logger/EnumString.hpp" namespace Aidge { diff --git a/include/aidge/utils/logger/EnumString.hpp b/include/aidge/utils/logger/EnumString.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6091d8bf50c1de37fef351c20c710b2f43e2f545 --- /dev/null +++ b/include/aidge/utils/logger/EnumString.hpp @@ -0,0 +1,23 @@ +/******************************************************************************** + * Copyright (c) 2023 CEA-List + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + ********************************************************************************/ + +#ifndef AIDGE_CORE_UTILS_LOGGER_ENUMSTRING_H_ +#define AIDGE_CORE_UTILS_LOGGER_ENUMSTRING_H_ + +namespace { +// This is the type that will hold all the strings. Each enumerate type will +// declare its own specialization. +template <typename T> struct EnumStrings { + static const char* const data[]; +}; +} + +#endif /* AIDGE_CORE_UTILS_LOGGER_ENUMSTRING_H_ */ diff --git a/src/data/Data.cpp b/src/data/DataFormat.cpp similarity index 50% rename from src/data/Data.cpp rename to src/data/DataFormat.cpp index 865b4ff2dcff68753fb5a4cc9cafccdd129e3c8a..fcded91bde1e0f5c579631c52759de23de40f491 100644 --- a/src/data/Data.cpp +++ b/src/data/DataFormat.cpp @@ -9,51 +9,7 @@ * ********************************************************************************/ -#include "aidge/data/Data.hpp" - -bool Aidge::isDataTypeFloatingPoint(const DataType& type) { - switch (type) { - case DataType::Float64: - case DataType::Float32: - case DataType::Float16: - case DataType::BFloat16: return true; - default: return false; - } - return false; -} - -size_t Aidge::getDataTypeBitWidth(const DataType& type) { - switch (type) { - case DataType::Float64: return 64; - case DataType::Float32: return 32; - case DataType::Float16: return 16; - case DataType::BFloat16: return 16; - case DataType::Binary: return 1; - case DataType::Ternary: return 2; - case DataType::Int2: return 2; - case DataType::Int3: return 3; - case DataType::Int4: return 4; - case DataType::Int5: return 5; - case DataType::Int6: return 6; - case DataType::Int7: return 7; - case DataType::Int8: return 8; - case DataType::Int16: return 16; - case DataType::Int32: return 32; - case DataType::Int64: return 64; - case DataType::UInt2: return 2; - case DataType::UInt3: return 3; - case DataType::UInt4: return 4; - case DataType::UInt5: return 5; - case DataType::UInt6: return 6; - case DataType::UInt7: return 7; - case DataType::UInt8: return 8; - case DataType::UInt16: return 16; - case DataType::UInt32: return 32; - case DataType::UInt64: return 64; - default: return 0; - } - return 0; -} +#include "aidge/data/DataFormat.hpp" Aidge::DataFormatTranspose Aidge::getDataFormatTranspose(const DataFormat& src, const DataFormat& dst) { // Permutation array from default format to src format diff --git a/src/data/DataType.cpp b/src/data/DataType.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d012d2f45a26541a4a21714ffd2c0236e878559d --- /dev/null +++ b/src/data/DataType.cpp @@ -0,0 +1,46 @@ +/******************************************************************************** + * Copyright (c) 2023 CEA-List + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + ********************************************************************************/ + +#include "aidge/data/DataType.hpp" + +#include <cstddef> // std::size_t + +std::size_t Aidge::getDataTypeBitWidth(const Aidge::DataType& type) { + switch (type) { + case DataType::Float64: return 64; + case DataType::Float32: return 32; + case DataType::Float16: return 16; + case DataType::BFloat16: return 16; + case DataType::Binary: return 1; + case DataType::Ternary: return 2; + case DataType::Int2: return 2; + case DataType::Int3: return 3; + case DataType::Int4: return 4; + case DataType::Int5: return 5; + case DataType::Int6: return 6; + case DataType::Int7: return 7; + case DataType::Int8: return 8; + case DataType::Int16: return 16; + case DataType::Int32: return 32; + case DataType::Int64: return 64; + case DataType::UInt2: return 2; + case DataType::UInt3: return 3; + case DataType::UInt4: return 4; + case DataType::UInt5: return 5; + case DataType::UInt6: return 6; + case DataType::UInt7: return 7; + case DataType::UInt8: return 8; + case DataType::UInt16: return 16; + case DataType::UInt32: return 32; + case DataType::UInt64: return 64; + default: return 0; + } +} \ No newline at end of file