NVIDIA Morpheus (24.06)
(Latest Version)

Program Listing for File type_util_detail.hpp

Return to documentation for file (morpheus/_lib/include/morpheus/utilities/type_util_detail.hpp)

Copy
Copied!
            

#pragma once #include <climits>// for CHAR_BIT #include <cstddef>// for size_t #include <cstdint>// for int32_t #include <string>// for string #ifndef NDEBUG #include <cxxabi.h> #endif namespace morpheus { // Pulled from cuDF template <typename T> constexpr std::size_t size_in_bits() { static_assert(CHAR_BIT == 8, "Size of a byte must be 8 bits."); return sizeof(T) * CHAR_BIT; } // Pulled from cudf enum class TypeId : int32_t { EMPTY, INT8, INT16, INT32, INT64, UINT8, UINT16, UINT32, UINT64, FLOAT32, FLOAT64, BOOL8, // TIMESTAMP_DAYS, ///< point in time in days since Unix Epoch in int32 // TIMESTAMP_SECONDS, ///< point in time in seconds since Unix Epoch in int64 // TIMESTAMP_MILLISECONDS, ///< point in time in milliseconds since Unix Epoch in int64 // TIMESTAMP_MICROSECONDS, ///< point in time in microseconds since Unix Epoch in int64 // TIMESTAMP_NANOSECONDS, ///< point in time in nanoseconds since Unix Epoch in int64 // DURATION_DAYS, ///< time interval of days in int32 // DURATION_SECONDS, ///< time interval of seconds in int64 // DURATION_MILLISECONDS, ///< time interval of milliseconds in int64 // DURATION_MICROSECONDS, ///< time interval of microseconds in int64 // DURATION_NANOSECONDS, ///< time interval of nanoseconds in int64 // DICTIONARY32, ///< Dictionary type using int32 indices // STRING, ///< String elements // LIST, ///< List elements // DECIMAL32, ///< Fixed-point type with int32_t // DECIMAL64, ///< Fixed-point type with int64_t // STRUCT, ///< Struct elements // `NUM_TYPE_IDS` must be last! NUM_TYPE_IDS }; struct DataType { DataType(TypeId tid); TypeId type_id() const; // Number of bytes per item size_t item_size() const; // Pretty print std::string name() const; // Returns the numpy string representation std::string type_str() const; // // Returns the triton string representation // std::string triton_str() const; bool operator==(const DataType& other) const; // from template template <typename T> static DataType create() { if constexpr (std::is_integral_v<T> && std::is_signed_v<T> && size_in_bits<T>() == 8) { return {TypeId::INT8}; } else if constexpr (std::is_integral_v<T> && std::is_signed_v<T> && size_in_bits<T>() == 16) { return {TypeId::INT16}; } else if constexpr (std::is_integral_v<T> && std::is_signed_v<T> && size_in_bits<T>() == 32) { return {TypeId::INT32}; } else if constexpr (std::is_integral_v<T> && std::is_signed_v<T> && size_in_bits<T>() == 64) { return {TypeId::INT64}; } else if constexpr (std::is_integral_v<T> && std::is_unsigned_v<T> && size_in_bits<T>() == 8) { return {TypeId::UINT8}; } else if constexpr (std::is_integral_v<T> && std::is_unsigned_v<T> && size_in_bits<T>() == 16) { return {TypeId::UINT16}; } else if constexpr (std::is_integral_v<T> && std::is_unsigned_v<T> && size_in_bits<T>() == 32) { return {TypeId::UINT32}; } else if constexpr (std::is_integral_v<T> && std::is_unsigned_v<T> && size_in_bits<T>() == 64) { return {TypeId::UINT64}; } else if constexpr (std::is_floating_point_v<T> && size_in_bits<T>() == 32) { return {TypeId::FLOAT32}; } else if constexpr (std::is_floating_point_v<T> && size_in_bits<T>() == 64) { return {TypeId::FLOAT64}; } else if constexpr (std::is_same_v<T, bool>) { return {TypeId::BOOL8}; } else { static_assert(!sizeof(T), "Type not implemented"); } // To hide compiler warnings return {TypeId::EMPTY}; } // From numpy static DataType from_numpy(const std::string& numpy_str); protected: char type_char() const; TypeId m_type_id; }; // end of group } // namespace morpheus

© Copyright 2023, NVIDIA. Last updated on Feb 3, 2023.