-
Notifications
You must be signed in to change notification settings - Fork 171
Design of Vector Arrays in ASR
To represent SIMD arrays, we currently have Array_t
with its physical type as SIMD
. Now in the ASR Passes or Backends, we might need to do some special checking/handling for SIMD
arrays. For example, if we have to skip the SIMD
array processing in some pass (for example array_op
pass), we do the following at (several) places wherever it is needed:
if (ASR::is_a<ASR::Array_t>(*ASRUtils::expr_type(x.m_target)) &&
ASR::down_cast<ASR::Array_t>(ASRUtils::expr_type(x.m_target))->m_physical_type
== ASR::array_physical_typeType::SIMDArray) {
return;
}
A drawback in this approach is that we do not have a representation for binary operations on arrays at the ASR Level. Consider the following example where A
, B
and C
are SIMD
arrays of type reals
:
C = A + B
The ASR that gets generated for the above line is
(=
(Var 2 c)
(RealBinOp
(Var 2 a)
Add
(Var 2 b)
(Array
(Real 4)
[((IntegerConstant 1 (Integer 4))
(IntegerConstant 8 (Integer 4)))]
SIMDArray
)
()
)
()
)
The concern in the above generated ASR is that it has a RealBinOp
node with two variables of type vector arrays
. That is, the node RealBinOp
does not have scalar real numbers as its children, but has VectorArray
's of real numbers.
Similar to how we supported UnsignedIntegers
at the ASR Level, we have the possibility of supporting Vector arrays by adding a new ttype_t
, that is VectorArray_t
. This new type will support only a single dimension that is in the order of power of 2
, unlike the regular arrays that can be multi-dimensional.
Along with the type VectorArray_t
, we can add nodes for operations on this type like visit_VectorAdd()
, visit_VectorSub()
and other operations. These can also be collectively grouped under visit_VectorBinOp()
.
For cast operations between Arrays and VectorArrays we can add a cast type like ArrayToVectorArray
or VectorArrayToArray
in the ASR Cast_t
node.