<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hi,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
> This should work according to the spec, but the conversion has not been implemented yet I think. I’ve created <a href="https://bugs.llvm.org/show_bug.cgi?id=47141">https://bugs.llvm.org/show_bug.cgi?id=47141</a> and linked it to <a href="https://bugs.llvm.org/show_bug.cgi?id=46163">https://bugs.llvm.org/show_bug.cgi?id=46163</a> which
should act as an umbrella issue to track the missing pieces.
<div style="margin: 0px"><br style="color: rgb(50, 49, 48); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; background-color: rgb(255, 255, 255)">
</div>
<div style="margin: 0px">Ah, I was unaware of that umbrella ticket. Thanks for that, and for raising the ticket.</div>
<div style="margin: 0px"><br>
</div>
<div style="margin: 0px">> 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.</div>
<div style="margin: 0px"><br>
</div>
<div style="margin: 0px">Not sure if there's a strong need, but from writing my first examples yesterday, I can see that it would be convenient and possibly cleaner too (i.e. less text/clutter). I am not sure about this one, but it's also what people would
expect perhaps?</div>
<div style="margin: 0px"><br>
</div>
</div>
<div id="appendonsend"></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
> 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.</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Yes, or the v8.6 matrix multiply accumulate instructions which multiply 8 bit values and store them to 32-bits.<br>
<div><br>
</div>
> 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. I</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
As I said, I haven't given this too much thought yet, so just for my understanding, what exactly is the surprising/awkward bit of the C/C++ spec here? I was guessing that the assignment of a result from a matrix operation, using an implicit/explicit conversion,
would take care of this?</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Cheers,</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Sjoerd.</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Florian Hahn <florian_hahn@apple.com><br>
<b>Sent:</b> 12 August 2020 18:22<br>
<b>To:</b> Sjoerd Meijer <Sjoerd.Meijer@arm.com><br>
<b>Cc:</b> cfe-dev@lists.llvm.org Developers <cfe-dev@lists.llvm.org><br>
<b>Subject:</b> Re: matrix type conversion</font>
<div> </div>
</div>
<div class="" style="word-wrap:break-word; line-break:after-white-space">Hi,
<div class=""><br class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">On Aug 12, 2020, at 12:25, Sjoerd Meijer <<a href="mailto:Sjoerd.Meijer@arm.com" class="">Sjoerd.Meijer@arm.com</a>> wrote:</div>
<br class="x_Apple-interchange-newline">
<div class="">
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt">
Hi Florian (+cfe-dev for visibilty),</div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt">
<br class="">
</div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt">
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:</div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt">
<br class="">
</div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt">
"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. "</div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt">
<br class="">
</div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt">
I have tried a different variants of this:</div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt">
<br class="">
</div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt">
typedef char m2x8_t __attribute__((matrix_type(2, 8)));
<div class=""> typedef char m8x2_t __attribute__((matrix_type(8, 2)));</div>
<div class=""> typedef char m2x2_char_t __attribute__((matrix_type(2, 2)));</div>
<div class=""> typedef int m2x2_int_t __attribute__((matrix_type(2, 2)));</div>
<div class=""><br class="">
</div>
<div class=""> m2x2_int_t f(m2x8_t a, m8x2_t b) {</div>
<div class=""> return static_cast<m2x2_int_t>(a *b);</div>
<div class=""> }</div>
<div class=""><br class="">
</div>
<div class="">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?</div>
<div class=""><br class="">
</div>
</div>
</div>
</blockquote>
<div><br class="">
</div>
This should work according to the spec, but the conversion has not been implemented yet I think. I’ve created <a href="https://bugs.llvm.org/show_bug.cgi?id=47141" class="">https://bugs.llvm.org/show_bug.cgi?id=47141</a> and linked it to <a href="https://bugs.llvm.org/show_bug.cgi?id=46163" class="">https://bugs.llvm.org/show_bug.cgi?id=46163</a>
which should act as an umbrella issue to track the missing pieces.</div>
<div><br class="">
</div>
<div><br class="">
</div>
<div>
<blockquote type="cite" class="">
<div class="">
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt">
<div class="">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.</div>
</div>
</div>
</blockquote>
<div><br class="">
</div>
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.</div>
<div><br class="">
</div>
<div>
<blockquote type="cite" class="">
<div class="">
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt">
<div class=""><br class="">
</div>
<div class="">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:</div>
<div class="">
<pre class="" style="overflow:auto hidden; font-family:Consolas,"Deja Vu Sans Mono","Bitstream Vera Sans Mono",monospace; font-size:0.95em; line-height:15.96px; padding:0.5em; border:1px solid rgb(204,204,204); background-color:rgb(248,248,248); text-align:left"><span class="x_n">vectorty</span> <span class="x_nd" style="color:rgb(85,85,85); font-weight:bold">@llvm</span><span class="x_o" style="color:rgb(102,102,102)">.</span><span class="x_n">matrix</span><span class="x_o" style="color:rgb(102,102,102)">.</span><span class="x_n">multiply</span><span class="x_o" style="color:rgb(102,102,102)">.*</span><span class="x_p">(</span><span class="x_n">vectorty</span> <span class="x_o" style="color:rgb(102,102,102)">%</span><span class="x_n">A</span><span class="x_p">,</span> <span class="x_n">vectorty</span> <span class="x_o" style="color:rgb(102,102,102)">%</span><span class="x_n">B</span><span class="x_p">, ...)</span></pre>
So perhaps we can relax this?</div>
</div>
</div>
</blockquote>
<br class="">
</div>
<div><br class="">
</div>
<div>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.</div>
<div><br class="">
</div>
<div>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.</div>
<div><br class="">
</div>
<div>Cheers,</div>
<div>Florian</div>
<br class="">
</div>
</div>
</body>
</html>