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
3 changes: 2 additions & 1 deletion projects/hipblaslt/clients/bench/src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,8 @@ try
set_device(device_id);

auto perf_monitor = EfficiencyMonitor::create();
perf_monitor->setDeviceId(device_id);
if(perf_monitor->enabled())
perf_monitor->setDeviceId(device_id);

if(datafile)
return hipblaslt_bench_datafile(filter, any_stride, props);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,67 @@
#include <vector>
#include <memory>

#ifndef _WIN32
#include <amd_smi/amdsmi.h>
Comment thread
tony-davis marked this conversation as resolved.
Resolved

// True when AMD-SMI is answering correctly but the platform can't provide
// the requested telemetry (e.g. some paravirtualized GPU setups don't expose
// a real PCI BDF), as opposed to a genuine AMD-SMI failure.
inline bool isAmdsmiTelemetryUnavailable(amdsmi_status_t status)
{
return status == AMDSMI_STATUS_NOT_SUPPORTED;
}

// Best-effort AMD-SMI processor index for `hipDeviceIndex` when BDF matching
// isn't available, clamped to a valid index.
inline uint32_t selectFallbackAmdsmiIndex(int hipDeviceIndex, uint32_t amdsmiDeviceCount)
{
if(amdsmiDeviceCount == 0)
return 0;
if(hipDeviceIndex <= 0)
return 0;

uint32_t index = static_cast<uint32_t>(hipDeviceIndex);
return index < amdsmiDeviceCount ? index : amdsmiDeviceCount - 1;
}

// Outcome of one step of GetAMDSMIIndex()'s BDF-matching loop.
enum class BdfMatchAction
{
ContinueSearch, // no match yet; check the next processor
ReturnIndex, // done - use BdfMatchDecision::index
Throw // genuine AMD-SMI failure
};

struct BdfMatchDecision
{
BdfMatchAction action;
uint32_t index = 0;
};

// Decision logic for one iteration of GetAMDSMIIndex(), factored out so it's
// unit testable without a GPU/AMD-SMI session.
inline BdfMatchDecision decideBdfMatch(amdsmi_status_t status,
uint32_t smiIndex,
uint64_t amdSmiPciId,
uint64_t hipPciId,
int hipDeviceIndex,
uint32_t amdsmiDeviceCount)
{
if(isAmdsmiTelemetryUnavailable(status))
return {BdfMatchAction::ReturnIndex,
selectFallbackAmdsmiIndex(hipDeviceIndex, amdsmiDeviceCount)};

if(status != AMDSMI_STATUS_SUCCESS)
return {BdfMatchAction::Throw, 0};

if(amdSmiPciId == hipPciId)
return {BdfMatchAction::ReturnIndex, smiIndex};

return {BdfMatchAction::ContinueSearch, 0};
}
#endif

