-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ttnn runtime debug lib, minor cmake cleanup
- Loading branch information
Showing
63 changed files
with
512 additions
and
305 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
if (NOT TTNN_RUNTIME_ENABLED OR NOT TT_RUNTIME_DEBUG) | ||
add_library(TTRuntimeTTNNDebug INTERFACE) | ||
return() | ||
endif() | ||
|
||
add_library(TTRuntimeTTNNDebug | ||
STATIC | ||
debug_apis.cpp | ||
) | ||
set_property(TARGET TTRuntimeTTNNDebug PROPERTY CXX_STANDARD 20) | ||
target_compile_options(TTRuntimeTTNNDebug PUBLIC -mavx -mavx2) | ||
target_include_directories(TTRuntimeTTNNDebug PUBLIC | ||
${PROJECT_SOURCE_DIR}/runtime/include | ||
${PROJECT_SOURCE_DIR}/runtime/lib/ttnn/include | ||
${PROJECT_BINARY_DIR}/include/ttmlir/Target/Common | ||
) | ||
target_include_directories(TTRuntimeTTNNDebug SYSTEM PUBLIC "$<BUILD_INTERFACE:${TTMETAL_INCLUDE_DIRS}>") | ||
add_dependencies(TTRuntimeTTNNDebug TTRuntimeTTNNUtils) | ||
target_link_libraries(TTRuntimeTTNNDebug PUBLIC TTRuntimeTTNNUtils) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// SPDX-FileCopyrightText: (c) 2024 Tenstorrent AI ULC | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#if !defined(TT_RUNTIME_DEBUG) || !TT_RUNTIME_DEBUG | ||
#error "TT_RUNTIME_DEBUG must be defined and set" | ||
#endif | ||
|
||
#include "tt/runtime/ttnn/debug_apis.h" | ||
#include "tt/runtime/detail/logger.h" | ||
#include "tt/runtime/ttnn/utils.h" | ||
|
||
namespace tt::runtime::ttnn::debug { | ||
|
||
static std::string toString(::ttnn::Layout layout) { | ||
switch (layout) { | ||
case ::ttnn::Layout::ROW_MAJOR: | ||
return "ROW_MAJOR"; | ||
case ::ttnn::Layout::TILE: | ||
return "TILE"; | ||
case ::ttnn::Layout::INVALID: | ||
return "INVALID"; | ||
} | ||
} | ||
|
||
static std::string toString(::ttnn::DataType dtype) { | ||
switch (dtype) { | ||
case ::ttnn::DataType::FLOAT32: | ||
return "FLOAT32"; | ||
case ::ttnn::DataType::BFLOAT16: | ||
return "BFLOAT16"; | ||
case ::ttnn::DataType::BFLOAT8_B: | ||
return "BFLOAT8_B"; | ||
case ::ttnn::DataType::BFLOAT4_B: | ||
return "BFLOAT4_B"; | ||
case ::ttnn::DataType::UINT32: | ||
return "UINT32"; | ||
case ::ttnn::DataType::UINT16: | ||
return "UINT16"; | ||
case ::ttnn::DataType::UINT8: | ||
return "UINT8"; | ||
case ::ttnn::DataType::INT32: | ||
return "INT32"; | ||
case ::ttnn::DataType::INVALID: | ||
return "INVALID"; | ||
} | ||
} | ||
|
||
void checkTensorRefMatchesTTNNTensor( | ||
const ::tt::target::ttnn::TensorRef *tensorRef, | ||
const ::ttnn::Tensor &ttnnTensor) { | ||
::ttnn::Layout expectedLayout = | ||
::tt::runtime::ttnn::utils::inferLayoutFromTileShape(tensorRef); | ||
::ttnn::Layout actualLayout = ttnnTensor.get_layout(); | ||
DEBUG_ASSERT(expectedLayout == actualLayout, "Layout mismatch, expected ", | ||
toString(expectedLayout), ", got ", toString(actualLayout)); | ||
|
||
::ttnn::DataType expectedDataType = | ||
::tt::runtime::ttnn::utils::toTTNNDataType( | ||
tensorRef->desc()->layout()->memory_desc()->data_type()); | ||
::ttnn::DataType actualDataType = ttnnTensor.get_dtype(); | ||
DEBUG_ASSERT(expectedDataType == actualDataType, | ||
"DataType mismatch, expected ", toString(expectedDataType), | ||
", got ", toString(actualDataType)); | ||
|
||
// TODO (jnie): Compare storage once we correctly determine it in the | ||
// flatbuffer. This requires compiler support which is missing. | ||
// | ||
// ::ttnn::StorageType expectedStorageType = | ||
// ::tt::runtime::ttnn::utils::toTTNNStorageType( | ||
// tensorRef->desc()->layout()->memory_desc()->storage_type()); | ||
// ::ttnn::StorageType actualStorageType = | ||
// ttnnTensor.storage_type(); | ||
// DEBUG_ASSERT(expectedStorageType == actualStorageType, "Storage type | ||
// mismatch, expected ", static_cast<int>(expectedStorageType), ", got ", | ||
// static_cast<int>(actualStorageType)); | ||
|
||
if (!::tt::runtime::ttnn::utils::inSystemMemory(tensorRef)) { | ||
const ::tt::target::ttnn::MemoryConfig *memcfg = | ||
::tt::runtime::ttnn::utils::getTensorRefMemoryConfig(tensorRef); | ||
DEBUG_ASSERT(memcfg, "Device tensor must have memory config"); | ||
::ttnn::MemoryConfig expectedMemoryConfig = | ||
::tt::runtime::ttnn::utils::createMemoryConfigIfNeeded(memcfg).value(); | ||
::ttnn::MemoryConfig actualMemoryConfig = ttnnTensor.memory_config(); | ||
DEBUG_ASSERT(expectedMemoryConfig == actualMemoryConfig, | ||
"Memory config mismatch, expected ", expectedMemoryConfig, | ||
", got ", actualMemoryConfig); | ||
} | ||
} | ||
} // namespace tt::runtime::ttnn::debug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SPDX-FileCopyrightText: (c) 2024 Tenstorrent AI ULC | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#ifndef TT_RUNTIME_TTNN_DEBUG_APIS_H | ||
#define TT_RUNTIME_TTNN_DEBUG_APIS_H | ||
|
||
#include "tt/runtime/detail/ttnn.h" | ||
#include "ttmlir/Target/TTNN/Target.h" | ||
|
||
#if defined(TT_RUNTIME_DEBUG) && TT_RUNTIME_DEBUG == 1 | ||
#define RUNTIME_DEBUG_MAYBE_CONST_INLINE | ||
#else | ||
#define RUNTIME_DEBUG_MAYBE_CONST_INLINE \ | ||
inline __attribute__((always_inline, const)) | ||
#endif | ||
|
||
namespace tt::runtime::ttnn::debug { | ||
|
||
RUNTIME_DEBUG_MAYBE_CONST_INLINE void | ||
checkTensorRefMatchesTTNNTensor(const ::tt::target::ttnn::TensorRef *tensorRef, | ||
const ::ttnn::Tensor &ttnnTensor) | ||
#if defined(TT_RUNTIME_DEBUG) && TT_RUNTIME_DEBUG == 1 | ||
; | ||
#else | ||
{ | ||
} | ||
#endif | ||
|
||
#undef RUNTIME_DEBUG_MAYBE_CONST_INLINE | ||
|
||
} // namespace tt::runtime::ttnn::debug | ||
|
||
#endif // TT_RUNTIME_TTNN_DEBUG_APIS_H |
Oops, something went wrong.