<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Bump.<div class=""><br class=""></div><span class="">I’d like to share a bit more context/motivation for the proposal. We are still looking for feedback and would appreciate any feedback/concerns on the overall proposal or any of the details!<br class=""><br class="">I’ve uploaded WIP patches that add the various proposed builtins and linked them to the initial commit: <a href="https://reviews.llvm.org/D72281" class="">https://reviews.llvm.org/D72281</a></span><div class=""><span class=""><br class="">Besides that I’ve prepared a two examples to illustrate the use of the builtins. First, I’ve put up a patch for test-suite that adds a set of tests that check the matrix builtins match the spec and a naive loop based implementation: <a href="https://reviews.llvm.org/D72770" class="">https://reviews.llvm.org/D72770</a></span></div><div class=""><span class=""><br class="">Second, I ran a few benchmarks comparing the performance of the matrix builtins and Eigen for operations on small matrixes (ranging from 3x3 to 16x16). The benchmarks compare the performance of a single matrix multiply, a matrix multiply add and a larger matrix expression. I’ve shared the numbers below. For sizes smaller than 16x16, the matrix builtins comfortably beat Eigen (between 1.5x and 3x speedups).<br class=""><br class="">Currently, Eigen still outperforms the matrix builtins for the following cases</span></div><div class=""><span class=""><br class=""><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>• 3x3 matrixes (we are aware of the issue there and have a good idea of how to improve those cases without much effort)<br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>• Larger matrixes (roughly 15x15+)<br class=""></div><div class=""><br class=""></div>The regression on larger matrixes is not surprising at the moment, as we have not implemented any sort of tiling for the matrix builtins. But this is certainly something we are planning on implementing in the future, extending the number of cases that can be handled by the matrix builtins.<br class=""><br class="">To summarize, we think that Eigen (and similar libraries) could get a nice speedup for operations on small matrixes by using the builtins, while also likely simplifying the implementation by off-leading vector code generation to the compiler, rather than using target-specific intrinsics.<br class=""><br class="">The benchmark code can be found here: <a href="https://gist.github.com/fhahn/03796abb21bfc242c083cf7333ac960c" class="">https://gist.github.com/fhahn/03796abb21bfc242c083cf7333ac960c</a></span><div class=""><span class=""><br class="">The numbers are gathered with LLVM master as of today, with the Clang patches applied on top of them. The benchmarks where built with -O3.<br class=""><br class=""><br class="">Cheers,</span><div class=""><span class="">Florian</span></div><div class=""><span class=""><br class=""><br class="">Benchmark numbers (CPU time in ns shown). Values < 1 in the (Matrix builtins / Eigen) column means the matrix builtin version out-performs Eigen.</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">X86 macOS</span></div><div class=""><span class=""><br class=""></span></div><div class="">
<table cellspacing="0" cellpadding="0" class="t1">
<tbody class="">
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class=""><b class="">name </b></span></p>
</td>
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class=""><b class="">Matrix builtins </b></span></p>
</td>
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class=""><b class="">Eigen. </b></span></p></td><td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class=""><b class="">(Matrix builtins / Eigen)</b></span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Square<float, 3, 3, 3, 3></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">4.61</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">6.65</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.693</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Square<double, 3, 3, 3, 3></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">3.93</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">6.17</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.638</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Square<float, 5, 5, 5, 5></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">13.06</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">25.44</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.513</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Square<double, 5, 5, 5, 5></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">18.53</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">42.29</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.438</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Square<float, 8, 8, 8, 8></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">34.26</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">108.32</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.316</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Square<double, 8, 8, 8, 8></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">70.07</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">178.25</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.393</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Square<float, 11, 11, 11, 11></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">151.37</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">306.53</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.494</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Square<double, 11, 11, 11, 11></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">215.47</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">422.73</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.51</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Square<float, 16, 16, 16, 16></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">357.9</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">466.22</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.768</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Square<double, 16, 16, 16, 16></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">719.86</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">722.31</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.997</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Add_Square<float, 3, 3, 3, 3></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">6.44</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">7.43</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.867</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Add_Square<double, 3, 3, 3, 3></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">4.77</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">7.94</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.601</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Add_Square<float, 5, 5, 5, 5></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">13.7</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">27.09</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.506</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Add_Square<double, 5, 5, 5, 5></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">20.83</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">44.82</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.465</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Add_Square<float, 8, 8, 8, 8></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">39.36</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">113.99</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.345</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Add_Square<double, 8, 8, 8, 8></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">75.4</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">186.2</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.405</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Add_Square<float, 11, 11, 11, 11></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">169.78</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">310.76</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.546</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Add_Square<double, 11, 11, 11, 11></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">243.95</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">497.39</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.49</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Add_Square<float, 16, 16, 16, 16></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">430.09</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">487.65</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.882</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Add_Square<double, 16, 16, 16, 16></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">854.13</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">843.71</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">1.012</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Expr_Square<float, 3, 3, 3, 3></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">10.89</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">18.13</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.6</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Expr_Square<double, 3, 3, 3, 3></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">9.41</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">17.17</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.548</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Expr_Square<float, 5, 5, 5, 5></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">28.07</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">54.42</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.516</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Expr_Square<double, 5, 5, 5, 5></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">40.45</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">72.36</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.559</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Expr_Square<float, 8, 8, 8, 8></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">79.37</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">222.89</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.356</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Expr_Square<double, 8, 8, 8, 8></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">152.4</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">393.13</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.388</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Expr_Square<float, 11, 11, 11, 11></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">299.12</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">659.46</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.454</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Expr_Square<double, 11, 11, 11, 11></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">444.06</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">862.66</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.515</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Expr_Square<float, 16, 16, 16, 16></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">772.21</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">842.29</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.917</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Expr_Square<double, 16, 16, 16, 16></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">1580.45</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">1578.02</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">1.002</span></p>
</td>
</tr>
</tbody>
</table><br class=""></div><div class=""><br class=""></div><div class=""><span class=""><br class="">ARM64 Darwin<br class=""></span>
<span class=""><table cellspacing="0" cellpadding="0" class="t1">
<tbody class="">
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class=""><b class="">name </b></span></p>
</td>
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class=""><b class="">Matrix builtins </b></span></p>
</td>
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class=""><b class="">Eigen (</b></span></p>
</td>
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class=""><b class="">Matrix builtins / Eigen)</b></span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Square<float, 3, 3, 3, 3></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">6.29</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">6</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">1.048</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Square<double, 3, 3, 3, 3></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">5.14</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">4.87</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">1.056</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Square<float, 5, 5, 5, 5></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">14.8</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">37.46</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.395</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Square<double, 5, 5, 5, 5></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">21</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">65.01</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.323</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Square<float, 8, 8, 8, 8></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">39.56</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">88.73</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.446</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Square<double, 8, 8, 8, 8></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">84.58</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">156.45</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.541</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Square<float, 11, 11, 11, 11></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">184.59</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">298.33</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.619</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Square<double, 11, 11, 11, 11></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">270.03</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">399.78</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.675</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Square<float, 16, 16, 16, 16></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">430.07</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">345.05</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">1.246</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Square<double, 16, 16, 16, 16></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">891.57</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">608.66</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">1.465</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Add_Square<float, 3, 3, 3, 3></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">8.87</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">6.77</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">1.31</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Add_Square<double, 3, 3, 3, 3></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">7.1</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">6.8</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">1.044</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Add_Square<float, 5, 5, 5, 5></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">16.23</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">37.89</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.428</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Add_Square<double, 5, 5, 5, 5></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">23.32</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">68.01</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.343</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Add_Square<float, 8, 8, 8, 8></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">42.61</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">91.3</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.467</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Add_Square<double, 8, 8, 8, 8></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">89.15</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">162.19</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.55</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Add_Square<float, 11, 11, 11, 11></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">216.04</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">304.33</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.71</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Add_Square<double, 11, 11, 11, 11></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">300.04</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">423.92</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.708</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Add_Square<float, 16, 16, 16, 16></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">440.06</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">374.63</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">1.175</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Mult_Add_Square<double, 16, 16, 16, 16></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">913</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">777.27</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">1.175</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Expr_Square<float, 3, 3, 3, 3></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">16.69</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">32.46</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.514</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Expr_Square<double, 3, 3, 3, 3></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">14.36</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">30.56</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.47</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Expr_Square<float, 5, 5, 5, 5></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">33.48</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">72.54</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.461</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Expr_Square<double, 5, 5, 5, 5></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">47.15</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">108.44</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.435</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Expr_Square<float, 8, 8, 8, 8></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">91.3</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">205.74</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.444</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Expr_Square<double, 8, 8, 8, 8></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">187.31</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">385.48</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.486</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Expr_Square<float, 11, 11, 11, 11></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">400.05</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">660.08</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.606</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Expr_Square<double, 11, 11, 11, 11></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">582.93</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">874.4</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">0.667</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Expr_Square<float, 16, 16, 16, 16></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">938.7</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">788.69</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">1.19</span></p>
</td>
</tr>
<tr class="">
<td valign="top" class="td1"><p class="p1"><span style="font-size: 12px;" class="">BM_GEMM_Expr_Square<double, 16, 16, 16, 16></span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">1900.25</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">1543.1</span></p>
</td>
<td valign="top" class="td1"><p class="p2"><span style="font-size: 12px;" class="">1.231</span></p><div class=""><br class=""></div></td></tr></tbody></table></span><span class=""><blockquote type="cite" class=""><br class="">Ping.<br class=""><br class="">I’ve also put up 2 patches on Phabricator, to illustrate how the implementation could look like:<br class=""><br class="">1. [Matrix] Add matrix type to Clang (WIP). <a href="https://reviews.llvm.org/D72281" class="">https://reviews.llvm.org/D72281</a><br class="">2. [Matrix] Add __builtin_matrix_insert to Clang (WIP). https://reviews.llvm.org/D72283<br class=""><br class=""><br class="">Cheers,<br class="">Florian<br class=""><br class=""><blockquote type="cite" class="">On Dec 20, 2019, at 18:31, Florian Hahn via cfe-dev <cfe-dev@lists.llvm.org> wrote:<br class=""><br class="">Hello,<br class=""><br class="">This is a Clang-focused follow up to the original proposal on llvm-dev (http://lists.llvm.org/pipermail/llvm-dev/2019-October/136240.html). On the LLVM side, we recently landed the first commit adding matrix intrinsics as proposed.<br class=""><br class="">On the Clang side, we would like to propose adding support for matrix math operations to Clang. This includes adding a new matrix type (similar to ext_vector_type) and a set of builtins to operate on values of the matrix type.<br class=""><br class="">Our main motivation for the matrix support in Clang is to give users a way to<br class=""><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>• Guarantee generation of high-quality code for matrix operations. For isolated operations, we can guarantee vector code generation suitable for the target. For trees of operations, the proposed value type helps with eliminating temporary loads & stores. <br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>• Make use of specialized matrix ISA extensions, like the new matrix instructions in ARM v8.6 or various proprietary matrix accelerators, in their C/C++ code. <br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>• Move optimizations from matrix wrapper libraries into the compiler. We use it internally to simplify an Eigen-style matrix library, by relying on LLVM for generating tiled & fused loops for matrix operations. <br class=""></div>The rest of this RFC is structured as follows: First we propose a draft specification for the matrix type and accompanying builtins. Next we show an example of how matrix operations will be lowered by Clang, followed by a discussion of the contributing criteria for new extensions. We wrap up the RFC by discussing possible extensions to the matrix type.<br class="">Draft Specification<br class=""><br class="">Matrix TYPE Attribute<br class=""><br class="">The attribute-token matrix_type is used to declare a matrix type. It shall appear at most once in each attribute-list. The attribute shall only appertain to a typedef-name of a typedef of a non-volatile type that is a signed integer type, an unsigned integer type, or a floating-point type. An attribute-argument-clause must be present and it shall have the form:<br class=""><br class="">(constant-expression, constant-expression)<br class=""><br class="">Both constant-expressions shall be a positive non-zero integral constant expressions. The maximum of the product of the constants is implementation defined. If that implementation defined limit is exceeded, the program is ill-formed.<br class=""><br class="">An attribute of the form matrix_type(R, C) forms a matrix type with an element type of the cv-qualified type the attribute appertains to and R rows and C columns.<br class=""><br class="">If a declaration of a typedef-name has a matrix_type attribute, then all declaration of that typedef-name shall have a matrix_type attribute with the same element type, number of rows, and number of columns.<br class=""><br class="">Matrix Type<br class=""><br class="">A matrix type has an underlying element type, a constant number of rows, and a constant number of columns. Matrix types with the same element type, rows, and columns are the same type. A value of a matrix type contains rows * columns values of the element type laid out in column-major order without padding in a way compatible with an array of at least that many elements of the underlying element type.<br class=""><br class="">A matrix type is a scalar type with the same alignment as its underlying element type, but objects of matrix type are not usable in constant expressions.<br class=""><br class="">TODO: Allow reinterpret_cast from pointer to element type. Make aliasing work.<br class="">Future Work: Initialization syntax.<br class="">Future Work: Access syntax. m[col][row].<br class="">Future Work: Conversions between matrix types with const qualified and unqualified element types.<br class="">Future Work: Conversions between matrix types with different element types.<br class=""><br class="">Matrix Type builtin Operations<br class=""><br class="">Each matrix type supports a collection of builtin expressions that look like function calls but do not form an overload set. Here they are described as function declarations with rules for how to construct the argument list types and return type and the library description elements from [library.description.structure.specifications]/3 in the C++ standard. <br class=""><br class="">Definitions:<br class=""><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>• M, M1, M2, M3 - Matrix types <br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>• T - Element type <br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>• row, col - Row and column arguments respectively. <br class=""></div>All operations on matrix types match the behavior of the underlying element type with respect to signed overflows.<br class=""><br class=""><br class="">Element Operations<br class=""><br class="">Preconditions: row and col are in the ranges [0, rows in M) and [0, columns in M) respectively.<br class=""><br class="">M __builtin_matrix_insert(M matrix, int row, int col, T elt)<br class=""><br class="">Remarks: The return type and the type T are inferred from the cv-unqualified type of the matrix argument and its cv-unqualified element type respectively.<br class=""><br class="">Returns: a copy of matrix with the element at the specified row and column set to elt.<br class=""><br class=""><br class="">T __builtin_matrix_extract(M matrix, int row, int col)<br class=""><br class="">The return type is inferred from the cv-unqualified type of the matrix argument’s element type.<br class=""><br class="">Returns: a copy of the element at the specified row and column.<br class=""><br class=""><br class="">Simple Binary Operations<br class=""><br class="">For the following binary operations matrix1 and matrix2 shall be matrix values of the same cv-unqualified type, and the return type is the cv-unqualified version of that type. <br class=""><br class="">M __builtin_matrix_add(M matrix1, M matrix2)<br class=""><br class="">Returns: A matrix Res equivalent to the code below, where col refers to the number of columns of M, row to the number of rows of M and EltTy to the element type of M.<br class="">M Res;<br class="">for (int C = 0; C < col; ++C) {<br class=""> for (int R = 0; R < row; ++R) {<br class=""> EltTy Elt = __builtin_matrix_extract(matrix1, R, C) + <br class=""> __builtin_matrix_extract(matrix2, R, C)<br class=""> Res = __builtin_matrix_insert(Res, R, C, Elt);<br class=""> }<br class="">}<br class=""><br class=""><br class="">M __builtin_matrix_sub(M matrix1, M matrix2)<br class=""><br class="">Returns: A matrix Res equivalent to the code below, where col refers to the number of columns of M, row to the number of rows of M and EltTy to the element type of M.<br class="">M Res;<br class="">for (int C = 0; C < col; ++C) {<br class=""> for (int R = 0; R < row; ++R) {<br class=""> EltTy Elt = __builtin_matrix_extract(matrix1, R, C) - <br class=""> __builtin_matrix_extract(matrix2, R, C)<br class=""> Res = __builtin_matrix_insert(Res, R, C, Elt);<br class=""> }<br class="">}<br class=""><br class=""><br class="">Other Operations<br class=""><br class="">M3 __builtin_matrix_multiply(M1 matrix1, M2 matrix2)<br class=""><br class="">Mandates: M1 and M2 shall be matrix types with the same cv-unqualified element type and M1’s number of columns matching M2’s number of row.<br class=""><br class="">Remarks: The return type is a cv-unqualified matrix type with the same element type as M1 and M2 if both M1 and M2’s element type is const, or the cv-unqualified element type otherwise, and with the same number of rows as M1 and the same number of columns as M2.<br class=""><br class="">Returns: A matrix Res equivalent to the code below, where col refers to the number of columns of M, row to the number of rows of M, EltTy to the element type of M and inner refers to the number of columns of M1.<br class="">M Res;<br class="">for (int C = 0; C < col; ++C) {<br class=""> for (int R = 0; R < row; ++R) {<br class=""> EltTy Elt = 0;<br class=""> for (int K = 0; K < inner; ++K) {<br class=""> Elt += __builtin_matrix_extract(matrix1, R, K) * <br class=""> __builtin_matrix_extract(matrix2, K, C)<br class=""> }<br class=""> Res = __builtin_matrix_insert(Res, R, C, Elt);<br class="">}<br class="">Remark: With respect to rounding errors, the operation preserves the behavior of the separate multiply and add operations by default. We propose to provide a Clang option to override this behavior and allow contraction of those operations (e.g. -ffp-contract=matrix).<br class=""><br class=""><br class="">M2 __builtin_matrix_transpose(M1 matrix)<br class=""><br class="">Remarks: The return type is a cv-unqualified matrix type that has the same element type as M1 and has the the same number of rows as M1 has columns and the same number of columns as M1 has rows.<br class=""><br class="">Returns: A matrix Res equivalent to the code below, where col refers to the number of columns of M, and row to the number of rows of M.<br class="">M Res;<br class="">for (int C = 0; C < col; ++C) {<br class=""> for (int R = 0; R < row; ++R) {<br class=""> EltTy Elt = __builtin_matrix_extract(matrix, R, C);<br class=""> Res = __builtin_matrix_insert(Res, C, R, Elt);<br class=""> }<br class="">}<br class=""><br class=""><br class="">M __builtin_matrix_column_load(T *ptr, int row, int col, int stride)<br class=""><br class="">Mandates: row and col shall be integral constants greater than 0. <br class=""><br class="">Preconditions: stride >= row.<br class=""><br class="">Remarks: The return type is a cv-unqualified matrix type with an element type of the cv-unqualified version of T and a number of rows and columns equal to row and col respectively.<br class=""><br class="">Returns: A matrix Res equivalent to:<br class="">M Res;<br class="">for (int C = 0; C < col; ++C) {<br class=""> for (int R = 0; R < row; ++K)<br class=""> Res = __builtin_matrix_insert(Res, R, C, ptr[R]);<br class=""> ptr += stride<br class="">}<br class=""><br class=""><br class="">void __builtin_matrix_column_store(M matrix, T *ptr, int stride)<br class=""><br class="">Preconditions: stride is greater than or equal to the number of rows in M.<br class=""><br class="">Effects: Equivalent to:<br class="">for (int C = 0; C < columns in M; ++C) {<br class=""> for (int R = 0; R < rows in M; ++K)<br class=""> ptr[R] = __builtin_matrix_extract(matrix, R, C);<br class=""> ptr += stride<br class="">}<br class="">Remarks: The type T is the const-unqualified version of the matrix argument’s element type.<br class=""><br class="">M __builtin_matrix_scalar_multiply(M matrix, T scalar)<br class=""><br class="">Returns: A matrix Res equivalent to the code below, where col refers to the number of columns of M, and row to the number of rows of M.<br class="">M Res;<br class="">for (int C = 0; C < col; ++C) {<br class=""> for (int R = 0; R < row; ++R) {<br class=""> EltTy Elt = __builtin_matrix_extract(matrix, R, C) * scalar;<br class=""> Res = __builtin_matrix_insert(Res, R, C, Elt);<br class=""> }<br class="">}<br class="">Remarks: The return type and the type T are the cv-unqualified type of the matrix argument and its cv-unqualified element type respectively.<br class=""><br class="">Example <br class=""><br class="">This code performs a matrix-multiply of two 4x4 matrices followed by an matrix addition:<br class="">typedef float m4x4_t __attribute__((matrix_type(4, 4)));<br class="">void f(m4x4_t *a, m4x4_t *b, m4x4_t *c, m4x4_t *r) {<br class=""> *r = __builtin_matrix_add(__builtin_matrix_multiply(*a, *b), *c);<br class="">}<br class="">This will get lowered by Clang to the LLVM IR below. In our current implementation, we use LLVM’s array type as storage type for the matrix data. Before accessing the data, we cast the array to a vector type. This allows us to use the element width as alignment, without running into issues with LLVM’s large default alignment for vector types, which is problematic in structs.<br class="">define void @f([16 x float]* %a, [16 x float]* %b, [16 x float]* %c, [16 x float]* %r) #0 {<br class="">entry:<br class=""> %a.addr = alloca [16 x float]*, align 8<br class=""> %b.addr = alloca [16 x float]*, align 8<br class=""> %c.addr = alloca [16 x float]*, align 8<br class=""> %r.addr = alloca [16 x float]*, align 8<br class=""> store [16 x float]* %a, [16 x float]** %a.addr, align 8<br class=""> store [16 x float]* %b, [16 x float]** %b.addr, align 8<br class=""> store [16 x float]* %c, [16 x float]** %c.addr, align 8<br class=""> store [16 x float]* %r, [16 x float]** %r.addr, align 8<br class=""> %0 = load [16 x float]*, [16 x float]** %a.addr, align 8<br class=""> %1 = bitcast [16 x float]* %0 to <16 x float>*<br class=""> %2 = load <16 x float>, <16 x float>* %1, align 4<br class=""> %3 = load [16 x float]*, [16 x float]** %b.addr, align 8<br class=""> %4 = bitcast [16 x float]* %3 to <16 x float>*<br class=""> %5 = load <16 x float>, <16 x float>* %4, align 4<br class=""> %6 = call <16 x float> @llvm.matrix.multiply.v16f32.v16f32.v16f32(<16 x float> %2, <16 x float> %5, i32 4, i32 4, i32 4)<br class=""> %7 = load [16 x float]*, [16 x float]** %c.addr, align 8<br class=""> %8 = bitcast [16 x float]* %7 to <16 x float>*<br class=""> %9 = load <16 x float>, <16 x float>* %8, align 4<br class=""> %10 = fadd <16 x float> %6, %9<br class=""> %11 = load [16 x float]*, [16 x float]** %r.addr, align 8<br class=""> %12 = bitcast [16 x float]* %11 to <16 x float>*<br class=""> store <16 x float> %10, <16 x float>* %12, align 4<br class=""> ret void<br class="">}<br class="">declare <16 x float> @llvm.matrix.multiply.v16f32.v16f32.v16f32(<16 x float>, <16 x float>, i32 immarg, i32 immarg, i32 immarg)<br class=""><br class="">Contributing Criteria<br class=""><br class="">Evidence of a significant user community: This is based on a number of factors, including an existing user community, the perceived likelihood that users would adopt such a feature if it were available, and any secondary effects that come from, e.g., a library adopting the feature and providing benefits to its users.<br class="">Currently this is part of one of our compiler toolchains and used on a few large internal codebases. The matrix type can be used by matrix libraries like Eigen, to offload some of the optimization responsibility from the library to the compiler. It would also be suitable target for implementing a standard matrix library. It also provides functionality similar to various libraries for matrix math on small matrixes, like https://developer.apple.com/documentation/accelerate/working_with_matrices, with more flexibility (supports any combination of input dimensions).<br class=""><br class="">A specific need to reside within the Clang tree: There are some extensions that would be better expressed as a separate tool, and should remain as separate tools even if they end up being hosted as part of the LLVM umbrella project.<br class="">We want to expose this feature at the C/C++ level. For that, it needs to be part of Clang.<br class=""><br class="">A specification: The specification must be sufficient to understand the design of the feature as well as interpret the meaning of specific examples. The specification should be detailed enough that another compiler vendor could implement the feature.<br class="">We currently have the design above and will work on a more comprehensive spec.<br class=""><br class="">Representation within the appropriate governing organization: For extensions to a language governed by a standards committee (C, C++, OpenCL), the extension itself must have an active proposal and proponent within that committee and have a reasonable chance of acceptance. Clang should drive the standard, not diverge from it. This criterion does not apply to all extensions, since some extensions fall outside of the realm of the standards bodies.<br class="">We think this extension would fall outside of the realm of the standards bodies. It is an implementation detail used to implement matrix math libraries and such, much like the vector extensions are an implementation detail for SIMD libraries.<br class=""><br class="">A long-term support plan: increasingly large or complex extensions to Clang need matching commitments to supporting them over time, including improving their implementation and specification as Clang evolves. The capacity of the contributor to make that commitment is as important as the commitment itself.<br class="">We are using this internally and adding this feature to Clang upstream means we intend to support it as part of our ongoing Clang work.<br class=""><br class="">A high-quality implementation: The implementation must fit well into Clang's architecture, follow LLVM's coding conventions, and meet Clang's quality standards, including diagnostics and complete AST representations. This is particularly important for language extensions, because users will learn how those extensions work through the behavior of the compiler.<br class="">Will we provide a series of patches to implement the extension soon and look forward to any feedback to make sure the patches meet the quality requirement.<br class=""><br class="">A test suite: Extensive testing is crucial to ensure that the language extension is not broken by ongoing maintenance in Clang. The test suite should be complete enough that another compiler vendor could conceivably validate their implementation of the feature against it<br class="">We will provide this as part of Clang’s unit tests and test-suite.<br class="">Extensions<br class=""><br class="">Initially we want to focus on 2D matrixes without padding in column-major layout as a concrete use case. This is similar to the defaults for the Matrix type in Eigen, for example. But our proposed type can be extended naturally to<br class=""><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>• Support N (known constant) dimensions by turning matrix_type attribute into a variadic attribute. <br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>• Support column/row-wise padding, by adding a column_padding clause to the attribute.<br class="">Dealing with the padding could be exclusively handled on the frontend side, by emitting additional shufflevector instructions to extract the data. If there is a desire to exploit the padding more on the LLVM side, we can add a set of intrinsics for that. <br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre"> </span>• Support row & column major layouts, by adding a layout clause to the attribute.<br class="">Again, this naively could be handled while lowering to LLVM IR in Clang using shufflevector to produce flattened vectors with the required layout. For better optimisations, the LLVM intrinsics relying on shape/layout information can be extended to take the layout as additional argument. Through propagating the layout information similar to the dimensions, we should be able to optimise the points where we need to transform the layout of the underlying matrixes. <br class=""></div>In all cases, we require known integer constants as dimensions and we do not plan to support dynamic dimensions for now, as the main optimization potential comes from the fact that we know the dimensions. Supporting dynamic dimensions should be fairly straight forward, but means we lose the ability to type check matrix expressions at compile time and we also have to rely on dynamic dimension during code generation.<br class=""><br class="">Cheers,<br class=""> Florian<br class="">_______________________________________________<br class="">cfe-dev mailing list<br class="">cfe-dev@lists.llvm.org<br class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev<br class=""></blockquote><br class="">_______________________________________________<br class="">cfe-dev mailing list<br class="">cfe-dev@lists.llvm.org<br class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev<br class=""></blockquote><br class=""></span></div></div></div></body></html>