14.2.6.2 Binary numeric promotions

博客介绍了预定义二元运算符的二进制数值提升规则,它会将操作数隐式转换为共同类型。规则按顺序包括不同类型操作数的转换,如decimal、double、float等。还指出不允许decimal与double、float混合运算,可通过强制类型转换解决不兼容问题。
This clause is informative.
Binary numeric promotion occurs for the operands of the predefined +, ?, *,
/, %, &, |, ^, ==, !=, >, <, >=,
and <= binary operators. Binary numeric promotion implicitly converts both
operands to a common type
which, in case of the non-relational operators, also becomes the result
type of the operation. Binary numeric
promotion consists of applying the following rules, in the order they
appear here:
?If either operand is of type decimal, the other operand is converted to
type decimal, or a compiletime
error occurs if the other operand is of type float or double.
?Otherwise, if either operand is of type double, the other operand is
converted to type double.
?Otherwise, if either operand is of type float, the other operand is
converted to type float.
?Otherwise, if either operand is of type ulong, the other operand is
converted to type ulong, or a
compile-time error occurs if the other operand is of type sbyte, short,
int, or long.
?Otherwise, if either operand is of type long, the other operand is
converted to type long.
?Otherwise, if either operand is of type uint and the other operand is of
type sbyte, short, or int,
both operands are converted to type long.
?Otherwise, if either operand is of type uint, the other operand is
converted to type uint.
?Otherwise, both operands are converted to type int.
[Note: The first rule disallows any operations that mix the decimal type
with the double and float types.
The rule follows from the fact that there are no implicit conversions
between the decimal type and the
double and float types. end note]
[Note: Also note that it is not possible for an operand to be of type ulong
when the other operand is of a
signed integral type. The reason is that no integral type exists that can
represent the full range of ulong as
well as the signed integral types. end note]
In both of the above cases, a cast expression can be used to explicitly
convert one operand to a type that is
compatible with the other operand.
[Example: In the example
decimal AddPercent(decimal x, double percent) {
return x * (1.0 + percent / 100.0);
}
a compile-time error occurs because a decimal cannot be multiplied by a
double. The error is resolved by
explicitly converting the second operand to decimal, as follows:
decimal AddPercent(decimal x, double percent) {
return x * (decimal)(1.0 + percent / 100.0);
}
end example]
End of informative text.
### 使用 DDK_6.4.6.2 中的 Acuity Toolkit 二进制工具进行模型量化 在使用 DDK_6.4.6.2 版本中的 Acuity Toolkit 二进制工具进行模型量化时,以下内容提供了详细的指导和相关说明。 #### 工具概述 Acuity Toolkit 是一种用于深度学习模型优化和量化的工具集[^1]。它支持从浮点模型到定点模型的转换,并提供多种量化策略以适应不同的硬件平台需求。DDK(Deep Learning Development Kit)版本 6.4.6.2 中包含了 Acuity Toolkit 的二进制工具,这些工具可以直接用于量化操作而无需重新编译。 #### 安装与环境配置 在使用 Acuity Toolkit 之前,需要确保安装了正确的 DDK 版本并配置好环境变量。以下是具体的安装步骤: ```bash # 解压 DDK 压缩包 tar -xvf DDK_6.4.6.2.tar.gz # 配置环境变量 export PATH=$PATH:/path/to/DDK_6.4.6.2/bin export LD_LIBRARY_PATH=/path/to/DDK_6.4.6.2/lib:$LD_LIBRARY_PATH ``` #### 模型量化流程 Acuity Toolkit 提供了一个命令行工具 `acuity_quantize` 用于执行模型量化操作。以下是其基本用法: ```bash acuity_quantize --input_model=path/to/floating_point_model.pb \ --output_model=path/to/quantized_model.pb \ --calibration_dataset=path/to/calibration_data \ --quantization_scheme=symmetric_per_tensor ``` - `--input_model`:指定输入的浮点模型文件路径。 - `--output_model`:指定输出的量化模型文件路径。 - `--calibration_dataset`:指定用于校准的数据集路径,通常为一组代表性的输入样本。 - `--quantization_scheme`:指定量化方案,例如对称量化或非对称量化[^2]。 #### 示例代码 以下是一个完整的脚本示例,展示如何使用 Acuity Toolkit 对模型进行量化: ```python import subprocess # 定义量化参数 input_model = "path/to/floating_point_model.pb" output_model = "path/to/quantized_model.pb" calibration_dataset = "path/to/calibration_data" quantization_scheme = "symmetric_per_tensor" # 调用 acuity_quantize 工具 command = [ "acuity_quantize", f"--input_model={input_model}", f"--output_model={output_model}", f"--calibration_dataset={calibration_dataset}", f"--quantization_scheme={quantization_scheme}" ] # 执行命令 subprocess.run(command, check=True) ``` #### 注意事项 在使用 Acuity Toolkit 进行模型量化时,需注意以下几点: - 校准数据集的质量直接影响量化模型的精度[^3]。建议选择能够充分覆盖模型输入分布的样本。 - 不同的量化方案可能适用于不同的硬件平台。例如,某些嵌入式设备可能更适合对称量化,而其他设备可能支持非对称量化[^4]。 - 在量化过程中,可以调整量化位宽(如 INT8、INT16)以平衡精度和性能[^5]。 ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值