pragma HLS bind_op - 2022.1 Chinese

Vitis 高层次综合用户指南 (UG1399)

Document ID
UG1399
Release Date
2022-06-07
Version
2022.1 简体中文

描述

Vitis HLS 使用特定实现来实现代码中的操作。BIND_OP 编译指示用于指定针对每个特定变量,都应将一项运算(muladddiv)映射到特定器件资源,以便在 RTL 内实现 (impl)。如果不指定 BIND_OP 编译指示,Vitis HLS 会自动判定用于运算的资源。

例如,您可使用 BIND_OP 编译指示来指明在器件互连结构内(而不是在 DSP 内)实现一项特定乘法器运算 (mul)。

您也可以使用 latency 选项来指定运算的时延。

重要: 要使用 latency 选项,运算必须具有 1 个可用的多阶段实现。HLS 工具可为所有基本算术运算(加减乘除)和所有浮点运算提供 1 个多阶段实现。

语法

将 C 语言源代码中的编译指示置于定义变量的函数主体内。

#pragma HLS bind_op variable=<variable> op=<type>\
impl=<value> latency=<int>

其中:

variable=<variable>
用于定义要将 BIND_OP 编译指示分配到的变量。在此例中,定义的变量就是该编译指示的目标运算结果所分配到的变量。
op=<type>
用于定义要绑定到特定实现资源的运算。受支持的函数运算包括:muladdsub
受支持的浮点运算包括:faddfsubfdivfexpflogfmulfrsqrtfrecipfsqrtdadddsubddivdexpdlogdmuldrsqrtdrecipdsqrthaddhsubhdivhmulhsqrt
提示: 浮点运算包括单精度 (f)、双精度 (d) 和半精度 (h)。
impl=<value>
定义用于指定运算的实现。
受支持的函数运算实现包括 fabricdsp
受支持的浮点运算实现包括:fabricmeddspfulldspmaxdspprimitivedsp
注释: primitivedsp 仅在 Versal® 器件上可用。
latency=<int>
定义运算的实现的默认时延。有效的时延值因指定的 opimpl 而异。默认值为 -1,即交由 Vitis HLS 选择时延。
下表反映了受支持的运算、实现和时延组合。
表 1. 受支持的函数运算、实现和时延组合
操作 实现 “Min Latency” “Max Latency”
add fabric 0 4
add dsp 0 4
mul fabric 0 4
mul dsp 0 4
sub fabric 0 4
sub dsp 0 0
提示: 比较运算符(如 dcmp)是在 LUT 中实现的,不得在互连结构外部实现,也不能映射到 DSP,因此无法通过 config_op 命令或 bind_op 命令来配置。
表 2. 受支持的浮点运算、实现和时延组合
操作 实现 “Min Latency” “Max Latency”
fadd fabric 0 13
fadd fulldsp 0 12
fadd primitivedsp 0 3
fsub fabric 0 13
fsub fulldsp 0 12
fsub primitivedsp 0 3
fdiv fabric 0 29
fexp fabric 0 24
fexp meddsp 0 21
fexp fulldsp 0 30
flog fabric 0 24
flog meddsp 0 23
flog fulldsp 0 29
fmul fabric 0 9
fmul meddsp 0 9
fmul fulldsp 0 9
fmul maxdsp 0 7
fmul primitivedsp 0 4
fsqrt fabric 0 29
frsqrt fabric 0 38
frsqrt fulldsp 0 33
frecip fabric 0 37
frecip fulldsp 0 30
dadd fabric 0 13
dadd fulldsp 0 15
dsub fabric 0 13
dsub fulldsp 0 15
ddiv fabric 0 58
dexp fabric 0 40
dexp meddsp 0 45
dexp fulldsp 0 57
dlog fabric 0 38
dlog meddsp 0 49
dlog fulldsp 0 65
dmul fabric 0 10
dmul meddsp 0 13
dmul fulldsp 0 13
dmul maxdsp 0 14
dsqrt fabric 0 58
drsqrt fulldsp 0 111
drecip fulldsp 0 36
hadd fabric 0 9
hadd meddsp 0 12
hadd fulldsp 0 12
hsub fabric 0 9
hsub meddsp 0 12
hsub fulldsp 0 12
hdiv fabric 0 16
hmul fabric 0 7
hmul fulldsp 0 7
hmul maxdsp 0 9
hsqrt fabric 0 16

示例

在以下示例中,指定了使用互连结构逻辑的二阶流水打拍乘法器来为函数 foo 的变量 c 实现乘法运算。

int foo (int a, int b) {
int c, d;
#pragma HLS BIND_OP variable=c op=mul impl=fabric latency=2
c = a*b;
d = a*c;
return d;
}
提示: HLS 工具会选择用于变量 d 的实现。