[cfe-dev] matrix type conversion

Florian Hahn via cfe-dev cfe-dev at lists.llvm.org
Wed Aug 12 10:22:51 PDT 2020


> On Aug 12, 2020, at 12:25, Sjoerd Meijer <Sjoerd.Meijer at arm.com> wrote:
> Hi Florian (+cfe-dev for visibilty),
> I was playing a little bit with Clang matrix language extension and and wanted to check with you to see if I am not missing something about the matrix type conversion. The draft spec says:
> "A value of matrix type can be converted to another matrix type if the number of rows and columns are the same and the value’s elements can be converted to the element type of the result type. "
> I have tried a different variants of this:
>     typedef char m2x8_t __attribute__((matrix_type(2, 8)));
>     typedef char m8x2_t __attribute__((matrix_type(8, 2)));
>     typedef char m2x2_char_t __attribute__((matrix_type(2, 2)));
>     typedef int  m2x2_int_t  __attribute__((matrix_type(2, 2)));
>     m2x2_int_t f(m2x8_t a, m8x2_t b) {
>       return static_cast<m2x2_int_t>(a *b);
>     }
> but am getting errors that this conversion is not allowed. Unless I am doing something very silly here, I am guessing that this because the matrix extension is work in progress?

This should work according to the spec, but the conversion has not been implemented yet I think. I’ve created https://bugs.llvm.org/show_bug.cgi?id=47141 and linked it to https://bugs.llvm.org/show_bug.cgi?id=46163 which should act as an umbrella issue to track the missing pieces.

> The draft spec also says that implicit conversions don't apply, but that would perhaps be convenient? But I haven't given this any thoughts yet though if that could be problematic.

I think currently we match the behavior for vector types and only convert scalar operands for binary operators implicitly to matrixes. If there’s a strong need for implicit conversions, this is certainly something that can be revisited.

> Moving on a bit to lowering this to te matrix multiply intrinsics. I think it would be convenient if the matrix multiply can accumulate in a wider type (because that's what some instructions do). While there are probably different approaches possible, the llvm intrinsic has the vector type for the return value and its arguments:
> vectorty @llvm.matrix.multiply.*(vectorty %A, vectorty %B, ...)
>  So perhaps we can relax this?

Yes we can certainly extend this, to allow use cases to map to hardware instructions that implement an extension step, like AAch64’s udot. IIRC it extends the sums, which I think would make the most sense to use, as otherwise it should be sufficient to extend the operands/result.

I think the more interesting question here would be how this fits into the C/C++ spec. I guess it would be possible to specify it so a multiply that gets extended lowers to the widening intrinsic, but this would seem quite surprising/awkward. In my opinion, a separate builtin would be a cleaner solution.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200812/2e31bd74/attachment.html>

More information about the cfe-dev mailing list