diff options
Diffstat (limited to 'chapters/type_conversion.adoc')
-rw-r--r-- | chapters/type_conversion.adoc | 104 |
1 files changed, 52 insertions, 52 deletions
diff --git a/chapters/type_conversion.adoc b/chapters/type_conversion.adoc index 37630e6..8f9e255 100644 --- a/chapters/type_conversion.adoc +++ b/chapters/type_conversion.adoc @@ -26,18 +26,18 @@ Casts a tensor from one data type to another. [source,c] .... -for_each (index in shape) { +for_each(index in shape) { in_t in = tensor_read<in_t>(input, shape, index); out_t out; - if (out_t==bool) { - out = (in!=0) ? true : false; - } else if (in_t==bool) { + if (out_t == bool_t) { + out = (in != 0) ? true : false; + } else if (in_t == bool_t) { out = (in) ? 1 : 0; - } else if (out_t==float) { + } else if (out_t == float_t) { out = round_to_nearest_float(in); - } else if (in_t==float) { - out = apply_clip(round_to_nearest_int(in), minimum<out_t>, maximum<out_t>); - } else if (sizeof(out_t)>=sizeof(in_t)) { + } else if (in_t == float_t) { + out = apply_clip<out_t>(round_to_nearest_int(in), minimum<out_t>, maximum<out_t>); + } else if (sizeof(out_t) >= sizeof(in_t)) { out = sign_extend(in); } else { out = truncate(in); @@ -51,24 +51,24 @@ for_each (index in shape) { |=== |Profile|Mode|in_t|out_t -|Any|bool to signed 8|bool|int8 -|Any|bool to signed 16|bool|int16 -|Any|bool to signed 32|bool|int32 -|Any|signed 8 to bool|int8|bool -|Any|signed 8 to signed 16|int8|int16 -|Any|signed 8 to signed 32|int8|int32 -|Any|signed 8 to float|int8|float -|Any|signed 16 to bool|int16|bool -|Any|signed 16 to signed 8|int16|int8 -|Any|signed 16 to signed 32|int16|int32 -|Any|signed 16 to float|int16|float -|Any|signed 32 to bool|int32|bool -|Any|signed 32 to signed 8|int32|int8 -|Any|signed 32 to signed 16|int32|int16 -|Any|signed 32 to float|int32|float -|Any|float to signed 8|float|int8 -|Any|float to signed 16|float|int16 -|Any|float to signed 32|float|int32 +|Any|bool to signed 8|bool_t|int8_t +|Any|bool to signed 16|bool_t|int16_t +|Any|bool to signed 32|bool_t|int32_t +|Any|signed 8 to bool|int8_t|bool_t +|Any|signed 8 to signed 16|int8_t|int16_t +|Any|signed 8 to signed 32|int8_t|int32_t +|Any|signed 8 to floating-point|int8_t|float_t +|Any|signed 16 to bool|int16_t|bool_t +|Any|signed 16 to signed 8|int16_t|int8_t +|Any|signed 16 to signed 32|int16_t|int32_t +|Any|signed 16 to floating-point|int16_t|float_t +|Any|signed 32 to bool|int32_t|bool_t +|Any|signed 32 to signed 8|int32_t|int8_t +|Any|signed 32 to signed 16|int32_t|int16_t +|Any|signed 32 to floating-point|int32_t|float_t +|Any|floating-point to signed 8|float_t|int8_t +|Any|floating-point to signed 16|float_t|int16_t +|Any|floating-point to signed 32|float_t|int32_t |=== ==== RESCALE @@ -93,26 +93,26 @@ Rescale quantized values into a new domain. This function scales by factor: mult |Attribute|out_t|output_zp|-|Output tensor zero point |Input (MT profile) Attribute (BI/MI profiles)|mul_t|multiplier[NC]|-|Scaling multiplier array |Input (MT profile) Attribute (BI/MI profiles)|uint6_t|shift[NC] |-|Scaling shift array -|Input (MT profile) Attribute (BI/MI profiles)|bool|scale32|-|if (scale32) mul_t=int32_t else mul_t=int16_t -|Attribute|bool|double_round|-|Select double round mode -|Attribute|bool|per_channel|-|if (per_channel) NC=shape[dims-1] else NC=1 +|Input (MT profile) Attribute (BI/MI profiles)|bool_t|scale32|-|if (scale32) mul_t=int32_t else mul_t=int16_t +|Attribute|bool_t|double_round|-|Select double round mode +|Attribute|bool_t|per_channel|-|if (per_channel) NC=shape[dims-1] else NC=1 |=== *Operation Function:* [source,c] .... -for_each (index in shape) { - assert(in_t == int8 || in_t == uint8 || input_zp == 0); - assert(out_t == int8 || out_t == uint8 || output_zp == 0); - assert((scale32 && in_t!=int48_t) || (!scale32 && !double_round)); - int48_t value = tensor_read<in_t>(input, shape, index, input_zp); +for_each(index in shape) { + assert(in_t == int8_t || in_t == uint8_t || input_zp == 0); + assert(out_t == int8_t || out_t == uint8_t || output_zp == 0); + assert((scale32 && in_t != int48_t_t) || (!scale32 && !double_round)); + int48_t_t value = tensor_read<in_t>(input, shape, index, input_zp); int c = (per_channel) ? index[dims-1] : 0; int32_t result = (scale32) ? - apply_scale_32(value, multiplier[c], shift[c], double_round) : - apply_scale_16(value, multiplier[c], shift[c]); - result = apply_clip(result + output_zp, minimum<out_t>, maximum<out_t>) - tensor_write<out_t>(output, shape, index, result) + apply_scale_32(value, multiplier[c], shift[c], double_round) : + apply_scale_16(value, multiplier[c], shift[c]); + result = apply_clip<out_t>(result + output_zp, minimum<out_t>, maximum<out_t>); + tensor_write<out_t>(output, shape, index, result); } .... @@ -121,18 +121,18 @@ for_each (index in shape) { |=== |Profile|Mode|in_t|out_t -|Any|signed 8 to signed 8|int8|int8 -|Any|signed 8 to signed 16|int8|int16 -|Any|signed 8 to signed 32|int8|int32 -|Any|signed 16 to signed 8|int16|int8 -|Any|signed 16 to signed 16|int16|int16 -|Any|signed 16 to signed 32|int16|int32 -|Any|signed 32 to signed 8|int32|int8 -|Any|signed 32 to signed 16|int32|int16 -|Any|signed 32 to signed 32|int32|int32 -|Any|signed 48 to signed 8|int48|int8 -|Any|signed 48 to signed 16|int48|int16 -|Any|signed 48 to signed 32|int48|int32 -|Any|unsigned 8 to signed 8|uint8|int8 -|Any|signed 8 to unsigned 8|int8|uint8 +|Any|signed 8 to signed 8|int8_t|int8_t +|Any|signed 8 to signed 16|int8_t|int16_t +|Any|signed 8 to signed 32|int8_t|int32_t +|Any|signed 16 to signed 8|int16_t|int8_t +|Any|signed 16 to signed 16|int16_t|int16_t +|Any|signed 16 to signed 32|int16_t|int32_t +|Any|signed 32 to signed 8|int32_t|int8_t +|Any|signed 32 to signed 16|int32_t|int16_t +|Any|signed 32 to signed 32|int32_t|int32_t +|Any|signed 48 to signed 8|int48_t_t|int8_t +|Any|signed 48 to signed 16|int48_t_t|int16_t +|Any|signed 48 to signed 32|int48_t_t|int32_t +|Any|unsigned 8 to signed 8|uint8_t|int8_t +|Any|signed 8 to unsigned 8|int8_t|uint8_t |=== |