Skip to content
Merged
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
2 changes: 1 addition & 1 deletion projects/amdsmi/include/amd_smi/impl/amd_smi_drm.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class AMDSmiDrm {
std::string find_file_in_folder(const std::string& folder, const std::string& regex);
std::vector<std::string> drm_paths_; // drm path (renderD128 for example)
std::vector<amdsmi_bdf_t> drm_bdfs_; // bdf
uint32_t vendor_id;
uint32_t vendor_id = 0;

AMDSmiLibraryLoader lib_loader_; // lazy load libdrm

Expand Down
2 changes: 1 addition & 1 deletion projects/amdsmi/include/amd_smi/impl/amd_smi_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class AMDSmiSystem {
amdsmi_status_t populate_brcm_switch_devices();
uint64_t init_flag_;
AMDSmiDrm drm_;
smi_nic_ctx_t ainic_ctx_;
smi_nic_ctx_t ainic_ctx_ = nullptr;
std::vector<AMDSmiAINICDevice::AINICInfo> ai_nic_info_;
#ifdef BRCM_NIC
AMDSmiNoDrmNIC no_drm_nic_;
Expand Down
4 changes: 3 additions & 1 deletion projects/amdsmi/src/amd_smi/amd_smi_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
namespace amd::smi {

AMDSmiSystem& AMDSmiSystem::getInstance() {
static AMDSmiSystem instance;
// Never destroyed, so the sockets and processors it owns stay reachable and valid when a
// process exits without amdsmi_shut_down() or with a thread still inside the library.
static AMDSmiSystem& instance = *new AMDSmiSystem();
Comment thread
adam360x marked this conversation as resolved.
Resolved
return instance;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright Advanced Micro Devices, Inc.
// SPDX-License-Identifier: MIT

#include <gtest/gtest.h>

#include <cstdlib>

#include "amd_smi/amdsmi.h"

// A process may exit without calling amdsmi_shut_down(). The death-test child re-runs this
// test and exits right after its second amdsmi_init(); under LeakSanitizer a leak fails it.
TEST(SystemFunctionalReadOnly, ExitWithoutShutDownIsClean) {
amdsmi_status_t status = amdsmi_init(AMDSMI_INIT_AMD_GPUS);
if (status == AMDSMI_STATUS_DRIVER_NOT_LOADED) GTEST_SKIP() << "amdgpu driver not loaded";
ASSERT_EQ(status, AMDSMI_STATUS_SUCCESS);
ASSERT_EQ(amdsmi_shut_down(), AMDSMI_STATUS_SUCCESS);

::testing::GTEST_FLAG(death_test_style) = "threadsafe";
EXPECT_EXIT(
{
if (amdsmi_init(AMDSMI_INIT_AMD_GPUS) != AMDSMI_STATUS_SUCCESS) std::exit(2);
std::exit(0);
},
::testing::ExitedWithCode(0), "");
}
Loading