Skip to content

Commit

Permalink
Splitting python bindings and cpp in ttnn library (#17957)
Browse files Browse the repository at this point in the history
Now we will have to libraries, ttnncpp and ttnn, where ttnncpp will work
as c++ backend while the tin library is the wrapper for python

### Ticket
#16418

### Problem description
Our implementation of ttnn was coupled to python, so if anybody wanted
to use the api directly from cpp, it could generate some linking issues.

### What's changed
With ttnn divided in two, a user could link to the cpp backend without
having to link to python, or use the python wrapper, depending on the
use case. This gives more flexibility to our users to decide the way
they decide to interact with the backend

### Checklist
- [x] [All post
commit](https://github.com/tenstorrent/tt-metal/actions/workflows/all-post-commit-workflows.yaml)
CI passes
- [x] [Blackhole Post
commit](https://github.com/tenstorrent/tt-metal/actions/workflows/blackhole-post-commit.yaml)
CI passes (if applicable)
- [X ] [Model
regression](https://github.com/tenstorrent/tt-metal/actions/workflows/perf-models.yaml)
CI passes (if applicable)
- [x] [Device performance
regression](https://github.com/tenstorrent/tt-metal/actions/workflows/perf-device-models.yaml)
CI passes (if applicable)
- [ ] **(For models and ops writers)** Full [new models
tests](https://github.com/tenstorrent/tt-metal/actions/workflows/full-new-models-suite.yaml)
CI passes (if applicable)
- [ ] New/Existing tests provide coverage for changes
  • Loading branch information
dgomezTT authored Mar 1, 2025
1 parent b309929 commit a019371
Show file tree
Hide file tree
Showing 7 changed files with 549 additions and 391 deletions.
31 changes: 21 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ endif()
# For top level install: cmake --build build --target install or make/ninja install -C build
############################################################################################################################
# Install for build artifacts that will upload build/lib

install(
TARGETS
tt_metal
Expand All @@ -280,17 +279,18 @@ install(
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT tar
)
install(
TARGETS
ttnn
ARCHIVE
DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT tar
)
if(WITH_PYTHON_BINDINGS)
# Install .so into src files for pybinds implementation
install(
TARGETS
ttnn
ARCHIVE
DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT dev
)

install(
TARGETS
ttnn
Expand All @@ -299,6 +299,17 @@ if(WITH_PYTHON_BINDINGS)
COMPONENT
tt_pybinds
)
else()
#when we don't build python bindings, we generate a dynamic library ttnncpp
install(
TARGETS
ttnncpp
ARCHIVE
DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT tar
)
endif()

# FIXME(17578): figure out what bits we actually need to ship and omit the rest
Expand Down
18 changes: 18 additions & 0 deletions build_metal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ show_help() {
echo " --toolchain-path Set path to CMake toolchain file."
echo " --configure-only Only configure the project, do not build."
echo " --enable-coverage Instrument the binaries for code coverage."
echo " --without-python-bindings Disable Python bindings (ttnncpp will be available as standalone library, otherwise ttnn will include the cpp backend and the python bindings), Enabled by default"
}

clean() {
Expand Down Expand Up @@ -75,6 +76,7 @@ ttnn_shared_sub_libs="OFF"
toolchain_path="cmake/x86_64-linux-clang-17-libcpp-toolchain.cmake"
configure_only="OFF"
enable_coverage="OFF"
with_python_bindings="ON"

declare -a cmake_args

Expand Down Expand Up @@ -114,6 +116,7 @@ ttnn-shared-sub-libs
toolchain-path:
configure-only
enable-coverage
without-python-bindings
"

# Flatten LONGOPTIONS into a comma-separated string for getopt
Expand Down Expand Up @@ -177,6 +180,8 @@ while true; do
ttnn_shared_sub_libs="ON";;
--configure-only)
configure_only="ON";;
--without-python-bindings)
with_python_bindings="OFF";;
--disable-unity-builds)
unity_builds="OFF";;
--disable-light-metal-trace)
Expand Down Expand Up @@ -256,6 +261,7 @@ echo "INFO: Build tests: $build_tests"
echo "INFO: Enable Unity builds: $unity_builds"
echo "INFO: TTNN Shared sub libs : $ttnn_shared_sub_libs"
echo "INFO: Enable Light Metal Trace: $light_metal_trace"
echo "INFO: With python bindings: $with_python_bindings"

# Prepare cmake arguments
cmake_args+=("-B" "$build_dir")
Expand Down Expand Up @@ -373,6 +379,18 @@ if [ "$build_all" = "ON" ]; then
cmake_args+=("-DBUILD_TT_TRAIN=ON")
fi

if [ "$light_metal_trace" = "ON" ]; then
cmake_args+=("-DTT_ENABLE_LIGHT_METAL_TRACE=ON")
else
cmake_args+=("-DTT_ENABLE_LIGHT_METAL_TRACE=OFF")
fi

if [ "$with_python_bindings" = "ON" ]; then
cmake_args+=("-DWITH_PYTHON_BINDINGS=ON")
else
cmake_args+=("-DWITH_PYTHON_BINDINGS=OFF")
fi

# toolchain and cxx_compiler settings would conflict with eachother
# only use toolchain if not setting cxx compiler directly
if [ "$cxx_compiler_path" == "" ]; then
Expand Down
Loading

0 comments on commit a019371

Please sign in to comment.