Nyuzi is an open source GPGPU developed by Jeff Bush(https://github.com/jbush001/NyuziProcessor). When examining your design in simulator, this C# winform application can help verify the C/C++ function call trace of a 4-threads Nyuzi core and show the result in a stack trace view. It may provide some useful information when the core isn't running as expect.
NyuziToolchain emits a CALL instruction for C/C++ function call and a MOVE PC, RA for function return. So the execution history of those two instruction reflects the running trace of compiler generated code. Before using this tool, a piece of code needs to be inserted into core's source to capture the occurrence of CALL (Nyuzi pipeline will convert it to a twisted MOVE RA, PC) and MOVE PC, RA. By reading the simulation log, this tool reconstructs the running trace of each thread.
As above mentioned, this tool obtains the runtime information by reading the log generated during simulation.
To generate the log accepted by this tool, first, make sure the head of file writeback_stage.sv contain timescale declaration and then insert following lines before the end of module writeback_stage.
integer fp = $fopen("trace.log");
always @(posedge clk) begin
#1;
if (ix_instruction_valid && ix_instruction.has_dest && ix_instruction.dest_reg == `REG_PC
&& !ix_instruction.dest_is_vector) begin
if ((ix_instruction.dest_reg == `REG_PC) && (ix_instruction.alu_op == OP_MOVE) && (ix_instruction.scalar_sel2 == `REG_RA)) begin
$fdisplay(fp, "[%d] %d@0x%08X retn to 0x%08X", $time()-1, wb_rollback_thread_idx, ix_instruction.pc, wb_rollback_pc);
end
end
else if (ix_instruction_valid && ix_rollback_en) begin
if ((ix_instruction.is_branch == 1) && ((ix_instruction.branch_type == BRANCH_CALL_OFFSET) || (ix_instruction.branch_type == BRANCH_CALL_REGISTER)) &&
(ix_instruction.dest_reg == `REG_RA) && (ix_instruction.alu_op == OP_MOVE) && (ix_instruction.scalar_sel2 == `REG_PC)) begin
$fdisplay(fp, "[%d] %d@0x%08X call to 0x%08X", $time()-1, wb_rollback_thread_idx, ix_instruction.pc, wb_rollback_pc);
end
end
end
After simulation, you will see trace.log appears.
Also, this tool can load symbol list generated by llvm-objdump for better output (if you don't need, click cancel when open symbol table), to generate the symbol list accepted by the tool, execute:
$ llvm-objdump [target.elf] -t > [symtable.sym]
MSBuild Nyuzi_StackTracer.sln /t:Clean /p:Configuration=Release
MSBuild Nyuzi_StackTracer.sln /t:Build /p:Configuration=Release