Cast (float to half/int32_t)
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
√ |
|
√ |
|
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 Cast(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 enum class and is used to control the precision conversion mode. The definition is as follows:
For Cast, the conversion can only be float-to-half (f322f16) or float-to-int32_t (f322s32). The supported RoundMode values are as follows:
For details about the precision conversion rules of Cast, see Table 1. |
Parameter |
Input/Output |
Description |
|---|---|---|
valueIn |
Input |
Scalar whose data type is to be converted. |
Returns
valueIn of the U type.
Constraints
None
Example
1 2 3 | float valueIn = 2.5; // Output (valueOut): 3. 2.5 is rounded up to 3. int32_t valueOut = AscendC::Cast<float, int32_t, AscendC::RoundMode::CAST_ROUND>(valueIn); |