class EfficiencyMonitor
{
public:
Expand Down
4 changes: 3 additions & 1 deletion projects/hipblaslt/clients/common/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ if(HIPBLASLT_ENABLE_BLIS)
endif()

if(amd_smi_FOUND)
target_link_libraries(hipblaslt-clients-common PRIVATE amd_smi)
# PUBLIC: efficiency_monitor.hpp includes <amd_smi/amdsmi.h> directly, so
# consumers like hipblaslt-bench need the include path propagated too.
target_link_libraries(hipblaslt-clients-common PUBLIC amd_smi)
endif()
34 changes: 29 additions & 5 deletions projects/hipblaslt/clients/common/src/efficiency_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "efficiency_monitor.hpp"
#include "hipblaslt/hipblaslt-ext-op.h"
#include "hipblaslt_ostream.hpp"

#ifndef _WIN32

Expand Down Expand Up @@ -491,15 +492,38 @@ class EfficiencyMonitorImp : public EfficiencyMonitor
m_socketHandles[device], &deviceCount, &m_processorHandles[0]));
for(uint32_t smiIndex = 0; smiIndex < deviceCount; smiIndex++)
{
uint64_t amdSMIPCIID{};
AMDSMI_CHECK_EXC(amdsmi_get_gpu_bdf_id(m_processorHandles[smiIndex], &amdSMIPCIID));
uint64_t amdSMIPCIID{};
amdsmi_status_t bdfStatus
= amdsmi_get_gpu_bdf_id(m_processorHandles[smiIndex], &amdSMIPCIID);

msg << smiIndex << ": " << amdSMIPCIID << std::endl;
BdfMatchDecision decision = decideBdfMatch(
bdfStatus, smiIndex, amdSMIPCIID, hipPCIID, hipDeviceIndex, deviceCount);

if(decision.action == BdfMatchAction::Throw)
AMDSMI_CHECK_EXC(bdfStatus);

if(hipPCIID == amdSMIPCIID)
if(decision.action == BdfMatchAction::ReturnIndex)
{
return smiIndex;
if(isAmdsmiTelemetryUnavailable(bdfStatus))
{
// No PCI BDF to match against on this platform; warn once
// and use a best-effort processor index instead of aborting.
static bool warned = false;
if(!warned)
{
hipblaslt_cerr
<< "Warning: AMD-SMI does not support PCI BDF queries "
"on this platform (e.g. WSL/DXG); disabling "
"BDF-based device matching for efficiency "
"monitoring and using processor "
<< decision.index << "." << std::endl;
warned = true;
}
}
return decision.index;
}

msg << smiIndex << ": " << amdSMIPCIID << std::endl;
}
}

