MetaScale/nt2 — pull request #138 by mgaunard (2012-03-04 02:40:28+00:00)
Title: Run assign

A lot of operations need to be specialized during the 'run' phase, which argument is an expression tree.
For all operations that return anything else than a scalar, we want to be able to define the operation in terms of an assignment. However, the hierarchy system does not allow to directly match on run(assign(elementwise, elementwise)), therefore an intermediate function was introduced: run_assign, that takes two arguments, the two branches of the assign node (plus optional state and data).

In particular this branch allows to specify that the existing run implementations are actually specific to element-wise operations, so that other operations (reductions, special kernels) can be defined separately.

A problem is still present: it is not possible to use the hierarchy system to match on both the semantic of the data and the category of the operation at the same time.

This branch made the choice of using the left-hand-side of the assignment as the semantic and the right-hand-side as the type of operation. Indeed, the right-hand-side is the only one suitable to match on the type of operation.
Unfortunately, this prevents detecting that an expression such as

table a = T(1);

is a scalar.
As a result, this expression now goes through the general-purpose element-wise mechanism which generates 2D loop-nests, potentially vectorized, parallelized, or GPU-accelerated.
As a side note, of_size was modified in order to support this properly.

Another thing that is not ideal is that the size of the assignment expression is normally computed by the generator of the assign node. However, since the assignment was unpacked, that information has been lost, and the assignment needs to be created again to get the correct size information that is needed to iterate the data.

Suggestions on how to best handle the issues welcome.