通过


加速器类

加速器是一种对数据并行计算进行优化的硬件加速能力。 加速器可以是连接到 PCIe 总线的设备(例如 GPU),也可以是主 CPU 上的扩展指令集。

语法

class accelerator;

成员

公共构造函数

名称 描述
accelerator 构造函数 初始化 accelerator 类的新实例。
~accelerator 析构函数 销毁 accelerator 对象。

公共方法

名称 描述
create_view 在此加速器中创建并返回一个 accelerator_view 对象。
get_all 返回一个 accelerator 对象的向量,这些对象代表所有可用的加速器。
get_auto_selection_view 返回自动选择 accelerator_view
get_dedicated_memory 返回 accelerator 的专用内存(单位为 KB)。
get_default_cpu_access_type 返回在此加速器上创建的缓冲区的默认access_type
get_default_view 返回与 accelerator_view 关联的默认 accelerator 对象。
get_description 返回 accelerator 设备的简短说明。
get_device_path 返回设备的路径。
get_has_display 确定 accelerator 是否附加到显示器。
get_is_debug 确定 accelerator 是否启用了调试层,以实现详细的错误报告。
get_is_emulated 确定 accelerator 是否被仿真。
get_supports_cpu_shared_memory 确定 accelerator 是否支持共享内存
get_supports_double_precision 确定 accelerator 是否连接到显示器。
get_supports_limited_double_precision 确定 accelerator 是否对双精度算术只提供有限的支持。
get_version 返回 accelerator 的版本。
设置默认值 返回默认加速器的路径。
set_default_cpu_access_type 设置此accelerator上的数组和隐式内存分配的默认 CPU 访问类型

公有运算符

名称 描述
operator!= 将此 accelerator 对象与另一个进行比较,相同则返回 false,否则返回 true
运算符= 将指定 accelerator 对象的内容复制到此对象中。
operator== 将此 accelerator 对象与另一个进行比较,相同则返回 true,否则返回 false

公共数据成员

名称 描述
cpu_accelerator 获取 CPU accelerator 的字符串常数。
dedicated_memory 获取 accelerator 的专用内存(单位为 KB)。
default_accelerator 获取默认 accelerator 的字符串常数。
default_cpu_access_type 获取或设置此accelerator上进行的数组和隐式内存分配的默认 CPU access_type
default_view 获取与 accelerator 关联的默认 accelerator_view 对象。
说明 获取 accelerator 设备的简短说明。
device_path 获取设备的路径。
direct3d_ref 获取 Direct3D 引用 accelerator 的字符串常数。
direct3d_warp 获取 accelerator 对象的字串符常数,该对象可用于在使用流式处理 SIMD 扩展 (SSE) 的多核 CPU 上执行 C++ AMP 代码。
has_display 获取一个布尔值,该值表示 accelerator 是否附加到显示器。
is_debug 指示是否为accelerator启用了DEBUG层,以便进行广泛的错误报告。
is_emulated 指示是否模拟 accelerator
支持CPU共享内存 指示 accelerator 是否支持共享内存。
支持双精度 指示加速器是否支持双精度数学。
支持有限双精度 指示加速器是否对双精度数学运算提供有限支持。
版本 获取 accelerator 的版本。

继承层次结构

accelerator

注解

加速器是一种对数据并行计算进行优化的硬件加速能力。 加速器通常是独立的 GPU,但也可以是虚拟的主机端实体,例如 DirectX REF 设备、WARP(通过 SSE 指令加速的 CPU 端设备)或 CPU 本身。

可以通过枚举可用设备或获取默认设备、引用设备或 WARP 设备来构造 accelerator 对象。

要求

标头:amprt.h

命名空间: 并发

~加速器

销毁 accelerator 对象。

~accelerator();

返回值

加速器

初始化 accelerator 类的新实例。

accelerator();

explicit accelerator(const std::wstring& _Device_path);

accelerator(const accelerator& _Other);

参数

_Device_path
物理设备的路径。

_其他
要复制的快捷键。

CPU加速器

