Skip to content

Commit

Permalink
Upgrade tt-metal to f6a2e5cb2b857bf4c72401bea68adf98c25bbe47 (#328)
Browse files Browse the repository at this point in the history
  • Loading branch information
nsmithtt authored Aug 8, 2024
1 parent ed88fe3 commit 83c705c
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 29 deletions.
2 changes: 1 addition & 1 deletion lib/SharedLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set(TTNN_RUNTIME_LIBS TTRuntime TTRuntimeTTNN TTBinary)

# Dependency libs from tt-metal/ttnn project for ttnn runtime
set(TTNN_LIBS TTMETAL_LIBRARY TTEAGER_LIBRARY TTNN_LIBRARY)
set(TTNN_LIBS TTMETAL_LIBRARY TTNN_LIBRARY)

# Libs from tt-mlir project
set(TTMLIR_LIBS
Expand Down
6 changes: 6 additions & 0 deletions runtime/include/tt/runtime/detail/ttmetal.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
#pragma clang diagnostic ignored "-Wunused-function"
#pragma clang diagnostic ignored "-Wpessimizing-move"
#pragma clang diagnostic ignored "-Wparentheses"
#pragma clang diagnostic ignored "-Wdeprecated-volatile"
#pragma clang diagnostic ignored "-Wdeprecated-this-capture"
#pragma clang diagnostic ignored "-Wc++23-extensions"
#pragma clang diagnostic ignored "-Wunused-but-set-variable"
#pragma clang diagnostic ignored "-Wlogical-op-parentheses"
#pragma clang diagnostic ignored "-Wundefined-inline"
#define FMT_HEADER_ONLY
#include "tt_metal/host_api.hpp"
#pragma clang diagnostic pop
Expand Down
16 changes: 12 additions & 4 deletions runtime/include/tt/runtime/detail/ttnn.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,22 @@
#pragma clang diagnostic ignored "-Wunused-function"
#pragma clang diagnostic ignored "-Wpessimizing-move"
#pragma clang diagnostic ignored "-Wparentheses"
#pragma clang diagnostic ignored "-Wdeprecated-volatile"
#pragma clang diagnostic ignored "-Wdeprecated-this-capture"
#pragma clang diagnostic ignored "-Wc++23-extensions"
#pragma clang diagnostic ignored "-Wunused-but-set-variable"
#pragma clang diagnostic ignored "-Wlogical-op-parentheses"
#pragma clang diagnostic ignored "-Wundefined-inline"
#define FMT_HEADER_ONLY
#include "ttnn/device.hpp"
#include "ttnn/operations/binary.hpp"
#include "ttnn/operations/copy.hpp"
#include "ttnn/operations/core.hpp"
#include "ttnn/operations/core/core.hpp"
#include "ttnn/operations/creation.hpp"
#include "ttnn/operations/matmul.hpp"
#include "ttnn/operations/normalization.hpp"
#include "ttnn/operations/data_movement/permute/permute.hpp"
#include "ttnn/operations/eltwise/binary/binary.hpp"
#include "ttnn/operations/eltwise/unary/unary.hpp"
#include "ttnn/operations/matmul/matmul.hpp"
#include "ttnn/operations/normalization/softmax/softmax.hpp"
#include "ttnn/operations/reduction/generic/generic_reductions.hpp"
#pragma clang diagnostic pop

Expand Down
1 change: 1 addition & 0 deletions runtime/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ endif()

message(STATUS "TT_RUNTIME_ENABLE_TTNN: ${TT_RUNTIME_ENABLE_TTNN} ${TT_RUNTIME_ENABLE_TTMETAL}")
add_library(TTRuntime STATIC runtime.cpp)
set_property(TARGET TTRuntime PROPERTY CXX_STANDARD 20)
if (TTMLIR_ENABLE_RUNTIME AND TT_RUNTIME_ENABLE_TTNN)
target_compile_definitions(TTRuntime PUBLIC TT_RUNTIME_ENABLE_TTNN)
endif()
Expand Down
2 changes: 2 additions & 0 deletions runtime/lib/ttmetal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ add_library(TTRuntimeTTMetal
runtime.cpp
command_queue.cpp
)
# We have to set the C++ standard to 20 because tt-metal requires it
set_property(TARGET TTRuntimeTTMetal PROPERTY CXX_STANDARD 20)
target_include_directories(TTRuntimeTTMetal PUBLIC
${PROJECT_SOURCE_DIR}/runtime/include
${PROJECT_BINARY_DIR}/include/ttmlir/Target/Common
Expand Down
2 changes: 2 additions & 0 deletions runtime/lib/ttnn/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ add_library(TTRuntimeTTNN
runtime.cpp
program.cpp
)
# We have to set the C++ standard to 20 because tt-metal requires it
set_property(TARGET TTRuntimeTTNN PROPERTY CXX_STANDARD 20)
target_compile_options(TTRuntimeTTNN PRIVATE -mavx -mavx2)
target_include_directories(TTRuntimeTTNN PUBLIC
${PROJECT_SOURCE_DIR}/runtime/include
Expand Down
21 changes: 5 additions & 16 deletions runtime/lib/ttnn/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@
#include "ttmlir/Target/TTNN/Target.h"
#include "ttmlir/Version.h"

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wignored-qualifiers"
// Including this in ttnn.h causes multiple definition linker error
// due to non-inlined function definitions
#include "ttnn/operations/unary.hpp"
#pragma clang diagnostic ignored "-Wsign-compare"
#pragma clang diagnostic ignored "-Wunused-variable"
#include "ttnn/operations/data_movement.hpp"
#pragma clang diagnostic pop

// It seems like `ttnn::to_layout` cannot be called inside of the
// `tt::runtime::ttnn` namespace. TTNN uses a lot of metaprogramming and for
// some reason a static_assert fails when this is called from within our
Expand Down Expand Up @@ -56,7 +46,7 @@ static ::ttnn::Tensor convertDataType(const ::ttnn::Tensor &input,
}
return ::ttnn::typecast(input, targetDataType);
} else {
throw runtime_error("Unsupported storage type");
throw std::runtime_error("Unsupported storage type");
}
}

Expand Down Expand Up @@ -288,7 +278,7 @@ run(::tt::target::ttnn::TransposeOp const *op, ::ttnn::device::Device &device,
int32_t dimension1 = op->dimension1();
int32_t dimension2 = op->dimension2();
auto input_rank = in.get_shape().rank();
std::vector<int> dimensionOrder(input_rank);
std::vector<std::int64_t> dimensionOrder(input_rank);
std::iota(dimensionOrder.begin(), dimensionOrder.end(), 0);
if (dimension1 < 0) {
dimension1 += input_rank;
Expand All @@ -297,8 +287,7 @@ run(::tt::target::ttnn::TransposeOp const *op, ::ttnn::device::Device &device,
dimension2 += input_rank;
}
std::swap(dimensionOrder[dimension1], dimensionOrder[dimension2]);
tensorPool.push_back(
::ttnn::operations::data_movement::permute(in, dimensionOrder));
tensorPool.push_back(::ttnn::permute(in, dimensionOrder));
liveTensors.try_emplace(op->out()->global_id(), &tensorPool.back());
}

Expand All @@ -309,8 +298,8 @@ run(::tt::target::ttnn::MatmulOp const *op, ::ttnn::Device &device,
std::list<::ttnn::Tensor> &tensorPool) {
auto &lhs = *liveTensors.at(op->in0()->global_id());
auto &rhs = *liveTensors.at(op->in1()->global_id());
tensorPool.push_back(
::ttnn::operations::matmul::matmul(lhs, rhs, std::nullopt));
tensorPool.push_back(::ttnn::operations::matmul::matmul(
lhs, rhs, std::nullopt, ::tt::operations::primary::Matmul{}));
liveTensors.try_emplace(op->out()->global_id(), &tensorPool.back());
}
// ANCHOR_END: adding_an_op_matmul_runtime
Expand Down
3 changes: 1 addition & 2 deletions runtime/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ if (NOT FLATBUFFERS_LIB)
endif()

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

target_link_libraries(TTRuntimeTEST INTERFACE
TTEAGER_LIBRARY
TTMETAL_LIBRARY
TTBinary
TTRuntime
Expand Down
12 changes: 6 additions & 6 deletions third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ 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/ttnn/cpp/ttnn/deprecated
${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
Expand All @@ -31,18 +32,17 @@ set(TTMETAL_INCLUDE_DIRS
${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
${PROJECT_SOURCE_DIR}/third_party/tt-metal/src/tt-metal/.cpmcache/reflect/e75434c4c5f669e4a74e4d84e0a30d7249c1e66f
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
Expand All @@ -55,15 +55,15 @@ ExternalProject_Add(
-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_TAG f6a2e5cb2b857bf4c72401bea68adf98c25bbe47
GIT_PROGRESS ON
BUILD_BYPRODUCTS ${TTNN_LIBRARY_PATH} ${TTMETAL_LIBRARY_PATH} ${TTEAGER_LIBRARY_PATH}
BUILD_BYPRODUCTS ${TTNN_LIBRARY_PATH} ${TTMETAL_LIBRARY_PATH}
)

set_target_properties(tt-metal PROPERTIES EXCLUDE_FROM_ALL TRUE)

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

foreach(lib_name lib_path IN ZIP_LISTS library_names library_paths)
add_library(${lib_name} SHARED IMPORTED GLOBAL)
Expand Down

0 comments on commit 83c705c

Please sign in to comment.