Skip to content

Commit

Permalink
#0: Remove dependency on tt_fabric.h and global xy_local_addr from tt…
Browse files Browse the repository at this point in the history
…_fabric_api.h
  • Loading branch information
tt-aho committed Feb 19, 2025
1 parent 20a4d36 commit a59ca64
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ void kernel_main() {
test_results[TT_FABRIC_MISC_INDEX] = 0xff000004;

// make sure fabric node gatekeeper is available.
tt_fabric_init();
fabric_endpoint_init();

socket_reader.init(data_buffer_start_addr, data_buffer_size_words);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ void kernel_main() {
uint32_t packet_count = 0;

// initalize client
tt_fabric_init();
fabric_endpoint_init(client_interface, outbound_eth_chan);
routing_table = reinterpret_cast<tt_l1_ptr fabric_router_l1_config_t*>(client_interface->routing_tables_l1_offset);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ void kernel_main() {
zero_l1_buf((uint32_t*)&packet_header, sizeof(packet_header_t));

// initalize client
tt_fabric_init();
fabric_endpoint_init(client_interface, gk_interface_addr_l, gk_interface_addr_h);
routing_table = reinterpret_cast<tt_l1_ptr fabric_router_l1_config_t*>(
client_interface->routing_tables_l1_offset + sizeof(fabric_router_l1_config_t) * routing_plane);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ constexpr uint32_t s_depth = get_compile_time_arg_val(27);
volatile tt_l1_ptr fabric_client_interface_t* client_interface =
(volatile tt_l1_ptr fabric_client_interface_t*)client_interface_addr;

uint64_t xy_local_addr;
uint32_t target_address;
uint32_t noc_offset;
uint32_t controller_noc_offset;
Expand Down
7 changes: 1 addition & 6 deletions tt_fabric/hw/inc/tt_fabric.h
Original file line number Diff line number Diff line change
Expand Up @@ -1591,9 +1591,4 @@ inline uint64_t tt_fabric_send_pull_request(uint64_t dest_addr, volatile local_p
return words_written_addr;
}

inline void tt_fabric_init() {
uint32_t noc_id_reg = NOC_CMD_BUF_READ_REG(noc_index, 0, NOC_CFG(NOC_ID_LOGICAL));
uint32_t my_x = noc_id_reg & NOC_NODE_ID_MASK;
uint32_t my_y = (noc_id_reg >> NOC_ADDR_NODE_ID_BITS) & NOC_NODE_ID_MASK;
xy_local_addr = NOC_XY_ADDR(my_x, my_y, 0);
}
inline void tt_fabric_init() { xy_local_addr = get_noc_addr(0); }
11 changes: 7 additions & 4 deletions tt_fabric/hw/inc/tt_fabric_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
#pragma once

#include "risc_attribs.h"
#include <hostdevcommon/common_values.hpp>
#include "dataflow_api.h"
#include "noc_overlay_parameters.h"
#include "ethernet/dataflow_api.h"
#include "tt_fabric_interface.h"

using namespace tt::tt_fabric;
namespace tt::tt_fabric {

#define ASYNC_WR_ADD_PR 1
#define ASYNC_WR_SEND 2
Expand Down Expand Up @@ -42,6 +41,9 @@ inline uint32_t get_next_hop_router_noc_xy(
inline void fabric_setup_pull_request(
volatile tt_l1_ptr fabric_client_interface_t* client_interface, uint32_t src_addr, uint32_t size) {
uint32_t size_in_words = (size + PACKET_WORD_SIZE_BYTES - 1) >> 4;
// TODO: Could return this value to the user and take this as an arg to avoid repeated lookup
// Added here to avoid user having to declare globals
uint64_t xy_local_addr = get_noc_addr(0);
client_interface->local_pull_request.pull_request.wr_ptr = size_in_words;
client_interface->local_pull_request.pull_request.rd_ptr = 0;
client_interface->local_pull_request.pull_request.size = size;
Expand Down Expand Up @@ -338,7 +340,7 @@ inline socket_handle_t* fabric_socket_open(
client_interface->gk_message.packet_header.session.command = SOCKET_OPEN;
client_interface->gk_message.packet_header.session.target_offset_h = client_interface->pull_req_buf_addr >> 32;
client_interface->gk_message.packet_header.session.target_offset_l = (uint32_t)client_interface->pull_req_buf_addr;
client_interface->gk_message.packet_header.session.ack_offset_h = xy_local_addr >> 32;
client_interface->gk_message.packet_header.session.ack_offset_h = NOC_XY_ENCODING(my_x[noc_index], my_y[noc_index]);
client_interface->gk_message.packet_header.session.ack_offset_l = (uint32_t)socket_handle;
client_interface->gk_message.packet_header.packet_parameters.socket_parameters.socket_id = socket_id;
client_interface->gk_message.packet_header.packet_parameters.socket_parameters.epoch_id = epoch_id;
Expand Down Expand Up @@ -386,7 +388,6 @@ inline void fabric_socket_connect(socket_handle_t* socket_handle) {
template <RoutingType routing_type = RoutingType::ROUTING_TABLE>
inline void fabric_endpoint_init(
volatile tt_l1_ptr fabric_client_interface_t* client_interface, uint32_t outbound_eth_chan) {
tt_fabric_init();
// TODO: Should not assume routing tables are immediately after the client interface
// This should be a separate address we take in
uint32_t routing_tables_offset = (uint32_t)client_interface + sizeof(fabric_client_interface_t);
Expand All @@ -403,3 +404,5 @@ inline void fabric_endpoint_init(
noc_async_read_barrier();
}
}

} // namespace tt::tt_fabric

0 comments on commit a59ca64

Please sign in to comment.