获取 CPU 加速器的字符串常数。

static const wchar_t cpu_accelerator[];

create_view

使用指定的排队模式,在此加速器上创建并返回一个 accelerator_view 对象。 如果未指定队列模式,则新的 accelerator_view 使用 queuing_mode::immediate 队列模式。

accelerator_view create_view(queuing_mode qmode = queuing_mode_automatic);

参数

qmode
排队模式。

返回值

使用指定的队列模式,在此加速器上创建的新 accelerator_view 对象。

专用内存

获取 accelerator 的专用内存(单位为 KB)。

__declspec(property(get= get_dedicated_memory)) size_t dedicated_memory;

默认加速器

获取默认 accelerator 的字符串常数。

static const wchar_t default_accelerator[];

默认CPU访问类型

对此accelerator进行的数组和隐式内存分配的默认 CPU 访问类型是

__declspec(property(get= get_default_cpu_access_type)) access_type default_cpu_access_type;

默认视图

获取与accelerator关联的默认加速器视图。

__declspec(property(get= get_default_view)) accelerator_view default_view;

描述

获取 accelerator 设备的简要描述。

__declspec(property(get= get_description)) std::wstring description;

设备路径

获取加速器的路径。 该路径在系统上是唯一的。

__declspec(property(get= get_device_path)) std::wstring device_path;

direct3d_ref

获取关于 Direct3D 引用加速器的字符串常数。

static const wchar_t direct3d_ref[];

direct3d_warp

获取 accelerator 对象的字符串常量,该对象可用于在使用流式 SIMD 扩展 (SSE) 的多核 CPU 上执行 C++ AMP 代码。

static const wchar_t direct3d_warp[];

get_all

返回一个 accelerator 对象的向量,这些对象代表所有可用的加速器。

static inline std::vector<accelerator> get_all();

返回值

可用加速器的列表

get_auto_selection_view

返回自动选择 accelerator_view,当指定为 parallel_for_each 目标时,运行时会自动选择用于执行 parallel_for_each 内核的目标 accelerator_view。 对于所有其他目的,此方法返回的 accelerator_view 与默认加速器的默认 accelerator_view 相同。

static accelerator_view __cdecl get_auto_selection_view();

返回值

自动选择功能 accelerator_view。

get_dedicated_memory

返回 accelerator 的专用内存(单位为 KB)。

size_t get_dedicated_memory() const;

返回值

accelerator 的专用内存(单位为 KB)。

get_default_cpu_access_type 默认 CPU 访问类型

获取在此加速器上创建的缓冲器的默认 CPU 访问类型

access_type get_default_cpu_access_type() const;

返回值

此加速器上创建的缓冲区的默认 CPU 访问类型。

获取默认视图

返回与 accelerator_view 关联的默认 accelerator 对象。

accelerator_view get_default_view() const;

返回值

accelerator_view 关联的默认 accelerator 对象。

获取描述

返回 accelerator 设备的简短说明。

std::wstring get_description() const;

返回值

accelerator 设备的简短说明。

get_device_path

返回加速器的路径。 该路径在系统上是唯一的。

std::wstring get_device_path() const;

返回值

系统范围的唯一设备实例路径。

get_has_display

返回一个布尔值,该值指示 accelerator 是否可以输出到显示器。

bool get_has_display() const;

返回值

如果 true 可以输出到显示器,则为 accelerator;否则为 false

get_is_debug

确定 accelerator 是否启用了调试层,以实现详细的错误报告。

bool get_is_debug() const;

返回值

如果 accelerator 启用了 DEBUG 层以进行广泛的错误报告。 否则为 false

get_is_emulated

确定 accelerator 是否被仿真。

bool get_is_emulated() const;

返回值

如果模拟 true,则返回值为 accelerator。 否则为 false

get_supports_cpu_shared_memory (获取 CPU 共享内存支持)

返回一个布尔值,指示加速器是否支持加速器和 CPU 均可访问的内存。

bool get_supports_cpu_shared_memory() const;

返回值

如果加速器支持 CPU 共享内存,则返回值为 true;否则,为 false

