Skip to content

Commit

Permalink
replace extern RunTimeOptions OptionG; with RunTimeOptions::get_insta…
Browse files Browse the repository at this point in the history
…nce() to avoid edge-case bugs with order of initialization of static variables.
  • Loading branch information
mbezuljTT committed Dec 10, 2024
1 parent 60373c8 commit ab63bc4
Show file tree
Hide file tree
Showing 52 changed files with 321 additions and 298 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ class CompileProgramWithKernelPathEnvVarFixture : public ::testing::Test {
}

void setup_kernel_dir(const string& orig_kernel_file, const string& new_kernel_file) {
const string& kernel_dir = llrt::OptionsG.get_kernel_dir();
const string& kernel_dir = llrt::RunTimeOptions::get_instance().get_kernel_dir();
const std::filesystem::path& kernel_file_path_under_kernel_dir(kernel_dir + new_kernel_file);
const std::filesystem::path& dirs_under_kernel_dir = kernel_file_path_under_kernel_dir.parent_path();
std::filesystem::create_directories(dirs_under_kernel_dir);

const string& metal_root = llrt::OptionsG.get_root_dir();
const string& metal_root = llrt::RunTimeOptions::get_instance().get_root_dir();
const std::filesystem::path& kernel_file_path_under_metal_root(metal_root + orig_kernel_file);
std::filesystem::copy(kernel_file_path_under_metal_root, kernel_file_path_under_kernel_dir);
}

