Files | Classes | Macros | Typedefs | Functions
Type Dispatcher

Files

file  type_dispatcher.hpp
 Defines the mapping between cudf::type_id runtime type information and concrete C++ types.
 

Classes

struct  cudf::type_to_name
 
struct  cudf::id_to_type_impl< t >
 
struct  cudf::dispatch_storage_type< Id >
 Use this specialization on type_dispatcher whenever you only need to operate on the underlying stored type. More...
 
struct  cudf::type_to_scalar_type_impl< T >
 
struct  cudf::type_to_scalar_type_impl< std::string >
 
struct  cudf::type_to_scalar_type_impl< cudf::string_view >
 
struct  cudf::type_to_scalar_type_impl< numeric::decimal32 >
 
struct  cudf::type_to_scalar_type_impl< numeric::decimal64 >
 
struct  cudf::type_to_scalar_type_impl< numeric::decimal128 >
 
struct  cudf::type_to_scalar_type_impl< cudf::dictionary32 >
 
struct  cudf::type_to_scalar_type_impl< cudf::list_view >
 
struct  cudf::type_to_scalar_type_impl< cudf::struct_view >
 

Macros

#define CUDF_TYPE_MAPPING(Type, Id)
 Macro used to define a mapping between a concrete C++ type and a cudf::type_id enum. More...
 
#define MAP_NUMERIC_SCALAR(Type)
 
#define MAP_TIMESTAMP_SCALAR(Type)
 
#define MAP_DURATION_SCALAR(Type)
 

Typedefs

template<cudf::type_id Id>
using cudf::id_to_type = typename id_to_type_impl< Id >::type
 Maps a cudf::type_id to it's corresponding concrete C++ type. More...
 
template<typename T >
using cudf::device_storage_type_t = std::conditional_t< std::is_same_v< numeric::decimal32, T >, int32_t, std::conditional_t< std::is_same_v< numeric::decimal64, T >, int64_t, std::conditional_t< std::is_same_v< numeric::decimal128, T >, __int128_t, T > >>
 "Returns" the corresponding type that is stored on the device when using cudf::column More...
 
template<typename T >
using cudf::scalar_type_t = typename type_to_scalar_type_impl< T >::ScalarType
 Maps a C++ type to the scalar type required to hold its value. More...
 
template<typename T >
using cudf::scalar_device_type_t = typename type_to_scalar_type_impl< T >::ScalarDeviceType
 

Functions

template<typename T >
constexpr type_id cudf::type_to_id ()
 Maps a C++ type to it's corresponding cudf::type_id More...
 
template<typename T >
constexpr bool cudf::type_id_matches_device_storage_type (type_id id)
 Checks if fixed_point-like types have template type T matching the column's stored type id. More...
 
