psyclone.psyir.transformations.intrinsics.matmul2code_trans#
Module providing a transformation from a PSyIR MATMUL operator to PSyIR code. This could be useful if the MATMUL operator is not supported by the back-end or if the performance in the inline code is better than the intrinsic. MATMUL supports both matrix multiply and matrix vector multiply. This transformation supports both with the restriction that the first matrix must be of at least rank 2.
Classes#
Matmul2CodeTrans: Provides a transformation from a PSyIR MATMUL Operator node to
- class psyclone.psyir.transformations.intrinsics.matmul2code_trans.Matmul2CodeTrans[source]#
Provides a transformation from a PSyIR MATMUL Operator node to equivalent code in a PSyIR tree. Validity checks are also performed.
For a matrix-vector multiplication, if the dimensions of
R,A, andBareR(N),A(N,M),B(M), the transformation replaces:R=MATMUL(A,B)
with the following code:
do i=1,N R(i) = 0.0 do j=1,M R(i) = R(i) + A(i,j) * B(j)
For a matrix-matrix multiplication, if the dimensions of
R,A, andBareR(P,M),A(P,N),B(N,M), the MATMUL is replaced with the following code:do j=1,M do i=1,P R(i,j) = 0.0 do ii=1,N R(i,j) = R(i,j) + A(i,ii) * B(ii,j)
Note that this transformation does not support the case where
Ais a rank-1 array.Inheritance

- apply(node, options=None, **kwargs)[source]#
Apply the MATMUL intrinsic conversion transformation to the specified node. This node must be a MATMUL IntrinsicCall. The first argument must currently have two dimensions while the second must have either one or two dimensions. Each argument is permitted to have additional dimensions (i.e. more than 2) but in each case it is only the first one or two which may be ranges. Further, the ranges must currently be for the full index space for that dimension (i.e. array subsections are not supported). If the transformation is successful then an assignment which includes a MATMUL IntrinsicCall node is converted to equivalent inline code.
- Parameters:
node (
psyclone.psyir.nodes.IntrinsicCall) – a MATMUL IntrinsicCall node.options (Optional[Dict[str, Any]]) – options for the transformation.
- validate(node, options=None, **kwargs)[source]#
Perform checks to ensure that it is valid to apply the Matmul2CodeTran transformation to the supplied node.
- Parameters:
node (
psyclone.psyir.nodes.IntrinsicCall) – the node that is being checked.options (Optional[Dict[str, Any]]) – options for the transformation.
- Raises:
TransformationError – if the node argument is not the expected type.
TransformationError – if the parent of the MATMUL operation is not an assignment.
TransformationError – if the matmul arguments are not in the required form.
TransformationError – if sub-sections of an array are present in the arguments.