Merge remote-tracking branch 'origin/tensor_core' into rtl
This commit is contained in:
@@ -56,6 +56,7 @@ extern "C" {
|
||||
void dpi_fmax(bool enable, int dst_fmt, int64_t a, int64_t b, int64_t* result, svBitVecVal* fflags);
|
||||
|
||||
void dpi_hmma(bool enable, const svBitVecVal* A_tile, const svBitVecVal* B_tile, const svBitVecVal* C_tile, svBitVecVal* D_tile);
|
||||
void dpi_print_results(int wid, int octet, const svBitVecVal* A_tile, const svBitVecVal* B_tile, const svBitVecVal* C_tile, const svBitVecVal* D_tile);
|
||||
}
|
||||
|
||||
inline uint64_t nan_box(uint32_t value) {
|
||||
@@ -413,4 +414,152 @@ void dpi_hmma(bool enable, const svBitVecVal* A_tile, const svBitVecVal* B_tile,
|
||||
}
|
||||
|
||||
write_float_array(D_tile, &c_D_tile[0][0], M, M);
|
||||
|
||||
// 1 copy per warp
|
||||
float A_tile_full[4][16][8];
|
||||
float B_tile_full[4][8][16];
|
||||
float C_tile_full[4][16][16];
|
||||
float D_tile_full[4][16][16];
|
||||
int steps[4];
|
||||
|
||||
void print_array(float* array, int rows, int cols) {
|
||||
for (int i = 0; i < rows; i += 1) {
|
||||
for (int j = 0; j < cols; j += 1) {
|
||||
std::cout << array[i*cols+j] << " ";
|
||||
}
|
||||
std::cout << "\n";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
void dpi_print_results(int wid, int octet, const svBitVecVal* A_tile, const svBitVecVal* B_tile, const svBitVecVal* C_tile, const svBitVecVal* D_tile) {
|
||||
// std::cout << "A: " << std::endl;
|
||||
fill_float_array(A_tile, &c_A_tile[0][0], M, K);
|
||||
// std::cout << "B: " << std::endl;
|
||||
fill_float_array(B_tile, &c_B_tile[0][0], K, M);
|
||||
// std::cout << "C: " << std::endl;
|
||||
fill_float_array(C_tile, &c_C_tile[0][0], M, M);
|
||||
// for some reason this still holds onto old value? very strange
|
||||
// std::cout << "D: " << std::endl;
|
||||
fill_float_array(D_tile, &c_D_tile[0][0], M, M);
|
||||
|
||||
int octet_row_offset;
|
||||
int octet_col_offset;
|
||||
switch(octet) {
|
||||
case 0:
|
||||
octet_row_offset = 0;
|
||||
octet_col_offset = 0;
|
||||
break;
|
||||
case 1:
|
||||
octet_row_offset = 8;
|
||||
octet_col_offset = 0;
|
||||
break;
|
||||
case 2:
|
||||
octet_row_offset = 0;
|
||||
octet_col_offset = 8;
|
||||
break;
|
||||
case 3:
|
||||
octet_row_offset = 8;
|
||||
octet_col_offset = 8;
|
||||
break;
|
||||
}
|
||||
|
||||
int step_row_offset;
|
||||
int step_col_offset;
|
||||
int step = (steps[wid] % 16) / 4;
|
||||
int set = (steps[wid] / 16);
|
||||
switch(step) {
|
||||
case 0:
|
||||
step_row_offset = 0;
|
||||
step_col_offset = 0;
|
||||
break;
|
||||
case 1:
|
||||
step_row_offset = 2;
|
||||
step_col_offset = 0;
|
||||
break;
|
||||
case 2:
|
||||
step_row_offset = 0;
|
||||
step_col_offset = 4;
|
||||
break;
|
||||
case 3:
|
||||
step_row_offset = 2;
|
||||
step_col_offset = 4;
|
||||
break;
|
||||
}
|
||||
|
||||
if (steps[0] >= 48) {
|
||||
// std::cout << "octet " << octet << " step " << steps[0] << "\n";
|
||||
// print_array(&c_D_tile[0][0], 4, 4);
|
||||
}
|
||||
|
||||
D_tile_full[wid][octet_row_offset+step_row_offset+0][octet_col_offset+step_col_offset+0] = c_D_tile[0][0];
|
||||
D_tile_full[wid][octet_row_offset+step_row_offset+0][octet_col_offset+step_col_offset+1] = c_D_tile[0][1];
|
||||
D_tile_full[wid][octet_row_offset+step_row_offset+0][octet_col_offset+step_col_offset+2] = c_D_tile[0][2];
|
||||
D_tile_full[wid][octet_row_offset+step_row_offset+0][octet_col_offset+step_col_offset+3] = c_D_tile[0][3];
|
||||
D_tile_full[wid][octet_row_offset+step_row_offset+1][octet_col_offset+step_col_offset+0] = c_D_tile[1][0];
|
||||
D_tile_full[wid][octet_row_offset+step_row_offset+1][octet_col_offset+step_col_offset+1] = c_D_tile[1][1];
|
||||
D_tile_full[wid][octet_row_offset+step_row_offset+1][octet_col_offset+step_col_offset+2] = c_D_tile[1][2];
|
||||
D_tile_full[wid][octet_row_offset+step_row_offset+1][octet_col_offset+step_col_offset+3] = c_D_tile[1][3];
|
||||
D_tile_full[wid][octet_row_offset+step_row_offset+4][octet_col_offset+step_col_offset+0] = c_D_tile[2][0];
|
||||
D_tile_full[wid][octet_row_offset+step_row_offset+4][octet_col_offset+step_col_offset+1] = c_D_tile[2][1];
|
||||
D_tile_full[wid][octet_row_offset+step_row_offset+4][octet_col_offset+step_col_offset+2] = c_D_tile[2][2];
|
||||
D_tile_full[wid][octet_row_offset+step_row_offset+4][octet_col_offset+step_col_offset+3] = c_D_tile[2][3];
|
||||
D_tile_full[wid][octet_row_offset+step_row_offset+5][octet_col_offset+step_col_offset+0] = c_D_tile[3][0];
|
||||
D_tile_full[wid][octet_row_offset+step_row_offset+5][octet_col_offset+step_col_offset+1] = c_D_tile[3][1];
|
||||
D_tile_full[wid][octet_row_offset+step_row_offset+5][octet_col_offset+step_col_offset+2] = c_D_tile[3][2];
|
||||
D_tile_full[wid][octet_row_offset+step_row_offset+5][octet_col_offset+step_col_offset+3] = c_D_tile[3][3];
|
||||
|
||||
if (octet == 0 || octet == 1) {
|
||||
octet_row_offset = octet * 8;
|
||||
if (step == 0) {
|
||||
step_row_offset = 0;
|
||||
}
|
||||
if (step == 1) {
|
||||
step_row_offset = 2;
|
||||
}
|
||||
if (step == 0 || step == 1) {
|
||||
A_tile_full[wid][octet_row_offset+step_row_offset+0][set*2+0] = c_A_tile[0][0];
|
||||
A_tile_full[wid][octet_row_offset+step_row_offset+0][set*2+1] = c_A_tile[0][1];
|
||||
A_tile_full[wid][octet_row_offset+step_row_offset+1][set*2+0] = c_A_tile[1][0];
|
||||
A_tile_full[wid][octet_row_offset+step_row_offset+1][set*2+1] = c_A_tile[1][1];
|
||||
A_tile_full[wid][octet_row_offset+step_row_offset+4][set*2+0] = c_A_tile[2][0];
|
||||
A_tile_full[wid][octet_row_offset+step_row_offset+4][set*2+1] = c_A_tile[2][1];
|
||||
A_tile_full[wid][octet_row_offset+step_row_offset+5][set*2+0] = c_A_tile[3][0];
|
||||
A_tile_full[wid][octet_row_offset+step_row_offset+5][set*2+1] = c_A_tile[3][1];
|
||||
}
|
||||
}
|
||||
|
||||
if (octet == 0 || octet == 2) {
|
||||
octet_col_offset = octet * 4;
|
||||
if (step == 0) {
|
||||
step_col_offset = 0;
|
||||
}
|
||||
else if (step == 2) {
|
||||
step_col_offset = 4;
|
||||
}
|
||||
if (step == 0 || step == 2) {
|
||||
B_tile_full[wid][set*2+0][octet_col_offset+step_col_offset+0] = c_B_tile[0][0];
|
||||
B_tile_full[wid][set*2+0][octet_col_offset+step_col_offset+1] = c_B_tile[0][1];
|
||||
B_tile_full[wid][set*2+0][octet_col_offset+step_col_offset+2] = c_B_tile[0][2];
|
||||
B_tile_full[wid][set*2+0][octet_col_offset+step_col_offset+3] = c_B_tile[0][3];
|
||||
B_tile_full[wid][set*2+1][octet_col_offset+step_col_offset+0] = c_B_tile[1][0];
|
||||
B_tile_full[wid][set*2+1][octet_col_offset+step_col_offset+1] = c_B_tile[1][1];
|
||||
B_tile_full[wid][set*2+1][octet_col_offset+step_col_offset+2] = c_B_tile[1][2];
|
||||
B_tile_full[wid][set*2+1][octet_col_offset+step_col_offset+3] = c_B_tile[1][3];
|
||||
}
|
||||
}
|
||||
|
||||
steps[wid] += 1;
|
||||
if (steps[wid] % 64 == 0) {
|
||||
steps[wid] = 0;
|
||||
std::cout << "warp " << wid << " finished wmma\n";
|
||||
std::cout << "A tile" << "\n";
|
||||
print_array(&A_tile_full[wid][0][0], 16, 8);
|
||||
std::cout << "B tile" << "\n";
|
||||
print_array(&B_tile_full[wid][0][0], 8, 16);
|
||||
// std::cout << "C tile" << "\n";
|
||||
// print_array(&C_tile_full[wid][0][0], 16, 16);
|
||||
std::cout << "D tile" << "\n";
|
||||
print_array(&D_tile_full[wid][0][0], 16, 16);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,5 +45,6 @@ import "DPI-C" function void dpi_fmin(input logic enable, input int dst_fmt, inp
|
||||
import "DPI-C" function void dpi_fmax(input logic enable, input int dst_fmt, input longint a, input longint b, output longint result, output bit[4:0] fflags);
|
||||
|
||||
import "DPI-C" function void dpi_hmma(input logic enable, input bit[3:0][1:0][31:0] A_tile, input bit[1:0][3:0][31:0] B_tile, input bit[3:0][3:0][31:0] C_tile, output bit[3:0][3:0][31:0] D_tile);
|
||||
import "DPI-C" function void dpi_print_results(input int wid, input int octet, input bit[3:0][1:0][31:0] A_tile, input bit[1:0][3:0][31:0] B_tile, input bit[3:0][3:0][31:0] C_tile, input bit[3:0][3:0][31:0] D_tile);
|
||||
|
||||
`endif
|
||||
|
||||
@@ -54,6 +54,7 @@ module VX_commit import VX_gpu_pkg::*; #(
|
||||
wire [`ISSUE_WIDTH-1:0][`NUM_THREADS-1:0] commit_tmask;
|
||||
wire [`ISSUE_WIDTH-1:0] commit_eop;
|
||||
wire [`ISSUE_WIDTH-1:0][`EX_BITS-1:0] commit_sel;
|
||||
`UNUSED_VAR (commit_sel)
|
||||
|
||||
for (genvar i = 0; i < `ISSUE_WIDTH; ++i) begin
|
||||
|
||||
@@ -176,14 +177,17 @@ module VX_commit import VX_gpu_pkg::*; #(
|
||||
// relies on 1 cycle delay of arbiter and continuous issuing of tensor instructions,
|
||||
// so probably want to change this at some point
|
||||
// (i.e. pass a "don't count this towards pending instructions" signal down the pipeline)
|
||||
logic [`ISSUE_WIDTH-1:0][4:0] hmma_ctr, hmma_ctr_n;
|
||||
// logic [`ISSUE_WIDTH-1:0][4:0] hmma_ctr, hmma_ctr_n;
|
||||
wire [`ISSUE_WIDTH-1:0] final_hmma;
|
||||
`ifdef EXT_T_ENABLE
|
||||
for (genvar i = 0; i < `ISSUE_WIDTH; ++i) begin
|
||||
assign hmma_ctr_n[i] = (tensor_commit_if[i].valid && tensor_commit_if[i].ready) ? hmma_ctr[i] + 5'b1 : hmma_ctr[i];
|
||||
assign final_hmma[i] = (commit_sel[i] != `EX_BITS'(2) || hmma_ctr == '0);
|
||||
// assign hmma_ctr_n[i] = (tensor_commit_if[i].valid && tensor_commit_if[i].ready) ? hmma_ctr[i] + 5'b1 : hmma_ctr[i];
|
||||
// assign final_hmma[i] = (commit_sel[i] != `EX_BITS'(2) || hmma_ctr == '0);
|
||||
// i suppose this is now a feature and not a bug
|
||||
// if PC is 0, this means it is not final step of a wmma, shouldn't be committed
|
||||
assign final_hmma[i] = (commit_if[i].data.PC != 32'b0);
|
||||
end
|
||||
|
||||
/*
|
||||
always @(posedge clk) begin
|
||||
if (reset) begin
|
||||
hmma_ctr <= '0;
|
||||
@@ -192,6 +196,7 @@ module VX_commit import VX_gpu_pkg::*; #(
|
||||
hmma_ctr <= hmma_ctr_n;
|
||||
end
|
||||
end
|
||||
*/
|
||||
`else
|
||||
assign final_hmma = '1;
|
||||
`endif
|
||||
|
||||
@@ -306,15 +306,14 @@ module VX_operands import VX_gpu_pkg::*; #(
|
||||
cycle <= cycle_n;
|
||||
end
|
||||
|
||||
if (cycle == 32'd25000) begin
|
||||
for (integer k = 0; k < `NUM_REGS * ISSUE_RATIO; ++k) begin
|
||||
$display("warp %0d, thread %0d, register %0d: %0x",
|
||||
i * ISSUE_RATIO + (k / `NUM_REGS),
|
||||
j,
|
||||
k % `NUM_REGS,
|
||||
gpr_ram.ram[k]);
|
||||
end
|
||||
end
|
||||
// if (cycle == 32'd25000) begin
|
||||
// for (integer k = 0; k < `NUM_REGS * ISSUE_RATIO; ++k) begin
|
||||
// integer warp = i * ISSUE_RATIO + (k / `NUM_REGS);
|
||||
// integer thread = j;
|
||||
// integer register = k % `NUM_REGS;
|
||||
// $display("warp %0d, thread %0d, register %0d: %0x", warp, thread, register, gpr_ram.ram[k]);
|
||||
// end
|
||||
// end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -58,7 +58,8 @@ module VX_tensor_core_warp import VX_gpu_pkg::*; #(
|
||||
logic result_valid;
|
||||
logic result_ready;
|
||||
VX_tensor_octet #(
|
||||
|
||||
.ISW(ISW),
|
||||
.OCTET(i)
|
||||
) octet (
|
||||
.clk(clk),
|
||||
.reset(reset),
|
||||
@@ -180,7 +181,8 @@ module VX_tensor_core_warp import VX_gpu_pkg::*; #(
|
||||
endmodule
|
||||
|
||||
module VX_tensor_octet #(
|
||||
|
||||
parameter ISW,
|
||||
parameter OCTET
|
||||
) (
|
||||
input clk,
|
||||
input reset,
|
||||
@@ -285,7 +287,8 @@ module VX_tensor_octet #(
|
||||
|
||||
wire do_hmma = (substep == 1'b1 && operands_valid && operands_ready);
|
||||
VX_tensor_dpu #(
|
||||
|
||||
.ISW(ISW),
|
||||
.OCTET(OCTET)
|
||||
) dpu (
|
||||
.clk(clk),
|
||||
.reset(reset),
|
||||
|
||||
@@ -92,5 +92,5 @@ HMMA_SET3_STEP3_0: begin
|
||||
uop = {NEXT, HMMA_SET3_STEP3_1, `EX_BITS'(`EX_TENSOR), `INST_OP_BITS'(3), `INST_MOD_BITS'(0), 1'b1, 1'b0, 1'b0, 32'b0, 32'b0, `FREG(22), `FREG(6), `FREG(14), `FREG(22)};
|
||||
end
|
||||
HMMA_SET3_STEP3_1: begin
|
||||
uop = {FINISH, HMMA_SET0_STEP0_0, `EX_BITS'(`EX_TENSOR), `INST_OP_BITS'(3), `INST_MOD_BITS'(1), 1'b1, 1'b0, 1'b0, 32'b0, 32'b0, `FREG(23), `FREG(7), `FREG(15), `FREG(23)};
|
||||
uop = {FINISH, HMMA_SET0_STEP0_0, `EX_BITS'(`EX_TENSOR), `INST_OP_BITS'(3), `INST_MOD_BITS'(1), 1'b1, 1'b0, 1'b0, 32'b1, 32'b1, `FREG(23), `FREG(7), `FREG(15), `FREG(23)};
|
||||
end
|
||||
|
||||
@@ -125,16 +125,16 @@ module VX_uop_sequencer import VX_gpu_pkg::*; (
|
||||
|
||||
always @(posedge clk) begin
|
||||
if (uop_start) begin
|
||||
$display("UOP start @ %t", $time);
|
||||
$display("use_uop=%0d, use_uop_1d=%0d, uop_start=%0d, ibuffer_if.valid=%0d, ibuffer_if.ready=%0d", use_uop, use_uop_1d, uop_start, ibuffer_if.valid, ibuffer_if.ready);
|
||||
// $display("UOP start @ %t", $time);
|
||||
// $display("use_uop=%0d, use_uop_1d=%0d, uop_start=%0d, ibuffer_if.valid=%0d, ibuffer_if.ready=%0d", use_uop, use_uop_1d, uop_start, ibuffer_if.valid, ibuffer_if.ready);
|
||||
end
|
||||
|
||||
if (uop_fire) begin
|
||||
$display("UOP fire @ %t", $time);
|
||||
// $display("UOP fire @ %t", $time);
|
||||
end
|
||||
|
||||
if (uop_finish) begin
|
||||
$display("UOP finish @ %t", $time);
|
||||
// $display("UOP finish @ %t", $time);
|
||||
end
|
||||
|
||||
if (reset) begin
|
||||
|
||||
@@ -55,17 +55,21 @@ with open('VX_tensor_ucode.vh', 'w') as f:
|
||||
finish = (next_sequence_num == 0)
|
||||
|
||||
name = "HMMA_SET{}_STEP{}_{}"
|
||||
ucode = "{}, HMMA_SET{}_STEP{}_{}, `EX_BITS'(`EX_TENSOR), `INST_OP_BITS'({}), `INST_MOD_BITS'({}), 1'b1, 1'b0, 1'b0, 32'b0, 32'b0, `FREG({}), `FREG({}), `FREG({}), `FREG({})"
|
||||
ucode = "{}, HMMA_SET{}_STEP{}_{}, `EX_BITS'(`EX_TENSOR), `INST_OP_BITS'({}), `INST_MOD_BITS'({}), 1'b1, 1'b0, 1'b0, 32'b{}, 32'b{}, `FREG({}), `FREG({}), `FREG({}), `FREG({})"
|
||||
|
||||
name = name.format(
|
||||
set_num, step, substep,
|
||||
)
|
||||
|
||||
pc_imm = 1 if finish else 0
|
||||
|
||||
ucode = ucode.format(
|
||||
"FINISH" if finish else "NEXT",
|
||||
next_set_num, next_step, next_substep,
|
||||
step,
|
||||
substep,
|
||||
pc_imm,
|
||||
pc_imm,
|
||||
rs3_rd[(step, substep)],
|
||||
rs1[(set_num, substep)],
|
||||
rs2[(set_num, substep)],
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
`include "VX_fpu_define.vh"
|
||||
|
||||
module VX_tensor_dpu #(
|
||||
|
||||
parameter ISW,
|
||||
parameter OCTET
|
||||
) (
|
||||
input clk,
|
||||
input reset,
|
||||
@@ -21,6 +22,12 @@ module VX_tensor_dpu #(
|
||||
always @(*) begin
|
||||
dpi_hmma(valid_in, A_tile, B_tile, C_tile, result_hmma);
|
||||
end
|
||||
|
||||
always @(posedge clk) begin
|
||||
if (~reset && valid_in) begin
|
||||
dpi_print_results(int'(ISW), int'(OCTET), A_tile, B_tile, C_tile, result_hmma);
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
VX_shift_register #(
|
||||
|
||||
Reference in New Issue
Block a user