FPGA開発日記

カテゴリ別記事インデックス https://msyksphinz.github.io/github_pages , English Version https://fpgadevdiary.hatenadiary.com/

RISC-V Matrix Extension Specificationについて読み進める (5. 行列乗算サンプルのデバッグ)

T-Headが提案しているRISC-VのMatrix Extensionについて、マニュアルを読みながら理解していこうと思う。

とりあえずマニュアルで、どのようなレジスタが存在しているのかを理解していく。プログラミングモデルとサンプルコードも読み進めていきたい。

github.com

前回のサンプルコードの動作を確認するために、サンプルコードを動かしてみたい。 リポジトリの中にサンプルプログラムの環境が含まれているので、それを動かしてみる。

gemm_int8:[160x160x160]
===== demo: matmul-intrinsic =====
Initial value of matrix:
ma:             mb:             ans:
16  15          1   2           0  0  
15  14          2   3           0  0  
Results of multiplication:
ma:             mb:             ans:
16  15          1   2           16 = 16 * 1   30 = 15 * 2   
15  14          2   3           30 = 15 * 2   42 = 14 * 3   
gemm_int8:[160x160x160]
===== demo: matmul-intrinsic =====
Initial value of matrix:
ma:             mb:             ans:
16  15          1   2           0  0  
15  14          2   3           0  0  
Results of multiplication:
ma:             mb:             ans:
16  15          1   2           16 = 16 * 1   30 = 15 * 2   
15  14          2   3           30 = 15 * 2   42 = 14 * 3   
gemm_int8:[160x160x160]
===== demo: matmul-intrinsic =====
Initial value of matrix:
ma:             mb:             ans:
16  15          1   2           0  0  
15  14          2   3           0  0  
Results of multiplication:
ma:             mb:             ans:
16  15          1   2           16 = 16 * 1   30 = 15 * 2   
15  14          2   3           30 = 15 * 2   42 = 14 * 3   

前回の通り、やはり2x2の行列演算になるようだ。

   int32_t x[N] = {16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
   int32_t y[N] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};

よく見てみたら、参照用のコードが違っている?

   for (row = 0; row < 2; row++)
   {
     for (col = 0; col < 2; col++)
     {
       printf("%-3d ", tmp_ma[row + col]);
     }

これは、以下のようにしなければならないような?

   for (row = 0; row < 2; row++)
   {
     for (col = 0; col < 2; col++)
     {
       printf("%-3d ", tmp_ma[row * 2 + col]);
     }

訂正すると以下のようになった。これでもよくわからないなあ?引き続き見ていこう。

gemm_int8:[160x160x160]
===== demo: matmul-intrinsic =====
Initial value of matrix:
ma:             mb:             ans:
16  15          1   2           0  0  
12  11          5   6           0  0  
Results of multiplication:
ma:             mb:             ans:
16  15          1   2           16 = 16 * 1   30 = 15 * 2   
12  11          5   6           60 = 12 * 5   66 = 11 * 6