Skip to content

Commit

Permalink
Add more DRAM translation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pjanevskiTT committed Nov 21, 2024
1 parent 8c738fc commit bbd768b
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 24 deletions.
48 changes: 28 additions & 20 deletions device/coordinate_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ CoreCoord CoordinateManager::to_dram_physical(const CoreCoord core_coord) {
tt_xy_pair physical_pair = dram_logical_to_physical.at({core_coord.x, core_coord.y});
return CoreCoord(physical_pair.x, physical_pair.y, CoreType::DRAM, CoordSystem::PHYSICAL);
}
case CoordSystem::PHYSICAL:
case CoordSystem::VIRTUAL:
return to_dram_physical(to_logical(core_coord));
case CoordSystem::PHYSICAL:
return core_coord;
case CoordSystem::TRANSLATED: {
CoreCoord physical_coord = core_coord;
physical_coord.coord_system = CoordSystem::PHYSICAL;
Expand All @@ -84,39 +86,45 @@ CoreCoord CoordinateManager::to_dram_logical(const CoreCoord core_coord) {
switch (core_coord.coord_system) {
case CoordSystem::LOGICAL:
return core_coord;
case CoordSystem::PHYSICAL:
case CoordSystem::VIRTUAL:
case CoordSystem::PHYSICAL: {
tt_xy_pair logical_pair = dram_physical_to_logical.at({core_coord.x, core_coord.y});
return CoreCoord(logical_pair.x, logical_pair.y, CoreType::DRAM, CoordSystem::LOGICAL);
}
case CoordSystem::VIRTUAL: {
tt_xy_pair virtual_pair = dram_virtual_to_logical.at({core_coord.x, core_coord.y});
return CoreCoord(virtual_pair.x, virtual_pair.y, CoreType::DRAM, CoordSystem::LOGICAL);
}
case CoordSystem::TRANSLATED:
// TODO(pjanevski): implement this
return core_coord;
return to_logical(to_physical(core_coord));
}
}

CoreCoord CoordinateManager::to_dram_virtual(const CoreCoord core_coord) {
switch (core_coord.coord_system) {
case CoordSystem::LOGICAL:
// TODO(pjanevski): implement this
return core_coord;
case CoordSystem::PHYSICAL:
case CoordSystem::VIRTUAL:
case CoordSystem::LOGICAL: {
tt_xy_pair virtual_pair = dram_logical_to_virtual.at({core_coord.x, core_coord.y});
return CoreCoord(virtual_pair.x, virtual_pair.y, CoreType::DRAM, CoordSystem::VIRTUAL);
}
case CoordSystem::TRANSLATED:
CoreCoord physical_coord = core_coord;
physical_coord.coord_system = CoordSystem::VIRTUAL;
return physical_coord;
case CoordSystem::PHYSICAL: {
return to_virtual(to_logical(core_coord));
}
case CoordSystem::VIRTUAL:
return core_coord;
}
}

CoreCoord CoordinateManager::to_dram_translated(const CoreCoord core_coord) {
switch (core_coord.coord_system) {
case CoordSystem::LOGICAL:
// TODO(pjanevski): implement this
return core_coord;
case CoordSystem::PHYSICAL:
case CoordSystem::VIRTUAL:
case CoordSystem::VIRTUAL: {
return to_dram_translated(to_dram_physical(core_coord));
}
case CoordSystem::PHYSICAL: {
return CoreCoord(core_coord.x, core_coord.y, CoreType::DRAM, CoordSystem::TRANSLATED);
}
case CoordSystem::TRANSLATED:
CoreCoord physical_coord = core_coord;
physical_coord.coord_system = CoordSystem::TRANSLATED;
return physical_coord;
return core_coord;
}
}

Expand Down
79 changes: 75 additions & 4 deletions tests/api/test_core_coord_translation_bh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ TEST(CoordinateManager, CoordinateManagerBHDRAMTopLeft) {
EXPECT_EQ(top_left_physical, expected_top_left_physical);
}

// // Test logical to physical coordinate translation.
// // For the full grid of logical coordinates we expect that there are no duplicates of physical coordinates.
// // For the reverse mapping back of physical to logical coordinates we expect that same logical coordinates are returned as from original mapping.
// Test logical to physical DRAM coordinate translation.
// For the full grid of logical coordinates we expect that there are no duplicates of physical coordinates.
// For the reverse mapping back of physical to logical coordinates we expect that same logical coordinates are returned as from original mapping.
TEST(CoordinateManager, CoordinateManagerBHDRAMLogicalPhysicalMapping) {

tt_SocDescriptor soc_desc = tt_SocDescriptor(test_utils::GetAbsPath("tests/soc_descs/blackhole_140_arch.yaml"));
Expand Down Expand Up @@ -289,4 +289,75 @@ TEST(CoordinateManager, CoordinateManagerBHDRAMLogicalPhysicalMapping) {
EXPECT_EQ(it.first, logical_coords);
}
}
}
}

