Skip to content

Commit

Permalink
Implement DRAM coordinate translation
Browse files Browse the repository at this point in the history
  • Loading branch information
pjanevskiTT committed Nov 21, 2024
1 parent 52c3fc2 commit 60d961a
Show file tree
Hide file tree
Showing 16 changed files with 396 additions and 89 deletions.
23 changes: 23 additions & 0 deletions device/blackhole/blackhole_coordinate_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,26 @@ CoreCoord BlackholeCoordinateManager::logical_to_translated_tensix(const CoreCoo
const CoreCoord virtual_coord = CoordinateManager::to_virtual(core_coord);
return CoreCoord(virtual_coord.x, virtual_coord.y, CoreType::TENSIX, CoordSystem::TRANSLATED);
}

void BlackholeCoordinateManager::dram_harvesting(const std::size_t dram_harvesting_mask) {

std::size_t get_num_harvested_x = __builtin_popcount(dram_harvesting_mask);

for (std::size_t x = 0; x < dram_grid_size.x - get_num_harvested_x; x++) {
for (std::size_t y = 0; y < dram_grid_size.y; y++) {
CoordinateManager::dram_logical_to_virtual[{x, y}] = CoordinateManager::dram_cores[x * dram_grid_size.y + y];
CoordinateManager::dram_virtual_to_logical[dram_cores[x * dram_grid_size.y + y]] = {x, y};
}
}

std::size_t logical_x = 0;
for (std::size_t x = 0; x < dram_grid_size.x; x++) {
if (!(dram_harvesting_mask & (1 << x))) {
for (std::size_t y = 0; y < dram_grid_size.y; y++) {
CoordinateManager::dram_logical_to_physical[{logical_x , y}] = CoordinateManager::dram_cores[x * dram_grid_size.y + y];
CoordinateManager::dram_physical_to_logical[dram_cores[x * dram_grid_size.y + y]] = {logical_x, y};
}
logical_x++;
}
}
}
8 changes: 6 additions & 2 deletions device/blackhole/blackhole_coordinate_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
#pragma once

#include "device/coordinate_manager.h"
#include "device/blackhole/blackhole_implementation.h"

class BlackholeCoordinateManager : public CoordinateManager {

public:
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) {}
BlackholeCoordinateManager(const tt_xy_pair& worker_grid_size, const std::vector<tt_xy_pair>& workers, const std::size_t tensix_harvesting_mask, const std::size_t dram_harvesting_mask)
: CoordinateManager(worker_grid_size, workers, tensix_harvesting_mask,
{tt::umd::blackhole::NUM_DRAM_BANKS, tt::umd::blackhole::NUM_NOC_PORTS_PER_DRAM_BANK}, tt::umd::blackhole::DRAM_CORES, dram_harvesting_mask) {}

void dram_harvesting(const std::size_t dram_harvesting_mask) override;

protected:
CoreCoord translated_to_logical_tensix(const CoreCoord core_coord) override;
Expand Down
16 changes: 16 additions & 0 deletions device/blackhole/blackhole_implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "device/architecture_implementation.h"
#include "device/tlb.h"
#include "device/tt_xy_pair.h"
#include <stdexcept>

