Skip to content

Commit

Permalink
Implement CoreCoord tensix translation
Browse files Browse the repository at this point in the history
  • Loading branch information
pjanevskiTT committed Nov 19, 2024
1 parent 90db4d1 commit 52c3fc2
Show file tree
Hide file tree
Showing 20 changed files with 348 additions and 497 deletions.
1 change: 1 addition & 0 deletions device/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ set(UMD_DEVICE_SRCS
coordinate_manager.cpp
blackhole/blackhole_coordinate_manager.cpp
wormhole/wormhole_coordinate_manager.cpp
grayskull/grayskull_coordinate_manager.cpp
pcie/pci_device.cpp
hugepage.cpp
)
Expand Down
14 changes: 7 additions & 7 deletions device/blackhole/blackhole_coordinate_manager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: (c) 2023 Tenstorrent Inc.
* SPDX-FileCopyrightText: (c) 2024 Tenstorrent Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -18,12 +18,12 @@ std::set<std::size_t> BlackholeCoordinateManager::get_x_coordinates_to_harvest(s
return x_to_harvest;
}

tt_translated_coords BlackholeCoordinateManager::to_translated_coords(tt_logical_coords logical_coords) {
tt_virtual_coords virtual_coords = to_virtual_coords(logical_coords);
return tt_translated_coords(virtual_coords.x, virtual_coords.y);
CoreCoord BlackholeCoordinateManager::translated_to_logical_tensix(const CoreCoord core_coord) {
const CoreCoord virtual_coord = CoreCoord(core_coord.x, core_coord.y, CoreType::TENSIX, CoordSystem::VIRTUAL);
return CoordinateManager::to_logical(virtual_coord);
}

tt_logical_coords BlackholeCoordinateManager::to_logical_coords(tt_translated_coords translated_coords) {
tt_virtual_coords virtual_coords = tt_virtual_coords(translated_coords.x, translated_coords.y);
return CoordinateManager::to_logical_coords(virtual_coords);
CoreCoord BlackholeCoordinateManager::logical_to_translated_tensix(const CoreCoord core_coord) {
const CoreCoord virtual_coord = CoordinateManager::to_virtual(core_coord);
return CoreCoord(virtual_coord.x, virtual_coord.y, CoreType::TENSIX, CoordSystem::TRANSLATED);
}
9 changes: 4 additions & 5 deletions device/blackhole/blackhole_coordinate_manager.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: (c) 2023 Tenstorrent Inc.
* SPDX-FileCopyrightText: (c) 2024 Tenstorrent Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -14,10 +14,9 @@ class BlackholeCoordinateManager : public CoordinateManager {
BlackholeCoordinateManager(const tt_xy_pair& worker_grid_size, const std::vector<tt_xy_pair>& workers, std::size_t harvesting_mask)
: CoordinateManager(worker_grid_size, workers, harvesting_mask) {}

tt_translated_coords to_translated_coords(tt_logical_coords logical_coords) override;
protected:
CoreCoord translated_to_logical_tensix(const CoreCoord core_coord) override;
CoreCoord logical_to_translated_tensix(const CoreCoord core_coord) override;

tt_logical_coords to_logical_coords(tt_translated_coords translated_coords) override;

protected:
std::set<std::size_t> get_x_coordinates_to_harvest(std::size_t harvesting_mask) override;
};
13 changes: 0 additions & 13 deletions device/cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2689,17 +2689,4 @@ tt_version Cluster::get_ethernet_fw_version() const {
return eth_fw_version;
}

// v1 functions
void Cluster::write_to_device(const void *mem_ptr, uint32_t size_in_bytes, chip_id_t chip, CoreCoord_V1 core_coord, uint64_t addr, const std::string& tlb_to_use) {
CoreCoord_V1 physical_core_coord = coordinate_manager->to_physical(core_coord);


}

void Cluster::read_from_device(void* mem_ptr, chip_id_t chip, CoreCoord_V1 core_coord, uint64_t addr, uint32_t size, const std::string& fallback_tlb) {
CoreCoord_V1 physical_core_coord = coordinate_manager->to_physical(core_coord);


}

}
4 changes: 2 additions & 2 deletions device/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,8 @@ class Cluster: public tt_device
PCIDevice *get_pci_device(int device_id) const;

// Core coordinates functions
virtual void write_to_device(const void *mem_ptr, uint32_t size_in_bytes, chip_id_t chip, CoreCoord_V1 core_coord, uint64_t addr);
virtual void read_from_device(void* mem_ptr, uint32_t size_in_bytes, chip_id_t chip, CoreCoord_V1 core_coord, uint64_t addr);
// virtual void write_to_device(const void *mem_ptr, uint32_t size_in_bytes, chip_id_t chip, CoreCoord core_coord, uint64_t addr);
// virtual void read_from_device(void* mem_ptr, uint32_t size_in_bytes, chip_id_t chip, CoreCoord core_coord, uint64_t addr);

// Destructor
virtual ~Cluster ();
Expand Down
141 changes: 105 additions & 36 deletions device/coordinate_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,59 +5,118 @@
*/
#include "device/coordinate_manager.h"
#include <memory>
#include <stdexcept>
#include "coordinate_manager.h"
#include "grayskull/grayskull_coordinate_manager.h"
#include "tt_core_coordinates.h"

tt_physical_coords CoordinateManager::to_physical_coords(tt_logical_coords logical_coords) {
return tt_physical_coords(logical_x_to_physical_x[logical_coords.x], logical_y_to_physical_y[logical_coords.y]);
}

// TODO(pjanevski): this is different for Wormhole and Blackhole.
// investigate and implement
tt_translated_coords CoordinateManager::to_translated_coords(tt_logical_coords logical_coords) {
tt_physical_coords physical_coords = to_physical_coords(logical_coords);
return tt_translated_coords(physical_coords.x, physical_coords.y);
}

tt_virtual_coords CoordinateManager::to_virtual_coords(tt_logical_coords logical_coords) {
return tt_virtual_coords(logical_x_to_virtual_x[logical_coords.x], logical_y_to_virtual_y[logical_coords.y]);
}

tt_logical_coords CoordinateManager::to_logical_coords(tt_physical_coords physical_coords) {
return tt_logical_coords(physical_x_to_logical_x[physical_coords.x], physical_y_to_logical_y[physical_coords.y]);
}

tt_virtual_coords CoordinateManager::to_virtual_coords(tt_physical_coords physical_coords) {
return to_virtual_coords(to_logical_coords(physical_coords));
CoreCoord CoordinateManager::to_tensix_physical(const CoreCoord core_coord) {
switch (core_coord.coord_system) {
case CoordSystem::LOGICAL:
return CoreCoord{logical_x_to_physical_x[core_coord.x], logical_y_to_physical_y[core_coord.y], CoreType::TENSIX, CoordSystem::PHYSICAL};
case CoordSystem::PHYSICAL:
return core_coord;
case CoordSystem::VIRTUAL:
return CoreCoord{logical_x_to_physical_x[virtual_x_to_logical_x[core_coord.x]], logical_y_to_physical_y[virtual_y_to_logical_y[core_coord.y]], CoreType::TENSIX, CoordSystem::PHYSICAL};
case CoordSystem::TRANSLATED:
return to_tensix_physical(translated_to_logical_tensix(core_coord));
}
}

tt_translated_coords CoordinateManager::to_translated_coords(tt_physical_coords physical_coords) {
return to_translated_coords(to_logical_coords(physical_coords));
CoreCoord CoordinateManager::to_tensix_virtual(const CoreCoord core_coord) {
switch (core_coord.coord_system) {
case CoordSystem::LOGICAL:
return CoreCoord{logical_x_to_virtual_x[core_coord.x], logical_y_to_virtual_y[core_coord.y], CoreType::TENSIX, CoordSystem::VIRTUAL};
case CoordSystem::PHYSICAL:
return CoreCoord{virtual_x_to_logical_x[core_coord.x], virtual_y_to_logical_y[core_coord.y], CoreType::TENSIX, CoordSystem::VIRTUAL};
case CoordSystem::VIRTUAL:
return core_coord;
case CoordSystem::TRANSLATED:
return to_tensix_virtual(to_tensix_logical(core_coord));
}
}

tt_logical_coords CoordinateManager::to_logical_coords(tt_virtual_coords virtual_coords) {
return tt_logical_coords(virtual_x_to_logical_x[virtual_coords.x], virtual_y_to_logical_y[virtual_coords.y]);
CoreCoord CoordinateManager::to_tensix_logical(const CoreCoord core_coord) {
switch (core_coord.coord_system) {
case CoordSystem::LOGICAL:
return core_coord;
case CoordSystem::PHYSICAL:
return CoreCoord{physical_x_to_logical_x[core_coord.x], physical_y_to_logical_y[core_coord.y], CoreType::TENSIX, CoordSystem::LOGICAL};
case CoordSystem::VIRTUAL:
return CoreCoord{virtual_x_to_logical_x[core_coord.x], virtual_y_to_logical_y[core_coord.y], CoreType::TENSIX, CoordSystem::LOGICAL};
case CoordSystem::TRANSLATED:
return translated_to_logical_tensix(core_coord);
}
}

tt_physical_coords CoordinateManager::to_physical_coords(tt_virtual_coords virtual_coords) {
return to_physical_coords(to_logical_coords(virtual_coords));
CoreCoord CoordinateManager::to_tensix_translated(const CoreCoord core_coord) {
switch (core_coord.coord_system) {
case CoordSystem::LOGICAL:
return logical_to_translated_tensix(core_coord);
case CoordSystem::PHYSICAL:
return to_translated(to_tensix_logical(core_coord));
case CoordSystem::VIRTUAL:
return to_translated(to_tensix_logical(core_coord));
case CoordSystem::TRANSLATED:
return core_coord;
}
}

tt_translated_coords CoordinateManager::to_translated_coords(tt_virtual_coords virtual_coords) {
return to_translated_coords(to_logical_coords(virtual_coords));
CoreCoord CoordinateManager::to_physical(const CoreCoord core_coord) {
switch (core_coord.core_type) {
case CoreType::TENSIX:
return to_tensix_physical(core_coord);
case CoreType::DRAM:
case CoreType::ARC:
case CoreType::ACTIVE_ETH:
case CoreType::IDLE_ETH:
case CoreType::PCIE:
case CoreType::ROUTER_ONLY:
throw std::runtime_error("Core type is not supported for conversion to physical coordinates");
}
throw std::runtime_error("Invalid coordinate system");
}

tt_logical_coords CoordinateManager::to_logical_coords(tt_translated_coords translated_coords) {
tt_physical_coords physical_coords = tt_physical_coords(translated_coords.x, translated_coords.y);
return to_logical_coords(physical_coords);
CoreCoord CoordinateManager::to_virtual(const CoreCoord core_coord) {
switch (core_coord.core_type) {
case CoreType::TENSIX:
return to_tensix_virtual(core_coord);
case CoreType::DRAM:
case CoreType::ARC:
case CoreType::ACTIVE_ETH:
case CoreType::IDLE_ETH:
case CoreType::PCIE:
case CoreType::ROUTER_ONLY:
throw std::runtime_error("Core type is not supported for conversion to virtual coordinates");
}
}

tt_physical_coords CoordinateManager::to_physical_coords(tt_translated_coords translated_coords) {
return to_physical_coords(to_logical_coords(translated_coords));
CoreCoord CoordinateManager::to_logical(const CoreCoord core_coord) {
switch (core_coord.core_type) {
case CoreType::TENSIX:
return to_tensix_logical(core_coord);
case CoreType::DRAM:
case CoreType::ARC:
case CoreType::ACTIVE_ETH:
case CoreType::IDLE_ETH:
case CoreType::PCIE:
case CoreType::ROUTER_ONLY:
throw std::runtime_error("Core type is not supported for conversion to logical coordinates");
}
}

tt_virtual_coords CoordinateManager::to_virtual_coords(tt_translated_coords translated_coords) {
return to_virtual_coords(to_logical_coords(translated_coords));
CoreCoord CoordinateManager::to_translated(const CoreCoord core_coord) {
switch (core_coord.core_type) {
case CoreType::TENSIX:
return to_tensix_translated(core_coord);
case CoreType::DRAM:
case CoreType::ARC:
case CoreType::ACTIVE_ETH:
case CoreType::IDLE_ETH:
case CoreType::PCIE:
case CoreType::ROUTER_ONLY:
throw std::runtime_error("Core type is not supported for conversion to translated coordinates");
}
}

void CoordinateManager::clear_harvesting_structures() {
Expand Down Expand Up @@ -190,3 +249,13 @@ std::unique_ptr<CoordinateManager> CoordinateManager::get_coordinate_manager(

throw std::runtime_error("Invalid architecture for creating coordinate manager");
}

// TODO(pjanevski): these functions should be deleted once
// deep copy of CoordinateManager for SocDescriptor is implemented
CoreCoord CoordinateManager::translated_to_logical_tensix(const CoreCoord core_coord) {
return core_coord;
}

CoreCoord CoordinateManager::logical_to_translated_tensix(const CoreCoord core_coord) {
return core_coord;
}
40 changes: 13 additions & 27 deletions device/coordinate_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,6 @@ class CoordinateManager {

virtual void perform_harvesting(std::size_t harvesting_mask);

virtual tt_physical_coords to_physical_coords(tt_logical_coords logical_coords);
virtual tt_translated_coords to_translated_coords(tt_logical_coords logical_coords);
virtual tt_virtual_coords to_virtual_coords(tt_logical_coords logical_coords);

virtual tt_logical_coords to_logical_coords(tt_physical_coords physical_coords);
virtual tt_virtual_coords to_virtual_coords(tt_physical_coords physical_coords);
virtual tt_translated_coords to_translated_coords(tt_physical_coords physical_coords);

virtual tt_logical_coords to_logical_coords(tt_virtual_coords virtual_coords);
virtual tt_physical_coords to_physical_coords(tt_virtual_coords virtual_coords);
virtual tt_translated_coords to_translated_coords(tt_virtual_coords virtual_coords);

virtual tt_logical_coords to_logical_coords(tt_translated_coords translated_coords);
virtual tt_physical_coords to_physical_coords(tt_translated_coords translated_coords);
virtual tt_virtual_coords to_virtual_coords(tt_translated_coords translated_coords);

static std::unique_ptr<CoordinateManager> get_coordinate_manager(
tt::ARCH arch,
const tt_xy_pair& worker_grid_size,
Expand All @@ -46,14 +30,10 @@ class CoordinateManager {

CoordinateManager(CoordinateManager& other) = default;

// v1 functions
// We need only one function per coordinate system for all core types.
virtual CoreCoord_V1 to_physical(const CoreCoord_V1 core_coords);

// v2 functions
// We need as many functions as there are core types for each coordinate system.
virtual TensixCoreCoord_V2 to_physical(const TensixCoreCoord_V2 tensix_coords);
virtual DramCoreCoord_V2 to_physical(const DramCoreCoord_V2 dram_coords);
CoreCoord to_physical(const CoreCoord core_coord);
CoreCoord to_logical(const CoreCoord core_coord);
CoreCoord to_virtual(const CoreCoord core_coord);
CoreCoord to_translated(const CoreCoord core_coord);

virtual ~CoordinateManager() = default;

Expand All @@ -68,9 +48,15 @@ class CoordinateManager {
const std::set<size_t>& physical_x_unharvested, const std::set<size_t>& physical_y_unharvested);
virtual void fill_logical_to_virtual_mapping(const std::set<size_t>& physical_x_unharvested, const std::set<size_t>& physical_y_unharvested);

// Helper functions for V1.
virtual CoreCoord_V1 to_tensix_physical(const CoreCoord_V1 core_coords);
virtual CoreCoord_V1 to_dram_physical(const CoreCoord_V1 core_coords);
CoreCoord to_tensix_physical(const CoreCoord core_coord);
CoreCoord to_tensix_logical(const CoreCoord core_coord);
CoreCoord to_tensix_virtual(const CoreCoord core_coord);
CoreCoord to_tensix_translated(const CoreCoord core_coord);

// TODO(pjanevski): this should be abstract functions
// Making deep copy of SocDescriptor is harded if these are abstract
virtual CoreCoord translated_to_logical_tensix(const CoreCoord core_coord);
virtual CoreCoord logical_to_translated_tensix(const CoreCoord core_coord);

std::map<std::size_t, std::size_t> physical_y_to_logical_y;
std::map<std::size_t, std::size_t> physical_x_to_logical_x;
Expand Down
16 changes: 16 additions & 0 deletions device/grayskull/grayskull_coordinate_manager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* SPDX-FileCopyrightText: (c) 2024 Tenstorrent Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "grayskull_coordinate_manager.h"

CoreCoord GrayskullCoordinateManager::translated_to_logical_tensix(const CoreCoord core_coord) {
const CoreCoord physical_coord = CoreCoord(core_coord.x, core_coord.y, CoreType::TENSIX, CoordSystem::PHYSICAL);
return CoordinateManager::to_logical(physical_coord);
}

CoreCoord GrayskullCoordinateManager::logical_to_translated_tensix(const CoreCoord core_coord) {
const CoreCoord physical_coord = CoordinateManager::to_physical(core_coord);
return CoreCoord(physical_coord.x, physical_coord.y, CoreType::TENSIX, CoordSystem::TRANSLATED);
}
4 changes: 4 additions & 0 deletions device/grayskull/grayskull_coordinate_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ class GrayskullCoordinateManager : public CoordinateManager {
public:
GrayskullCoordinateManager(const tt_xy_pair& worker_grid_size, const std::vector<tt_xy_pair>& workers, std::size_t harvesting_mask)
: CoordinateManager(worker_grid_size, workers, harvesting_mask) {}

protected:
CoreCoord translated_to_logical_tensix(const CoreCoord core_coord) override;
CoreCoord logical_to_translated_tensix(const CoreCoord core_coord) override;
};
Loading

0 comments on commit 52c3fc2

Please sign in to comment.