Skip to content

Commit

Permalink
Place the public API in a special place with a canonical way of acces…
Browse files Browse the repository at this point in the history
…sing them (#322)

### Issue
Solving part of #324

### Description
It's currently unclear which files consist of UMD's public API and which
are private headers.
Additionally, consumers like tt-metal are reaching around with arbitrary
paths to fetch headers. They shouldn't.
There should be one place for the public API and one way for consumers
to access it, and private stuff should remain private.

### List of the changes
* Place all UMD Device's public API under `api/umd/device/`
* Expose `api/` as the include dir, so all consumers must use
`umd/device/foo.h` to include API headers
    * Even internal to UMD::Device, though this is subjective.
* Do not expose any other directory publicly
* Inside Device we may include other headers, but external consumers
cannot.

### Testing
Corresponding PR in tt-metal to consume with the new paths: 

### API Changes
(When making API changes, don't merge this PR until tt_metal and
tt_debuda PRs are approved.)
(Then merge this PR, change the client PRs to point to UMD main, and
then merge them.)

(Remove following lines if untrue) This PR has API changes:
- [x] (If breaking change) tt_metal approved PR pointing to this branch:
tenstorrent/tt-metal#15322
- [x] (If breaking change) tt_debuda approved PR pointing to this
branch: tenstorrent/tt-lens#193
  • Loading branch information
afuller-TT authored Nov 27, 2024
1 parent 62f8d1b commit aea0eea
Show file tree
Hide file tree
Showing 73 changed files with 196 additions and 178 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ message(STATUS "UMD build type: ${CMAKE_BUILD_TYPE}")

include(dependencies)

add_subdirectory(common)
add_subdirectory(device)
add_subdirectory(src)

Expand Down
13 changes: 13 additions & 0 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
add_library(umd_common INTERFACE)
add_library(${PROJECT_NAME}::Common ALIAS umd_common)

target_sources(
umd_common
INTERFACE
assert.hpp
backtrace.hpp
gtest_initializer.hpp # FIXME: this should be tucked away with the tests
logger.hpp
)

target_include_directories(umd_common INTERFACE .)
2 changes: 1 addition & 1 deletion common/assert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <sstream>
#include <vector>

#include "common/logger.hpp"
#include "logger.hpp"

namespace tt {
template <typename A, typename B>
Expand Down
2 changes: 1 addition & 1 deletion common/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <pybind11/iostream.h>
#endif

#include "common/backtrace.hpp"
#include "backtrace.hpp"
#include "fmt/color.h"
#include "fmt/core.h"
#include "fmt/ostream.h"
Expand Down
4 changes: 2 additions & 2 deletions common/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ std::string get_abs_path(std::string path) {
std::filesystem::path current_file_path = std::filesystem::path(__FILE__);
std::filesystem::path umd_root;
if (current_file_path.is_absolute()) {
umd_root = current_file_path.parent_path().parent_path();
umd_root = current_file_path.parent_path().parent_path().parent_path();
} else {
std::filesystem::path umd_root_relative =
std::filesystem::relative(std::filesystem::path(__FILE__).parent_path().parent_path(), "../");
std::filesystem::relative(std::filesystem::path(__FILE__).parent_path().parent_path().parent_path(), "../");
umd_root = std::filesystem::canonical(umd_root_relative);
}
std::filesystem::path abs_path = umd_root / path;
Expand Down
54 changes: 28 additions & 26 deletions device/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,41 @@ set(POSITION_INDEPENDENT_CODE ON)

generate_fbs_header(${PROJECT_SOURCE_DIR}/device/simulation/tt_simulation_device.fbs)

set(UMD_DEVICE_SRCS
architecture_implementation.cpp
cpuset_lib.cpp
tlb.cpp
tt_cluster_descriptor.cpp
cluster.cpp
tt_silicon_driver_common.cpp
tt_soc_descriptor.cpp
xy_pair.cpp
simulation/tt_simulation_device.cpp
simulation/tt_simulation_host.cpp
blackhole/blackhole_implementation.cpp
grayskull/grayskull_implementation.cpp
wormhole/wormhole_implementation.cpp
coordinate_manager.cpp
blackhole/blackhole_coordinate_manager.cpp
wormhole/wormhole_coordinate_manager.cpp
pcie/pci_device.cpp
hugepage.cpp
)

add_library(device SHARED ${UMD_DEVICE_SRCS})
add_library(device SHARED)
add_library(${PROJECT_NAME}::device ALIAS device)
add_library(${PROJECT_NAME}_device ALIAS device) # For legacy I guess

target_sources(device PRIVATE ${FBS_GENERATED_HEADER})
target_sources(
device
PRIVATE
architecture_implementation.cpp
blackhole/blackhole_coordinate_manager.cpp
blackhole/blackhole_implementation.cpp
cluster.cpp
coordinate_manager.cpp
cpuset_lib.cpp
grayskull/grayskull_implementation.cpp
hugepage.cpp
pcie/pci_device.cpp
simulation/tt_simulation_device.cpp
simulation/tt_simulation_host.cpp
tlb.cpp
tt_cluster_descriptor.cpp
tt_silicon_driver_common.cpp
tt_soc_descriptor.cpp
wormhole/wormhole_coordinate_manager.cpp
wormhole/wormhole_implementation.cpp
xy_pair.cpp
${FBS_GENERATED_HEADER}
)

target_include_directories(
device
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/api>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/device>
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
)

Expand All @@ -49,6 +49,8 @@ target_link_libraries(
flatbuffers
uv
PRIVATE
umd::Common
umd::Firmware
hwloc
rt
Boost::interprocess
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#include <tuple>
#include <vector>

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

struct tt_driver_host_address_params;
struct tt_driver_eth_interface_params;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include <array>
#include <stdexcept>

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

namespace tt::umd {

Expand Down
8 changes: 4 additions & 4 deletions device/cluster.h → device/api/umd/device/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
#include <unordered_set>
#include <vector>

#include "device/tlb.h"
#include "device/tt_cluster_descriptor_types.h"
#include "device/tt_io.hpp"
#include "fmt/core.h"
#include "pcie/pci_device.hpp"
#include "tt_silicon_driver_common.hpp"
#include "tt_soc_descriptor.h"
#include "tt_xy_pair.h"
#include "umd/device/pci_device.hpp"
#include "umd/device/tlb.h"
#include "umd/device/tt_cluster_descriptor_types.h"
#include "umd/device/tt_io.hpp"

using TLB_DATA = tt::umd::tlb_data;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include <set>
#include <vector>

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

class CoordinateManager {
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
*/

#pragma once
#include "device/cluster.h"
#include "device/driver_atomics.h"
#include "umd/device/cluster.h"
#include "umd/device/driver_atomics.h"
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include <array>

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

namespace tt::umd {

Expand Down
2 changes: 1 addition & 1 deletion device/hugepage.h → device/api/umd/device/hugepage.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <cstdint>
#include <string>

#include "device/tt_cluster_descriptor_types.h"
#include "umd/device/tt_cluster_descriptor_types.h"

namespace tt::umd {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
#include <unordered_map>
#include <vector>

#include "common/semver.hpp"
#include "device/tlb.h"
#include "device/tt_arch_types.h"
#include "device/tt_cluster_descriptor_types.h"
#include "device/tt_xy_pair.h"
#include "fmt/format.h"
#include "umd/device/semver.hpp"
#include "umd/device/tlb.h"
#include "umd/device/tt_arch_types.h"
#include "umd/device/tt_cluster_descriptor_types.h"
#include "umd/device/tt_xy_pair.h"

// TODO: this is used up in cluster.cpp but that logic ought to be
// lowered into the PCIDevice class since it is specific to PCIe cards.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
#include <unordered_set>
#include <vector>

#include "device/tt_cluster_descriptor_types.h"
#include "device/tt_xy_pair.h"
#include "tt_arch_types.h"
#include "umd/device/tt_arch_types.h"
#include "umd/device/tt_cluster_descriptor_types.h"
#include "umd/device/tt_xy_pair.h"

namespace YAML {
class Node;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include <fstream>
#include <vector>

#include "device/cluster.h"
#include "device/simulation/tt_simulation_host.hpp"
#include "umd/device/cluster.h"
#include "umd/device/tt_simulation_host.hpp"

class tt_SimulationDevice : public tt_device {
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <memory>
#include <vector>

#include "device/tt_xy_pair.h"
#include "umd/device/tt_xy_pair.h"

#define NNG_SOCKET_PREFIX "ipc:///tmp/"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
#include <unordered_map>
#include <vector>

#include "device/coordinate_manager.h"
#include "device/tt_arch_types.h"
#include "fmt/core.h"
#include "tt_xy_pair.h"
#include "umd/device/coordinate_manager.h"
#include "umd/device/tt_arch_types.h"
#include "umd/device/tt_xy_pair.h"

namespace YAML {
class Node;
Expand Down
2 changes: 1 addition & 1 deletion device/tt_xy_pair.h → device/api/umd/device/tt_xy_pair.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <regex>

#include "device/xy_pair.h"
#include "umd/device/xy_pair.h"

using tt_xy_pair = tt::umd::xy_pair;
using tt_cxy_pair = tt::umd::cxy_pair;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include <array>

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

namespace tt::umd {

Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions device/architecture_implementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
//
// SPDX-License-Identifier: Apache-2.0

#include "device/architecture_implementation.h"
#include "umd/device/architecture_implementation.h"

#include "device/blackhole/blackhole_implementation.h"
#include "device/grayskull/grayskull_implementation.h"
#include "device/wormhole/wormhole_implementation.h"
#include "umd/device/blackhole_implementation.h"
#include "umd/device/grayskull_implementation.h"
#include "umd/device/wormhole_implementation.h"

namespace tt::umd {

Expand Down
2 changes: 1 addition & 1 deletion device/blackhole/blackhole_coordinate_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#pragma once

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

class BlackholeCoordinateManager : public CoordinateManager {
public:
Expand Down
8 changes: 4 additions & 4 deletions device/blackhole/blackhole_implementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
//
// SPDX-License-Identifier: Apache-2.0

#include "blackhole_implementation.h"
#include "umd/device/blackhole_implementation.h"

#include "device/cluster.h"
#include "src/firmware/riscv/blackhole/eth_interface.h"
#include "src/firmware/riscv/blackhole/host_mem_address_map.h"
#include "blackhole/eth_interface.h"
#include "blackhole/host_mem_address_map.h"
#include "umd/device/cluster.h"

constexpr std::uint32_t NOC_ADDR_LOCAL_BITS = 36; // source: noc_parameters.h, common for WH && BH
constexpr std::uint32_t NOC_ADDR_NODE_ID_BITS = 6; // source: noc_parameters.h, common for WH && BH
Expand Down
22 changes: 10 additions & 12 deletions device/cluster.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: (c) 2023 Tenstorrent Inc.
//
// SPDX-License-Identifier: Apache-2.0
#include "cluster.h"
#include "umd/device/cluster.h"

#include <assert.h>
#include <dirent.h>
Expand Down Expand Up @@ -36,15 +36,13 @@
#include <utility>
#include <vector>

#include "common/logger.hpp"
#include "device/architecture_implementation.h"
#include "device/driver_atomics.h"
#include "device/hugepage.h"
#include "device/tlb.h"
#include "device/tt_arch_types.h"
#include "device/tt_cluster_descriptor.h"
#include "tt_arch_types.h"
#include "tt_cluster_descriptor.h"
#include "logger.hpp"
#include "umd/device/architecture_implementation.h"
#include "umd/device/driver_atomics.h"
#include "umd/device/hugepage.h"
#include "umd/device/tlb.h"
#include "umd/device/tt_arch_types.h"
#include "umd/device/tt_cluster_descriptor.h"
#include "yaml-cpp/yaml.h"

using namespace boost::interprocess;
Expand Down Expand Up @@ -119,8 +117,8 @@ const tt_SocDescriptor& tt_device::get_soc_descriptor(chip_id_t chip_id) const {
#include <iomanip>
#include <thread>

#include "tt_silicon_driver_common.hpp"
#include "tt_xy_pair.h"
#include "umd/device/tt_silicon_driver_common.hpp"
#include "umd/device/tt_xy_pair.h"

struct routing_cmd_t {
uint64_t sys_addr;
Expand Down
Loading

0 comments on commit aea0eea

Please sign in to comment.