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

Integrate torch-mlir with tt-mlir #312

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ jobs:
-DCMAKE_BUILD_TYPE=${{ matrix.build.build_type }} \
-DTTMLIR_ENABLE_RUNTIME=${{ matrix.build.enable_runtime }} \
-DTTMLIR_ENABLE_RUNTIME_TESTS=${{ matrix.build.enable_runtime }} \
-DTTMLIR_ENABLE_TORCH_MLIR=ON \
-S ${{ github.workspace }}

- name: Build
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ if (NOT DEFINED ENV{TTMLIR_ENV_ACTIVATED})
endif()

option(TT_RUNTIME_ENABLE_PERF_TRACE "Enable performance mode" OFF)
option(TTMLIR_ENABLE_TORCH_MLIR "Enable TORCH MLIR support" OFF)

set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)

Expand Down
1 change: 1 addition & 0 deletions env/build-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ wheel
setuptools
black
pre-commit
Torch
75 changes: 4 additions & 71 deletions third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,73 +1,6 @@
include(ExternalProject)

if ("$ENV{ARCH_NAME}" STREQUAL "grayskull")
set(ARCH_NAME "grayskull")
set(ARCH_EXTRA_DIR "grayskull")
elseif ("$ENV{ARCH_NAME}" STREQUAL "wormhole_b0")
set(ARCH_NAME "wormhole")
set(ARCH_EXTRA_DIR "wormhole/wormhole_b0_defines")
elseif ("$ENV{ARCH_NAME}" STREQUAL "blackhole")
set(ARCH_NAME "blackhole")
set(ARCH_EXTRA_DIR "blackhole")
else()
message(FATAL_ERROR "Unsupported ARCH_NAME: $ENV{ARCH_NAME}")
endif()

if (TT_RUNTIME_ENABLE_PERF_TRACE)
add_compile_definitions(TRACY_ENABLE)
set(ENV{ENABLE_TRACY} "1")
else()
set(ENV{ENABLE_TRACY} "0")
endif()

set(TTMETAL_INCLUDE_DIRS
${PROJECT_SOURCE_DIR}/third_party/tt-metal/src/tt-metal/ttnn/cpp
${PROJECT_SOURCE_DIR}/third_party/tt-metal/src/tt-metal
${PROJECT_SOURCE_DIR}/third_party/tt-metal/src/tt-metal/tt_metal
${PROJECT_SOURCE_DIR}/third_party/tt-metal/src/tt-metal/tt_metal/third_party/umd
${PROJECT_SOURCE_DIR}/third_party/tt-metal/src/tt-metal/tt_metal/third_party/fmt
${PROJECT_SOURCE_DIR}/third_party/tt-metal/src/tt-metal/tt_metal/hw/inc
${PROJECT_SOURCE_DIR}/third_party/tt-metal/src/tt-metal/tt_metal/hw/inc/${ARCH_NAME}
${PROJECT_SOURCE_DIR}/third_party/tt-metal/src/tt-metal/tt_metal/hw/inc/${ARCH_EXTRA_DIR}
${PROJECT_SOURCE_DIR}/third_party/tt-metal/src/tt-metal/tt_metal/third_party/umd/src/firmware/riscv/${ARCH_NAME}
${PROJECT_SOURCE_DIR}/third_party/tt-metal/src/tt-metal/tt_eager
PARENT_SCOPE
)

set(TTMETAL_LIBRARY_DIR ${PROJECT_SOURCE_DIR}/third_party/tt-metal/src/tt-metal-build/lib)
set(TTNN_LIBRARY_PATH ${TTMETAL_LIBRARY_DIR}/_ttnn.so)
set(TTMETAL_LIBRARY_PATH ${TTMETAL_LIBRARY_DIR}/libtt_metal.so)
set(TTEAGER_LIBRARY_PATH ${TTMETAL_LIBRARY_DIR}/libtt_eager.so)

