-
Notifications
You must be signed in to change notification settings - Fork 105
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
LightMetal - Initial Host API + Device Capture infra/library and unit tests (#17039) #17514
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
set(UNIT_TESTS_LIGHTMETAL_SRC ${CMAKE_CURRENT_SOURCE_DIR}/test_lightmetal.cpp) | ||
|
||
add_executable(unit_tests_lightmetal ${UNIT_TESTS_LIGHTMETAL_SRC}) | ||
TT_ENABLE_UNITY_BUILD(unit_tests_lightmetal) | ||
|
||
target_link_libraries(unit_tests_lightmetal PUBLIC test_metal_common_libs) | ||
|
||
target_include_directories( | ||
unit_tests_lightmetal | ||
PRIVATE | ||
"$<TARGET_PROPERTY:Metalium::Metal,INCLUDE_DIRECTORIES>" | ||
${PROJECT_SOURCE_DIR}/tests | ||
${PROJECT_SOURCE_DIR}/tests/tt_metal/tt_metal/common | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
${CMAKE_CURRENT_SOURCE_DIR}/common | ||
) | ||
|
||
set_target_properties( | ||
unit_tests_lightmetal | ||
PROPERTIES | ||
RUNTIME_OUTPUT_DIRECTORY | ||
${PROJECT_BINARY_DIR}/test/tt_metal | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// SPDX-FileCopyrightText: © 2025 Tenstorrent Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include "dispatch_fixture.hpp" | ||
#include <tt-metalium/device_impl.hpp> | ||
#include <tt-metalium/hal.hpp> | ||
#include <tt-metalium/host_api.hpp> | ||
#include <tt-metalium/tt_metal.hpp> | ||
#include <circular_buffer_constants.h> | ||
#include <tt-metalium/kernel.hpp> | ||
#include <tt-metalium/tt_backend_api_types.hpp> | ||
#include "command_queue_fixture.hpp" | ||
#include <lightmetal_binary.hpp> | ||
|
||
class SingleDeviceLightMetalFixture : public CommandQueueFixture { | ||
protected: | ||
std::string trace_bin_path_; | ||
bool write_bin_to_disk_; | ||
Comment on lines
+20
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can these two be specified by a single env variable that specifies Alternatively, this can be boolean, and we can always write to a random location in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I iterated on this a bit last year before ending up in current state. It might change in the future as tests evolve, but for now prefer to keep it as is because:
|
||
|
||
void SetUp() override { | ||
this->validate_dispatch_mode(); | ||
this->arch_ = tt::get_arch_from_string(tt::test_utils::get_umd_arch_name()); | ||
} | ||
|
||
void CreateDeviceAndBeginCapture( | ||
const size_t trace_region_size, const bool replay_binary = true, const std::string trace_bin_path = "") { | ||
// Skip writing to disk by default, unless user sets env var for local testing | ||
write_bin_to_disk_ = tt::parse_env("LIGHTMETAL_SAVE_BINARY", false); | ||
|
||
// If user didn't provide a specific trace bin path, set a default here based on test name | ||
if (trace_bin_path == "") { | ||
const auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); | ||
auto trace_filename = test_info ? std::string(test_info->name()) + ".bin" : "lightmetal_trace.bin"; | ||
this->trace_bin_path_ = "/tmp/" + trace_filename; | ||
} | ||
|
||
this->create_device(trace_region_size); | ||
// TODO (kmabee) - revisit placement. CreateDevice() path calls CreateKernel() on programs not | ||
// created with CreateProgram() traced API which leads to "program not in global_id map" | ||
LightMetalBeginCapture(); | ||
} | ||
|
||
// End light metal tracing, write to optional filename and optionally run from binary blob | ||
void TearDown() override { | ||
LightMetalBinary binary = LightMetalEndCapture(); | ||
|
||
if (binary.is_empty()) { | ||
FAIL() << "Light Metal Binary is empty for test, unexpected."; | ||
} | ||
if (write_bin_to_disk_ && !this->trace_bin_path_.empty() && !binary.is_empty()) { | ||
log_info(tt::LogTest, "Writing light metal binary {} bytes to {}", binary.size(), this->trace_bin_path_); | ||
binary.save_to_file(this->trace_bin_path_); | ||
} | ||
|
||
if (!this->IsSlowDispatch()) { | ||
tt::tt_metal::CloseDevice(this->device_); | ||
} | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cmake/C++ define temporary for next little bit, just here as quick way to disable feature from compile time. Plan to remove this in a few weeks once it's settled.