aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Kunze <eric.kunze@arm.com>2020-12-15 15:41:05 -0800
committerEric Kunze <eric.kunze@arm.com>2020-12-16 14:25:20 -0800
commite5d22a77300643f0a3013ad40ccd2b5b76788b42 (patch)
tree61ccb85014ce007166882c79c690ceae1534f289
parent5d60c71300ecb78cd59ca30f6383ec7f5527d3c5 (diff)
downloadspecification-e5d22a77300643f0a3013ad40ccd2b5b76788b42.tar.gz
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
-rw-r--r--chapters/ewise_unary.adoc12
-rw-r--r--chapters/image.adoc16
-rw-r--r--chapters/introduction.adoc19
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<in_t>(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<in_t>(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)||(0<shift && shift<=11));
+assert((resize_t==float && shift==0)||(0<shift && shift<=11));
assert(stride_x>0 && stride_y>0);
for_each (0<=n<N, 0<=oy<OH, 0<=ox<OW; 0<=c<C) {
- unit = (scale_t==float) ? 1.0 : (1<<shift);
+ unit = (resize_t==float) ? 1.0 : (1<<shift);
y = oy * stride_y + offset_y
x = ox * stride_x + offset_x
- if (scale_t==float) {
+ if (resize_t==float) {
iy = (int)floor(y); dy = y - (float)iy;
ix = (int)floor(x); dx = x - (float)ix;
} else {
@@ -92,7 +92,7 @@ for_each (0<=n<N, 0<=oy<OH, 0<=ox<OW; 0<=c<C) {
*Supported Data Types:*
|===
-|Profile|Mode|scale_t|in_t|out_t
+|Profile|Mode|resize_t|in_t|out_t
|Any|signed 8, bilinear|int16|int8|int32
|Any|signed 8, nearest |int16|int8|int8
@@ -101,7 +101,7 @@ for_each (0<=n<N, 0<=oy<OH, 0<=ox<OW; 0<=c<C) {
|MI,MT|float |float|float|float
|===
-*Scaling Modes:*
+*Resize Modes:*
|===
|Mode|Description
diff --git a/chapters/introduction.adoc b/chapters/introduction.adoc
index 3133f36..da1c1b1 100644
--- a/chapters/introduction.adoc
+++ b/chapters/introduction.adoc
@@ -330,8 +330,9 @@ acc_t apply_sub<acc_t>(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]]
....
<type> apply_max<type>(<type> a, <type> 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