From 71b02b19a1bc9c73b3f2ac9b65086151588e3e27 Mon Sep 17 00:00:00 2001 From: Eric Kunze Date: Fri, 12 Mar 2021 11:09:39 -0800 Subject: Add 8-bit support to TABLE It is challenging to work back from the RESCALE->TABLE->RESCALE for a simple 8-bit lookup. This adds support to TOSA for a simple direct 256 entry 8-bit lookup table for the TABLE operator. The 16-bit interpolated table is still required for a conformant implementation. Change-Id: I0ef218444f0b57b880aa8d1c7e96efedae72eb53 Signed-off-by: Eric Kunze --- chapters/ewise_binary.adoc | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/chapters/ewise_binary.adoc b/chapters/ewise_binary.adoc index c005611..6a5c575 100644 --- a/chapters/ewise_binary.adoc +++ b/chapters/ewise_binary.adoc @@ -591,14 +591,14 @@ for_each(index in shape) { ==== TABLE -Interpolated table lookup operation. The int16_t input is treated as a fixed-point 9.7 value. The high 9 bits are used to index into the table. The fractional 7 bits are used to interpolate based on table[index] and table[index+1]. The TABLE operator returns a 16.7 interpolated value which can then be input to the RESCALE operator to scale to the required output data type. Note that table has 513 values to handle table[index+1] when index=511. - -An int8_t to int8_t table lookup can be constructed in TOSA as follows: - -* Use RESCALE (in_t=int8_t, out_t=int16_t, input_zp=0, scale=1<<14, shift=7) to perform a shift left of 7 and convert to int16_t -* Use the TABLE operator to produce a fixed point 16.7 result. The lower 7 bits will be zero and only the central 256 table entries will be used. -* Use RESCALE (in_t=int32_t, out_t=int8_t, scale=1<<14, shift=28) to scale the output to int8_t range (or alternate scale as required) -* Note that this TOSA sequence can be implemented in software as a 256 entry 8-bit lookup table. +Table lookup operation. +For int8_t TABLE operation, perform a 256 entry table lookup returning an int8_t value. +For int16_t tables, the int16_t input is treated as a fixed-point 9.7 value. +The most significant 9 bits are used to index into the table. +The fractional 7 bits are used to interpolate based on table[index] and table[index+1]. +For int16_t inputs, the TABLE operator returns a 16.7 interpolated value in an int32_t. +This value can then be input to the RESCALE operator to scale to the required output data type. +Note that int16_t table has 513 values to handle table[index+1] when index=511. An int16_t to int16_t table lookup can be constructed in TOSA as follows: @@ -611,7 +611,7 @@ An int16_t to int16_t table lookup can be constructed in TOSA as follows: |Argument|Type|Name|Shape|Description |Input|in_t*|Input|shape|Input tensor -|Input|table_t*|table|[513]|Lookup table tensor +|Input|table_t*|table|[TABLE_SIZE]|Lookup table tensor |Output|out_t*|output|shape|Output tensor |=== @@ -625,7 +625,11 @@ None ---- for_each(index in shape) { in_t value = tensor_read(input, shape, index); - out_t acc = apply_lookup(table, value); + if (in_t == int8_t) { + out_t acc = table[value]; + } else { + out_t acc = apply_lookup(table, value); + } tensor_write(output, shape, index, acc); } ---- @@ -633,8 +637,9 @@ for_each(index in shape) { *Supported Data Types:* |=== -|Profile|Mode|in_t|table_t|out_t +|Profile|Mode|in_t|table_t|TABLE_SIZE|out_t -|Any|signed 16|int16_t|int16_t|int32_t +|Any|signed 8|int8_t|int8_t|256|int8_t +|Any|signed 16|int16_t|int16_t|513|int32_t |=== -- cgit v1.2.1