文件 | | | 类型定义 | 函数
类型调度器

文件

文件  type_dispatcher.hpp
 定义了 cudf::type_id 运行时类型信息与具体的 C++ 类型之间的映射。
 

结构体  cudf::dispatch_storage_type< Id >
 当您只需要对底层存储类型进行操作时,请使用 type_dispatcher 的此特化版本。 更多...
 

#define CUDF_TYPE_MAPPING(Type, Id)
 用于定义具体 C++ 类型与 cudf::type_id 枚举之间映射的宏。 更多...
 
#define MAP_NUMERIC_SCALAR(Type)
 用于定义 cudf::numeric_scalar 模板类中数值 C++ 类型的标量类型和设备标量类型的宏。 更多...
 
#define MAP_TIMESTAMP_SCALAR(Type)
 用于定义 cudf::timestamp_scalar 模板类中时间戳 C++ 类型的标量类型和设备标量类型的宏。 更多...
 
#define MAP_DURATION_SCALAR(Type)
 用于定义 cudf::duration_scalar 模板类中持续时间 C++ 类型的标量类型和设备标量类型的宏。 更多...
 

类型定义

template<cudf::type_id Id>
使用 cudf::id_to_type = typename id_to_type_impl< Id >::type
 cudf::type_id 映射到其对应的具体 C++ 类型。 更多...
 
template<typename T >
使用 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 > >>
 使用 cudf::column 时,“返回”存储在设备上的相应类型。 更多...
 
template<typename T >
使用 cudf::scalar_type_t = typename type_to_scalar_type_impl< T >::ScalarType
 将 C++ 类型映射到保存其值所需的标量类型。 更多...
 
template<typename T >
使用 cudf::scalar_device_type_t = typename type_to_scalar_type_impl< T >::ScalarDeviceType
 将 C++ 类型映射到保存其值所需的设备标量类型。 更多...
 

函数

template<typename T >
constexpr CUDF_HOST_DEVICE type_id cudf::base_type_to_id ()
 将 C++ 类型映射到其对应的 cudf::type_id 更多...
 
template<typename T >
constexpr type_id cudf::type_to_id ()
 将 C++ 类型映射到其对应的 cudf::type_id 更多...
 
template<>
constexpr type_id cudf::base_type_to_id< char > ()
 将 'char' 类型映射到 type_id::INT8 的特化。 更多...
 
template<typename T >
constexpr bool cudf::type_id_matches_device_storage_type (type_id id)
 检查类似 fixed_point 的类型是否具有与列的存储类型 ID 匹配的模板类型 T更多...
 
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)
 根据指定的 cudf::data_typeid(),使用类型实例化调用 operator() 模板。 更多...
 
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)
 将两个类型模板参数调度到可调用对象。 更多...
 
std::string cudf::type_to_name (data_type type)
 返回给定类型的名称。 更多...
 

详细描述

宏定义文档

◆ CUDF_TYPE_MAPPING

#define CUDF_TYPE_MAPPING (   Type,
  Id 
)
template <> \
constexpr inline type_id base_type_to_id<Type>() \
{ \
return Id; \
} \
template <> \
inline std::string type_to_name_impl::operator()<Type>() \
{ \
return CUDF_STRINGIFY(Type); \
} \
template <> \
struct id_to_type_impl<Id> { \
using type = Type; \
};
#define CUDF_STRINGIFY(x)
将宏参数字符串化。
定义于: error.hpp:147
type_id
标识列的逻辑元素类型。
定义于: types.hpp:203

用于定义具体 C++ 类型与 cudf::type_id 枚举之间映射的宏。

参数
Type具体的 C++ 类型
Idcudf::type_id 枚举

定义于文件 type_dispatcher.hpp 的第 145 行。

◆ MAP_DURATION_SCALAR

