forall tensor constructs in VADL
#364
benedikt-l-huber
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This is a summary of a discussion where @Jozott00 and @benedikt-l-huber tried to
find an agreement on the semantics of VADL's
forallconstructs.There are three
forallconstructs in VADL.forall ... tensor
The
forall i in 3..0 tensor someExpressionexpression.someExpressioncan be of any type (also a tensor).The number of dimensions of the resulting tensor is the number of
indices in the index list ( e.g.,
i in 3..0, j in 4..1) plus the number of dimensions ofsomeExpressione.g.:
Has 5 dimensions. We can access a single Bit like this
e(1)(0)(1)(2)(14).Note that all operations in
someExpressionhave to be defined in VADL.The reason is the types on which
+is defined. In thefjexamplez(j)andp(j)are of type
UInt<2><32>for which+is not defined.Tensor construction with
forall ... tensoris done from left to right. I.e., the "next" element isappended to the right.
In the following example
x = bandaisxin reversed order.forall ... do
The
forall i in 3..0 do someStatementstatement which can read write registers.VADL's semantics ensures that all reads occur before all writes.
The
forall ... dostatement is especially useful for strides writes.e.g.:
In theory this could be rewritten using only the
forall ... tensorexpression asBut this is much less readable and it would necessitate further analysis
to find out that writes to the odd indices of
Xare the identity function.forall ... fold
The
forall i in 0..3 fold + with someExpressioncan be used to make a reduction of one dimension.There can only be a single index in the list. It signifies the dimension across which the reduction
occurs. Again the operation (in this example the
+) has to work with someExpression.Right now VADL restricts the operation to a set of these binary operators
+ - * & | ^.Note that this list contains also contains
-which is not distributive, thus theorder of the indices has to be fixed. It is defined by the index list which can be
increasing or decreasing. Again the "next" operand is applied to the right of the operand.
So
e = gandf = yin the following example:This semantics leads to a composition problem, like in the following example:
This works in VADL since all uses of
+are supported.If we want to compose the same thing with
letexpressions for the individual dimensionsthe problem becomes apparent. The expression
estill has to list all dimensions, socomposition does not work well.
A possible solution would be to define
+also for more dimensional tensors in VADL.Then the following would be possible, which composes better.
Note that the
+for expressionmnow has to be defined on for the typeUInt<3><32>As a comparison: Pytorch provides a number of reduction operators e.g.,
argmaxthatdo a similar thing than VADL's
forall ... fold. These pytorch operators explicitlytake the dimension on which to perform the reduction as a parameter.
For the type
UInt<32>, in VADL+is already defined on both the inner type (Bits) andthe outer type (
UInt). So in the following bothkandlare defined in VADL at the moment.So extending operations to even more dimensions seems to be quite natural for VADL.
This would make it possible to describe more complex tensor operations in a convenient way.
Nevertheless, we think that this proposed extension is not necessary at the moment.
Since most tensor operation that will be described in VADL are far less complex than
the ones that appear in e.g., pytorch.
Beta Was this translation helpful? Give feedback.
All reactions