set(TTMETAL_LIBRARY_DIR ${TTMETAL_LIBRARY_DIR} PARENT_SCOPE)
set(TTNN_LIBRARY_PATH ${TTNN_LIBRARY_PATH} PARENT_SCOPE)
set(TTMETAL_LIBRARY_PATH ${TTMETAL_LIBRARY_PATH} PARENT_SCOPE)
set(TTEAGER_LIBRARY_PATH ${TTEAGER_LIBRARY_PATH} PARENT_SCOPE)


ExternalProject_Add(
tt-metal
PREFIX ${TTMLIR_SOURCE_DIR}/third_party/tt-metal
CMAKE_GENERATOR Ninja
CMAKE_ARGS
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}
-DTRACY_ENABLE=${TT_RUNTIME_ENABLE_PERF_TRACE}
GIT_REPOSITORY https://github.com/tenstorrent/tt-metal.git
GIT_TAG v0.49.0
GIT_PROGRESS ON
BUILD_BYPRODUCTS ${TTNN_LIBRARY_PATH} ${TTMETAL_LIBRARY_PATH} ${TTEAGER_LIBRARY_PATH}
)

set_target_properties(tt-metal PROPERTIES EXCLUDE_FROM_ALL TRUE)

list(APPEND library_names TTNN_LIBRARY TTEAGER_LIBRARY TTMETAL_LIBRARY)
list(APPEND library_paths ${TTNN_LIBRARY_PATH} ${TTMETAL_LIBRARY_PATH} ${TTEAGER_LIBRARY_PATH})

foreach(lib_name lib_path IN ZIP_LISTS library_names library_paths)
add_library(${lib_name} SHARED IMPORTED GLOBAL)
set_target_properties(${lib_name} PROPERTIES EXCLUDE_FROM_ALL TRUE IMPORTED_LOCATION ${lib_path})
add_dependencies(${lib_name} tt-metal)
endforeach()
include(tt-metal.cmake)
if (TTMLIR_ENABLE_TORCH_MLIR)
include(torch-mlir.cmake)
endif ()
19 changes: 19 additions & 0 deletions third_party/torch-mlir.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
include(ExternalProject)

set(TORCH_MLIR_VERSION "b1a232222f12d4e5640fd62320d02f6c832bdc4e")

ExternalProject_Add(
torch-mlir
PREFIX ${TTMLIR_TOOLCHAIN_DIR}
CMAKE_GENERATOR Ninja
CMAKE_ARGS
-DCMAKE_BUILD_TYPE=Release
-DPython3_FIND_VIRTUALENV=ONLY
-DCMAKE_INSTALL_PREFIX=${TTMLIR_TOOLCHAIN_DIR}
-DMLIR_DIR=${TTMLIR_TOOLCHAIN_DIR}/llvm-project/lib/cmake/mlir/
-DLLVM_DIR=${TTMLIR_TOOLCHAIN_DIR}/llvm-project/lib/cmake/llvm/
-DMLIR_ENABLE_BINDINGS_PYTHON=ON
-DLLVM_TARGETS_TO_BUILD=host
GIT_REPOSITORY https://github.com/llvm/torch-mlir
GIT_TAG ${TORCH_MLIR_VERSION}
)
73 changes: 73 additions & 0 deletions third_party/tt-metal.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
include(ExternalProject)

if ("$ENV{ARCH_NAME}" STREQUAL "grayskull")
set(ARCH_NAME "grayskull")
set(ARCH_EXTRA_DIR "grayskull")
elseif ("$ENV{ARCH_NAME}" STREQUAL "wormhole_b0")
set(ARCH_NAME "wormhole")
set(ARCH_EXTRA_DIR "wormhole/wormhole_b0_defines")
elseif ("$ENV{ARCH_NAME}" STREQUAL "blackhole")
set(ARCH_NAME "blackhole")
set(ARCH_EXTRA_DIR "blackhole")
else()
message(FATAL_ERROR "Unsupported ARCH_NAME: $ENV{ARCH_NAME}")
endif()

