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

Fix broken unit tests + update CMake infra #31

Merged
merged 3 commits into from
Aug 16, 2024
Merged
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
35 changes: 17 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 3.16)
project(umd_device)
find_package(yaml-cpp REQUIRED)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
Expand All @@ -11,47 +10,47 @@ if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
message("-- UMD: Building as master project")
endif()

if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Release build is the default" FORCE)
endif()
if(MASTER_PROJECT)
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Release build is the default" FORCE)
endif()

message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
add_library(compiler_flags INTERFACE)
target_compile_options(compiler_flags INTERFACE -DFMT_HEADER_ONLY)
endif()
message(STATUS "UMD build type: ${CMAKE_BUILD_TYPE}")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g -DDEBUG=DEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -DDEBUG=DEBUG")

include(${PROJECT_SOURCE_DIR}/cmake/dependencies.cmake)

add_library(umd_common_directories INTERFACE)
target_include_directories(umd_common_directories INTERFACE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/device)
target_include_directories(umd_common_directories INTERFACE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/device ${PROJECT_SOURCE_DIR}/third_party/fmt/include)

if(NOT DEFINED ENV{ARCH_NAME})
message(FATAL_ERROR "Please set ARCH_NAME to grayskull, wormhole_b0, or blackhole")
elseif($ENV{ARCH_NAME} STREQUAL "grayskull")
message("-- UMD: Building for Grayskull")
message(STATUS "UMD: Building for Grayskull")
target_include_directories(umd_common_directories INTERFACE
${PROJECT_SOURCE_DIR}/device/grayskull
${PROJECT_SOURCE_DIR}/src/firmware/riscv/grayskull
)
elseif($ENV{ARCH_NAME} STREQUAL "wormhole_b0")
message("-- UMD: Building for Wormhole")
message(STATUS "UMD: Building for Wormhole")
target_include_directories(umd_common_directories INTERFACE
${PROJECT_SOURCE_DIR}/device/wormhole
${PROJECT_SOURCE_DIR}/src/firmware/riscv/wormhole
)
elseif($ENV{ARCH_NAME} STREQUAL "blackhole")
message("-- UMD: Building for Blackhole")
message(STATUS "UMD: Building for Blackhole")
target_include_directories(umd_common_directories INTERFACE
${PROJECT_SOURCE_DIR}/device/blackhole
${PROJECT_SOURCE_DIR}/src/firmware/riscv/blackhole
)
endif()

include(${PROJECT_SOURCE_DIR}/cmake/dependencies.cmake)

add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/fmt)
add_subdirectory(${PROJECT_SOURCE_DIR}/device)

if(MASTER_PROJECT)
add_subdirectory(${PROJECT_SOURCE_DIR}/tests EXCLUDE_FROM_ALL)
endif()
add_subdirectory(${PROJECT_SOURCE_DIR}/tests EXCLUDE_FROM_ALL)

45 changes: 36 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,52 @@
# UMD

## Dependencies

Required Ubuntu dependencies:
```
sudo apt install -y libhwloc-dev
```

## Build flow
We are transitioning away from Make. The main libraries and tests should now be built with CMake.
Specify the `ARCH_NAME` environment variable as `grayskull` or `wormhole_b0` before building.

To build `libdevice.so`:
```
cmake -B build -G Ninja
ninja -C build
# or
ninja umd_device -C build
```

To build tests:
```
ninja umd_tests -C build
```

## As a submodule/external project
If your project has CMake support, simply add this repo as a subdirectory:
```
add_subdirectory(<path to umd>)
```
You can then use `libdevice.so` by linking against the `umd_device` target wheverever is needed.
```
target_link_libraries(tt_metal PUBLIC umd_device)
```

## Deprecated Make flow
This flow is no longer maintained. `libdevice.so` will build however if you want to run tests, we suggest using the CMake flow

Required Ubuntu dependencies:
```
sudo apt install -y libyaml-cpp-dev libhwloc-dev libgtest-dev libboost-dev
```
## Build

This target builds `libdevice.so`. Specify the `ARCH_NAME` environment variable when building (`wormhole_b0` or `grayskull`):

```
make build
```

## Test

