From e507342095416b159c7b14c4573d1248173900e0 Mon Sep 17 00:00:00 2001 From: David Ma Date: Tue, 5 Dec 2023 00:48:29 +0000 Subject: [PATCH] #3970: Update DPRINT docs/tests for TSLICE printing on Math RISC Since Math RISC doesn't have access to CBs, TileSlice printing isn't expected to work. Give the user a suitable warning and update the docs accordingly. --- docs/source/tools/kernel_print.rst | 24 ++++++++++--------- .../dprint/test_print_all_harts.cpp | 2 ++ tt_metal/hw/inc/debug/dprint_test_common.h | 3 --- tt_metal/impl/debug/dprint_server.cpp | 13 +++++++--- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/docs/source/tools/kernel_print.rst b/docs/source/tools/kernel_print.rst index 0296e7e1aff..dec37c98020 100644 --- a/docs/source/tools/kernel_print.rst +++ b/docs/source/tools/kernel_print.rst @@ -23,6 +23,17 @@ To generate kernel debug prints on the device: uint16_t my_bf16_val = 0x3dfb; // Equivalent to 0.122559 DPRINT << BF16(my_bf16_val) << ENDL(); + // dprint.h includes macros for a subset of std::ios and std::iomanip functionality: + // SETPRECISION macro has the same behaviour as std::setprecision + DPRINT << SETPRECISION(5) << 0.123456f << ENDL(); + // FIXED and DEFAULTFLOAT macros have the same behaviour as std::fixed and std::defaultfloat + DPRINT << FIXED() << 0.123456f << DEFAULTFLOAT() << 0.123456f << ENDL(); + // SETW macro is the same as std::setw, but with an optional sticky flag (default true) + DPRINT << "SETW (sticky): " << SETW(10) << 1 << 2 << ENDL(); + DPRINT << "SETW (non-sticky): " << SETW(10, false) << 1 << 2 << ENDL(); + // HEX/DEC/OCT macros corresponding to std::hex/std::dec/std::oct + DPRINT << HEX() << 15 << DEC() << 15 << OCT() << 15 << ENDL(); + // The following prints only occur on a particular RISCV core: DPRINT_MATH(DPRINT << "this is the math kernel" << ENDL()); DPRINT_PACK(DPRINT << "this is the pack kernel" << ENDL()); @@ -32,23 +43,14 @@ To generate kernel debug prints on the device: // Print a tile slice DPRINT_PACK({ DPRINT << TSLICE(CB::c_intermed1, 0, SliceRange::hw0_32_16()) << ENDL(); }); + // Note that since the MATH core does not have acces to CBs, so this is an invalid print: + DPRINT_MATH({ DPRINT << TSLICE(CB::c_intermed1, 0, SliceRange::hw0_32_16()) << ENDL(); }); // Invalid // Print a full tile for (int32_t r = 0; r < 32; ++r) { SliceRange sr = SliceRange{.h0 = r, .h1 = r+1, .hs = 1, .w0 = 0, .w1 = 32, .ws = 1}; DPRINT << (uint)r << " --READ--cin0-- " << TileSlice(0, 0, sr, true, false) << ENDL(); } - - // dprint.h includes macros for a subset of std::ios and std::iomanip functionality: - // SETPRECISION macro has the same behaviour as std::setprecision - DPRINT << SETPRECISION(5) << 0.123456f << ENDL(); - // FIXED and DEFAULTFLOAT macros have the same behaviour as std::fixed and std::defaultfloat - DPRINT << FIXED() << 0.123456f << DEFAULTFLOAT() << 0.123456f << ENDL(); - // SETW macro is the same as std::setw, but with an optional sticky flag (default true) - DPRINT << "SETW (sticky): " << SETW(10) << 1 << 2 << ENDL(); - DPRINT << "SETW (non-sticky): " << SETW(10, false) << 1 << 2 << ENDL(); - // HEX/DEC/OCT macros corresponding to std::hex/std::dec/std::oct - DPRINT << HEX() << 15 << DEC() << 15 << OCT() << 15 << ENDL(); } The ``TSLICE`` macros support printing tile contents with a given sample count, starting index and stride. The diff --git a/tests/tt_metal/tt_metal/unit_tests_fast_dispatch/dprint/test_print_all_harts.cpp b/tests/tt_metal/tt_metal/unit_tests_fast_dispatch/dprint/test_print_all_harts.cpp index f89b6cfed20..63a4e701137 100644 --- a/tests/tt_metal/tt_metal/unit_tests_fast_dispatch/dprint/test_print_all_harts.cpp +++ b/tests/tt_metal/tt_metal/unit_tests_fast_dispatch/dprint/test_print_all_harts.cpp @@ -86,6 +86,8 @@ SETPRECISION/FIXED/DEFAULTFLOAT: HEX/OCT/DEC: 1e240361100123456 SLICE: +Warning: MATH core does not support TileSlice printing, omitting print... +Warning: MATH core does not support TileSlice printing, omitting print... Test Debug Print: Pack Basic Types: 101-1.61800337@0.122558594 diff --git a/tt_metal/hw/inc/debug/dprint_test_common.h b/tt_metal/hw/inc/debug/dprint_test_common.h index 33cf5be0da4..ef6701da3cb 100644 --- a/tt_metal/hw/inc/debug/dprint_test_common.h +++ b/tt_metal/hw/inc/debug/dprint_test_common.h @@ -19,10 +19,7 @@ inline void print_test_data() { DPRINT << "SETW:\n" << SETW(10) << my_int << my_int << SETW(4) << "ab" << ENDL(); DPRINT << "HEX/OCT/DEC:\n" << HEX() << my_int << OCT() << my_int << DEC() << my_int << ENDL(); DPRINT << "SLICE:\n"; -// See issue #3970, disable TSLICE printing for math for now. -#ifndef UCK_CHLKC_MATH cb_wait_front(tt::CB::c_in0, 1); DPRINT << TSLICE(tt::CB::c_in0, 0, SliceRange::hw0_32_8()); DPRINT << TSLICE(tt::CB::c_in0, 0, SliceRange::hw0_32_4()); -#endif } diff --git a/tt_metal/impl/debug/dprint_server.cpp b/tt_metal/impl/debug/dprint_server.cpp index df3c77574ed..f9ce034f656 100644 --- a/tt_metal/impl/debug/dprint_server.cpp +++ b/tt_metal/impl/debug/dprint_server.cpp @@ -145,7 +145,15 @@ struct DebugPrintServerContext { bool peek_flush_one_hart_nonblocking(int chip_id, const CoreCoord& core, int hart_index); }; -static void print_tile_slice(ostream& stream, uint8_t* ptr) { +static void print_tile_slice(ostream& stream, uint8_t* ptr, int hart_id) { + // Since MATH RISCV doesn't have access to CBs, we can't print tiles from it. If the user still + // tries to do this print a relevant message. + if ((1 << hart_id) == DPRINT_RISCV_TR1) { + stream << "Warning: MATH core does not support TileSlice printing, omitting print..." + << endl << std::flush; + return; + } + TileSliceHostDev<0>* ts = reinterpret_cast*>(ptr); stream << "TILE: (" << endl << std::flush; if (ts->w0_ == 0xFFFF) { @@ -183,7 +191,6 @@ static void print_tile_slice(ostream& stream, uint8_t* ptr) { stream << endl; } } -done: stream << endl << " ptr=" << ts->ptr_ << ")" << endl; } @@ -258,7 +265,7 @@ bool DebugPrintServerContext::peek_flush_one_hart_nonblocking(int chip_id, const TT_ASSERT(sz == strlen(cptr)+1); break; case DEBUG_PRINT_TYPEID_TILESLICE: - print_tile_slice(stream, ptr); + print_tile_slice(stream, ptr, hart_id); break; case DEBUG_PRINT_TYPEID_ENDL: