Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable clang for device/ folder #264

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions device/.clang-format

This file was deleted.

12 changes: 8 additions & 4 deletions device/architecture_implementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ namespace tt::umd {

std::unique_ptr<architecture_implementation> architecture_implementation::create(tt::ARCH architecture) {
switch (architecture) {
case tt::ARCH::BLACKHOLE: return std::make_unique<blackhole_implementation>();
case tt::ARCH::GRAYSKULL: return std::make_unique<grayskull_implementation>();
case tt::ARCH::WORMHOLE_B0: return std::make_unique<wormhole_implementation>();
default: return nullptr;
case tt::ARCH::BLACKHOLE:
return std::make_unique<blackhole_implementation>();
case tt::ARCH::GRAYSKULL:
return std::make_unique<grayskull_implementation>();
case tt::ARCH::WORMHOLE_B0:
return std::make_unique<wormhole_implementation>();
default:
return nullptr;
}
}

Expand Down
7 changes: 4 additions & 3 deletions device/architecture_implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
#include <vector>

#include "device/tlb.h"
#include "device/xy_pair.h"
#include "device/tt_arch_types.h"
#include "device/xy_pair.h"

struct tt_driver_host_address_params;

namespace tt::umd {

class architecture_implementation {
public:
public:
virtual ~architecture_implementation() = default;

virtual tt::ARCH get_architecture() const = 0;
Expand Down Expand Up @@ -63,7 +63,8 @@ class architecture_implementation {
virtual std::tuple<xy_pair, xy_pair> multicast_workaround(xy_pair start, xy_pair end) const = 0;
virtual tlb_configuration get_tlb_configuration(uint32_t tlb_index) const = 0;
virtual std::optional<std::tuple<std::uint64_t, std::uint64_t>> describe_tlb(std::int32_t tlb_index) const = 0;
virtual std::pair<std::uint64_t, std::uint64_t> get_tlb_data(std::uint32_t tlb_index, const tlb_data& data) const = 0;
virtual std::pair<std::uint64_t, std::uint64_t> get_tlb_data(
std::uint32_t tlb_index, const tlb_data& data) const = 0;

virtual tt_driver_host_address_params get_host_address_params() const = 0;

Expand Down
8 changes: 4 additions & 4 deletions device/blackhole/blackhole_coordinate_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
#include "device/coordinate_manager.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, std::size_t harvesting_mask) :
CoordinateManager(worker_grid_size, workers, harvesting_mask) {}

tt_translated_coords to_translated_coords(tt_logical_coords logical_coords) override;

tt_logical_coords to_logical_coords(tt_translated_coords translated_coords) override;

protected:
protected:
std::set<std::size_t> get_x_coordinates_to_harvest(std::size_t harvesting_mask) override;
};
14 changes: 6 additions & 8 deletions device/blackhole/blackhole_implementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

#include "blackhole_implementation.h"

#include "src/firmware/riscv/blackhole/host_mem_address_map.h"

#include "device/tt_device.h"
#include "src/firmware/riscv/blackhole/host_mem_address_map.h"

namespace tt::umd {

Expand All @@ -22,18 +21,17 @@ std::tuple<xy_pair, xy_pair> blackhole_implementation::multicast_workaround(xy_p
}

tlb_configuration blackhole_implementation::get_tlb_configuration(uint32_t tlb_index) const {

// If TLB index is in range for 4GB tlbs (8 TLBs after 202 TLBs for 2MB)
if (tlb_index >= blackhole::TLB_COUNT_2M && tlb_index < blackhole::TLB_COUNT_2M + blackhole::TLB_COUNT_4G) {
return tlb_configuration {
return tlb_configuration{
.size = blackhole::DYNAMIC_TLB_4G_SIZE,
.base = blackhole::DYNAMIC_TLB_4G_BASE,
.cfg_addr = blackhole::DYNAMIC_TLB_4G_CFG_ADDR,
.index_offset = tlb_index - blackhole::TLB_BASE_INDEX_4G,
.offset = blackhole::TLB_4G_OFFSET,
};
}

return tlb_configuration{
.size = blackhole::DYNAMIC_TLB_2M_SIZE,
.base = blackhole::DYNAMIC_TLB_2M_BASE,
Expand Down Expand Up @@ -69,17 +67,17 @@ std::optional<std::tuple<std::uint64_t, std::uint64_t>> blackhole_implementation

std::pair<std::uint64_t, std::uint64_t> blackhole_implementation::get_tlb_data(
std::uint32_t tlb_index, const tlb_data& data) const {

if (tlb_index < blackhole::TLB_COUNT_2M) {
return data.apply_offset(blackhole::TLB_2M_OFFSET);
} else {
throw std::runtime_error("Invalid TLB index for Blackhole arch");
}

}

tt_driver_host_address_params blackhole_implementation::get_host_address_params() const {
return {::blackhole::host_mem::address_map::ETH_ROUTING_BLOCK_SIZE, ::blackhole::host_mem::address_map::ETH_ROUTING_BUFFERS_START};
return {
::blackhole::host_mem::address_map::ETH_ROUTING_BLOCK_SIZE,
::blackhole::host_mem::address_map::ETH_ROUTING_BUFFERS_START};
}

} // namespace tt::umd
96 changes: 61 additions & 35 deletions device/blackhole/blackhole_implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
#pragma once

#include <array>
#include <stdexcept>

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

namespace tt::umd {

Expand Down Expand Up @@ -59,30 +59,8 @@ enum class arc_message_type {

// DEVICE_DATA
static constexpr std::array<xy_pair, 24> DRAM_LOCATIONS = {
{{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}}};
{{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, 1> ARC_LOCATIONS = {{{8, 0}}};
static constexpr std::array<xy_pair, 1> PCI_LOCATIONS = {{{11, 0}}};
Expand Down Expand Up @@ -113,14 +91,14 @@ static constexpr uint32_t BROADCAST_TLB_INDEX = 0; // TODO: Copied from worm
static constexpr uint32_t STATIC_TLB_CFG_ADDR = 0x1fc00000;

static constexpr uint32_t TLB_COUNT_2M = 202;
static constexpr uint32_t TLB_BASE_2M = 0; // 0 in BAR0
static constexpr uint32_t TLB_BASE_2M = 0; // 0 in BAR0
static constexpr uint32_t TLB_BASE_INDEX_2M = 0;
static constexpr uint32_t TLB_2M_SIZE = 2 * 1024 * 1024;

static constexpr uint32_t TLB_CFG_REG_SIZE_BYTES = 12;

static constexpr uint32_t TLB_COUNT_4G = 8;
static constexpr uint32_t TLB_BASE_4G = 0; // 0 in BAR4
static constexpr uint32_t TLB_BASE_4G = 0; // 0 in BAR4
static constexpr uint32_t TLB_BASE_INDEX_4G = TLB_COUNT_2M;
static constexpr uint64_t TLB_4G_SIZE = 4ULL * 1024ULL * 1024ULL * 1024ULL;
static constexpr uint64_t DYNAMIC_TLB_4G_SIZE = TLB_4G_SIZE;
Expand Down Expand Up @@ -168,59 +146,108 @@ static constexpr uint32_t MSG_TYPE_SETUP_IATU_FOR_PEER_TO_PEER = 0x97;
} // namespace blackhole

class blackhole_implementation : public architecture_implementation {
public:
public:
tt::ARCH get_architecture() const override { return tt::ARCH::BLACKHOLE; }

uint32_t get_arc_message_arc_get_harvesting() const override {
return static_cast<uint32_t>(blackhole::arc_message_type::ARC_GET_HARVESTING);
}

uint32_t get_arc_message_arc_go_busy() const override {
return static_cast<uint32_t>(blackhole::arc_message_type::ARC_GO_BUSY);
}

uint32_t get_arc_message_arc_go_long_idle() const override {
return static_cast<uint32_t>(blackhole::arc_message_type::ARC_GO_LONG_IDLE);
}

uint32_t get_arc_message_arc_go_short_idle() const override {
return static_cast<uint32_t>(blackhole::arc_message_type::ARC_GO_SHORT_IDLE);
}

uint32_t get_arc_message_deassert_riscv_reset() const override {
return static_cast<uint32_t>(blackhole::arc_message_type::DEASSERT_RISCV_RESET);
}

uint32_t get_arc_message_get_aiclk() const override {
return static_cast<uint32_t>(blackhole::arc_message_type::GET_AICLK);
}

uint32_t get_arc_message_setup_iatu_for_peer_to_peer() const override {
return static_cast<uint32_t>(blackhole::arc_message_type::SETUP_IATU_FOR_PEER_TO_PEER);
}

uint32_t get_arc_message_test() const override { return static_cast<uint32_t>(blackhole::arc_message_type::TEST); }
uint32_t get_arc_csm_mailbox_offset() const override { throw std::runtime_error("Not supported for Blackhole arch"); return 0; }

uint32_t get_arc_csm_mailbox_offset() const override {
throw std::runtime_error("Not supported for Blackhole arch");
return 0;
}

uint32_t get_arc_reset_arc_misc_cntl_offset() const override { return blackhole::ARC_RESET_ARC_MISC_CNTL_OFFSET; }

uint32_t get_arc_reset_scratch_offset() const override { return blackhole::ARC_RESET_SCRATCH_OFFSET; }

uint32_t get_dram_channel_0_peer2peer_region_start() const override {
return blackhole::DRAM_CHANNEL_0_PEER2PEER_REGION_START;
}

uint32_t get_dram_channel_0_x() const override { return blackhole::DRAM_CHANNEL_0_X; }

uint32_t get_dram_channel_0_y() const override { return blackhole::DRAM_CHANNEL_0_Y; }

uint32_t get_broadcast_tlb_index() const override { return blackhole::BROADCAST_TLB_INDEX; }

uint32_t get_dynamic_tlb_2m_base() const override { return blackhole::DYNAMIC_TLB_2M_BASE; }

uint32_t get_dynamic_tlb_2m_size() const override { return blackhole::DYNAMIC_TLB_2M_SIZE; }
uint32_t get_dynamic_tlb_16m_base() const override { throw std::runtime_error("No 16MB TLBs for Blackhole arch"); return 0; }
uint32_t get_dynamic_tlb_16m_size() const override { throw std::runtime_error("No 16MB TLBs for Blackhole arch"); return 0; }
uint32_t get_dynamic_tlb_16m_cfg_addr() const override { throw std::runtime_error("No 16MB TLBs for Blackhole arch"); return 0; }

uint32_t get_dynamic_tlb_16m_base() const override {
throw std::runtime_error("No 16MB TLBs for Blackhole arch");
return 0;
}

uint32_t get_dynamic_tlb_16m_size() const override {
throw std::runtime_error("No 16MB TLBs for Blackhole arch");
return 0;
}

uint32_t get_dynamic_tlb_16m_cfg_addr() const override {
throw std::runtime_error("No 16MB TLBs for Blackhole arch");
return 0;
}

uint32_t get_mem_large_read_tlb() const override { return blackhole::MEM_LARGE_READ_TLB; }

uint32_t get_mem_large_write_tlb() const override { return blackhole::MEM_LARGE_WRITE_TLB; }

uint32_t get_static_tlb_cfg_addr() const override { return blackhole::STATIC_TLB_CFG_ADDR; }
uint32_t get_static_tlb_size() const override { return blackhole::STATIC_TLB_SIZE; }

uint32_t get_static_tlb_size() const override { return blackhole::STATIC_TLB_SIZE; }

uint32_t get_reg_tlb() const override { return blackhole::REG_TLB; }
uint32_t get_tlb_base_index_16m() const override { throw std::runtime_error("No 16MB TLBs for Blackhole arch"); return 0; }

uint32_t get_tlb_base_index_16m() const override {
throw std::runtime_error("No 16MB TLBs for Blackhole arch");
return 0;
}

uint32_t get_tensix_soft_reset_addr() const override { return blackhole::TENSIX_SOFT_RESET_ADDR; }

uint32_t get_grid_size_x() const override { return blackhole::GRID_SIZE_X; }

uint32_t get_grid_size_y() const override { return blackhole::GRID_SIZE_Y; }

uint32_t get_tlb_cfg_reg_size_bytes() const override { return blackhole::TLB_CFG_REG_SIZE_BYTES; }

uint32_t get_small_read_write_tlb() const override { return blackhole::MEM_SMALL_READ_WRITE_TLB; }

const std::vector<uint32_t>& get_harvesting_noc_locations() const override {
return blackhole::HARVESTING_NOC_LOCATIONS;
}

const std::vector<uint32_t>& get_t6_x_locations() const override { return blackhole::T6_X_LOCATIONS; }

const std::vector<uint32_t>& get_t6_y_locations() const override { return blackhole::T6_Y_LOCATIONS; }

std::tuple<xy_pair, xy_pair> multicast_workaround(xy_pair start, xy_pair end) const override;
Expand All @@ -229,7 +256,6 @@ class blackhole_implementation : public architecture_implementation {
std::pair<std::uint64_t, std::uint64_t> get_tlb_data(std::uint32_t tlb_index, const tlb_data& data) const override;

tt_driver_host_address_params get_host_address_params() const override;

};

} // namespace tt::umd
26 changes: 13 additions & 13 deletions device/coordinate_manager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "device/coordinate_manager.h"

#include <memory>

#include "coordinate_manager.h"
#include "grayskull/grayskull_coordinate_manager.h"

Expand Down Expand Up @@ -66,13 +68,9 @@ void CoordinateManager::clear_harvesting_structures() {
virtual_y_to_logical_y.clear();
}

std::set<std::size_t> CoordinateManager::get_x_coordinates_to_harvest(std::size_t harvesting_mask) {
return {};
}
std::set<std::size_t> CoordinateManager::get_x_coordinates_to_harvest(std::size_t harvesting_mask) { return {}; }

std::set<std::size_t> CoordinateManager::get_y_coordinates_to_harvest(std::size_t harvesting_mask) {
return {};
}
std::set<std::size_t> CoordinateManager::get_y_coordinates_to_harvest(std::size_t harvesting_mask) { return {}; }

void CoordinateManager::perform_harvesting(std::size_t harvesting_mask) {
clear_harvesting_structures();
Expand All @@ -99,14 +97,16 @@ void CoordinateManager::perform_harvesting(std::size_t harvesting_mask) {
logical_x_to_virtual_x.resize(grid_size_x - num_harvested_x);
logical_y_to_virtual_y.resize(grid_size_y - num_harvested_y);

fill_logical_to_physical_mapping(x_coordinates_to_harvest, y_coordinates_to_harvest, physical_x_unharvested, physical_y_unharvested);
fill_logical_to_physical_mapping(
x_coordinates_to_harvest, y_coordinates_to_harvest, physical_x_unharvested, physical_y_unharvested);
fill_logical_to_virtual_mapping(physical_x_unharvested, physical_y_unharvested);
}

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) {

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) {
auto physical_y_it = physical_y_unharvested.begin();
std::size_t logical_y = 0;
for (size_t y = 0; y < worker_grid_size.y; y++) {
Expand All @@ -125,7 +125,7 @@ void CoordinateManager::fill_logical_to_physical_mapping(

auto physical_x_it = physical_x_unharvested.begin();
std::size_t logical_x = 0;
for(std::size_t x = 0; x < worker_grid_size.x; x++) {
for (std::size_t x = 0; x < worker_grid_size.x; x++) {
if (x_to_harvest.find(x) == x_to_harvest.end()) {
logical_x_to_physical_x[logical_x] = *physical_x_it;
if (physical_x_to_logical_x.find(*physical_x_it) != physical_x_to_logical_x.end()) {
Expand All @@ -140,7 +140,8 @@ void CoordinateManager::fill_logical_to_physical_mapping(
}
}

void CoordinateManager::fill_logical_to_virtual_mapping(const std::set<size_t>& physical_x_unharvested, const std::set<size_t>& physical_y_unharvested) {
void CoordinateManager::fill_logical_to_virtual_mapping(
const std::set<size_t>& physical_x_unharvested, const std::set<size_t>& physical_y_unharvested) {
auto physical_y_it = physical_y_unharvested.begin();
for (std::size_t y = 0; y < logical_y_to_virtual_y.size(); y++) {
logical_y_to_virtual_y[y] = *physical_y_it;
Expand Down Expand Up @@ -171,7 +172,6 @@ std::unique_ptr<CoordinateManager> CoordinateManager::get_coordinate_manager(
const tt_xy_pair& worker_grid_size,
const std::vector<tt_xy_pair>& workers,
std::size_t harvesting_mask) {

switch (arch) {
case tt::ARCH::GRAYSKULL:
return std::make_unique<GrayskullCoordinateManager>(worker_grid_size, workers, harvesting_mask);
Expand Down
Loading
Loading