Run this target to build library, and gtest suite.

```
Expand All @@ -29,15 +59,12 @@ Running test suite:
make run
```

## Clean

To Clean build directory
```
make clean
```

## Device Selection

Change the `ARCH_NAME` flag in the top-level Makefile or run:
To change device selection, change the `ARCH_NAME` flag in the top-level Makefile or run:

```
make build ARCH_NAME=...
Expand Down
29 changes: 29 additions & 0 deletions cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,29 @@ CPMAddPackage(
OPTIONS "INSTALL_GTEST OFF"
)

############################################################################################################################
# yaml-cpp
############################################################################################################################
CPMAddPackage(
NAME yaml-cpp
GITHUB_REPOSITORY jbeder/yaml-cpp
GIT_TAG 0.8.0
OPTIONS
"YAML_CPP_BUILD_TESTS OFF"
"YAML_CPP_BUILD_TOOLS OFF"
"YAML_BUILD_SHARED_LIBS OFF"
)

if (yaml-cpp_ADDED)
set_target_properties(yaml-cpp PROPERTIES DEBUG_POSTFIX "")
endif()

############################################################################################################################
# boost::interprocess
############################################################################################################################
include(${PROJECT_SOURCE_DIR}/cmake/fetch_boost.cmake)
fetch_boost_library(interprocess)

############################################################################################################################
# Nanomsg
############################################################################################################################
Expand Down Expand Up @@ -53,3 +76,9 @@ CPMAddPackage(
OPTIONS
"LIBUV_BUILD_TESTS OFF"
)

if(NOT MASTER_PROJECT)
set(nng_include_dir ${nanomsg_SOURCE_DIR}/include PARENT_SCOPE)
set(flatbuffers_include_dir ${flatbuffers_SOURCE_DIR}/include PARENT_SCOPE)
set(libuv_include_dir ${libuv_SOURCE_DIR}/include PARENT_SCOPE)
endif()
23 changes: 23 additions & 0 deletions cmake/fetch_boost.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function(fetch_boost_library BOOST_PROJECT_NAME)
CPMAddPackage(
NAME boost_${BOOST_PROJECT_NAME}
GITHUB_REPOSITORY boostorg/${BOOST_PROJECT_NAME}
GIT_TAG boost-1.85.0
OPTIONS
"BUILD_SHARED_LIBS OFF"
)

get_target_property(BOOST_INTERFACE_LINK_LIBRARIES
boost_${BOOST_PROJECT_NAME} INTERFACE_LINK_LIBRARIES)

if(NOT BOOST_INTERFACE_LINK_LIBRARIES STREQUAL
BOOST_INTERFACE_LINK_LIBRARIES-NOTFOUND)
foreach(BOOST_INTERFACE_LINK_LIBRARY IN
ITEMS ${BOOST_INTERFACE_LINK_LIBRARIES})
if(NOT TARGET ${BOOST_INTERFACE_LINK_LIBRARY}
AND BOOST_INTERFACE_LINK_LIBRARY MATCHES "^Boost::([a-z0-9_]+)$")
fetch_boost_library(${CMAKE_MATCH_1})
endif()
endforeach()
endif()
endfunction()
12 changes: 9 additions & 3 deletions device/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/simulation)

set(UMD_DEVICE_SRCS
architecture_implementation.cpp
Expand All @@ -14,11 +13,18 @@ set(UMD_DEVICE_SRCS
tt_soc_descriptor.cpp
tt_versim_stub.cpp
wormhole_implementation.cpp
simulation/tt_simulation_device.cpp
simulation/tt_simulation_host.cpp
)
add_library(umd_device SHARED ${UMD_DEVICE_SRCS})
target_link_libraries(umd_device
PUBLIC umd_common_directories simulation
PRIVATE yaml-cpp hwloc rt fmt::fmt-header-only
PUBLIC yaml-cpp::yaml-cpp umd_common_directories nng uv compiler_flags
PRIVATE hwloc rt Boost::interprocess
)
target_include_directories(umd_device PUBLIC
${flatbuffers_SOURCE_DIR}/include
${nanomsg_SOURCE_DIR}/include
${libuv_SOURCE_DIR}/include
)
set_target_properties(umd_device PROPERTIES
OUTPUT_NAME device
Expand Down
14 changes: 0 additions & 14 deletions device/simulation/CMakeLists.txt

This file was deleted.

2 changes: 1 addition & 1 deletion device/tt_silicon_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4294,7 +4294,7 @@ void tt_SiliconDevice::broadcast_write_to_cluster(const void *mem_ptr, uint32_t
else if (arch_name == tt::ARCH::BLACKHOLE) {
auto architecture_implementation = tt::umd::architecture_implementation::create(static_cast<tt::umd::architecture>(arch_name));
if(cols_to_exclude.find(0) == cols_to_exclude.end() or cols_to_exclude.find(9) == cols_to_exclude.end()) {
log_assert(!tensix_or_eth_in_broadcast(cols_to_exclude, architecture_implementation.get()), "Cannot broadcast to tensix/ethernet and DRAM simultaneously on Wormhole.");
log_assert(!tensix_or_eth_in_broadcast(cols_to_exclude, architecture_implementation.get()), "Cannot broadcast to tensix/ethernet and DRAM simultaneously on Blackhole.");
if(cols_to_exclude.find(0) == cols_to_exclude.end()) {
// When broadcast includes column zero do not exclude anything
std::set<uint32_t> unsafe_rows = {};
Expand Down
14 changes: 12 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@

add_library(test_common INTERFACE)
target_link_libraries(test_common INTERFACE umd_device gtest_main gtest pthread fmt::fmt-header-only)
target_link_libraries(test_common INTERFACE umd_device gtest_main gtest pthread)
target_include_directories(test_common INTERFACE
${PROJECT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/simulation)
add_custom_target(tests DEPENDS simulation_tests)
if($ENV{ARCH_NAME} STREQUAL "wormhole_b0")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/wormhole)
else()
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/$ENV{ARCH_NAME})
endif()

add_custom_target(umd_tests DEPENDS umd_unit_tests simulation_tests)
13 changes: 13 additions & 0 deletions tests/blackhole/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

set(UNIT_TESTS_BH_SRCS
test_silicon_driver_bh.cpp
)

add_executable(unit_tests_blackhole ${UNIT_TESTS_BH_SRCS})
target_link_libraries(unit_tests_blackhole PRIVATE test_common)
set_target_properties(unit_tests_blackhole PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/test/umd/blackhole
OUTPUT_NAME unit_tests
)

add_custom_target(umd_unit_tests DEPENDS unit_tests_blackhole)
15 changes: 10 additions & 5 deletions tests/blackhole/test_bh_common.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
// SPDX-FileCopyrightText: (c) 2023 Tenstorrent Inc.
//
// SPDX-License-Identifier: Apache-2.0

#pragma once
#include "../test_utils/stimulus_generators.hpp"
#include "eth_l1_address_map.h"
#include "tt_xy_pair.h"
#include <tt_cluster_descriptor.h>
#include <tt_device.h>
#include "tt_cluster_descriptor.h"
#include "tt_device.h"

#include "tests/test_utils/stimulus_generators.hpp"
#include "eth_l1_address_map.h"

namespace tt::umd::test::utils {

Expand Down Expand Up @@ -57,7 +62,7 @@ class BlackholeTestFixture : public ::testing::Test {
std::set<chip_id_t> target_devices = {devices.begin(), devices.end()};
uint32_t num_host_mem_ch_per_mmio_device = 1;
std::unordered_map<std::string, std::int32_t> dynamic_tlb_config = {}; // Don't set any dynamic TLBs in this test
device = std::make_unique<tt_SiliconDevice>(SOC_DESC_PATH, GetClusterDescYAML().string(), target_devices, num_host_mem_ch_per_mmio_device, dynamic_tlb_config, false, true, true);
device = std::make_unique<tt_SiliconDevice>(test_utils::GetAbsPath(SOC_DESC_PATH), test_utils::GetClusterDescYAML(), target_devices, num_host_mem_ch_per_mmio_device, dynamic_tlb_config, false, true, true);
assert(device != nullptr);
assert(device->get_cluster_description()->get_number_of_chips() == get_detected_num_chips());

Expand Down
Loading