From 54ff87d31637c97958ac49e40312e9b6de0a8f1a Mon Sep 17 00:00:00 2001 From: Eric Kunze Date: Mon, 22 Feb 2021 13:21:05 -0800 Subject: Change CONCAT to allow a list of input tensors Originally only a pair of input tensors were allowed. This aligns with what the frameworks do, and simplifies the translation of frameworks into TOSA and allows compilers to view the output as a whole. Change-Id: Id4461abdf0cc763e84e086142222e87d28cd8afc Signed-off-by: Eric Kunze --- chapters/data_layout.adoc | 30 ++++++++++++++++++------------ chapters/data_nodes.adoc | 6 +++--- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/chapters/data_layout.adoc b/chapters/data_layout.adoc index 5d54e62..9d01e71 100644 --- a/chapters/data_layout.adoc +++ b/chapters/data_layout.adoc @@ -10,31 +10,37 @@ === Data Layout ==== CONCAT -Concatenate two tensors along a given axis. No data conversion happens during a concat operation. +Concatenate a list of tensors along a given axis. +No data conversion happens during a concat operation. *Arguments:* |=== |Argument|Type|Name|Shape|Description -|Input|in_t*|input1|shape1|Input tensor with rank from 1 to 4 -|Input|in_t*|input2|shape2|Input tensor with rank matching input1 -|Attribute|int|axis|-|Axis along which concatenation is to occur. -|Output|in_t*|output|shape|Output tensor of same type, size as the input tensor +|Input|in_t**|input1|shapes1[]|List of input tensors +|Attribute|int|axis|-|Axis along which concatenation is to occur +|Output|in_t*|output|shape|Output tensor |=== *Operation Function:* [source,c] ---- -for_each (index1 in shape) { - index2 = index1 - index2[axis] = index1[axis] - shape1[axis] - in_t value = (index2[axis] < 0) ? - tensor_read(input1, shape1, index1) : - tensor_read(input2, shape2, index2) ; - tensor_write(output, shape, index1, value); +for_each(index1 in shape) { + index2 = index1; + for (tensor t = 0; t < length(input1); t++) { + // Continue to concatenate along axis from each tensor + // For each output location, we are looking for the + // appropriate input tensor + if (index2[axis] >= 0 && index2[axis] < shapes1[t][axis]) { + in_t value = tensor_read(input1[t], shapes1[t], index2); + tensor_write(output, shape, index1, value); + } + index2[axis] = index2[axis] - shapes1[t][axis]; + } } + ---- *Supported Data Types:* diff --git a/chapters/data_nodes.adoc b/chapters/data_nodes.adoc index 4297a9a..87b0b9b 100644 --- a/chapters/data_nodes.adoc +++ b/chapters/data_nodes.adoc @@ -43,7 +43,7 @@ Returns a tensor with the same shape, type, and contents as the input. |=== |Argument|Type|Name|Shape|Description -|Input|in_t|input1|shape|Input tensor +|Input|in_t*|input1|shape|Input tensor |Output|in_t*|output|shape|Output tensor of same type, size as the input tensor |=== @@ -68,8 +68,8 @@ Returns a list of tensors with the same shape, type, and contents as the input l |=== |Argument|Type|Name|Shape|Description -|Input|in_t|input1|[shape1, shape2, …]|List of input tensors -|Output|in_t*|output|[shape1, shape2, …]|List of output tensors of same type, size as the input tensors +|Input|in_t**|input1|shape[]|List of input tensors +|Output|in_t**|output|shape[]|List of output tensors of same type, size as the input tensors |=== *Supported Data Types:* -- cgit v1.2.1