获取支持双精度

返回一个布尔值,指示加速器是否支持双精度数学,包括融合乘加 (FMA)、除法、倒数以及 intdouble 之间的强制转换。

bool get_supports_double_precision() const;

返回值

返回值为 true 如果加速器支持双精度计算;否则为 false

get_supports_limited_double_precision

返回一个布尔值,指示加速器是否对双精度数学运算的支持有限。 如果加速器仅提供有限的支持,则不支持融合乘加 (FMA)、除法、求倒数以及 intdouble 之间的类型转换。

bool get_supports_limited_double_precision() const;

返回值

如果加速器对双精度数学支持有限,则返回值为 true;否则为 false

获取版本

返回 accelerator 的版本。

unsigned int get_version() const;

返回值

accelerator 的版本。

has_display

获取一个布尔值,指示 accelerator 是否可以输出到显示器。

__declspec(property(get= get_has_display)) bool has_display;

is_debug

获取一个布尔值,指示 accelerator 是否为详细错误报告启用了 DEBUG 层。

__declspec(property(get= get_is_debug)) bool is_debug;

是否被仿真

获取一个布尔值,该布尔值指示 accelerator 是否被模拟。

__declspec(property(get= get_is_emulated)) bool is_emulated;

operator!=

将此 accelerator 对象与另一个进行比较,相同则返回 false,否则返回 true

bool operator!= (const accelerator& _Other) const;

参数

_其他
与此对象相比较的 accelerator 对象。

返回值

如果两个 false 对象相同,则为 accelerator;否则为 true

运算符=

将指定 accelerator 对象的内容复制到此对象中。

accelerator& operator= (const accelerator& _Other);

参数

_其他
accelerator 对象,要从其复制。

返回值

对此 accelerator 对象的引用。

operator==

将此 accelerator 对象与另一个进行比较,相同则返回 true,否则返回 false

bool operator== (const accelerator& _Other) const;

参数

_其他
与此对象相比较的 accelerator 对象。

返回值

如果另一个 true 对象与此 accelerator 对象相同;则返回值为 accelerator;否则,为 false

设置默认值

设置默认加速器,用于任何隐式使用默认加速器的操作。 仅当运行时选择的默认加速器尚未在隐式使用默认加速器的操作中使用时,此方法才会成功。

static inline bool set_default(std::wstring _Path);

参数

_路径
加速器的路径。

返回值

true 表示调用成功设置了默认加速器。 否则为 false

set_default_cpu_access_type

为在此加速器上创建的数组或作为在此加速器上访问的数组视图一部分的隐式内存分配设置默认的 CPU 访问类型。 仅当之前对此方法的调用尚未重写加速器的 default_cpu_access_type,并且运行时选择的用于此加速器的 default_cpu_access_type 尚未用于分配数组或为在此加速器上访问的 array_view 提供支持的隐式内存分配时,此方法才会成功。

bool set_default_cpu_access_type(access_type _Default_cpu_access_type);

参数

_Default_cpu_access_type
用于此加速器上 array/array_view 内存分配的默认 cpu access_type。

返回值

一个布尔值,指示是否成功设置加速器的默认 cpu access_type。

支持_cpu_共享内存

获取一个布尔值,指示 accelerator 是否支持共享内存。

__declspec(property(get= get_supports_cpu_shared_memory)) bool supports_cpu_shared_memory;

支持双精度

获取一个布尔值,该布尔值指示加速器是否支持双精度数学运算。

__declspec(property(get= get_supports_double_precision)) bool supports_double_precision;

支持有限双精度

获取一个布尔值,指示加速器是否对双精度计算的支持有限。 如果加速器仅提供有限的支持,则不支持融合乘加 (FMA)、除法、求倒数以及 intdouble 之间的类型转换。

__declspec(property(get= get_supports_limited_double_precision)) bool supports_limited_double_precision;

版本

获取 accelerator 的版本。

__declspec(property(get= get_version)) unsigned int version;

另请参阅

并发命名空间 (C++ AMP)