constexpr bool cudf::is_fixed_point (cudf::type_id id)
 Checks if id is fixed_point (DECIMAL32/64/128) More...
 
 cudf::CUDF_TYPE_MAPPING (bool, type_id::BOOL8)
 Defines all of the mappings between C++ types and their corresponding cudf::type_id values.
 
 cudf::CUDF_TYPE_MAPPING (int8_t, type_id::INT8)
 
 cudf::CUDF_TYPE_MAPPING (int16_t, type_id::INT16)
 
 cudf::CUDF_TYPE_MAPPING (int32_t, type_id::INT32)
 
 cudf::CUDF_TYPE_MAPPING (int64_t, type_id::INT64)
 
 cudf::CUDF_TYPE_MAPPING (uint8_t, type_id::UINT8)
 
 cudf::CUDF_TYPE_MAPPING (uint16_t, type_id::UINT16)
 
 cudf::CUDF_TYPE_MAPPING (uint32_t, type_id::UINT32)
 
 cudf::CUDF_TYPE_MAPPING (uint64_t, type_id::UINT64)
 
 cudf::CUDF_TYPE_MAPPING (float, type_id::FLOAT32)
 
 cudf::CUDF_TYPE_MAPPING (double, type_id::FLOAT64)
 
 cudf::CUDF_TYPE_MAPPING (cudf::string_view, type_id::STRING)
 
 cudf::CUDF_TYPE_MAPPING (cudf::timestamp_D, type_id::TIMESTAMP_DAYS)
 
 cudf::CUDF_TYPE_MAPPING (cudf::timestamp_s, type_id::TIMESTAMP_SECONDS)
 
 cudf::CUDF_TYPE_MAPPING (cudf::timestamp_ms, type_id::TIMESTAMP_MILLISECONDS)
 
 cudf::CUDF_TYPE_MAPPING (cudf::timestamp_us, type_id::TIMESTAMP_MICROSECONDS)
 
 cudf::CUDF_TYPE_MAPPING (cudf::timestamp_ns, type_id::TIMESTAMP_NANOSECONDS)
 
 cudf::CUDF_TYPE_MAPPING (cudf::duration_D, type_id::DURATION_DAYS)
 
 cudf::CUDF_TYPE_MAPPING (cudf::duration_s, type_id::DURATION_SECONDS)
 
 cudf::CUDF_TYPE_MAPPING (cudf::duration_ms, type_id::DURATION_MILLISECONDS)
 
 cudf::CUDF_TYPE_MAPPING (cudf::duration_us, type_id::DURATION_MICROSECONDS)
 
 cudf::CUDF_TYPE_MAPPING (cudf::duration_ns, type_id::DURATION_NANOSECONDS)
 
 cudf::CUDF_TYPE_MAPPING (dictionary32, type_id::DICTIONARY32)
 
 cudf::CUDF_TYPE_MAPPING (cudf::list_view, type_id::LIST)
 
 cudf::CUDF_TYPE_MAPPING (numeric::decimal32, type_id::DECIMAL32)
 
 cudf::CUDF_TYPE_MAPPING (numeric::decimal64, type_id::DECIMAL64)
 
 cudf::CUDF_TYPE_MAPPING (numeric::decimal128, type_id::DECIMAL128)
 
 cudf::CUDF_TYPE_MAPPING (cudf::struct_view, type_id::STRUCT)
 
 cudf::MAP_NUMERIC_SCALAR (bool)
 
template<template< cudf::type_id > typename IdTypeMap = id_to_type_impl, typename Functor , typename... Ts>
CUDF_HOST_DEVICE constexpr decltype(auto) __forceinline__ cudf::type_dispatcher (cudf::data_type dtype, Functor f, Ts &&... args)
 Invokes an operator() template with the type instantiation based on the specified cudf::data_type's id(). More...
 
template<template< cudf::type_id > typename IdTypeMap = id_to_type_impl, typename F , typename... Ts>
CUDF_HOST_DEVICE constexpr decltype(auto) __forceinline__ cudf::double_type_dispatcher (cudf::data_type type1, cudf::data_type type2, F &&f, Ts &&... args)
 Dispatches two type template parameters to a callable. More...
 

Detailed Description

Macro Definition Documentation

◆ CUDF_TYPE_MAPPING

#define CUDF_TYPE_MAPPING (   Type,
  Id 
)
Value:
template <> \
constexpr inline type_id type_to_id<Type>() \
{ \
return Id; \
} \
template <> \
inline std::string type_to_name::operator()<Type>() \
{ \
return CUDF_STRINGIFY(Type); \
} \
template <> \
struct id_to_type_impl<Id> { \
using type = Type; \
}

Macro used to define a mapping between a concrete C++ type and a cudf::type_id enum.

Parameters
TypeThe concrete C++ type
IdThe cudf::type_id enum

Definition at line 145 of file type_dispatcher.hpp.

◆ MAP_DURATION_SCALAR

#define MAP_DURATION_SCALAR (   Type)
Value:
template <> \
struct type_to_scalar_type_impl<Type> { \
using ScalarType = cudf::duration_scalar<Type>; \
using ScalarDeviceType = cudf::duration_scalar_device_view<Type>; \
};

Definition at line 300 of file type_dispatcher.hpp.

◆ MAP_NUMERIC_SCALAR

#define MAP_NUMERIC_SCALAR (   Type)
Value:
template <> \
struct type_to_scalar_type_impl<Type> { \
using ScalarType = cudf::numeric_scalar<Type>; \
using ScalarDeviceType = cudf::numeric_scalar_device_view<Type>; \
};