void cleanup_kernel_dir() {
const string& kernel_dir = llrt::OptionsG.get_kernel_dir();
const string& kernel_dir = llrt::RunTimeOptions::get_instance().get_kernel_dir();
for (const std::filesystem::directory_entry& entry : std::filesystem::directory_iterator(kernel_dir)) {
std::filesystem::remove_all(entry);
}
Expand All @@ -63,11 +63,11 @@ class CompileProgramWithKernelPathEnvVarFixture : public ::testing::Test {

bool are_env_vars_set() {
bool are_set = true;
if (!llrt::OptionsG.is_root_dir_specified()) {
if (!llrt::RunTimeOptions::get_instance().is_root_dir_specified()) {
log_info(LogTest, "Skipping test: TT_METAL_HOME must be set");
are_set = false;
}
if (!llrt::OptionsG.is_kernel_dir_specified()) {
if (!llrt::RunTimeOptions::get_instance().is_kernel_dir_specified()) {
log_info(LogTest, "Skipping test: TT_METAL_KERNEL_PATH must be set");
are_set = false;
}
Expand All @@ -76,7 +76,7 @@ class CompileProgramWithKernelPathEnvVarFixture : public ::testing::Test {

bool is_kernel_dir_valid() {
bool is_valid = true;
const string& kernel_dir = llrt::OptionsG.get_kernel_dir();
const string& kernel_dir = llrt::RunTimeOptions::get_instance().get_kernel_dir();
if (!this->does_path_exist(kernel_dir) || !this->is_path_a_directory(kernel_dir) ||
!this->is_dir_empty(kernel_dir)) {
log_info(LogTest, "Skipping test: TT_METAL_KERNEL_PATH must be an existing, empty directory");
Expand Down
6 changes: 3 additions & 3 deletions tests/tt_metal/tt_metal/common/command_queue_fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class CommandQueueFixture : public DispatchFixture {

void create_device(const size_t trace_region_size = DEFAULT_TRACE_REGION_SIZE) {
const chip_id_t device_id = 0;
const auto& dispatch_core_config = tt::llrt::OptionsG.get_dispatch_core_config();
const auto& dispatch_core_config = tt::llrt::RunTimeOptions::get_instance().get_dispatch_core_config();
this->device_ =
tt::tt_metal::CreateDevice(device_id, 1, DEFAULT_L1_SMALL_SIZE, trace_region_size, dispatch_core_config);
}
Expand Down Expand Up @@ -88,7 +88,7 @@ class CommandQueueSingleCardFixture : virtual public DispatchFixture {
}

void create_devices(const std::size_t trace_region_size = DEFAULT_TRACE_REGION_SIZE) {
const auto& dispatch_core_config = tt::llrt::OptionsG.get_dispatch_core_config();
const auto& dispatch_core_config = tt::llrt::RunTimeOptions::get_instance().get_dispatch_core_config();
const chip_id_t mmio_device_id = 0;
this->reserved_devices_ = tt::tt_metal::detail::CreateDevices(
{mmio_device_id}, 1, DEFAULT_L1_SMALL_SIZE, trace_region_size, dispatch_core_config);
Expand Down Expand Up @@ -143,7 +143,7 @@ class CommandQueueMultiDeviceFixture : public DispatchFixture {
chip_ids.push_back(id);
}

const auto& dispatch_core_config = tt::llrt::OptionsG.get_dispatch_core_config();
const auto& dispatch_core_config = tt::llrt::RunTimeOptions::get_instance().get_dispatch_core_config();
reserved_devices_ = tt::tt_metal::detail::CreateDevices(
chip_ids, 1, DEFAULT_L1_SMALL_SIZE, DEFAULT_TRACE_REGION_SIZE, dispatch_core_config);
for (const auto& [id, device] : reserved_devices_) {
Expand Down
2 changes: 1 addition & 1 deletion tests/tt_metal/tt_metal/common/device_fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class DeviceFixture : public DispatchFixture {
}

void create_devices(const std::vector<chip_id_t>& device_ids) {
const auto& dispatch_core_config = tt::llrt::OptionsG.get_dispatch_core_config();
const auto& dispatch_core_config = tt::llrt::RunTimeOptions::get_instance().get_dispatch_core_config();
tt::DevicePool::initialize(
device_ids, 1, DEFAULT_L1_SMALL_SIZE, DEFAULT_TRACE_REGION_SIZE, dispatch_core_config);
this->devices_ = tt::DevicePool::instance().get_all_active_devices();
Expand Down
4 changes: 2 additions & 2 deletions tests/tt_metal/tt_metal/common/dispatch_fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ class DispatchFixture : public ::testing::Test {
}
ids.push_back(id);
}
const auto& dispatch_core_config = tt::llrt::OptionsG.get_dispatch_core_config();
const auto& dispatch_core_config = tt::llrt::RunTimeOptions::get_instance().get_dispatch_core_config();
tt::DevicePool::initialize(
ids,
tt::llrt::OptionsG.get_num_hw_cqs(),
tt::llrt::RunTimeOptions::get_instance().get_num_hw_cqs(),
DEFAULT_L1_SMALL_SIZE,
DEFAULT_TRACE_REGION_SIZE,
dispatch_core_config);
Expand Down
2 changes: 1 addition & 1 deletion tests/tt_metal/tt_metal/common/multi_device_fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class N300DeviceFixture : public MultiDeviceFixture {
ids.push_back(id);
}

const auto& dispatch_core_config = tt::llrt::OptionsG.get_dispatch_core_config();
const auto& dispatch_core_config = tt::llrt::RunTimeOptions::get_instance().get_dispatch_core_config();
tt::DevicePool::initialize(ids, 1, DEFAULT_L1_SMALL_SIZE, DEFAULT_TRACE_REGION_SIZE, dispatch_core_config);
this->devices_ = tt::DevicePool::instance().get_all_active_devices();
} else {
Expand Down
98 changes: 49 additions & 49 deletions tests/tt_metal/tt_metal/debug_tools/debug_tools_fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DebugToolsFixture : public DispatchFixture {

void TearDown() override {
DispatchFixture::TearDown();
tt::llrt::OptionsG.set_watcher_enabled(watcher_previous_enabled);
tt::llrt::RunTimeOptions::get_instance().set_watcher_enabled(watcher_previous_enabled);
}

template <typename T>
Expand Down Expand Up @@ -45,17 +45,17 @@ class DPrintFixture : public DebugToolsFixture {
// The core range (physical) needs to be set >= the set of all cores
// used by all tests using this fixture, so set dprint enabled for
// all cores and all devices
tt::llrt::OptionsG.set_feature_enabled(tt::llrt::RunTimeDebugFeatureDprint, true);
tt::llrt::OptionsG.set_feature_all_cores(
tt::llrt::RunTimeOptions::get_instance().set_feature_enabled(tt::llrt::RunTimeDebugFeatureDprint, true);
tt::llrt::RunTimeOptions::get_instance().set_feature_all_cores(
tt::llrt::RunTimeDebugFeatureDprint, CoreType::WORKER, tt::llrt::RunTimeDebugClassWorker);
tt::llrt::OptionsG.set_feature_all_cores(
tt::llrt::RunTimeOptions::get_instance().set_feature_all_cores(
tt::llrt::RunTimeDebugFeatureDprint, CoreType::ETH, tt::llrt::RunTimeDebugClassWorker);
tt::llrt::OptionsG.set_feature_all_chips(tt::llrt::RunTimeDebugFeatureDprint, true);
tt::llrt::RunTimeOptions::get_instance().set_feature_all_chips(tt::llrt::RunTimeDebugFeatureDprint, true);
// Send output to a file so the test can check after program is run.
tt::llrt::OptionsG.set_feature_file_name(tt::llrt::RunTimeDebugFeatureDprint, dprint_file_name);
tt::llrt::OptionsG.set_test_mode_enabled(true);
watcher_previous_enabled = tt::llrt::OptionsG.get_watcher_enabled();
tt::llrt::OptionsG.set_watcher_enabled(false);
tt::llrt::RunTimeOptions::get_instance().set_feature_file_name(tt::llrt::RunTimeDebugFeatureDprint, dprint_file_name);
tt::llrt::RunTimeOptions::get_instance().set_test_mode_enabled(true);
watcher_previous_enabled = tt::llrt::RunTimeOptions::get_instance().get_watcher_enabled();
tt::llrt::RunTimeOptions::get_instance().set_watcher_enabled(false);

ExtraSetUp();

Expand All @@ -71,15 +71,15 @@ class DPrintFixture : public DebugToolsFixture {
std::remove(dprint_file_name.c_str());

// Reset DPrint settings
tt::llrt::OptionsG.set_feature_cores(tt::llrt::RunTimeDebugFeatureDprint, {});
tt::llrt::OptionsG.set_feature_enabled(tt::llrt::RunTimeDebugFeatureDprint, false);
tt::llrt::OptionsG.set_feature_all_cores(
tt::llrt::RunTimeOptions::get_instance().set_feature_cores(tt::llrt::RunTimeDebugFeatureDprint, {});
tt::llrt::RunTimeOptions::get_instance().set_feature_enabled(tt::llrt::RunTimeDebugFeatureDprint, false);
tt::llrt::RunTimeOptions::get_instance().set_feature_all_cores(
tt::llrt::RunTimeDebugFeatureDprint, CoreType::WORKER, tt::llrt::RunTimeDebugClassNoneSpecified);
tt::llrt::OptionsG.set_feature_all_cores(
tt::llrt::RunTimeOptions::get_instance().set_feature_all_cores(
tt::llrt::RunTimeDebugFeatureDprint, CoreType::ETH, tt::llrt::RunTimeDebugClassNoneSpecified);
tt::llrt::OptionsG.set_feature_all_chips(tt::llrt::RunTimeDebugFeatureDprint, false);
tt::llrt::OptionsG.set_feature_file_name(tt::llrt::RunTimeDebugFeatureDprint, "");
tt::llrt::OptionsG.set_test_mode_enabled(false);
tt::llrt::RunTimeOptions::get_instance().set_feature_all_chips(tt::llrt::RunTimeDebugFeatureDprint, false);
tt::llrt::RunTimeOptions::get_instance().set_feature_file_name(tt::llrt::RunTimeDebugFeatureDprint, "");
tt::llrt::RunTimeOptions::get_instance().set_test_mode_enabled(false);
}

void RunTestOnDevice(
Expand All @@ -101,8 +101,8 @@ class DPrintDisableDevicesFixture : public DPrintFixture {
protected:
void ExtraSetUp() override {
// For this test, mute each devices using the environment variable
tt::llrt::OptionsG.set_feature_all_chips(tt::llrt::RunTimeDebugFeatureDprint, false);
tt::llrt::OptionsG.set_feature_chip_ids(tt::llrt::RunTimeDebugFeatureDprint, {});
tt::llrt::RunTimeOptions::get_instance().set_feature_all_chips(tt::llrt::RunTimeDebugFeatureDprint, false);
tt::llrt::RunTimeOptions::get_instance().set_feature_chip_ids(tt::llrt::RunTimeDebugFeatureDprint, {});
}
};

Expand Down Expand Up @@ -135,20 +135,20 @@ class WatcherFixture : public DebugToolsFixture {
bool test_mode_previous;
void SetUp() override {
// Enable watcher for this test, save the previous state so we can restore it later.
watcher_previous_enabled = tt::llrt::OptionsG.get_watcher_enabled();
watcher_previous_interval = tt::llrt::OptionsG.get_watcher_interval();
watcher_previous_dump_all = tt::llrt::OptionsG.get_watcher_dump_all();
watcher_previous_append = tt::llrt::OptionsG.get_watcher_append();
watcher_previous_auto_unpause = tt::llrt::OptionsG.get_watcher_auto_unpause();
watcher_previous_noinline = tt::llrt::OptionsG.get_watcher_noinline();
test_mode_previous = tt::llrt::OptionsG.get_test_mode_enabled();
tt::llrt::OptionsG.set_watcher_enabled(true);
tt::llrt::OptionsG.set_watcher_interval(interval_ms);
tt::llrt::OptionsG.set_watcher_dump_all(false);
tt::llrt::OptionsG.set_watcher_append(false);
tt::llrt::OptionsG.set_watcher_auto_unpause(true);
tt::llrt::OptionsG.set_watcher_noinline(true);
tt::llrt::OptionsG.set_test_mode_enabled(true);
watcher_previous_enabled = tt::llrt::RunTimeOptions::get_instance().get_watcher_enabled();
watcher_previous_interval = tt::llrt::RunTimeOptions::get_instance().get_watcher_interval();
watcher_previous_dump_all = tt::llrt::RunTimeOptions::get_instance().get_watcher_dump_all();
watcher_previous_append = tt::llrt::RunTimeOptions::get_instance().get_watcher_append();
watcher_previous_auto_unpause = tt::llrt::RunTimeOptions::get_instance().get_watcher_auto_unpause();
watcher_previous_noinline = tt::llrt::RunTimeOptions::get_instance().get_watcher_noinline();
test_mode_previous = tt::llrt::RunTimeOptions::get_instance().get_test_mode_enabled();
tt::llrt::RunTimeOptions::get_instance().set_watcher_enabled(true);
tt::llrt::RunTimeOptions::get_instance().set_watcher_interval(interval_ms);
tt::llrt::RunTimeOptions::get_instance().set_watcher_dump_all(false);
tt::llrt::RunTimeOptions::get_instance().set_watcher_append(false);
tt::llrt::RunTimeOptions::get_instance().set_watcher_auto_unpause(true);
tt::llrt::RunTimeOptions::get_instance().set_watcher_noinline(true);
tt::llrt::RunTimeOptions::get_instance().set_test_mode_enabled(true);
tt::watcher_clear_log();

// Parent class initializes devices and any necessary flags
Expand All @@ -160,12 +160,12 @@ class WatcherFixture : public DebugToolsFixture {
DebugToolsFixture::TearDown();

// Reset watcher settings to their previous values
tt::llrt::OptionsG.set_watcher_interval(watcher_previous_interval);
tt::llrt::OptionsG.set_watcher_dump_all(watcher_previous_dump_all);
tt::llrt::OptionsG.set_watcher_append(watcher_previous_append);
tt::llrt::OptionsG.set_watcher_auto_unpause(watcher_previous_auto_unpause);
tt::llrt::OptionsG.set_watcher_noinline(watcher_previous_noinline);
tt::llrt::OptionsG.set_test_mode_enabled(test_mode_previous);
tt::llrt::RunTimeOptions::get_instance().set_watcher_interval(watcher_previous_interval);
tt::llrt::RunTimeOptions::get_instance().set_watcher_dump_all(watcher_previous_dump_all);
tt::llrt::RunTimeOptions::get_instance().set_watcher_append(watcher_previous_append);
tt::llrt::RunTimeOptions::get_instance().set_watcher_auto_unpause(watcher_previous_auto_unpause);
tt::llrt::RunTimeOptions::get_instance().set_watcher_noinline(watcher_previous_noinline);
tt::llrt::RunTimeOptions::get_instance().set_test_mode_enabled(test_mode_previous);
tt::watcher_server_set_error_flag(false);
}

Expand All @@ -188,19 +188,19 @@ class WatcherDelayFixture : public WatcherFixture {
std::map<CoreType, std::vector<CoreCoord>> delayed_cores;

void SetUp() override {
tt::llrt::OptionsG.set_watcher_debug_delay(5000000);
tt::llrt::RunTimeOptions::get_instance().set_watcher_debug_delay(5000000);
delayed_cores[CoreType::WORKER] = {{0, 0}, {1, 1}};

// Store the previous state of the watcher features
saved_target_selection[tt::llrt::RunTimeDebugFeatureReadDebugDelay] = tt::llrt::OptionsG.get_feature_targets(tt::llrt::RunTimeDebugFeatureReadDebugDelay);
saved_target_selection[tt::llrt::RunTimeDebugFeatureWriteDebugDelay] = tt::llrt::OptionsG.get_feature_targets(tt::llrt::RunTimeDebugFeatureWriteDebugDelay);
saved_target_selection[tt::llrt::RunTimeDebugFeatureAtomicDebugDelay] = tt::llrt::OptionsG.get_feature_targets(tt::llrt::RunTimeDebugFeatureAtomicDebugDelay);
saved_target_selection[tt::llrt::RunTimeDebugFeatureReadDebugDelay] = tt::llrt::RunTimeOptions::get_instance().get_feature_targets(tt::llrt::RunTimeDebugFeatureReadDebugDelay);
saved_target_selection[tt::llrt::RunTimeDebugFeatureWriteDebugDelay] = tt::llrt::RunTimeOptions::get_instance().get_feature_targets(tt::llrt::RunTimeDebugFeatureWriteDebugDelay);
saved_target_selection[tt::llrt::RunTimeDebugFeatureAtomicDebugDelay] = tt::llrt::RunTimeOptions::get_instance().get_feature_targets(tt::llrt::RunTimeDebugFeatureAtomicDebugDelay);

// Enable read and write debug delay for the test core
tt::llrt::OptionsG.set_feature_enabled(tt::llrt::RunTimeDebugFeatureReadDebugDelay, true);
tt::llrt::OptionsG.set_feature_cores(tt::llrt::RunTimeDebugFeatureReadDebugDelay, delayed_cores);
tt::llrt::OptionsG.set_feature_enabled(tt::llrt::RunTimeDebugFeatureWriteDebugDelay, true);
tt::llrt::OptionsG.set_feature_cores(tt::llrt::RunTimeDebugFeatureWriteDebugDelay, delayed_cores);
tt::llrt::RunTimeOptions::get_instance().set_feature_enabled(tt::llrt::RunTimeDebugFeatureReadDebugDelay, true);
tt::llrt::RunTimeOptions::get_instance().set_feature_cores(tt::llrt::RunTimeDebugFeatureReadDebugDelay, delayed_cores);
tt::llrt::RunTimeOptions::get_instance().set_feature_enabled(tt::llrt::RunTimeDebugFeatureWriteDebugDelay, true);
tt::llrt::RunTimeOptions::get_instance().set_feature_cores(tt::llrt::RunTimeDebugFeatureWriteDebugDelay, delayed_cores);

// Call parent
WatcherFixture::SetUp();
Expand All @@ -211,8 +211,8 @@ class WatcherDelayFixture : public WatcherFixture {
WatcherFixture::TearDown();

// Restore
tt::llrt::OptionsG.set_feature_targets(tt::llrt::RunTimeDebugFeatureReadDebugDelay, saved_target_selection[tt::llrt::RunTimeDebugFeatureReadDebugDelay]);
tt::llrt::OptionsG.set_feature_targets(tt::llrt::RunTimeDebugFeatureWriteDebugDelay, saved_target_selection[tt::llrt::RunTimeDebugFeatureWriteDebugDelay]);
tt::llrt::OptionsG.set_feature_targets(tt::llrt::RunTimeDebugFeatureAtomicDebugDelay, saved_target_selection[tt::llrt::RunTimeDebugFeatureAtomicDebugDelay]);
tt::llrt::RunTimeOptions::get_instance().set_feature_targets(tt::llrt::RunTimeDebugFeatureReadDebugDelay, saved_target_selection[tt::llrt::RunTimeDebugFeatureReadDebugDelay]);
tt::llrt::RunTimeOptions::get_instance().set_feature_targets(tt::llrt::RunTimeDebugFeatureWriteDebugDelay, saved_target_selection[tt::llrt::RunTimeDebugFeatureWriteDebugDelay]);
tt::llrt::RunTimeOptions::get_instance().set_feature_targets(tt::llrt::RunTimeDebugFeatureAtomicDebugDelay, saved_target_selection[tt::llrt::RunTimeDebugFeatureAtomicDebugDelay]);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ TEST_F(DPrintFixture, TensixTestPrintInvalidCore) {
// device setup, but not the print server should simply ignore the invalid cores.
std::map<CoreType, std::vector<CoreCoord>> dprint_cores;
dprint_cores[CoreType::WORKER] = {{0, 0}, {1, 1}, {100, 100}};
tt::llrt::OptionsG.set_feature_cores(tt::llrt::RunTimeDebugFeatureDprint, dprint_cores);
tt::llrt::RunTimeOptions::get_instance().set_feature_cores(tt::llrt::RunTimeDebugFeatureDprint, dprint_cores);

// We expect that even though illegal worker cores were requested, device setup did not hang.
// So just make sure that device setup worked and then close the device.
for (Device* device : this->devices_) {
EXPECT_TRUE(device != nullptr);
}
tt::llrt::OptionsG.set_feature_enabled(tt::llrt::RunTimeDebugFeatureDprint, false);
tt::llrt::RunTimeOptions::get_instance().set_feature_enabled(tt::llrt::RunTimeDebugFeatureDprint, false);
}
Loading

0 comments on commit ab63bc4

Please sign in to comment.