Skip to content

Commit

Permalink
Core coordinates prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
pjanevskiTT committed Nov 5, 2024
1 parent d9f0d6e commit b160428
Show file tree
Hide file tree
Showing 11 changed files with 392 additions and 18 deletions.
2 changes: 1 addition & 1 deletion device/coordinate_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,4 @@ std::unique_ptr<CoordinateManager> CoordinateManager::get_coordinate_manager(
}

throw std::runtime_error("Invalid architecture for creating coordinate manager");
}
}
16 changes: 16 additions & 0 deletions device/coordinate_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "device/tt_xy_pair.h"
#include "device/tt_arch_types.h"
#include "tt_core_coordinates.h"

class CoordinateManager {

Expand Down Expand Up @@ -45,6 +46,17 @@ 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);

virtual ~CoordinateManager() = default;

protected:
virtual void clear_harvesting_structures();

Expand All @@ -55,6 +67,10 @@ class CoordinateManager {
const std::set<size_t>& x_to_harvest, const std::set<size_t>& y_to_harvest,
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);

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
57 changes: 57 additions & 0 deletions device/tt_core_coordinates.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* SPDX-FileCopyrightText: (c) 2024 Tenstorrent Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include "device/tt_xy_pair.h"


/*
* CoordSystem is an enum class that represents all types of coordinate
* systems that can be used to represent a core's location.
* This is used both for V1 and V2.
*/
enum class CoordSystem {
LOGICAL,
PHYSICAL,
VIRTUAL,
TRANSLATED,
};

// ************************************************************************************************
// V1

/*
* CoreType is an enum class that represents all types of cores
* present on the Tenstorrent chip.
*/
enum class CoreType {
ARC,
DRAM,
ETH,
PCIE,
TENSIX,
ROUTER_ONLY,
};

struct CoreCoord_V1 : public tt_xy_pair {
CoreType core_type;
CoordSystem coord_system;
};

// ************************************************************************************************
// V2
struct CoreCoord_V2 : public tt_xy_pair {
CoordSystem coord_system;
};

struct TensixCoreCoord_V2 : public CoreCoord_V2 {

};

struct DramCoreCoord_V2 : public CoreCoord_V2 {

};
23 changes: 21 additions & 2 deletions device/tt_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
#include <vector>
#include <set>

#include "tt_core_coordinates.h"
#include "tt_soc_descriptor.h"
#include "tt_xy_pair.h"
#include "tt_silicon_driver_common.hpp"
#include "device/tt_cluster_descriptor_types.h"
#include "device/tlb.h"
#include "device/tt_io.hpp"
#include "device/tt_core_coordinates.h"

