Skip to content

Commit

Permalink
#3970: Update DPRINT docs/tests for TSLICE printing on Math RISC
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tt-dma committed Dec 5, 2023
1 parent a7af92e commit e507342
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
24 changes: 13 additions & 11 deletions docs/source/tools/kernel_print.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
[email protected]
Expand Down
3 changes: 0 additions & 3 deletions tt_metal/hw/inc/debug/dprint_test_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
13 changes: 10 additions & 3 deletions tt_metal/impl/debug/dprint_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<TileSliceHostDev<0>*>(ptr);
stream << "TILE: (" << endl << std::flush;
if (ts->w0_ == 0xFFFF) {
Expand Down Expand Up @@ -183,7 +191,6 @@ static void print_tile_slice(ostream& stream, uint8_t* ptr) {
stream << endl;
}
}
done:
stream << endl << " ptr=" << ts->ptr_ << ")" << endl;
}

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit e507342

Please sign in to comment.