Expand Down
1 change: 1 addition & 0 deletions projects/hipblaslt/clients/tests/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ target_sources(hipblaslt-test
${CMAKE_CURRENT_SOURCE_DIR}/caching_library_gtest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/secure_env_gtest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/arch_revision_gtest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/efficiency_monitor_gtest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/matmul_gtest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/auxiliary_gtest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/benchmark_stats_gtest.cpp
Expand Down
117 changes: 117 additions & 0 deletions projects/hipblaslt/clients/tests/src/efficiency_monitor_gtest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Copyright Advanced Micro Devices, Inc., or its affiliates.
// SPDX-License-Identifier: MIT

// Host-only regression test for ROCM-30983 (WSL2/DXG hipblaslt-bench crash).
//
// GetAMDSMIIndex() itself needs a real AMD-SMI/HIP session, which this
// client test binary can't fake. So the NOT_SUPPORTED-tolerance and
// fallback-index policy that fixes the crash is factored into
// decideBdfMatch() / selectFallbackAmdsmiIndex() (efficiency_monitor.hpp) -
// pure functions with no HIP/AMD-SMI device calls - and exercised directly
// here. A regression that deletes the isAmdsmiTelemetryUnavailable() branch
// from decideBdfMatch() and restores an unconditional throw would turn
// smoke_NotSupportedFallsBackInsteadOfThrowing's ReturnIndex into a Throw and
// fail the test.
//
// Smoke tier: PR CI runs hipBLASLt with TEST_TYPE=quick, which selects
// --gtest_filter=*smoke* (test/therock/test_hipblaslt.py). The test names
// below carry the `smoke` token so this fast, host-only guard runs on the PR
// gate, not only in the full/nightly lane.

#include "efficiency_monitor.hpp"

#include <gtest/gtest.h>

// isAmdsmiTelemetryUnavailable()/decideBdfMatch() and the AMD-SMI status enum
// they classify are only declared under !_WIN32 (efficiency_monitor.hpp
// mirrors the platform split already in efficiency_monitor.cpp; AMD-SMI is
// not used on Windows).
#ifndef _WIN32
namespace
{
constexpr uint64_t kHipPciId = 0x1234;
constexpr uint64_t kOtherPciId = 0x5678;

TEST(EfficiencyMonitorSmoke, smoke_NotSupportedIsTolerated)
Comment thread
tony-davis marked this conversation as resolved.
Resolved
{
EXPECT_TRUE(isAmdsmiTelemetryUnavailable(AMDSMI_STATUS_NOT_SUPPORTED));
}

TEST(EfficiencyMonitorSmoke, smoke_SuccessIsNotTelemetryUnavailable)
{
EXPECT_FALSE(isAmdsmiTelemetryUnavailable(AMDSMI_STATUS_SUCCESS));
}

TEST(EfficiencyMonitorSmoke, smoke_OtherFailuresStayFatal)
{
EXPECT_FALSE(isAmdsmiTelemetryUnavailable(AMDSMI_STATUS_UNKNOWN_ERROR));
}

// The actual ROCM-30983 regression check: NOT_SUPPORTED must fall back,
// not throw.
TEST(EfficiencyMonitorSmoke, smoke_NotSupportedFallsBackInsteadOfThrowing)
{
BdfMatchDecision decision = decideBdfMatch(AMDSMI_STATUS_NOT_SUPPORTED,
/*smiIndex=*/0,
/*amdSmiPciId=*/0,
kHipPciId,
/*hipDeviceIndex=*/0,
/*amdsmiDeviceCount=*/1);
EXPECT_EQ(decision.action, BdfMatchAction::ReturnIndex);
EXPECT_EQ(decision.index, 0u);
}

TEST(EfficiencyMonitorSmoke, smoke_OtherFailuresThrow)
{
BdfMatchDecision decision = decideBdfMatch(AMDSMI_STATUS_UNKNOWN_ERROR,
/*smiIndex=*/0,
/*amdSmiPciId=*/0,
kHipPciId,
/*hipDeviceIndex=*/0,
/*amdsmiDeviceCount=*/1);
EXPECT_EQ(decision.action, BdfMatchAction::Throw);
}

TEST(EfficiencyMonitorSmoke, smoke_SuccessfulMatchReturnsMatchingIndex)
{
BdfMatchDecision decision = decideBdfMatch(AMDSMI_STATUS_SUCCESS,
/*smiIndex=*/2,
/*amdSmiPciId=*/kHipPciId,
kHipPciId,
/*hipDeviceIndex=*/0,
/*amdsmiDeviceCount=*/4);
EXPECT_EQ(decision.action, BdfMatchAction::ReturnIndex);
EXPECT_EQ(decision.index, 2u);
}

TEST(EfficiencyMonitorSmoke, smoke_SuccessfulNonMatchContinuesSearching)
{
BdfMatchDecision decision = decideBdfMatch(AMDSMI_STATUS_SUCCESS,
/*smiIndex=*/0,
/*amdSmiPciId=*/kOtherPciId,
kHipPciId,
/*hipDeviceIndex=*/0,
/*amdsmiDeviceCount=*/1);
EXPECT_EQ(decision.action, BdfMatchAction::ContinueSearch);
}

// Reviewer concern: a fixed "processor 0" fallback silently attributes
// telemetry to the wrong GPU whenever the user targets a device other
// than 0 on a multi-GPU WSL host. The fallback must track
// hipDeviceIndex instead of ignoring it.
TEST(EfficiencyMonitorSmoke, smoke_FallbackUsesHipDeviceIndexNotAlwaysZero)
{
EXPECT_EQ(selectFallbackAmdsmiIndex(/*hipDeviceIndex=*/2, /*amdsmiDeviceCount=*/4), 2u);
}

TEST(EfficiencyMonitorSmoke, smoke_FallbackClampsOutOfRangeDeviceIndex)
{
EXPECT_EQ(selectFallbackAmdsmiIndex(/*hipDeviceIndex=*/9, /*amdsmiDeviceCount=*/4), 3u);
}

TEST(EfficiencyMonitorSmoke, smoke_FallbackHandlesNegativeDeviceIndex)
{
EXPECT_EQ(selectFallbackAmdsmiIndex(/*hipDeviceIndex=*/-1, /*amdsmiDeviceCount=*/4), 0u);
}
} // namespace
#endif // !_WIN32
Loading