|
| 1 | +// SPDX-FileCopyrightText: © 2025 Tenstorrent AI ULC |
| 2 | +// |
| 3 | +// SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +#include <fmt/base.h> |
| 6 | +#include <gtest/gtest.h> |
| 7 | +#include <gmock/gmock.h> |
| 8 | + |
| 9 | +#include <impl/context/metal_context.hpp> |
| 10 | +#include <tt-metalium/control_plane.hpp> |
| 11 | +#include <tt-metalium/distributed_context.hpp> |
| 12 | +#include <tt-metalium/system_mesh.hpp> |
| 13 | +#include <tt-metalium/mesh_coord.hpp> |
| 14 | +#include <tt-metalium/distributed_host_buffer.hpp> |
| 15 | +#include <tt-metalium/fabric_types.hpp> |
| 16 | +#include <tt-metalium/host_buffer.hpp> |
| 17 | + |
| 18 | +#include <tt-metalium/tt_metal.hpp> |
| 19 | + |
| 20 | +namespace tt::tt_metal::distributed { |
| 21 | + |
| 22 | +using tt_fabric::HostRankId; |
| 23 | +using tt_fabric::MeshId; |
| 24 | +using tt_fabric::MeshScope; |
| 25 | + |
| 26 | +TEST(BigMeshDualRankTestT3K, DistributedContext) { |
| 27 | + auto& dctx = MetalContext::instance().get_distributed_context(); |
| 28 | + auto world_size = dctx.size(); |
| 29 | + EXPECT_EQ(*world_size, 2); |
| 30 | +} |
| 31 | + |
| 32 | +TEST(BigMeshDualRankTestT3K, LocalRankBinding) { |
| 33 | + auto& dctx = MetalContext::instance().get_distributed_context(); |
| 34 | + auto& control_plane = MetalContext::instance().get_control_plane(); |
| 35 | + |
| 36 | + tt_fabric::HostRankId local_rank_binding = control_plane.get_local_host_rank_id_binding(); |
| 37 | + if (*dctx.rank() == 0) { |
| 38 | + EXPECT_EQ(*local_rank_binding, 0); |
| 39 | + } else { |
| 40 | + EXPECT_EQ(*local_rank_binding, 1); |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +TEST(BigMeshDualRankTestT3K, SystemMeshValidation) { |
| 45 | + EXPECT_NO_THROW({ |
| 46 | + const auto& system_mesh = SystemMesh::instance(); |
| 47 | + EXPECT_EQ(system_mesh.shape(), MeshShape(2,4)); |
| 48 | + EXPECT_EQ(system_mesh.local_shape(), MeshShape(2,2)); |
| 49 | + }); |
| 50 | +} |
| 51 | + |
| 52 | +TEST(BigMeshDualRankTestT3K, MeshDevice2x4Validation) { |
| 53 | + auto mesh_device = MeshDevice::create(MeshDeviceConfig(MeshShape(2,4)), DEFAULT_L1_SMALL_SIZE, DEFAULT_TRACE_REGION_SIZE, 1, tt::tt_metal::DispatchCoreType::WORKER); |
| 54 | + EXPECT_EQ(mesh_device->shape(), MeshShape(2,4)); |
| 55 | +} |
| 56 | + |
| 57 | +TEST(BigMeshDualRankTestT3K, SystemMeshShape) { |
| 58 | + const auto& system_mesh = SystemMesh::instance(); |
| 59 | + EXPECT_EQ(system_mesh.local_shape(), MeshShape(2, 2)); |
| 60 | + |
| 61 | + auto& control_plane = MetalContext::instance().get_control_plane(); |
| 62 | + auto rank = control_plane.get_local_host_rank_id_binding(); |
| 63 | + |
| 64 | + if (rank == HostRankId{0}) { |
| 65 | + EXPECT_NO_THROW(system_mesh.get_physical_device_id(MeshCoordinate(0, 0))); |
| 66 | + EXPECT_NO_THROW(system_mesh.get_physical_device_id(MeshCoordinate(0, 1))); |
| 67 | + EXPECT_NO_THROW(system_mesh.get_physical_device_id(MeshCoordinate(1, 0))); |
| 68 | + EXPECT_NO_THROW(system_mesh.get_physical_device_id(MeshCoordinate(1, 1))); |
| 69 | + } else { |
| 70 | + EXPECT_NO_THROW(system_mesh.get_physical_device_id(MeshCoordinate(0, 2))); |
| 71 | + EXPECT_NO_THROW(system_mesh.get_physical_device_id(MeshCoordinate(0, 3))); |
| 72 | + EXPECT_NO_THROW(system_mesh.get_physical_device_id(MeshCoordinate(1, 2))); |
| 73 | + EXPECT_NO_THROW(system_mesh.get_physical_device_id(MeshCoordinate(1, 3))); |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +} // namespace tt::tt_metal::distributed |
0 commit comments