Definition at line 214 of file type_dispatcher.hpp.

◆ MAP_TIMESTAMP_SCALAR

#define MAP_TIMESTAMP_SCALAR (   Type)
Value:
template <> \
struct type_to_scalar_type_impl<Type> { \
using ScalarType = cudf::timestamp_scalar<Type>; \
using ScalarDeviceType = cudf::timestamp_scalar_device_view<Type>; \
};

Definition at line 285 of file type_dispatcher.hpp.

Typedef Documentation

◆ device_storage_type_t

template<typename T >
using cudf::device_storage_type_t = typedef std::conditional_t<std::is_same_v<numeric::decimal32, T>, int32_t, std::conditional_t<std::is_same_v<numeric::decimal64, T>, int64_t, std::conditional_t<std::is_same_v<numeric::decimal128, T>, __int128_t, T> >>

"Returns" the corresponding type that is stored on the device when using cudf::column

For decimal32, the storage type is an int32_t. For decimal64, the storage type is an int64_t. For decimal128, the storage type is an __int128_t.

Use this "type function" with the using type alias:

using Type = device_storage_type_t<Element>;
Template Parameters
TThe literal type that is stored on the host

Definition at line 101 of file type_dispatcher.hpp.

◆ id_to_type

template<cudf::type_id Id>
using cudf::id_to_type = typedef typename id_to_type_impl<Id>::type

Maps a cudf::type_id to it's corresponding concrete C++ type.

Example:

static_assert(std::is_same<int32_t, id_to_type<id_type::INT32>);
Template Parameters
tThe cudf::type_id to map

Definition at line 83 of file type_dispatcher.hpp.

◆ scalar_type_t

template<typename T >
using cudf::scalar_type_t = typedef typename type_to_scalar_type_impl<T>::ScalarType

Maps a C++ type to the scalar type required to hold its value.

Template Parameters
TThe concrete C++ type to map

Definition at line 320 of file type_dispatcher.hpp.

Function Documentation

◆ double_type_dispatcher()

template<template< cudf::type_id > typename IdTypeMap = id_to_type_impl, typename F , typename... Ts>
CUDF_HOST_DEVICE constexpr decltype(auto) __forceinline__ cudf::double_type_dispatcher ( cudf::data_type  type1,
cudf::data_type  type2,
F &&  f,
Ts &&...  args 
)
constexpr

Dispatches two type template parameters to a callable.

This function expects a callable f with an operator() template accepting two typename template parameters T1 and T2.

Parameters
type1The data_type used to dispatch a type for the first template parameter of the callable F
type2The data_type used to dispatch a type for the second template parameter of the callable F
fThe callable whose operator() template is invoked
argsParameter pack forwarded to the operator() invocation F.

Definition at line 564 of file type_dispatcher.hpp.

◆ is_fixed_point()

constexpr bool cudf::is_fixed_point ( cudf::type_id  id)
constexpr

Checks if id is fixed_point (DECIMAL32/64/128)

Returns
true if id is DECIMAL32, DECIMAL64 or DECIMAL128
false otherwise

Definition at line 130 of file type_dispatcher.hpp.

◆ type_dispatcher()

template<template< cudf::type_id > typename IdTypeMap = id_to_type_impl, typename Functor , typename... Ts>
CUDF_HOST_DEVICE constexpr decltype(auto) __forceinline__ cudf::type_dispatcher ( cudf::data_type  dtype,
Functor  f,
Ts &&...  args 
)
constexpr

Invokes an operator() template with the type instantiation based on the specified cudf::data_type's id().

Example usage with a functor that returns the size of the dispatched type:

struct size_of_functor{
template <typename T>
int operator()(){
return sizeof(T);
}
};
cudf::data_type t{INT32};
cudf::type_dispatcher(t, size_of_functor{}); // returns 4

The type_dispatcher uses cudf::type_to_id<t> to provide a default mapping of cudf::type_ids to dispatched C++ types. However, this mapping may be customized by explicitly specifying a user-defined trait struct for the IdTypeMap. For example, to always dispatch int32_t

