Skip to content

Commit

Permalink
#8164: DPRINT support for printing from CB rd/wr pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
tt-dma committed Oct 4, 2024
1 parent 0d1eb7d commit 9860091
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
8 changes: 7 additions & 1 deletion docs/source/tt-metalium/tools/kernel_print.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,13 @@ back of the CB, the ``DPRINT`` call has to occur between the ``cb_reserve_back``
// 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();
// On data movement RISCs, tiles can be printed from either the CB read or write pointers
DPRINT_DATA0({ DPRINT << (uint)r << " --READ--cin1-- " << TileSlice(0, 0, sr, TSLICE_RD_PTR, true, false) << ENDL(); });
DPRINT_DATA1({ DPRINT << (uint)r << " --READ--cin1-- " << TileSlice(0, 0, sr, TSLICE_WR_PTR, true, false) << ENDL(); });
// Unpacker RISC only has rd_ptr, so no extra arg
DPRINT_UNPACK({ DPRINT << (uint)r << " --READ--cin1-- " << TileSlice(0, 0, sr, true, false) << ENDL(); });
// Packer RISC only has wr_ptr
DPRINT_PACK({ DPRINT << (uint)r << " --READ--cin1-- " << TileSlice(0, 0, sr, true, false) << ENDL(); });
}
...
Expand Down
6 changes: 6 additions & 0 deletions tt_metal/hw/inc/debug/dprint_test_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ inline void print_test_data() {
// Eth cores don't have CBs, so don't try TSLICE printing.
DPRINT << "SLICE:\n";
cb_wait_front(tt::CB::c_in0, 1);
#if defined(COMPILE_FOR_BRISC) || defined(COMPILE_FOR_NCRISC)
// Since brisc is writing to the CB before printing, should look at read pointer
DPRINT << TSLICE(tt::CB::c_in0, 0, SliceRange::hw0_32_8(), TSLICE_RD_PTR);
DPRINT << TSLICE(tt::CB::c_in0, 0, SliceRange::hw0_32_4(), TSLICE_RD_PTR);
#else
DPRINT << TSLICE(tt::CB::c_in0, 0, SliceRange::hw0_32_8());
DPRINT << TSLICE(tt::CB::c_in0, 0, SliceRange::hw0_32_4());
#endif
#endif
}
31 changes: 25 additions & 6 deletions tt_metal/hw/inc/debug/dprint_tile.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ struct SliceRange {
// MAXCOUNT is the size of reserved space in the print buffer
// if the total element count produced by the slice spec exceeds MAXCOUNT, it will be truncated
//
typedef bool dprint_tslice_ptr_t;
#define TSLICE_RD_PTR true
#define TSLICE_WR_PTR false

template<int MAXCOUNT=32>
struct TileSlice : TileSliceHostDev<MAXCOUNT> {
static inline int min_(int a, int b) { return a < b ? a : b; } // to avoid inclusion of <algorithm>
Expand All @@ -53,16 +57,31 @@ struct TileSlice : TileSliceHostDev<MAXCOUNT> {
// samples the tile using python style slice with strides [h0:h1:hs, w0:w1:ws]
// endl_rows=false skips printing the endl in the end of row, so it's easier to visualize tall columns

__attribute__((__noinline__))
TileSlice(int cb, int itile, const SliceRange& s, bool endl_rows = true, bool print_untilized = true) {
__attribute__((__noinline__)) TileSlice(
int cb,
int itile,
const SliceRange& s,
// For NCRISC and BRISC, have access to both rd and wr ptr, let user choose w/ arg.
#if defined(COMPILE_FOR_NCRISC)
dprint_tslice_ptr_t ptr_type = TSLICE_WR_PTR,
#elif defined(COMPILE_FOR_BRISC)
dprint_tslice_ptr_t ptr_type = TSLICE_RD_PTR,
#endif
bool endl_rows = true,
bool print_untilized = true) {
// The math risc uses a different mechanism for syncing data, and as such doesn't have
// access to CBs, so TileSlice printing is skipped on this risc.
this->count_ = 0;
volatile Tile* t;
#if defined(UCK_CHLKC_PACK) || defined(COMPILE_FOR_NCRISC)
this->ptr_ = cb_interface[cb].fifo_wr_ptr<<4;
#elif defined(UCK_CHLKC_UNPACK) || defined(COMPILE_FOR_BRISC)
this->ptr_ = cb_interface[cb].fifo_rd_ptr<<4;
// Pointer value depends on whether we're looking at read or write ptr
#if defined(UCK_CHLKC_PACK)
this->ptr_ = cb_interface[cb].fifo_wr_ptr << 4; // PACK only has write pointer
#elif defined(UCK_CHLKC_UNPACK)
this->ptr_ = cb_interface[cb].fifo_rd_ptr << 4; // UNPACK only has read pointer
#elif defined(COMPILE_FOR_NCRISC) || defined(COMPILE_FOR_BRISC)
// For BRISC/NCRISC, user chooses which pointer.
this->ptr_ =
(ptr_type == TSLICE_WR_PTR) ? cb_interface[cb].fifo_wr_ptr << 4 : cb_interface[cb].fifo_rd_ptr << 4;
#else
this->ptr_ = 0;
#endif
Expand Down
3 changes: 1 addition & 2 deletions tt_metal/impl/debug/dprint_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ static void PrintTileSlice(ostream& stream, uint8_t* ptr, int hart_id) {
uint16_t *samples_ = reinterpret_cast<uint16_t *>(ptr) + offsetof(TileSliceHostDev<0>, samples_) / sizeof(uint16_t);

if (ts->w0_ == 0xFFFF) {
stream << "BAD TILE POINTER" << std::flush;
stream << " count=" << ts->count_ << std::flush;
stream << fmt::format("BAD TILE POINTER (ptr={}, count={})\n", ts->ptr_, ts->count_) << std::flush;
} else {
uint32_t i = 0;
bool count_exceeded = false;
Expand Down

0 comments on commit 9860091

Please sign in to comment.