#define MAP_DURATION_SCALAR (   Type)
template <> \
struct type_to_scalar_type_impl<Type> { \
using ScalarType = cudf::duration_scalar<Type>; \
using ScalarDeviceType = cudf::duration_scalar_device_view<Type>; \
};
一种 scalar_device_view 类型,存储指向持续时间值的指针。
表示设备内存中持续时间值的拥有类。
定义于: scalar.hpp:667

用于定义 cudf::duration_scalar 模板类中持续时间 C++ 类型的标量类型和设备标量类型的宏。

参数
Type持续时间 C++ 类型

定义于文件 type_dispatcher.hpp 的第 346 行。

◆ MAP_NUMERIC_SCALAR

#define MAP_NUMERIC_SCALAR (   Type)
template <> \
struct type_to_scalar_type_impl<Type> { \
using ScalarType = cudf::numeric_scalar<Type>; \
using ScalarDeviceType = cudf::numeric_scalar_device_view<Type>; \
};
一种 scalar_device_view 类型,存储指向数值的指针。
表示设备内存中数值的拥有类。
定义于: scalar.hpp:239

用于定义 cudf::numeric_scalar 模板类中数值 C++ 类型的标量类型和设备标量类型的宏。

参数
Type数值 C++ 类型

定义于文件 type_dispatcher.hpp 的第 248 行。

◆ MAP_TIMESTAMP_SCALAR

#define MAP_TIMESTAMP_SCALAR (   Type)
template <> \
struct type_to_scalar_type_impl<Type> { \
using ScalarType = cudf::timestamp_scalar<Type>; \
using ScalarDeviceType = cudf::timestamp_scalar_device_view<Type>; \
};
一种 scalar_device_view 类型,存储指向时间戳值的指针。
表示设备内存中时间戳值的拥有类。
定义于: scalar.hpp:611

用于定义 cudf::timestamp_scalar 模板类中时间戳 C++ 类型的标量类型和设备标量类型的宏。

参数
Type时间戳 C++ 类型

定义于文件 type_dispatcher.hpp 的第 325 行。

类型定义文档

◆ 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> >>

使用 cudf::column 时,“返回”存储在设备上的相应类型。

对于 decimal32,存储类型为 int32_t。对于 decimal64,存储类型为 int64_t。对于 decimal128,存储类型为 __int128_t

将此“类型函数”与 using 类型别名一起使用

using Type = device_storage_type_t<Element>;
模板参数
T存储在主机上的字面类型

定义于文件 type_dispatcher.hpp 的第 110 行。

◆ id_to_type

template<cudf::type_id Id>
using cudf::id_to_type = typedef 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

定义于文件 type_dispatcher.hpp 的第 92 行。

◆ scalar_device_type_t

template<typename T >
using cudf::scalar_device_type_t = typedef typename type_to_scalar_type_impl<T>::ScalarDeviceType

将 C++ 类型映射到保存其值所需的设备标量类型。

模板参数
T要映射的具体 C++ 类型

定义于文件 type_dispatcher.hpp 的第 374 行。

◆ scalar_type_t

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

将 C++ 类型映射到保存其值所需的标量类型。

模板参数
T要映射的具体 C++ 类型

定义于文件 type_dispatcher.hpp 的第 366 行。

函数文档

◆ base_type_to_id()

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

将 C++ 类型映射到其对应的 cudf::type_id

当明确传递给定类型的模板参数时,返回指定 C++ 类型的相应 type_id 枚举。

示例

return cudf::base_type_to_id<int32_t>(); // 返回 INT32
模板参数
T要映射到 cudf::type_id 的非 cv 类型
返回值
与指定类型对应的 cudf::type_id

定义于文件 type_dispatcher.hpp 的第 56 行。

◆ base_type_to_id< char >()

template<>
constexpr type_id cudf::base_type_to_id< char > ( )
inlineconstexpr

将 'char' 类型映射到 type_id::INT8 的特化。

将 device_uvector<char> 传递给列构造函数时需要。在 PR 14202 合并后可能可以移除。

