Skip to content

Commit

Permalink
Allow cudf::type_to_id<T const>()
Browse files Browse the repository at this point in the history
Currently, `cudf::type_to_id<X>` where X is a valid type for converting to a `cudf::id` only works if X is neither `const` nor `volatile`.  However, if it has either of those "cv" qualifiers, the function returns `type_id::EMPTY`.

With this change, return the correct type id no matter the cv-qualifiers.
  • Loading branch information
esoha-nvidia committed Jan 27, 2025
1 parent 03e1f64 commit 6b0b91c
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions cpp/include/cudf/utilities/type_dispatcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ namespace CUDF_EXPORT cudf {
* For example:
*
* ```
* return cudf::type_to_id<int32_t>(); // Returns INT32
* return cudf::base_type_to_id<int32_t>(); // Returns INT32
* ```
*
* @tparam T The type to map to a `cudf::type_id`
* @tparam T The non-cv type to map to a `cudf::type_id`
* @return The `cudf::type_id` corresponding to the specified type
*/
template <typename T>
CUDF_HOST_DEVICE inline constexpr type_id type_to_id()
CUDF_HOST_DEVICE inline constexpr type_id base_type_to_id()
{
return type_id::EMPTY;
};
Expand Down Expand Up @@ -130,6 +130,27 @@ constexpr bool type_id_matches_device_storage_type(type_id id)
(id == type_id::DECIMAL128 && std::is_same_v<T, __int128_t>) || id == type_to_id<T>();
}

/**
* @brief Maps a C++ type to its corresponding `cudf::type_id`
*
* When explicitly passed a template argument of a given type, returns the
* appropriate `type_id` enum for the specified C++ type.
*
* For example:
*
* ```
* return cudf::type_to_id<int32_t>(); // Returns INT32
* ```
*
* @tparam T The type to map to a `cudf::type_id`
* @return The `cudf::type_id` corresponding to the specified type
*/
template <typename T>
constexpr inline type_id type_to_id()
{
return base_type_to_id<std::remove_cv_t<T>>();
}

/**
* @brief Macro used to define a mapping between a concrete C++ type and a
*`cudf::type_id` enum.
Expand All @@ -140,7 +161,7 @@ constexpr bool type_id_matches_device_storage_type(type_id id)
#ifndef CUDF_TYPE_MAPPING
#define CUDF_TYPE_MAPPING(Type, Id) \
template <> \
constexpr inline type_id type_to_id<Type>() \
constexpr inline type_id base_type_to_id<Type>() \
{ \
return Id; \
} \
Expand Down Expand Up @@ -194,7 +215,7 @@ CUDF_TYPE_MAPPING(cudf::struct_view, type_id::STRUCT)
* @return id for 'char' type
*/
template <> // CUDF_TYPE_MAPPING(char,INT8) causes duplicate id_to_type_impl definition
constexpr inline type_id type_to_id<char>()
constexpr inline type_id base_type_to_id<char>()
{
return type_id::INT8;
}
Expand Down

0 comments on commit 6b0b91c

Please sign in to comment.