namespace tt::umd {
Expand Down Expand Up @@ -58,6 +59,21 @@ enum class arc_message_type {
};

// DEVICE_DATA
const std::size_t NUM_DRAM_BANKS = 8;
const std::size_t NUM_NOC_PORTS_PER_DRAM_BANK = 3;

static const std::vector<tt_xy_pair> DRAM_CORES = {
{
{0, 0}, {0, 1}, {0, 11},
{0, 2}, {0, 10}, {0, 3},
{0, 9}, {0, 4}, {0, 8},
{0, 5}, {0, 7}, {0, 6},
{9, 0}, {9, 1}, {9, 11},
{9, 2}, {9, 10}, {9, 3},
{9, 9}, {9, 4}, {9, 8},
{9, 5}, {9, 7}, {9, 6}
}};

static constexpr std::array<xy_pair, 24> DRAM_LOCATIONS = {
{{0, 0},
{0, 1},
Expand Down
99 changes: 91 additions & 8 deletions device/coordinate_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#include <stdexcept>
#include "coordinate_manager.h"
#include "grayskull/grayskull_coordinate_manager.h"
#include "grayskull/grayskull_implementation.h"
#include "tt_core_coordinates.h"
#include "device/tt_xy_pair.h"

CoreCoord CoordinateManager::to_tensix_physical(const CoreCoord core_coord) {
switch (core_coord.coord_system) {
Expand Down Expand Up @@ -62,11 +64,68 @@ CoreCoord CoordinateManager::to_tensix_translated(const CoreCoord core_coord) {
}
}

CoreCoord CoordinateManager::to_dram_physical(const CoreCoord core_coord) {
switch (core_coord.coord_system) {
case CoordSystem::LOGICAL: {
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:
case CoordSystem::TRANSLATED: {
CoreCoord physical_coord = core_coord;
physical_coord.coord_system = CoordSystem::PHYSICAL;
return physical_coord;
}
}
}

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::TRANSLATED:
// TODO(pjanevski): implement this
return 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::TRANSLATED:
CoreCoord physical_coord = core_coord;
physical_coord.coord_system = CoordSystem::VIRTUAL;
return physical_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::TRANSLATED:
CoreCoord physical_coord = core_coord;
physical_coord.coord_system = CoordSystem::TRANSLATED;
return physical_coord;
}
}

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:
return to_dram_physical(core_coord);
case CoreType::ARC:
case CoreType::ACTIVE_ETH:
case CoreType::IDLE_ETH:
Expand All @@ -82,6 +141,7 @@ CoreCoord CoordinateManager::to_virtual(const CoreCoord core_coord) {
case CoreType::TENSIX:
return to_tensix_virtual(core_coord);
case CoreType::DRAM:
return to_dram_virtual(core_coord);
case CoreType::ARC:
case CoreType::ACTIVE_ETH:
case CoreType::IDLE_ETH:
Expand All @@ -96,6 +156,7 @@ CoreCoord CoordinateManager::to_logical(const CoreCoord core_coord) {
case CoreType::TENSIX:
return to_tensix_logical(core_coord);
case CoreType::DRAM:
return to_dram_logical(core_coord);
case CoreType::ARC:
case CoreType::ACTIVE_ETH:
case CoreType::IDLE_ETH:
Expand All @@ -110,6 +171,7 @@ CoreCoord CoordinateManager::to_translated(const CoreCoord core_coord) {
case CoreType::TENSIX:
return to_tensix_translated(core_coord);
case CoreType::DRAM:
return to_dram_translated(core_coord);
case CoreType::ARC:
case CoreType::ACTIVE_ETH:
case CoreType::IDLE_ETH:
Expand All @@ -119,7 +181,7 @@ CoreCoord CoordinateManager::to_translated(const CoreCoord core_coord) {
}
}

void CoordinateManager::clear_harvesting_structures() {
void CoordinateManager::clear_tensix_harvesting_structures() {
logical_x_to_physical_x.clear();
logical_y_to_physical_y.clear();
logical_x_to_virtual_x.clear();
Expand All @@ -130,6 +192,13 @@ void CoordinateManager::clear_harvesting_structures() {
virtual_y_to_logical_y.clear();
}

void CoordinateManager::clear_dram_harvesting_structures() {
dram_logical_to_virtual.clear();
dram_logical_to_physical.clear();
dram_virtual_to_logical.clear();
dram_physical_to_logical.clear();
}

std::set<std::size_t> CoordinateManager::get_x_coordinates_to_harvest(std::size_t harvesting_mask) {
return {};
}
Expand All @@ -138,8 +207,8 @@ std::set<std::size_t> CoordinateManager::get_y_coordinates_to_harvest(std::size_
return {};
}

void CoordinateManager::perform_harvesting(std::size_t harvesting_mask) {
clear_harvesting_structures();
void CoordinateManager::tensix_harvesting(const std::size_t harvesting_mask) {
clear_tensix_harvesting_structures();

std::set<size_t> physical_x_unharvested;
std::set<size_t> physical_y_unharvested;
Expand Down Expand Up @@ -167,6 +236,19 @@ void CoordinateManager::perform_harvesting(std::size_t harvesting_mask) {
fill_logical_to_virtual_mapping(physical_x_unharvested, physical_y_unharvested);
}

void CoordinateManager::dram_harvesting(const std::size_t dram_harvesting_mask) {

for (std::size_t x = 0; x < dram_grid_size.x; x++) {
for (std::size_t y = 0; y < dram_grid_size.y; y++) {
dram_logical_to_virtual[{x, y}] = dram_cores[x * dram_grid_size.y + y];
dram_virtual_to_logical[dram_cores[x * dram_grid_size.y + y]] = {x, y};

dram_logical_to_physical[{x, y}] = dram_cores[x * dram_grid_size.y + y];
dram_physical_to_logical[dram_cores[x * dram_grid_size.y + y]] = {x, y};
}
}
}

void CoordinateManager::fill_logical_to_physical_mapping(
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) {
Expand Down Expand Up @@ -226,23 +308,24 @@ void CoordinateManager::fill_logical_to_virtual_mapping(const std::set<size_t>&
}
}

#include "device/blackhole/blackhole_coordinate_manager.h"
#include "device/grayskull/grayskull_coordinate_manager.h"
#include "device/wormhole/wormhole_coordinate_manager.h"
#include "device/blackhole/blackhole_coordinate_manager.h"

std::unique_ptr<CoordinateManager> CoordinateManager::get_coordinate_manager(
tt::ARCH arch,
const tt_xy_pair& worker_grid_size,
const std::vector<tt_xy_pair>& workers,
std::size_t harvesting_mask) {
const std::size_t tensix_harvesting_mask,
const std::size_t dram_harvesting_mask) {

switch (arch) {
case tt::ARCH::GRAYSKULL:
return std::make_unique<GrayskullCoordinateManager>(worker_grid_size, workers, harvesting_mask);
return std::make_unique<GrayskullCoordinateManager>(worker_grid_size, workers, tensix_harvesting_mask, dram_harvesting_mask);
case tt::ARCH::WORMHOLE_B0:
return std::make_unique<WormholeCoordinateManager>(worker_grid_size, workers, harvesting_mask);
return std::make_unique<WormholeCoordinateManager>(worker_grid_size, workers, tensix_harvesting_mask, dram_harvesting_mask);
case tt::ARCH::BLACKHOLE:
return std::make_unique<BlackholeCoordinateManager>(worker_grid_size, workers, harvesting_mask);
return std::make_unique<BlackholeCoordinateManager>(worker_grid_size, workers, tensix_harvesting_mask, dram_harvesting_mask);
case tt::ARCH::Invalid:
throw std::runtime_error("Invalid architecture for creating coordinate manager");
}
Expand Down
38 changes: 31 additions & 7 deletions device/coordinate_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,23 @@
class CoordinateManager {

public:
CoordinateManager(const tt_xy_pair& worker_grid_size, const std::vector<tt_xy_pair>& workers, std::size_t harvesting_mask)
: worker_grid_size(worker_grid_size), workers(workers), harvesting_mask(harvesting_mask) {}
CoordinateManager(
const tt_xy_pair& worker_grid_size, const std::vector<tt_xy_pair>& workers, const std::size_t tensix_harvesting_mask,
const tt_xy_pair& dram_grid_size, const std::vector<tt_xy_pair>& dram_cores, const std::size_t dram_harvesting_mask)
: worker_grid_size(worker_grid_size), workers(workers), tensix_harvesting_mask(tensix_harvesting_mask),
dram_grid_size(dram_grid_size), dram_cores(dram_cores), dram_harvesting_mask(dram_harvesting_mask)
{}

virtual void perform_harvesting(std::size_t harvesting_mask);
virtual void tensix_harvesting(const std::size_t harvesting_mask);

virtual void dram_harvesting(const std::size_t dram_harvesting_mask);

static std::unique_ptr<CoordinateManager> get_coordinate_manager(
tt::ARCH arch,
const tt_xy_pair& worker_grid_size,
const std::vector<tt_xy_pair>& workers,
std::size_t harvesting_mask);
const std::size_t tensix_harvesting_mask,
const std::size_t dram_harvesting_mask);

CoordinateManager(CoordinateManager& other) = default;

Expand All @@ -38,8 +45,9 @@ class CoordinateManager {
virtual ~CoordinateManager() = default;

protected:
virtual void clear_harvesting_structures();

void clear_tensix_harvesting_structures();
void clear_dram_harvesting_structures();

virtual std::set<std::size_t> get_x_coordinates_to_harvest(std::size_t harvesting_mask);
virtual std::set<std::size_t> get_y_coordinates_to_harvest(std::size_t harvesting_mask);

Expand All @@ -53,6 +61,11 @@ class CoordinateManager {
CoreCoord to_tensix_virtual(const CoreCoord core_coord);
CoreCoord to_tensix_translated(const CoreCoord core_coord);

CoreCoord to_dram_physical(const CoreCoord core_coord);
CoreCoord to_dram_logical(const CoreCoord core_coord);
CoreCoord to_dram_virtual(const CoreCoord core_coord);
CoreCoord to_dram_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);
Expand All @@ -70,7 +83,18 @@ class CoordinateManager {
std::map<std::size_t, std::size_t> virtual_y_to_logical_y;
std::map<std::size_t, std::size_t> virtual_x_to_logical_x;

std::map<tt_xy_pair, tt_xy_pair> dram_logical_to_virtual;
std::map<tt_xy_pair, tt_xy_pair> dram_logical_to_physical;

std::map<tt_xy_pair, tt_xy_pair> dram_virtual_to_logical;
std::map<tt_xy_pair, tt_xy_pair> dram_physical_to_logical;

const tt_xy_pair worker_grid_size;
const std::vector<tt_xy_pair>& workers;
const std::size_t harvesting_mask;
const std::size_t tensix_harvesting_mask;

// TODO(pjanevski): put const for this attributes
const tt_xy_pair dram_grid_size;
const std::vector<tt_xy_pair> dram_cores;
const std::size_t dram_harvesting_mask;
};
7 changes: 5 additions & 2 deletions device/grayskull/grayskull_coordinate_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
#pragma once

#include "device/coordinate_manager.h"
#include "device/grayskull/grayskull_implementation.h"
#include "grayskull_implementation.h"

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) {}
GrayskullCoordinateManager(const tt_xy_pair& worker_grid_size, const std::vector<tt_xy_pair>& workers, const std::size_t tensix_harvesting_mask, const std::size_t dram_harvesting_mask)
: CoordinateManager(worker_grid_size, workers, tensix_harvesting_mask,
{tt::umd::grayskull::NUM_DRAM_BANKS, tt::umd::grayskull::NUM_NOC_PORTS_PER_DRAM_BANK}, tt::umd::grayskull::DRAM_CORES, dram_harvesting_mask) {}

protected:
CoreCoord translated_to_logical_tensix(const CoreCoord core_coord) override;
Expand Down
12 changes: 12 additions & 0 deletions device/grayskull/grayskull_implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "device/architecture_implementation.h"
#include "device/tlb.h"
#include "device/tt_xy_pair.h"

namespace tt::umd {

Expand Down Expand Up @@ -104,6 +105,17 @@ enum class arc_message_type {
};

// DEVICE_DATA
const std::size_t NUM_DRAM_BANKS = 8;
const std::size_t NUM_NOC_PORTS_PER_DRAM_BANK = 1;
static const std::vector<tt_xy_pair> DRAM_CORES = {{
{1, 0},
{1, 6},
{4, 0},
{4, 6},
{7, 0},
{7, 6},
{10, 0},
{10, 6}}};
static const std::array<xy_pair, 8> DRAM_LOCATIONS = {{{1, 6}, {4, 6}, {7, 6}, {10, 6}, {1, 0}, {4, 0}, {7, 0}, {10, 0}}};
static const std::array<xy_pair, 1> ARC_LOCATIONS = {{{0, 2}}};
static const std::array<xy_pair, 1> PCI_LOCATIONS = {{{0, 4}}};
Expand Down
5 changes: 5 additions & 0 deletions device/tt_core_coordinates.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,9 @@ enum class CoreType {

CoreType core_type;
CoordSystem coord_system;

bool operator==(const CoreCoord& other) const
{
return this->x == other.x && this->y == other.y && this->core_type == other.core_type && this->coord_system == other.coord_system;
}
};
Loading

0 comments on commit 60d961a

Please sign in to comment.