// Test logical to virtual DRAM coordinate translation.
// For the full grid of logical coordinates we expect that there are no duplicates of virtual coordinates.
// For the reverse mapping back of virtual to logical coordinates we expect that same logical coordinates are returned as from original mapping.
TEST(CoordinateManager, CoordinateManagerBHDRAMLogicalVirtualMapping) {

const std::size_t max_num_banks_harvested = tt::umd::blackhole::NUM_DRAM_BANKS;
const std::size_t num_dram_banks = tt::umd::blackhole::NUM_DRAM_BANKS;
const std::size_t num_noc_ports_per_bank = tt::umd::blackhole::NUM_NOC_PORTS_PER_DRAM_BANK;

tt_SocDescriptor soc_desc = tt_SocDescriptor(test_utils::GetAbsPath("tests/soc_descs/blackhole_140_arch.yaml"));

for (std::size_t harvesting_mask = 0; harvesting_mask < (1 << max_num_banks_harvested); harvesting_mask++) {

soc_desc.dram_harvesting(harvesting_mask);

std::map<CoreCoord, CoreCoord> logical_to_virtual;
std::set<CoreCoord> virtual_coords_set;

std::size_t num_harvested_banks = test_utils::get_num_harvested(harvesting_mask);

for (size_t x = 0; x < num_dram_banks - num_harvested_banks; x++) {
for (size_t y = 0; y < num_noc_ports_per_bank; y++) {
CoreCoord logical_coords = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL);
CoreCoord virtual_coords = soc_desc.to_virtual(logical_coords);
logical_to_virtual[logical_coords] = virtual_coords;

// Expect that logical to virtual translation is 1-1 mapping. No duplicates for virtual coordinates.
EXPECT_EQ(virtual_coords_set.count(virtual_coords), 0);
virtual_coords_set.insert(virtual_coords);
}
}

for (auto it : logical_to_virtual) {
CoreCoord virtual_coords = it.second;
CoreCoord logical_coords = soc_desc.to_logical(virtual_coords);

// Expect that reverse mapping of virtual coordinates gives the same logical coordinates
// using which we got the virtual coordinates.
EXPECT_EQ(it.first, logical_coords);
}
}
}

// Test equality of physical and translated coordinates for all logical coordinates for any harvesting mask.
TEST(CoordinateManager, CoordinateManagerBHDRAMPhysicalTranslatedEquality) {
const std::size_t max_num_banks_harvested = tt::umd::blackhole::NUM_DRAM_BANKS;
const std::size_t num_dram_banks = tt::umd::blackhole::NUM_DRAM_BANKS;
const std::size_t num_noc_ports_per_bank = tt::umd::blackhole::NUM_NOC_PORTS_PER_DRAM_BANK;

tt_SocDescriptor soc_desc = tt_SocDescriptor(test_utils::GetAbsPath("tests/soc_descs/blackhole_140_arch.yaml"));

for (std::size_t harvesting_mask = 0; harvesting_mask < (1 << max_num_banks_harvested); harvesting_mask++) {

soc_desc.dram_harvesting(harvesting_mask);

const std::size_t num_harvested_banks = test_utils::get_num_harvested(harvesting_mask);

for (size_t x = 0; x < num_dram_banks - num_harvested_banks; x++) {
for (size_t y = 0; y < num_noc_ports_per_bank; y++) {
const CoreCoord logical_coords = CoreCoord(x, y, CoreType::TENSIX, CoordSystem::LOGICAL);

const CoreCoord physical_coords = soc_desc.to_physical(logical_coords);
const CoreCoord translated_coords = soc_desc.to_translated(logical_coords);

EXPECT_EQ(physical_coords.x, translated_coords.x);
EXPECT_EQ(physical_coords.y, translated_coords.y);
}
}
}
}

0 comments on commit bbd768b

Please sign in to comment.