#include "pcie/pci_device.hpp"
#include "fmt/core.h"
Expand Down Expand Up @@ -606,7 +608,7 @@ class tt_device
*/
class tt_SiliconDevice: public tt_device
{
public:
public:
// Constructor
/**
* Silicon Driver constructor.
Expand Down Expand Up @@ -707,10 +709,27 @@ class tt_SiliconDevice: public tt_device
// TODO: This should be accessible through public API, probably to be moved to tt_device.
PCIDevice *get_pci_device(int device_id) const;

// Core coordinates functions

// v1 functions
// We need only one function for all core types. For example we would have only one write_to_device.
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);

// v2 functions

// We need one function for each core type. We would have write_to_device for tensix, dram, pcie, arc, eth...
// tensix core coord
virtual void write_to_device(const void *mem_ptr, uint32_t size_in_bytes, chip_id_t chip, TensixCoreCoord_V2 core_coord, uint64_t addr);
virtual void read_from_device(void* mem_ptr, uint32_t size_in_bytes, chip_id_t chip, TensixCoreCoord_V2 core_coord, uint64_t addr);
// dram core coord
virtual void write_to_device(const void *mem_ptr, uint32_t size_in_bytes, chip_id_t chip, DramCoreCoord_V2 core_coord, uint64_t addr);
virtual void read_from_device(void* mem_ptr, uint32_t size_in_bytes, chip_id_t chip, DramCoreCoord_V2 core_coord, uint64_t addr, uint32_t size);

// Destructor
virtual ~tt_SiliconDevice ();

private:
private:
// Helper functions
// Startup + teardown
void create_device(const std::unordered_set<chip_id_t> &target_mmio_device_ids, const uint32_t &num_host_mem_ch_per_mmio_device, const bool skip_driver_allocs, const bool clean_system_resources);
Expand Down
63 changes: 63 additions & 0 deletions device/tt_silicon_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include <dirent.h>
#include <errno.h>

#include "tt_core_coordinates.h"
#include "tt_soc_descriptor.h"
#include "yaml-cpp/yaml.h"
#include "common/logger.hpp"

Expand Down Expand Up @@ -2957,3 +2959,64 @@ tt_version tt_SiliconDevice::get_ethernet_fw_version() const {
log_assert(eth_fw_version.major != 0xffff and eth_fw_version.minor != 0xff and eth_fw_version.patch != 0xff, "Device must be started before querying Ethernet FW version.");
return eth_fw_version;
}

// v1 functions
void tt_SiliconDevice::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 tt_SiliconDevice::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);


}

// v2 functions

// tensix core coord
void tt_SiliconDevice::write_to_device(const void *mem_ptr, uint32_t size_in_bytes, chip_id_t chip, TensixCoreCoord_V2 core_coord, uint64_t addr) {
TensixCoreCoord_V2 physical_tensix_core_coords = coordinate_manager->to_physical(core_coord);

// This shows how API is the same for all coordinate systems and all core types. Client can use any coordinate system
// physical_tensix_core_coords has physical (NOC0) coordiantes in x and y fields
// from here we can use already existing infrastructure to write to device
// I won't implement that fully here since it requires slight modifications, but for example we can just call
//
// write_to_device(mem_ptr, size_in_bytes, tt_cxy_pair(chip, physical_tensix_core_coords.x, physical_tensix_core_coords.y), addr);
}

void tt_SiliconDevice::read_from_device(void* mem_ptr, uint32_t size_in_bytes, chip_id_t chip, TensixCoreCoord_V2 core_coord, uint64_t addr, uint32_t size) {
TensixCoreCoord_V2 physical_tensix_core_coords = coordinate_manager->to_physical(core_coord);

// This shows how API is the same for all coordinate systems and all core types. Client can use any coordinate system
// physical_tensix_core_coords has physical (NOC0) coordiantes in x and y fields
// from here we can use already existing infrastructure to read from device
// I won't implement that fully here since it requires slight modifications, but for example we can just call
//
// read_from_device(mem_ptr, size_in_bytes, tt_cxy_pair(chip, physical_tensix_core_coords.x, physical_tensix_core_coords.y), addr);
}

// dram core coord
void tt_SiliconDevice::write_to_device(const void *mem_ptr, uint32_t size_in_bytes, chip_id_t chip, DramCoreCoord_V2 core_coord, uint64_t addr) {
DramCoreCoord_V2 physical_dram_core_coords = coordinate_manager->to_physical(core_coord);

// This shows how API for one core type is the same for all coordinate systems. Client can use any coordinate system
// physical_tensix_core_coords has physical (NOC0) coordiantes in x and y fields
// from here we can use already existing infrastructure to write to device
// I won't implement that fully here since it requires slight modifications, but for example we can just call
//
// write_to_device(mem_ptr, size_in_bytes, tt_cxy_pair(chip, physical_tensix_core_coords.x, physical_tensix_core_coords.y), addr);
}

void tt_SiliconDevice::read_from_device(void* mem_ptr, uint32_t size_in_bytes, chip_id_t chip, DramCoreCoord_V2 core_coord, uint64_t addr) {
DramCoreCoord_V2 physical_dram_core_coords = coordinate_manager->to_physical(core_coord);

// This shows how API for one core type is the same for all coordinate systems. Client can use any coordinate system
// physical_tensix_core_coords has physical (NOC0) coordiantes in x and y fields
// from here we can use already existing infrastructure to read from device
// I won't implement that fully here since it requires slight modifications, but for example we can just call
//
// read_from_device(mem_ptr, size_in_bytes, tt_cxy_pair(chip, physical_tensix_core_coords.x, physical_tensix_core_coords.y), addr);
}
2 changes: 1 addition & 1 deletion device/tt_soc_descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void tt_SocDescriptor::load_core_descriptors_from_device_descriptor(YAML::Node &
for (const auto &core_string : worker_cores) {
CoreDescriptor core_descriptor;
core_descriptor.coord = format_node(core_string);
core_descriptor.type = CoreType::WORKER;
core_descriptor.type = CoreType::TENSIX;
core_descriptor.l1_size = worker_l1_size;
cores.insert({core_descriptor.coord, core_descriptor});
workers.push_back(core_descriptor.coord);
Expand Down
14 changes: 1 addition & 13 deletions device/tt_soc_descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "device/tt_arch_types.h"

#include "device/coordinate_manager.h"
#include "device/tt_core_coordinates.h"

#include "fmt/core.h"

Expand Down Expand Up @@ -66,19 +67,6 @@ std::string format_node(tt_xy_pair xy);

tt_xy_pair format_node(std::string str);

//! SocCore type enumerations
/*! Superset for all chip generations */
enum class CoreType {
ARC,
DRAM,
ETH,
PCIE,
WORKER,
HARVESTED,
ROUTER_ONLY,

};

//! SocNodeDescriptor contains information regarding the Node/Core
/*!
Should only contain relevant configuration for SOC
Expand Down
103 changes: 102 additions & 1 deletion device/wormhole/wormhole_coordinate_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,105 @@ tt_translated_coords WormholeCoordinateManager::to_translated_coords(tt_logical_

tt_logical_coords WormholeCoordinateManager::to_logical_coords(tt_translated_coords translated_coords) {
return tt_logical_coords(translated_coords.x - translated_coordinate_start_x, translated_coords.y - translated_coordinate_start_y);
}
}

// General ways of how we translate coordinates is not a key part of this PR.
// Main things to look at here is the way we are using the functions to translate coordinates
// To understand how the translations works for V1 and V2, based on struct types.

// v1 functions
CoreCoord_V1 WormholeCoordinateManager::to_tensix_physical(CoreCoord_V1 core_coords) {
CoreCoord_V1 physical_tensix_coords;
physical_tensix_coords.coord_system = CoordSystem::PHYSICAL;
physical_tensix_coords.core_type = CoreType::TENSIX;
switch (core_coords.coord_system) {
case CoordSystem::LOGICAL:
physical_tensix_coords.x = logical_x_to_physical_x[core_coords.x];
physical_tensix_coords.y = logical_y_to_physical_y[core_coords.y];
case CoordSystem::PHYSICAL:
return core_coords;
case CoordSystem::VIRTUAL:
physical_tensix_coords.x = logical_x_to_physical_x[virtual_x_to_logical_x[core_coords.x]];
physical_tensix_coords.y = logical_y_to_physical_y[virtual_y_to_logical_y[core_coords.y]];
case CoordSystem::TRANSLATED:
physical_tensix_coords.x = logical_x_to_physical_x[core_coords.x - translated_coordinate_start_x];
physical_tensix_coords.y = logical_y_to_physical_y[core_coords.y - translated_coordinate_start_y];
}

return physical_tensix_coords;
}

CoreCoord_V1 WormholeCoordinateManager::to_dram_physical(CoreCoord_V1 core_coords) {
CoreCoord_V1 physical_dram_coords;
physical_dram_coords.coord_system = CoordSystem::PHYSICAL;
physical_dram_coords.core_type = CoreType::DRAM;
switch(core_coords.coord_system) {
case CoordSystem::LOGICAL:

case CoordSystem::PHYSICAL:
return core_coords;
case CoordSystem::VIRTUAL:
physical_dram_coords.x = core_coords.x;
physical_dram_coords.y = core_coords.y;
case CoordSystem::TRANSLATED:
physical_dram_coords.x = core_coords.x;
physical_dram_coords.y = core_coords.y;
}

return physical_dram_coords;
}

CoreCoord_V1 WormholeCoordinateManager::to_physical(CoreCoord_V1 core_coords) {
switch (core_coords.core_type) {
case CoreType::TENSIX:
return to_tensix_physical(core_coords);
case CoreType::DRAM:
return to_dram_physical(core_coords);
}

throw std::runtime_error("Invalid core type");
}

// v2 functions
TensixCoreCoord_V2 WormholeCoordinateManager::to_physical(TensixCoreCoord_V2 tensix_coords) {
TensixCoreCoord_V2 physical_tensix_coords;
physical_tensix_coords.coord_system = CoordSystem::PHYSICAL;
switch (tensix_coords.coord_system) {
case CoordSystem::LOGICAL:
physical_tensix_coords.x = logical_x_to_physical_x[tensix_coords.x];
physical_tensix_coords.y = logical_y_to_physical_y[tensix_coords.y];
case CoordSystem::PHYSICAL:
return tensix_coords;
case CoordSystem::VIRTUAL:
physical_tensix_coords.x = logical_x_to_physical_x[virtual_x_to_logical_x[tensix_coords.x]];
physical_tensix_coords.y = logical_y_to_physical_y[virtual_y_to_logical_y[tensix_coords.y]];
case CoordSystem::TRANSLATED:
physical_tensix_coords.x = logical_x_to_physical_x[tensix_coords.x - translated_coordinate_start_x];
physical_tensix_coords.y = logical_y_to_physical_y[tensix_coords.y - translated_coordinate_start_y];
}

return physical_tensix_coords;
}

DramCoreCoord_V2 WormholeCoordinateManager::to_physical(DramCoreCoord_V2 dram_coords) {
DramCoreCoord_V2 physical_dram_coords;
physical_dram_coords.coord_system = CoordSystem::PHYSICAL;
switch(dram_coords.coord_system) {
case CoordSystem::LOGICAL:
// TODO implement logical to physical translation for dram coordinates
// but that for review it is not important how that logic is going to look like
return dram_coords;
case CoordSystem::PHYSICAL:
return dram_coords;
case CoordSystem::VIRTUAL:
// virtual coords for DRAM same as physical for Wormhole.
physical_dram_coords.x = dram_coords.x;
physical_dram_coords.y = dram_coords.y;
case CoordSystem::TRANSLATED:
// translated coords for DRAM same as physical for Wormhole.
physical_dram_coords.x = dram_coords.x;
physical_dram_coords.y = dram_coords.y;
}

return physical_dram_coords;
}
10 changes: 10 additions & 0 deletions device/wormhole/wormhole_coordinate_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,19 @@ class WormholeCoordinateManager : public CoordinateManager {

tt_logical_coords to_logical_coords(tt_translated_coords translated_coords) override;

// v1 functions
CoreCoord_V1 to_physical(CoreCoord_V1 core_coords) override;

// v2 functions
TensixCoreCoord_V2 to_physical(TensixCoreCoord_V2 tensix_coords) override;
DramCoreCoord_V2 to_physical(DramCoreCoord_V2 dram_coords) override;

protected:
std::set<std::size_t> get_y_coordinates_to_harvest(std::size_t harvesting_mask) override;

CoreCoord_V1 to_tensix_physical(const CoreCoord_V1 core_coords) override;
CoreCoord_V1 to_dram_physical(const CoreCoord_V1 core_coords) override;

private:
static const std::size_t translated_coordinate_start_x = 18;
static const std::size_t translated_coordinate_start_y = 18;
Expand Down
Loading

0 comments on commit b160428

Please sign in to comment.