aboutsummaryrefslogtreecommitdiff
path: root/chapters/introduction.adoc
diff options
context:
space:
mode:
authorEric Kunze <eric.kunze@arm.com>2021-03-08 16:17:26 -0800
committerEric Kunze <eric.kunze@arm.com>2021-03-11 10:20:06 -0800
commit8e4a9d33f0527107fda724fc0f7b6b7c1f42bf79 (patch)
treebdb67b880fcae88f08cf45c27fdd5e572df007d4 /chapters/introduction.adoc
parent1e9ba65f263a15f1f9cf9b9484047ea51237187a (diff)
downloadspecification-8e4a9d33f0527107fda724fc0f7b6b7c1f42bf79.tar.gz
Adjust pseudocode types to account for zero point
When reading tensor values with zero point, the returned value has one more bit than the original to account for zero point. Update cases of apply_clip to properly represent the types involved. Change-Id: I60c17b1b244c34b4f04f042807936ae0f282ce93
Diffstat (limited to 'chapters/introduction.adoc')
-rw-r--r--chapters/introduction.adoc38
1 files changed, 22 insertions, 16 deletions
diff --git a/chapters/introduction.adoc b/chapters/introduction.adoc
index 3257ab0..7039e27 100644
--- a/chapters/introduction.adoc
+++ b/chapters/introduction.adoc
@@ -197,14 +197,20 @@ The padding array represents the before and after pair for each dimension.
....
assert((pad == NULL) || size(pad) == 2 * size(shape));
out_t tensor_read<in_t>(in_t *address, dim_t shape, dim_t index, in_t zero_point=0, dim_t pad=NULL) {
- assert(in_t == int8_t || zero_point == 0)
- unsigned offset = 0;
- for (i = 0; i < rank(shape); i++)
- if (index[i] < 0) { assert(pad && pad[2 * i] + index[i] >= 0); return 0; }
- if (index[i] >= shape[i]) { assert(pad && index[i] < shape[i] + pad[2 * i + 1]); return 0; }
- offset = offset * shape[i] + index[i]
- }
- return address[offset] - zero_point;
+ assert(in_t == int8_t || zero_point == 0)
+ unsigned offset = 0;
+ for (i = 0; i < rank(shape); i++) {
+ if (index[i] < 0) {
+ assert(pad && pad[2 * i] + index[i] >= 0);
+ return 0;
+ }
+ if (index[i] >= shape[i]) {
+ assert(pad && index[i] < shape[i] + pad[2 * i + 1]);
+ return 0;
+ }
+ offset = offset * shape[i] + index[i];
+ }
+ return address[offset] - zero_point;
}
....
@@ -212,12 +218,12 @@ out_t tensor_read<in_t>(in_t *address, dim_t shape, dim_t index, in_t zero_point
....
tensor_write<type>(<type> *address, dim_t shape, dim_t index, <type> value) {
- unsigned offset = 0;
- for (i = 0; i < rank(shape); i++)
- assert (index[i] >= 0 && index[i] < shape[i]);
- offset = offset * shape[i] + index[i];
- }
- address[offset] = value;
+ unsigned offset = 0;
+ for (i = 0; i < rank(shape); i++) {
+ assert (index[i] >= 0 && index[i] < shape[i]);
+ offset = offset * shape[i] + index[i];
+ }
+ address[offset] = value;
}
....
@@ -346,7 +352,7 @@ All table lookups are based on the following reference lookup function that take
....
int32_t apply_lookup(int16_t *table, int32_t value)
{
- int16_t clipped_value = apply_clip<int16_t>(value, -32768, +32767);
+ int16_t clipped_value = (int16_t)apply_clip<int32_t>(value, -32768, +32767);
int32_t index = (clipped_value + 32768) >> 7;
int32_t fraction = clipped_value & 0x7f;
int16_t base = table[index];
@@ -364,7 +370,7 @@ void generate_lookup_table(int16_t *table, int32_t (*reference)(int32_t))
{
for (int i = -256; i <= 256; i++) {
int32_t value = (*reference)(i);
- table[i + 256] = apply_clip<int16_t>(value, -32768, +32767)
+ table[i + 256] = (int16_t)apply_clip<int32_t>(value, -32768, +32767)
}
}
....