Issue
RedMulE instructions are not 100% compliant with the available RISC-V instruction formats.
- The mconfig instruction adheres to the RISC-V R-Type with
rd, funct3, and funct7 left unused.
- The marith is a custom type for no reason, while it could easily be R-Type.
Idea
Restructure the mconfig and marith instructions to adhere to standard RISC-V instruction types (R/S-Type).
Proposal
mcnfig
The mcnfig instruction currently only holds the matrix sizes (M, N, K) in the rs1 and rs2 fields. This instrcution could also make use of the funct3 field to host information about the operand formats (8/16/32/64-bit + custom format enableing).
| Imm [31:25] |
rs2 [24:20] |
rs1 [19:15] |
funct3 [14:12] |
Imm [11:7] |
OpCode [6:0] |
| 0 |
N Size |
[K - M] Size |
FormatConfig |
0 |
0x0B |
The rs1 structure should be:
| Bitfield |
Content |
| rs1 [31:16] |
K Size |
| rs1 [15:0] |
M Size |
The FormatConfig field (func3) encoding should be:
| funct3 [2] |
Custom Format |
| 0b0 |
Disabled |
| 0b1 |
Enabled |
| funct3 [1:0] |
Data Format |
| 0b00 |
32-bit |
| 0b01 |
64-bit |
| 0b10 |
16-bit |
| 0b11 |
8-bit |
The Data Format field of func3 follows the spec defined in the CVFPU format encoding.
marith
The marith instruction is currently a custom type while it could adhere the R-Type. The idea is to use the rs1, rs2, and rd fields to store the pointers to the start addresses of X, W, and Y tensors following the current instruction implementation. In addition to this, the idea is to make use of func3 and func7 to define the peculiarities of the matrix operation that has to be performed.
| func7 [31:25] |
rs2 [24:20] |
rs1 [19:15] |
funct3 [14:12] |
rd [11:7] |
OpCode [6:0] |
| MatrixOpConfig |
W pointer |
X pointer |
MatrixOpConfig |
Y pointer |
0x2B |
The encoding of the MatrixOpConfig in the func3 field should be:
| func3 [2:0] |
Kernel |
op1 |
op2 |
Res |
| 0b000 |
GEMM |
x |
+ |
Z = (X x W) + Z |
| 0b001 |
Maximum Critical Path |
+ |
max |
Z = max[(X + W), Z] |
| 0b010 |
All-Pairs Shortest Paths |
+ |
min |
Z = min[(X + W), Z] |
| 0b011 |
Maximum Reliability Path |
x |
max |
Z = max[(X x W), Z] |
| 0b100 |
Minimum Reliability Path |
x |
max |
Z = min[(X x W), Z] |
| 0b101 |
Minimum Spanning Tree |
max |
min |
Z = min[max(X, W), Z] |
| 0b110 |
Maximum Capacity Tree |
min |
max |
Z = max[min(X, W), Z] |
The encoding of the MatrixOpConfig in the func7 field should be:
| funct7 [0] |
Precision |
| 0b0 |
Floating Point |
| 0b1 |
Integer |
| funct7 [1] |
Y != 0 |
| 0b0 |
No |
| 0b1 |
Yes |