返回值
'char' 类型的 ID

定义于文件 type_dispatcher.hpp 的第 201 行。

◆ 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

将两个类型模板参数调度到可调用对象。

此函数需要一个可调用对象 f,它包含一个接受两个 typename 模板参数 T1T2operator() 模板。

参数
type1用于调度可调用对象 F 的第一个模板参数类型的 data_type
type2用于调度可调用对象 F 的第二个模板参数类型的 data_type
foperator() 模板被调用的可调用对象
args转发到 Foperator() 调用的参数包。
返回值
调用 f.template operator(args) 的结果

定义于文件 type_dispatcher.hpp 的第 627 行。

◆ 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

根据指定的 cudf::data_typeid(),使用类型实例化调用 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{}); // 返回 4
指示列中元素的逻辑数据类型。
定义于: types.hpp:243
CUDF_HOST_DEVICE constexpr decltype(auto) __forceinline__ type_dispatcher(cudf::data_type dtype, Functor f, Ts &&... args)
根据指定的 cudf::data_type 的 i...,使用类型实例化调用 operator() 模板。

type_dispatcher 使用 cudf::type_to_id 提供 cudf::type_id 到调度 C++ 类型的默认映射。但是,可以通过明确指定用户定义的 IdTypeMap 特征结构体来定制此映射。例如,始终调度 int32_t

template<cudf::type_id t> struct always_int{ using type = int32_t; }
// 这将始终调用 operator()
cudf::type_dispatcher<always_int>(data_type, f);

有时需要为不同的类型定制调度 Functor 的 operator()。这可以通过几种方式完成。

第一种方法是使用显式模板特化。这对于针对单一类型进行特化行为非常有用。例如,一个 Functor 在使用 int32_tdouble 调用时打印相应的类型名称,否则打印 unhandled type

struct type_printer {
template <typename ColumnType>
void operator()() { std::cout << "unhandled type\n"; }
};
// 由于 g++ 中的一个 bug,显式成员函数特化需要在类定义之外定义
// 定义在类定义之外
template <>
void type_printer::operator()<int32_t>() { std::cout << "int32_t\n"; }
template <>
void type_printer::operator()<double>() { std::cout << "double\n"; }

第二种方法是使用带有 std::enable_if_t 的 SFINAE。这对于针对共享某些属性的类型集合进行特化非常有用。例如,一个 Functor 对于整型或浮点型打印 integralfloating 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_implcudf::type_id 映射到其调度的 C++ 类型
Functor可调用对象的类型
Ts可变参数包类型
参数
dtypecudf::data_type,其 id() 确定调用哪个模板实例化
foperator() 模板被调用的可调用对象
args转发到 operator() 调用的参数包
返回值
可调用对象的 operator() 返回的任何值

定义于文件 type_dispatcher.hpp 的第 476 行。

◆ type_id_matches_device_storage_type()

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

检查类似 fixed_point 的类型是否具有与列的存储类型 ID 匹配的模板类型 T

模板参数
T存储在设备上的类型
参数
id列的 data_type::id
返回值
true 如果 T 与存储的列 type_id 匹配
false 如果 T 与存储的列 type_id 不匹配

定义于文件 type_dispatcher.hpp 的第 216 行。

◆ type_to_id()

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

将 C++ 类型映射到其对应的 cudf::type_id

当明确传递给定类型的模板参数时,返回指定 C++ 类型的相应 type_id 枚举。

示例

return cudf::type_to_id<int32_t>(); // 返回 INT32
模板参数
T要映射到 cudf::type_id 的类型
返回值
与指定类型对应的 cudf::type_id

定义于文件 type_dispatcher.hpp 的第 132 行。

◆ type_to_name()

std::string cudf::type_to_name ( data_type  type)

返回给定类型的名称。

返回的类型名称用于错误消息,不保证稳定性。

参数
typedata_type
返回值
类型名称