From e5d22a77300643f0a3013ad40ccd2b5b76788b42 Mon Sep 17 00:00:00 2001 From: Eric Kunze Date: Tue, 15 Dec 2020 15:41:05 -0800 Subject: Disambiguate scale_t in RESIZE command scale_t is already defined globally for the rescaling. Move pseudocode for count_leading_zeros to introduction, and use it in the implementation of CLZ. Change-Id: I2453bce93b6dd25e870b8a010fc62af4c001cbf9 --- chapters/ewise_unary.adoc | 12 +----------- chapters/image.adoc | 16 ++++++++-------- chapters/introduction.adoc | 19 +++++++++++++++++-- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/chapters/ewise_unary.adoc b/chapters/ewise_unary.adoc index c64bef7..8cdce3d 100644 --- a/chapters/ewise_unary.adoc +++ b/chapters/ewise_unary.adoc @@ -122,17 +122,7 @@ Elementwise count leading zeros operation for_each (index in shape) { in_t acc = 0 in_t value1 = tensor_read(input1, shape, index) - if (value1 == 0) { - acc = 32 // input1_width - } - else { - mask = 1 << (32 - 1) // input1_width - 1 - acc = 0 - while (mask & value1 == 0) { - mask = mask >> 1 - acc = acc + 1 - } - } + acc = count_leading_zeros(value1) tensor_write(output, shape, index, acc) } ---- diff --git a/chapters/image.adoc b/chapters/image.adoc index e8b2917..a8e0219 100644 --- a/chapters/image.adoc +++ b/chapters/image.adoc @@ -38,9 +38,9 @@ from the strides. |Input|in_t*|input|[N,IH,IW,C]|Input tensor |Attribute|int*|output_size|[2]|[OH,OW] -|Attribute|scale_t*|stride|[2]|[stride_y, stride_x] -|Attribute|scale_t*|offset|[2]|[offset_y, offset_x] -|Attribute|int|shift|Shift value (must be zero if scale_t is float) +|Attribute|resize_t*|stride|[2]|[stride_y, stride_x] +|Attribute|resize_t*|offset|[2]|[offset_y, offset_x] +|Attribute|int|shift|Shift value (must be zero if resize_t is float) |Attribute|mode_t|mode|-|BILINEAR or NEAREST |Output|out_t*|output|[N,OH,OW,C]|Output tensor |=== @@ -54,13 +54,13 @@ None [source,c] ---- // scale assert prevents int32_t accumulator overflow for in_t==int8_t -assert((scale_t==float && shift==0)||(00 && stride_y>0); for_each (0<=n(acc_t a, acc_t b) { } .... -The following functions are used in the pseudocode to take maximum, minimum or clip values to a range. - +The following functions are used in the pseudocode to take maximum, +minimum, clip values to a range, or count leading zeros. +[[count_leading_zeros]] .... apply_max( a, b) { if (a >= b) return a; else return b; @@ -347,6 +348,20 @@ The following functions are used in the pseudocode to take maximum, minimum or c value = apply_min(value, max_val); return value; } + +int32_t count_leading_zeros(int32_t a) { + int32_t acc = 32; + if (a != 0) { + uint32_t mask; + mask = 1 << (32 - 1); // width of int32_t - 1 + acc = 0; + while ((mask & a) == 0) { + mask = mask >> 1; + acc = acc + 1; + } + } + return acc; +} .... ==== Quantized Convolutions -- cgit v1.2.1