Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement TTDevice get_board_type #591

Merged
merged 2 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions device/api/umd/device/tt_device/blackhole_tt_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class BlackholeTTDevice : public TTDevice {

uint32_t get_clock() override;

BoardType get_board_type() override;

private:
static constexpr uint64_t ATU_OFFSET_IN_BH_BAR2 = 0x1200;
std::set<size_t> iatu_regions_;
Expand Down
2 changes: 2 additions & 0 deletions device/api/umd/device/tt_device/grayskull_tt_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ class GrayskullTTDevice : public TTDevice {
GrayskullTTDevice(std::unique_ptr<PCIDevice> pci_device);

ChipInfo get_chip_info() override;

BoardType get_board_type() override;
};
} // namespace tt::umd
2 changes: 2 additions & 0 deletions device/api/umd/device/tt_device/tt_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ class TTDevice {

virtual uint32_t get_clock();

virtual BoardType get_board_type() = 0;

protected:
std::unique_ptr<PCIDevice> pci_device_;
std::unique_ptr<architecture_implementation> architecture_impl_;
Expand Down
2 changes: 2 additions & 0 deletions device/api/umd/device/tt_device/wormhole_tt_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ class WormholeTTDevice : public TTDevice {
ChipInfo get_chip_info() override;

uint32_t get_clock() override;

BoardType get_board_type() override;
};
} // namespace tt::umd
7 changes: 6 additions & 1 deletion device/api/umd/device/types/cluster_descriptor_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ inline BlackholeChipType get_blackhole_chip_type(const BoardType board_type, con
}
}

// TODO: add Wormhole and Grayskull board types to this function
inline BoardType get_board_type_from_board_id(const uint64_t board_id) {
uint64_t upi = (board_id >> 36) & 0xFFFFF;

Expand All @@ -124,6 +123,12 @@ inline BoardType get_board_type_from_board_id(const uint64_t board_id) {
return BoardType::P150;
} else if (upi == 0x44 || upi == 0x45 || upi == 0x46) {
return BoardType::P300;
} else if (upi == 0x14) {
return BoardType::N300;
} else if (upi == 0x18) {
return BoardType::N150;
} else if (upi == 0xB) {
return BoardType::GALAXY;
}

throw std::runtime_error(fmt::format("No existing board type for board id {}", board_id));
Expand Down
1 change: 1 addition & 0 deletions device/api/umd/device/wormhole_implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ static constexpr auto TLB_16M_OFFSET = tlb_offsets{

enum class arc_message_type {
NOP = 0x11, // Do nothing
GET_SMBUS_TELEMETRY_ADDR = 0x2C,
GET_AICLK = 0x34,
ARC_GO_BUSY = 0x52,
ARC_GO_SHORT_IDLE = 0x53,
Expand Down
6 changes: 6 additions & 0 deletions device/tt_device/blackhole_tt_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,10 @@ uint32_t BlackholeTTDevice::get_clock() {
throw std::runtime_error("AICLK telemetry not available for Blackhole device.");
}

BoardType BlackholeTTDevice::get_board_type() {
return get_board_type_from_board_id(
((uint64_t)telemetry->read_entry(blackhole::TAG_BOARD_ID_HIGH) << 32) |
(telemetry->read_entry(blackhole::TAG_BOARD_ID_LOW)));
}

} // namespace tt::umd
6 changes: 6 additions & 0 deletions device/tt_device/grayskull_tt_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ ChipInfo GrayskullTTDevice::get_chip_info() {
throw std::runtime_error("Reading ChipInfo is not supported for Grayskull.");
}

BoardType GrayskullTTDevice::get_board_type() {
throw std::runtime_error(
"Base TTDevice class does not have get_board_type implemented. Move this to abstract function once Grayskull "
"TTDevice is deleted.");
}

} // namespace tt::umd
25 changes: 25 additions & 0 deletions device/tt_device/wormhole_tt_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,29 @@ uint32_t WormholeTTDevice::get_clock() {
return arc_msg_return_values[0];
}

BoardType WormholeTTDevice::get_board_type() {
::std::vector<uint32_t> arc_msg_return_values = {0};
static const uint32_t timeout_ms = 1000;
uint32_t exit_code = get_arc_messenger()->send_message(
tt::umd::wormhole::ARC_MSG_COMMON_PREFIX |
(uint32_t)tt::umd::wormhole::arc_message_type::GET_SMBUS_TELEMETRY_ADDR,
arc_msg_return_values,
0,
0,
timeout_ms);

static constexpr uint64_t noc_telemetry_offset = 0x810000000;
uint64_t telemetry_struct_offset = arc_msg_return_values[0] + noc_telemetry_offset;

uint32_t board_id_lo;
uint32_t board_id_hi;
tt_xy_pair arc_core = tt::umd::wormhole::ARC_CORES[0];
static uint64_t board_id_hi_telemetry_offset = 16;
static uint64_t board_id_lo_telemetry_offset = 20;
read_from_device(&board_id_hi, arc_core, telemetry_struct_offset + board_id_hi_telemetry_offset, sizeof(uint32_t));
read_from_device(&board_id_lo, arc_core, telemetry_struct_offset + board_id_lo_telemetry_offset, sizeof(uint32_t));

return get_board_type_from_board_id(((uint64_t)board_id_hi << 32) | board_id_lo);
}

} // namespace tt::umd
15 changes: 14 additions & 1 deletion tests/api/test_tt_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ tt_xy_pair get_any_tensix_core(tt::ARCH arch) {
}
}

TEST(TTDeviceTest, BasicTTDeviceIO) {
TEST(ApiTTDeviceTest, BasicTTDeviceIO) {
std::vector<int> pci_device_ids = PCIDevice::enumerate_devices();

uint64_t address = l1_mem::address_map::NCRISC_FIRMWARE_BASE;
Expand All @@ -44,3 +44,16 @@ TEST(TTDeviceTest, BasicTTDeviceIO) {
data_read = std::vector<uint32_t>(data_write.size(), 0);
}
}

TEST(ApiTTDeviceTest, TTDeviceGetBoardType) {
std::vector<int> pci_device_ids = PCIDevice::enumerate_devices();
for (int pci_device_id : pci_device_ids) {
std::unique_ptr<TTDevice> tt_device = TTDevice::create(pci_device_id);

BoardType board_type = tt_device->get_board_type();

EXPECT_TRUE(
board_type == BoardType::N150 || board_type == BoardType::N300 || board_type == BoardType::P100 ||
board_type == BoardType::P150 || board_type == BoardType::P300 || board_type == BoardType::GALAXY);
}
}
Loading