实用程序调度器#
- group 类型 调度器
定义
-
CUDF_TYPE_MAPPING(Type, Id)#
用于定义具体 C++ 类型与
cudf::type_id
枚举之间映射的宏。- 参数:
Type – 具体 C++ 类型
Id –
cudf::type_id
枚举
-
MAP_NUMERIC_SCALAR(Type)#
用于为数值 C++ 类型定义
cudf::numeric_scalar
模板类的标量类型和标量设备类型的宏。- 参数:
Type – 数值 C++ 类型
-
MAP_TIMESTAMP_SCALAR(Type)#
用于为时间戳 C++ 类型定义
cudf::timestamp_scalar
模板类的标量类型和标量设备类型的宏。- 参数:
Type – 时间戳 C++ 类型
-
MAP_DURATION_SCALAR(Type)#
用于为持续时间 C++ 类型定义
cudf::duration_scalar
模板类的标量类型和标量设备类型的宏。- 参数:
Type – 持续时间 C++ 类型
类型定义
-
template<cudf::type_id Id>
using id_to_type = typename id_to_type_impl<Id>::type# 将
cudf::type_id
映射到其对应的具体 C++ 类型。示例
static_assert(std::is_same<int32_t, id_to_type<id_type::INT32>);
- 模板参数:
t – 要映射的
cudf::type_id
-
template<typename T>
using 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>>># 使用
cudf::column
时,返回存储在设备上的对应类型。对于
decimal32
,存储类型是int32_t
。对于decimal64
,存储类型是int64_t
。对于decimal128
,存储类型是__int128_t
。使用此“类型函数”配合
using
类型别名使用using Type = device_storage_type_t<Element>;
- 模板参数:
T – 存储在主机上的字面类型
函数
-
template<typename T>
inline constexpr type_id base_type_to_id()# 将 C++ 类型映射到其对应的
cudf::type_id
当显式传递给定类型的模板参数时,返回指定 C++ 类型的相应
type_id
枚举。例如
return cudf::base_type_to_id<int32_t>(); // Returns INT32
- 模板参数:
T – 要映射到
cudf::type_id
的非 cv 限定类型- 返回:
与指定类型对应的
cudf::type_id
-
template<typename T>
inline constexpr type_id type_to_id()# 将 C++ 类型映射到其对应的
cudf::type_id
当显式传递给定类型的模板参数时,返回指定 C++ 类型的相应
type_id
枚举。例如
return cudf::type_to_id<int32_t>(); // Returns INT32
- 模板参数:
T – 要映射到
cudf::type_id
的类型- 返回:
与指定类型对应的
cudf::type_id
-
template<>
inline constexpr type_id base_type_to_id<char>()# 将 ‘char’ 类型映射到 type_id::INT8 的特化。
将 device_uvector<char> 传递给列构造函数时必需。当 PR 14202 合并后可能会被移除。
- 返回:
‘char’ 类型的 id
-
template<typename T>
constexpr bool type_id_matches_device_storage_type(type_id id)# 检查
fixed_point
类类型是否其模板类型T
与列存储的类型 id 匹配。- 模板参数:
T – 存储在设备上的类型
- 参数:
id – 列的
data_type::id
- 返回:
true
如果 T 与存储的列type_id
匹配- 返回:
false
如果 T 与存储的列type_id
不匹配
-
template<template<cudf::type_id> typename IdTypeMap = id_to_type_impl, typename Functor, typename ...Ts>
constexpr type_dispatcher(cudf::data_type dtype, Functor f, Ts&&... args)# 根据指定的
cudf::data_type
的id()
,调用带有类型实例化的operator()
模板。返回调度类型的 Functor 的使用示例
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
type_dispatcher
使用cudf::type_to_id<t>
提供cudf::type_id
到调度 C++ 类型的默认映射。然而,可以通过显式指定IdTypeMap
的用户定义特性结构体来定制此映射。例如,始终调度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);
有时需要为不同类型定制被调度的 functor 的
operator()
。这可以通过几种方式实现。第一种方法是使用显式模板特化。这对于针对单个类型进行行为特化很有用。例如,一个 functor 在使用
int32_t
或double
调用时打印int32_t
或double
,否则打印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"; }
第二种方法是使用 SFINAE 结合
std::enable_if_t
。这对于针对共享某些属性的一组类型进行特化很有用。例如,一个 functor 对于整数类型或浮点类型打印integral
或floating point
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"; } };
有关 SFINAE 和
std::enable_if
的更多信息,请参阅 https://eli.thegreenplace.net/2014/sfinae-and-enable_if/functor 的“operator()” lambda 的所有模板实例化的返回类型必须相同,否则会发生编译器错误,因为你将尝试从同一函数返回不同的类型。
- 模板参数:
id_to_type_impl – 将
cudf::type_id
映射到其调度的 C++ 类型Functor – 可调用对象的类型
Ts – 可变参数包类型
- 参数:
dtype – 其
id()
决定调用哪个模板实例化的cudf::data_type
f – 其
operator()
模板被调用的可调用对象args – 转发给
operator()
调用的参数包
- 返回:
可调用对象的
operator()
返回的值
-
template<cudf::type_id Id>
struct dispatch_storage_type# - #include <type_dispatcher.hpp>
当你只需要操作底层存储类型时,请在
type_dispatcher
上使用此特化。例如,sort.cu 中的
cudf::sort
使用cudf::type_dispatcher<dispatch_storage_type>(...)
。gather.cuh 中的cudf::gather
也使用cudf::type_dispatcher<dispatch_storage_type>(...)
。然而,归约需要同时使用data_type
和底层类型,因此不能使用此特化。公共类型
-
using type = device_storage_type_t<id_to_type<Id>>#
底层类型。
-
using type = device_storage_type_t<id_to_type<Id>>#
-
CUDF_TYPE_MAPPING(Type, Id)#