template<cudf::type_id t> struct always_int{ using type = int32_t; }
// This will always invoke operator()<int32_t>
cudf::type_dispatcher<always_int>(data_type, f);

It is sometimes necessary to customize the dispatched functor's operator() for different types. This can be done in several ways.

The first method is to use explicit template specialization. This is useful for specializing behavior for single types. For example, a functor that prints int32_t or double when invoked with either of those types, else it prints unhandled type:

struct type_printer {
template <typename ColumnType>
void operator()() { std::cout << "unhandled type\n"; }
};
// Due to a bug in g++, explicit member function specializations need to be
// defined outside of the class definition
template <>
void type_printer::operator()<int32_t>() { std::cout << "int32_t\n"; }
template <>
void type_printer::operator()<double>() { std::cout << "double\n"; }

A second method is to use SFINAE with std::enable_if_t. This is useful for specializing for a set of types that share some property. For example, a functor that prints integral or floating point for integral or floating point types:

struct integral_or_floating_point {
template <typename ColumnType,
std::enable_if_t<not std::is_integral_v<ColumnType> and
not std::is_floating_point_v<ColumnType> >* = nullptr>
void operator()() {
std::cout << "neither integral nor floating point\n "; }
template <typename ColumnType,
std::enable_if_t<std::is_integral_v<ColumnType> >* = nullptr>
void operator()() { std::cout << "integral\n"; }
template <typename ColumnType,
std::enable_if_t<std::is_floating_point_v<ColumnType> >* = nullptr>
void operator()() { std::cout << "floating point\n"; }
};

For more info on SFINAE and std::enable_if, see https://eli.thegreenplace.net/2014/sfinae-and-enable_if/

The return type for all template instantiations of the functor's "operator()" lambda must be the same, else there will be a compiler error as you would be trying to return different types from the same function.

Template Parameters
id_to_type_implMaps a cudf::type_id its dispatched C++ type
FunctorThe callable object's type
TsVariadic parameter pack type
Parameters
dtypeThe cudf::data_type whose id() determines which template instantiation is invoked
fThe callable whose operator() template is invoked
argsParameter pack of arguments forwarded to the operator() invocation
Returns
Whatever is returned by the callable's operator()

Definition at line 423 of file type_dispatcher.hpp.

◆ type_id_matches_device_storage_type()

template<typename T >
constexpr bool cudf::type_id_matches_device_storage_type ( type_id  id)
constexpr

Checks if fixed_point-like types have template type T matching the column's stored type id.

Template Parameters
TThe type that is stored on the device
Parameters
idThe data_type::id of the column
Returns
true If T matches the stored column type_id
false If T does not match the stored column type_id

Definition at line 117 of file type_dispatcher.hpp.

◆ type_to_id()

template<typename T >
constexpr type_id cudf::type_to_id ( )
inlineconstexpr

Maps a C++ type to it's 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
Template Parameters
TThe type to map to a cudf::type_id

Definition at line 56 of file type_dispatcher.hpp.

cudf::timestamp_scalar
Definition: scalar.hpp:563
cudf::type_id
type_id
Identifies a column's logical element type.
Definition: types.hpp:202
cudf::timestamp_scalar_device_view
A type of scalar_device_view that stores a pointer to a timestamp value.
Definition: scalar_device_view.cuh:290
cudf::duration_scalar_device_view
A type of scalar_device_view that stores a pointer to a duration value.
Definition: scalar_device_view.cuh:302
cudf::duration_scalar
Definition: scalar.hpp:606
cudf::type_dispatcher
CUDF_HOST_DEVICE constexpr decltype(auto) __forceinline__ type_dispatcher(cudf::data_type dtype, Functor f, Ts &&... args)
Invokes an operator() template with the type instantiation based on the specified cudf::data_type's i...
Definition: type_dispatcher.hpp:423
cudf::numeric_scalar
An owning class to represent a numerical value in device memory.
Definition: scalar.hpp:218
cudf::data_type
Indicator for the logical data type of an element in a column.
Definition: types.hpp:242
cudf::numeric_scalar_device_view
A type of scalar_device_view that stores a pointer to a numerical value.
Definition: scalar_device_view.cuh:211