if (TT_RUNTIME_ENABLE_PERF_TRACE)
add_compile_definitions(TRACY_ENABLE)
set(ENV{ENABLE_TRACY} "1")
else()
set(ENV{ENABLE_TRACY} "0")
endif()

set(TTMETAL_INCLUDE_DIRS
${PROJECT_SOURCE_DIR}/third_party/tt-metal/src/tt-metal/ttnn/cpp
${PROJECT_SOURCE_DIR}/third_party/tt-metal/src/tt-metal
${PROJECT_SOURCE_DIR}/third_party/tt-metal/src/tt-metal/tt_metal
${PROJECT_SOURCE_DIR}/third_party/tt-metal/src/tt-metal/tt_metal/third_party/umd
${PROJECT_SOURCE_DIR}/third_party/tt-metal/src/tt-metal/tt_metal/third_party/fmt
${PROJECT_SOURCE_DIR}/third_party/tt-metal/src/tt-metal/tt_metal/hw/inc
${PROJECT_SOURCE_DIR}/third_party/tt-metal/src/tt-metal/tt_metal/hw/inc/${ARCH_NAME}
${PROJECT_SOURCE_DIR}/third_party/tt-metal/src/tt-metal/tt_metal/hw/inc/${ARCH_EXTRA_DIR}
${PROJECT_SOURCE_DIR}/third_party/tt-metal/src/tt-metal/tt_metal/third_party/umd/src/firmware/riscv/${ARCH_NAME}
${PROJECT_SOURCE_DIR}/third_party/tt-metal/src/tt-metal/tt_eager
PARENT_SCOPE
)

set(TTMETAL_LIBRARY_DIR ${PROJECT_SOURCE_DIR}/third_party/tt-metal/src/tt-metal-build/lib)
set(TTNN_LIBRARY_PATH ${TTMETAL_LIBRARY_DIR}/_ttnn.so)
set(TTMETAL_LIBRARY_PATH ${TTMETAL_LIBRARY_DIR}/libtt_metal.so)
set(TTEAGER_LIBRARY_PATH ${TTMETAL_LIBRARY_DIR}/libtt_eager.so)

set(TTMETAL_LIBRARY_DIR ${TTMETAL_LIBRARY_DIR} PARENT_SCOPE)
set(TTNN_LIBRARY_PATH ${TTNN_LIBRARY_PATH} PARENT_SCOPE)
set(TTMETAL_LIBRARY_PATH ${TTMETAL_LIBRARY_PATH} PARENT_SCOPE)
set(TTEAGER_LIBRARY_PATH ${TTEAGER_LIBRARY_PATH} PARENT_SCOPE)


ExternalProject_Add(
tt-metal
PREFIX ${TTMLIR_SOURCE_DIR}/third_party/tt-metal
CMAKE_GENERATOR Ninja
CMAKE_ARGS
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}
-DTRACY_ENABLE=${TT_RUNTIME_ENABLE_PERF_TRACE}
GIT_REPOSITORY https://github.com/tenstorrent/tt-metal.git
GIT_TAG v0.49.0
GIT_PROGRESS ON
BUILD_BYPRODUCTS ${TTNN_LIBRARY_PATH} ${TTMETAL_LIBRARY_PATH} ${TTEAGER_LIBRARY_PATH}
)

set_target_properties(tt-metal PROPERTIES EXCLUDE_FROM_ALL TRUE)

list(APPEND library_names TTNN_LIBRARY TTEAGER_LIBRARY TTMETAL_LIBRARY)
list(APPEND library_paths ${TTNN_LIBRARY_PATH} ${TTMETAL_LIBRARY_PATH} ${TTEAGER_LIBRARY_PATH})

foreach(lib_name lib_path IN ZIP_LISTS library_names library_paths)
add_library(${lib_name} SHARED IMPORTED GLOBAL)
set_target_properties(${lib_name} PROPERTIES EXCLUDE_FROM_ALL TRUE IMPORTED_LOCATION ${lib_path})
add_dependencies(${lib_name} tt-metal)
endforeach()
Loading