Skip to content

Commit

Permalink
Cleanup runtime build (#2191)
Browse files Browse the repository at this point in the history
### Ticket
closes #2138 

### What's changed
* Moved cpp files out of include subdirs and in the same directory as
cmake files.
* Split ttnn utils library into ttnn utils and ttnn types.
* Didn't merge testing utils and ttnn utils since the testing utils are
purely helpers for testing - thus I didn't want to expose these APIs in
the ttnn utils lib. These APIs are guarded by the
`TTMLIR_ENABLE_RUNTIME_TESTS` cmake flag, and won't be compiled if
`TTMLIR_ENABLE_RUNTIME_TESTS` is not set.
* Renamed some libraries to make their purposes clearer.
  • Loading branch information
jnie-TT authored Feb 16, 2025
1 parent bd97bc4 commit 6b9a55e
Show file tree
Hide file tree
Showing 17 changed files with 87 additions and 68 deletions.
4 changes: 3 additions & 1 deletion runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ endforeach()

add_subdirectory(lib)
add_subdirectory(tools)
add_subdirectory(test)
if (TTMLIR_ENABLE_RUNTIME_TESTS)
add_subdirectory(test)
endif()
23 changes: 4 additions & 19 deletions runtime/lib/ttnn/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
add_library(TTRuntimeTTNNHelpers
STATIC
${CMAKE_CURRENT_SOURCE_DIR}/include/tt/runtime/ttnn/utils.cpp
${CMAKE_CURRENT_SOURCE_DIR}/include/tt/runtime/ttnn/types.cpp
)
set_property(TARGET TTRuntimeTTNNHelpers PROPERTY CXX_STANDARD 20)
target_compile_options(TTRuntimeTTNNHelpers PUBLIC -mavx -mavx2 -fsized-deallocation)
target_include_directories(TTRuntimeTTNNHelpers PUBLIC
${PROJECT_SOURCE_DIR}/runtime/include
${PROJECT_SOURCE_DIR}/runtime/lib/ttnn/include
${PROJECT_SOURCE_DIR}/runtime/lib/ttnn/operations/include
${PROJECT_BINARY_DIR}/include/ttmlir/Target/Common
)
target_include_directories(TTRuntimeTTNNHelpers SYSTEM PUBLIC "$<BUILD_INTERFACE:${TTMETAL_INCLUDE_DIRS}>")
add_dependencies(TTRuntimeTTNNHelpers TTNN_LIBRARY tt-metal FBS_GENERATION)
target_link_libraries(TTRuntimeTTNNHelpers PUBLIC TTNN_LIBRARY)

add_subdirectory(types)
add_subdirectory(utils)
add_subdirectory(operations)

add_library(TTRuntimeTTNN
Expand All @@ -32,5 +17,5 @@ target_include_directories(TTRuntimeTTNN PUBLIC
${PROJECT_BINARY_DIR}/include/ttmlir/Target/Common
)
target_include_directories(TTRuntimeTTNN SYSTEM PUBLIC "$<BUILD_INTERFACE:${TTMETAL_INCLUDE_DIRS}>")
target_link_libraries(TTRuntimeTTNN PUBLIC TTRuntimeTTNNOps TTRuntimeTTNNHelpers)
add_dependencies(TTRuntimeTTNN TTRuntimeTTNNOps)
target_link_libraries(TTRuntimeTTNN PUBLIC TTRuntimeTTNNOps TTRuntimeTTNNTypes TTRuntimeTTNNUtils)
add_dependencies(TTRuntimeTTNN TTRuntimeTTNNOps TTRuntimeTTNNTypes TTRuntimeTTNNUtils)
6 changes: 3 additions & 3 deletions runtime/lib/ttnn/operations/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ add_library(TTRuntimeTTNNOps
)

set_property(TARGET TTRuntimeTTNNOps PROPERTY CXX_STANDARD 20)
target_compile_options(TTRuntimeTTNNOps PUBLIC -mavx -mavx2 -fsized-deallocation)
target_compile_options(TTRuntimeTTNNOps PUBLIC -mavx -mavx2)
target_include_directories(TTRuntimeTTNNOps PRIVATE
${PROJECT_SOURCE_DIR}/runtime/lib/ttnn
)
Expand All @@ -67,11 +67,11 @@ target_include_directories(TTRuntimeTTNNOps PUBLIC
)

target_include_directories(TTRuntimeTTNNOps SYSTEM PUBLIC "$<BUILD_INTERFACE:${TTMETAL_INCLUDE_DIRS}>")
target_link_libraries(TTRuntimeTTNNOps PUBLIC TTNN_LIBRARY TTRuntimeTTNNHelpers)
target_link_libraries(TTRuntimeTTNNOps PUBLIC TTNN_LIBRARY TTRuntimeTTNNTypes TTRuntimeTTNNUtils)

if (TT_RUNTIME_ENABLE_PERF_TRACE)
target_link_libraries(TTRuntimeTTNNOps PUBLIC TRACY_LIBRARY)
endif()


add_dependencies(TTRuntimeTTNNOps TTNN_LIBRARY tt-metal FBS_GENERATION TTRuntimeTTNNHelpers)
add_dependencies(TTRuntimeTTNNOps TTNN_LIBRARY tt-metal FBS_GENERATION TTRuntimeTTNNTypes TTRuntimeTTNNUtils)
14 changes: 14 additions & 0 deletions runtime/lib/ttnn/types/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
add_library(TTRuntimeTTNNTypes
STATIC
types.cpp
)
set_property(TARGET TTRuntimeTTNNTypes PROPERTY CXX_STANDARD 20)
target_compile_options(TTRuntimeTTNNTypes PUBLIC -mavx -mavx2)
target_include_directories(TTRuntimeTTNNTypes PUBLIC
${PROJECT_SOURCE_DIR}/runtime/include
${PROJECT_SOURCE_DIR}/runtime/lib/ttnn/include
${PROJECT_BINARY_DIR}/include/ttmlir/Target/Common
)
target_include_directories(TTRuntimeTTNNTypes SYSTEM PUBLIC "$<BUILD_INTERFACE:${TTMETAL_INCLUDE_DIRS}>")
add_dependencies(TTRuntimeTTNNTypes TTNN_LIBRARY tt-metal FBS_GENERATION)
target_link_libraries(TTRuntimeTTNNTypes PUBLIC TTNN_LIBRARY)
File renamed without changes.
14 changes: 14 additions & 0 deletions runtime/lib/ttnn/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
add_library(TTRuntimeTTNNUtils
STATIC
utils.cpp
)
set_property(TARGET TTRuntimeTTNNUtils PROPERTY CXX_STANDARD 20)
target_compile_options(TTRuntimeTTNNUtils PUBLIC -mavx -mavx2)
target_include_directories(TTRuntimeTTNNUtils PUBLIC
${PROJECT_SOURCE_DIR}/runtime/include
${PROJECT_SOURCE_DIR}/runtime/lib/ttnn/include
${PROJECT_BINARY_DIR}/include/ttmlir/Target/Common
)
target_include_directories(TTRuntimeTTNNUtils SYSTEM PUBLIC "$<BUILD_INTERFACE:${TTMETAL_INCLUDE_DIRS}>")
add_dependencies(TTRuntimeTTNNUtils TTNN_LIBRARY tt-metal FBS_GENERATION)
target_link_libraries(TTRuntimeTTNNUtils PUBLIC TTNN_LIBRARY)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace tt::runtime::ttnn::utils {

using ::tt::runtime::DeviceRuntime;

// TODO (bug #701)
// Currently the memory layout/location in flatbuffer is incorrect
// These methods are workarounds for operations such that we query the info
Expand Down
41 changes: 8 additions & 33 deletions runtime/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,5 @@
if (NOT TTMLIR_ENABLE_RUNTIME_TESTS)
add_library(TTRuntimeTTNNTestHelpers INTERFACE)
return()
endif()

if (NOT TTMLIR_ENABLE_RUNTIME OR (NOT TT_RUNTIME_ENABLE_TTNN AND NOT TT_RUNTIME_ENABLE_TTMETAL))
message(FATAL_ERROR "Runtime tests require -DTTMLIR_ENABLE_RUNTIME=ON and at least one backend runtime to be enabled")
endif()

if (NOT TT_RUNTIME_ENABLE_TTNN)
add_library(TTRuntimeTTNNTestHelpers INTERFACE)
else()
add_library(TTRuntimeTTNNTestHelpers
STATIC
${CMAKE_CURRENT_SOURCE_DIR}/include/tt/runtime/ttnn/test/utils.cpp
${CMAKE_CURRENT_SOURCE_DIR}/include/tt/runtime/ttnn/test/dylib.cpp
)
set_property(TARGET TTRuntimeTTNNTestHelpers PROPERTY CXX_STANDARD 20)
target_compile_options(TTRuntimeTTNNTestHelpers PUBLIC -mavx -mavx2 -fsized-deallocation)
target_include_directories(TTRuntimeTTNNTestHelpers PUBLIC
${PROJECT_SOURCE_DIR}/runtime/include
${PROJECT_SOURCE_DIR}/runtime/lib/ttnn/include
${PROJECT_BINARY_DIR}/include/ttmlir/Target/Common
)
target_include_directories(TTRuntimeTTNNTestHelpers SYSTEM PUBLIC "$<BUILD_INTERFACE:${TTMETAL_INCLUDE_DIRS}>")
add_dependencies(TTRuntimeTTNNTestHelpers TTRuntime tt-metal FBS_GENERATION)
target_link_libraries(TTRuntimeTTNNTestHelpers PUBLIC TTRuntime TTNN_LIBRARY)
message(FATAL_ERROR "Runtime tests require at least one backend runtime to be enabled")
endif()

enable_testing()
Expand Down Expand Up @@ -52,15 +27,15 @@ if (NOT FLATBUFFERS_LIB)
message(FATAL_ERROR "flatbuffers library not found")
endif()

add_library(TTRuntimeTEST INTERFACE)
add_dependencies(TTRuntimeTEST TTRuntimeTTNN TTRuntimeTTMetal TTRuntime TTRuntimeDebug TTRuntimeWorkarounds TTMETAL_LIBRARY)
target_include_directories(TTRuntimeTEST INTERFACE
add_library(TTRuntimeGTestLib INTERFACE)
add_dependencies(TTRuntimeGTestLib TTRuntimeTTNN TTRuntimeTTMetal TTRuntime TTRuntimeDebug TTRuntimeWorkarounds TTMETAL_LIBRARY)
target_include_directories(TTRuntimeGTestLib INTERFACE
${PROJECT_SOURCE_DIR}/runtime/include
${PROJECT_BINARY_DIR}/include/ttmlir/Target/Common
${TTMLIR_TOOLCHAIN}/include
)

target_link_libraries(TTRuntimeTEST INTERFACE
target_link_libraries(TTRuntimeGTestLib INTERFACE
TTMETAL_LIBRARY
DEVICE_LIBRARY
TTBinary
Expand All @@ -75,14 +50,14 @@ target_link_libraries(TTRuntimeTEST INTERFACE
)

if (TT_RUNTIME_ENABLE_PERF_TRACE)
list(APPEND TTRuntimeTEST TRACY_LIBRARY)
list(APPEND TTRuntimeGTestLib TRACY_LIBRARY)
endif()

function(add_runtime_gtest test_name)
add_executable(${test_name} ${ARGN})
set_property(TARGET ${test_name} PROPERTY CXX_STANDARD 20)
add_dependencies(${test_name} TTRuntimeTEST)
target_link_libraries(${test_name} PRIVATE TTRuntimeTEST)
add_dependencies(${test_name} TTRuntimeGTestLib)
target_link_libraries(${test_name} PRIVATE TTRuntimeGTestLib)
gtest_discover_tests(${test_name})
endfunction()

Expand Down
File renamed without changes.
File renamed without changes.
25 changes: 24 additions & 1 deletion runtime/test/ttnn/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
add_runtime_gtest(subtract_test test_subtract.cpp)
if (NOT TTMLIR_ENABLE_RUNTIME_TESTS OR NOT TT_RUNTIME_ENABLE_TTNN)
add_library(TTRuntimeTTNNTestLib INTERFACE)
return()
endif()

add_library(TTRuntimeTTNNTestLib
STATIC
utils.cpp
dylib.cpp
)
set_property(TARGET TTRuntimeTTNNTestLib PROPERTY CXX_STANDARD 20)
target_compile_options(TTRuntimeTTNNTestLib PUBLIC -mavx -mavx2)
target_include_directories(TTRuntimeTTNNTestLib PUBLIC
${PROJECT_SOURCE_DIR}/runtime/include
${PROJECT_SOURCE_DIR}/runtime/lib/ttnn/include
${PROJECT_SOURCE_DIR}/runtime/lib/test/include
${PROJECT_SOURCE_DIR}/runtime/test/include
${PROJECT_BINARY_DIR}/include/ttmlir/Target/Common
)
target_include_directories(TTRuntimeTTNNTestLib SYSTEM PUBLIC "$<BUILD_INTERFACE:${TTMETAL_INCLUDE_DIRS}>")
add_dependencies(TTRuntimeTTNNTestLib TTRuntimeTTNNUtils TTNN_LIBRARY FBS_GENERATION)
target_link_libraries(TTRuntimeTTNNTestLib PUBLIC TTRuntimeTTNNUtils TTNN_LIBRARY)

add_subdirectory(gtest)
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
//
// SPDX-License-Identifier: Apache-2.0

#include "tt/runtime/test/dylib.h"
#include "tt/runtime/ttnn/test/dylib.h"

#include "tt/runtime/detail/logger.h"
#include "tt/runtime/runtime.h"
#include "tt/runtime/test/utils.h"
#include "tt/runtime/ttnn/types.h"
#include "tt/runtime/ttnn/utils.h"
#include "tt/runtime/types.h"
Expand Down
1 change: 1 addition & 0 deletions runtime/test/ttnn/gtest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_runtime_gtest(subtract_test test_subtract.cpp)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: Apache-2.0

#include "tt/runtime/test/utils.h"
#include "tt/runtime/ttnn/test/utils.h"
#include "tt/runtime/detail/logger.h"
#include "tt/runtime/runtime.h"
#include "tt/runtime/ttnn/types.h"
Expand All @@ -21,7 +21,7 @@ Layout getDramInterleavedTileLayout(::tt::target::DataType dataType) {
return Layout(
std::static_pointer_cast<void>(
std::make_shared<::tt::runtime::ttnn::LayoutDesc>(layoutDesc)),
::tt::runtime::DeviceRuntime::TTNN);
DeviceRuntime::TTNN);
}
Layout getDramInterleavedRowMajorLayout(::tt::target::DataType dataType) {
LOG_ASSERT(getCurrentRuntime() == DeviceRuntime::TTNN);
Expand All @@ -33,7 +33,7 @@ Layout getDramInterleavedRowMajorLayout(::tt::target::DataType dataType) {
return Layout(
std::static_pointer_cast<void>(
std::make_shared<::tt::runtime::ttnn::LayoutDesc>(layoutDesc)),
::tt::runtime::DeviceRuntime::TTNN);
DeviceRuntime::TTNN);
}
::tt::runtime::Layout getHostRowMajorLayout(::tt::target::DataType dataType) {
LOG_ASSERT(getCurrentRuntime() == DeviceRuntime::TTNN);
Expand All @@ -45,6 +45,6 @@ ::tt::runtime::Layout getHostRowMajorLayout(::tt::target::DataType dataType) {
return Layout(
std::static_pointer_cast<void>(
std::make_shared<::tt::runtime::ttnn::LayoutDesc>(layoutDesc)),
::tt::runtime::DeviceRuntime::TTNN);
DeviceRuntime::TTNN);
}
} // namespace tt::runtime::ttnn::test
10 changes: 7 additions & 3 deletions runtime/tools/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@
linklibs += [
"TTRuntimeTTNN",
"TTRuntimeTTNNOps",
"TTRuntimeTTNNHelpers",
"TTRuntimeTTNNTypes",
"TTRuntimeTTNNUtils",
":_ttnn.so",
]

if enable_ttnn and enable_runtime_tests:
linklibs += ["TTRuntimeTTNNTestHelpers"]
linklibs += ["TTRuntimeTTNNTestLib"]

if enable_ttmetal:
runlibs += ["libtt_metal.so"]
Expand Down Expand Up @@ -235,6 +236,7 @@ def package_files(directory):
include_dirs=[
f"{toolchain}/include",
f"{src_dir}/runtime/include",
f"{src_dir}/runtime/test/include",
f"{ttmlir_build_dir}/include",
f"{ttmlir_build_dir}/include/ttmlir/Target/Common",
],
Expand All @@ -243,9 +245,11 @@ def package_files(directory):
f"{ttmlir_build_dir}/runtime/lib",
f"{ttmlir_build_dir}/runtime/lib/common",
f"{ttmlir_build_dir}/runtime/lib/ttnn",
f"{ttmlir_build_dir}/runtime/lib/ttnn/types",
f"{ttmlir_build_dir}/runtime/lib/ttnn/utils",
f"{ttmlir_build_dir}/runtime/lib/ttnn/operations",
f"{ttmlir_build_dir}/runtime/lib/ttmetal",
f"{ttmlir_build_dir}/runtime/test",
f"{ttmlir_build_dir}/runtime/test/ttnn",
f"{toolchain}/lib",
f"{ttmlir_build_dir}/runtime/tools/python/ttrt/runtime",
f"{metaldir}/lib",
Expand Down
4 changes: 2 additions & 2 deletions runtime/tools/python/ttrt/runtime/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include "tt/runtime/runtime.h"
#include "tt/runtime/utils.h"
#if defined(TTMLIR_ENABLE_RUNTIME_TESTS) && TTMLIR_ENABLE_RUNTIME_TESTS == 1
#include "tt/runtime/test/dylib.h"
#include "tt/runtime/test/utils.h"
#include "tt/runtime/ttnn/test/dylib.h"
#include "tt/runtime/ttnn/test/utils.h"
#endif

#include <pybind11/functional.h>
Expand Down

0 comments on commit 6b9a55e

Please sign in to comment.