ScalarCast
Applicability
Product |
Supported/Unsupported |
|---|---|
√ |
|
√ |
|
x |
|
√ |
|
x |
|
x |
Function Usage
Converts the data type of a scalar.
Prototype
1 2 | template <typename T, typename U, RoundMode roundMode> __aicore__ inline U ScalarCast(T valueIn) |
Parameters
Parameter |
Description |
||
|---|---|---|---|
T |
Data type of valueIn. The value can be float. |
||
U |
Data type after conversion. The value can be half or int32_t. |
||
roundMode |
Precision conversion mode. The type is RoundMode. RoundMode is of the enumeration type and is used to control the precision conversion mode. The definition is as follows:
For ScalarCast, the conversion can only be float-to-half (f322f16) or float-to-int32_t (f322s32). The supported round modes are as follows:
The precision conversion rule of ScalarCast is the same as that of Cast. For details, see Table 1. |
Parameter |
Input/Output |
Description |
|---|---|---|
valueIn |
Input |
Scalar of the data type to be converted. |
Returns
ValueIn of the U type.
Constraints
None
Example
1 2 3 | float valueIn = 2.5; // Output (valueOut): 3 int32_t valueOut = AscendC::ScalarCast<float, int32_t, AscendC::RoundMode::CAST_ROUND>(valueIn); |