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
8 changes: 6 additions & 2 deletions projects/amdsmi/rocm_smi/src/rocm_smi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5694,13 +5694,16 @@ rsmi_status_t rsmi_topo_get_p2p_status(uint32_t dv_ind_src, uint32_t dv_ind_dst,
}

bool node_is_find = false;
// Keep the matched link alive; io_link_map_tmp.clear() invalidates the iterator.
std::shared_ptr<amd::smi::IOLink> found_link;
std::map<uint32_t, std::shared_ptr<amd::smi::IOLink>> io_link_map_tmp;
std::map<uint32_t, std::shared_ptr<amd::smi::IOLink>>::iterator it;
// Iterate over P2P links
if (DiscoverP2PLinksPerNode(node_ind_src, &io_link_map_tmp) == 0) {
for (it = io_link_map_tmp.begin(); it != io_link_map_tmp.end(); it++) {
if (it->first == node_ind_dst) {
node_is_find = true;
found_link = it->second;
break;
}
}
Expand All @@ -5715,6 +5718,7 @@ rsmi_status_t rsmi_topo_get_p2p_status(uint32_t dv_ind_src, uint32_t dv_ind_dst,
for (it = io_link_map_tmp.begin(); it != io_link_map_tmp.end(); it++) {
if (it->first == node_ind_dst) {
node_is_find = true;
found_link = it->second;
break;
}
}
Expand All @@ -5725,7 +5729,7 @@ rsmi_status_t rsmi_topo_get_p2p_status(uint32_t dv_ind_src, uint32_t dv_ind_dst,
}

if (node_is_find) {
amd::smi::IO_LINK_TYPE io_link_type = it->second->type();
amd::smi::IO_LINK_TYPE io_link_type = found_link->type();
if (io_link_type == amd::smi::IOLINK_TYPE_PCIEXPRESS) {
*type = RSMI_IOLINK_TYPE_PCIEXPRESS;
} else if (io_link_type == amd::smi::IOLINK_TYPE_XGMI) {
Expand All @@ -5746,7 +5750,7 @@ rsmi_status_t rsmi_topo_get_p2p_status(uint32_t dv_ind_src, uint32_t dv_ind_dst,
* some time to implement and test it, should we consider it is *really necessary*.
*
*/
auto tmp_capability = it->second->get_link_capability();
auto tmp_capability = found_link->get_link_capability();
if (auto link_direction_result =
amd::smi::DiscoverIOLinkPerNodeDirection(node_ind_src, node_ind_dst);
link_direction_result == amd::smi::IOLinkDirectionType_t::kBiDirectional) {
Expand Down
14 changes: 13 additions & 1 deletion projects/amdsmi/rocm_smi/src/rocm_smi_device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,19 @@ static const std::map<const char*, dev_depends_t> kDevFuncDependsMap = {
}

Device::Device(std::string p, RocmSMI_env_vars const* e)
: monitor_(nullptr), path_(p), env_(e), evt_notif_anon_fd_(-1), m_gpu_metrics_header{0, 0, 0} {
: monitor_(nullptr),
path_(p),
card_indx_(0),
drm_render_minor_(0),
env_(e),
bdfid_(UINT64_MAX),
kfd_gpu_id_(0),
evt_notif_anon_fd_(-1),
Comment thread
SakaSitharammurthy marked this conversation as resolved.
Resolved
evt_notif_anon_file_ptr_(nullptr),
m_gpu_metrics_header{0, 0, 0},
m_gpu_metrics_updated_timestamp(0),
m_device_id(0),
m_partition_id(0) {
Comment thread
SakaSitharammurthy marked this conversation as resolved.
Resolved
#ifndef DEBUG
env_ = nullptr;
#endif
Expand Down
51 changes: 26 additions & 25 deletions projects/amdsmi/src/amd_smi/amd_smi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3159,6 +3159,9 @@ amdsmi_status_t amdsmi_topo_get_link_type(amdsmi_processor_handle processor_hand
amdsmi_processor_handle processor_handle_dst,
uint64_t* hops, amdsmi_link_type_t* type) {
AMDSMI_CHECK_INIT();
if (hops == nullptr || type == nullptr) {
return AMDSMI_STATUS_INVAL;
}

amd::smi::AMDSmiGPUDevice* src_device = nullptr;
amd::smi::AMDSmiGPUDevice* dst_device = nullptr;
Expand Down Expand Up @@ -3204,6 +3207,9 @@ amdsmi_status_t amdsmi_topo_get_p2p_status(amdsmi_processor_handle processor_han
amdsmi_processor_handle processor_handle_dst,
amdsmi_link_type_t* type, amdsmi_p2p_capability_t* cap) {
AMDSMI_CHECK_INIT();
if (type == nullptr || cap == nullptr) {
return AMDSMI_STATUS_INVAL;
}

amd::smi::AMDSmiGPUDevice* src_device = nullptr;
amd::smi::AMDSmiGPUDevice* dst_device = nullptr;
Expand Down Expand Up @@ -3311,16 +3317,11 @@ amdsmi_status_t amdsmi_get_gpu_memory_partition_config(amdsmi_processor_handle p
return AMDSMI_STATUS_INVAL;
}

*config = {};

// initialization for devices which do not support partitions
amdsmi_nps_caps_t flags;
flags.nps_flags.nps1_cap = 0;
flags.nps_flags.nps2_cap = 0;
flags.nps_flags.nps4_cap = 0;
flags.nps_flags.nps8_cap = 0;
config->partition_caps = flags;
amdsmi_nps_caps_t flags = {};
config->mp_mode = AMDSMI_MEMORY_PARTITION_UNKNOWN;
// TODO(amdsmi_team): Will BM/guest VMs have numa ranges?
config->num_numa_ranges = 0;

// current memory partition
constexpr uint32_t kCurrentPartitionSize = 5;
Expand Down Expand Up @@ -3350,7 +3351,8 @@ amdsmi_status_t amdsmi_get_gpu_memory_partition_config(amdsmi_processor_handle p
auto status_mem_caps = rsmi_wrapper(rsmi_dev_memory_partition_capabilities_get, processor_handle,
0, memory_caps, kLenCapsSize);
ss << __PRETTY_FUNCTION__ << " | rsmi_dev_memory_partition_capabilities_get Returning: "
<< smi_amdgpu_get_status_string(status, false) << " | Type: memory_partition_capabilities"
<< smi_amdgpu_get_status_string(status_mem_caps, false)
<< " | Type: memory_partition_capabilities"
<< " | Data: " << memory_caps;
LOG_DEBUG(ss);
std::string memory_caps_str = "N/A";
Expand Down Expand Up @@ -3454,6 +3456,8 @@ amdsmi_status_t amdsmi_get_gpu_accelerator_partition_profile_config(
return AMDSMI_STATUS_INVAL;
}

*profile_config = {};

// Initialize values
amdsmi_status_t return_status = AMDSMI_STATUS_NOT_SUPPORTED;
amdsmi_status_t status = AMDSMI_STATUS_NOT_SUPPORTED;
Expand All @@ -3464,11 +3468,7 @@ amdsmi_status_t amdsmi_get_gpu_accelerator_partition_profile_config(
profile_config->resource_profiles->resource_type = AMDSMI_ACCELERATOR_MAX;
profile_config->resource_profiles->partition_resource = 0;
profile_config->resource_profiles->num_partitions_share_resource = 0;
amdsmi_nps_caps_t flags;
flags.nps_flags.nps1_cap = 0;
flags.nps_flags.nps2_cap = 0;
flags.nps_flags.nps4_cap = 0;
flags.nps_flags.nps8_cap = 0;
amdsmi_nps_caps_t flags = {};

ss << __PRETTY_FUNCTION__ << " | 1";
// std::cout << ss.str() << std::endl;
Expand All @@ -3480,7 +3480,7 @@ amdsmi_status_t amdsmi_get_gpu_accelerator_partition_profile_config(
// ex. SPX, DPX, QPX, CPX
std::string accelerator_caps_str = "N/A";
constexpr uint32_t kLenXCPConfigSize = 30;
char supported_xcp_configs[kLenXCPConfigSize];
char supported_xcp_configs[kLenXCPConfigSize] = {};
bool use_xcp_config = false;
return_status = rsmi_wrapper(rsmi_dev_compute_partition_supported_xcp_configs_get,
processor_handle, 0, supported_xcp_configs, kLenXCPConfigSize);
Expand Down Expand Up @@ -3617,7 +3617,7 @@ amdsmi_status_t amdsmi_get_gpu_accelerator_partition_profile_config(
* *supported_configs, uint32_t len);
*/
constexpr uint32_t kLenNPSConfigSize = 30;
char supported_nps_configs[kLenNPSConfigSize];
char supported_nps_configs[kLenNPSConfigSize] = {};
std::string supported_nps_caps_str = "N/A";
status = rsmi_wrapper(rsmi_dev_compute_partition_supported_nps_configs_get, processor_handle, 0,
supported_nps_configs, kLenNPSConfigSize);
Expand All @@ -3642,7 +3642,11 @@ amdsmi_status_t amdsmi_get_gpu_accelerator_partition_profile_config(
r < static_cast<int>(RSMI_ACCELERATOR_MAX); r++) {
rsmi_accelerator_partition_resource_type_t type =
static_cast<rsmi_accelerator_partition_resource_type_t>(r);
rsmi_accelerator_partition_resource_profile_t profile;
rsmi_accelerator_partition_resource_profile_t profile = {};
if (resource_index >= AMDSMI_MAX_CP_PROFILE_RESOURCES) {
break;
}
profile_config->resource_profiles[resource_index].resource_type = AMDSMI_ACCELERATOR_MAX;
status = rsmi_wrapper(rsmi_dev_compute_partition_resource_profile_get, processor_handle, 0,
&type, &profile);
if (status == AMDSMI_STATUS_SUCCESS) {
Expand Down Expand Up @@ -3847,11 +3851,7 @@ amdsmi_status_t amdsmi_get_gpu_accelerator_partition_profile(
profile->profile_index = std::numeric_limits<uint32_t>::max();
profile->num_resources = 0;

amdsmi_nps_caps_t flags;
flags.nps_flags.nps1_cap = 0;
flags.nps_flags.nps2_cap = 0;
flags.nps_flags.nps4_cap = 0;
flags.nps_flags.nps8_cap = 0;
amdsmi_nps_caps_t flags = {};
profile->memory_caps = flags;

// TODO(amdsmi_team): add resources here ^
Expand All @@ -3870,13 +3870,14 @@ amdsmi_status_t amdsmi_get_gpu_accelerator_partition_profile(
// ex. SPX = 0, DPX = 1, QPX = 2, CPX = 3; other devices may have different values
std::string accelerator_capabilities = "N/A";
constexpr uint32_t kLenXCPConfigSize = 30;
char supported_xcp_configs[kLenXCPConfigSize];
char supported_xcp_configs[kLenXCPConfigSize] = {};
bool use_xcp_config = false;
status = rsmi_wrapper(rsmi_dev_compute_partition_supported_xcp_configs_get, processor_handle, 0,
supported_xcp_configs, kLenXCPConfigSize);
if (status == AMDSMI_STATUS_SUCCESS) {
accelerator_capabilities.clear();
accelerator_capabilities = std::string(supported_xcp_configs);
accelerator_capabilities = amd::smi::trimAllWhiteSpace(accelerator_capabilities);
use_xcp_config = true;
}

Expand Down Expand Up @@ -3915,7 +3916,7 @@ amdsmi_status_t amdsmi_get_gpu_accelerator_partition_profile(
<< current_partition << "|";
LOG_DEBUG(ss);
current_partition_str = current_partition;
if (status == AMDSMI_STATUS_SUCCESS) {
if (compute_status == AMDSMI_STATUS_SUCCESS) {
// 1) get profile index from
// /sys/class/drm/../device/compute_partition_config/supported_xcp_configs
if (current_partition_str == "SPX" || current_partition_str == "DPX" ||
Expand Down Expand Up @@ -4001,7 +4002,7 @@ amdsmi_status_t amdsmi_get_gpu_accelerator_partition_profile(

// Add memory partition capabilities here
constexpr uint32_t kLenCapsSize = 30;
char memory_caps[kLenCapsSize];
char memory_caps[kLenCapsSize] = {};
status = rsmi_wrapper(rsmi_dev_memory_partition_capabilities_get, processor_handle, 0,
memory_caps, kLenCapsSize);
ss << __PRETTY_FUNCTION__ << " | rsmi_dev_memory_partition_capabilities_get Returning: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,25 @@ void TestHWTopologyRead::Run(void) {

uint32_t num_devices = num_monitor_devs();

// Null output pointers must be rejected regardless of topology.
if (num_devices > 0) {
amdsmi_link_type_t null_type;
amdsmi_p2p_capability_t null_cap;
uint64_t null_hops;
ASSERT_EQ(amdsmi_topo_get_link_type(processor_handles_[0], processor_handles_[0], nullptr,
&null_type),
AMDSMI_STATUS_INVAL);
ASSERT_EQ(amdsmi_topo_get_link_type(processor_handles_[0], processor_handles_[0], &null_hops,
nullptr),
AMDSMI_STATUS_INVAL);
ASSERT_EQ(amdsmi_topo_get_p2p_status(processor_handles_[0], processor_handles_[0], nullptr,
&null_cap),
AMDSMI_STATUS_INVAL);
ASSERT_EQ(amdsmi_topo_get_p2p_status(processor_handles_[0], processor_handles_[0], &null_type,
nullptr),
AMDSMI_STATUS_INVAL);
}

// gpu_link_t gpu_links[num_devices][num_devices];
std::vector<std::vector<gpu_link_t>> gpu_links(num_devices, std::vector<gpu_link_t>(num_devices));
// uint32_t numa_numbers[num_devices];
Expand Down
6 changes: 6 additions & 0 deletions projects/amdsmi/tests/python/functional/gpu/test_xgmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,9 @@ def test_topo_get_p2p_status(self):
amdsmi_topo_get_p2p_status=amdsmi.amdsmi_topo_get_p2p_status
)
return

def test_topo_get_p2p_status_rejects_non_handle(self):
self.common.print_func_name("")
with self.assertRaises(amdsmi.AmdSmiParameterException):
amdsmi.amdsmi_topo_get_p2p_status("not_a_handle", "not_a_handle")
return
43 changes: 43 additions & 0 deletions projects/amdsmi/tests/python/unit/gpu/test_topology.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python3
#
# Copyright (C) Advanced Micro Devices. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""Topology API handle-validation unit tests (hardware-free)."""

from __future__ import annotations

import unittest

from common.common import amdsmi


class TestAmdSmiTopologyHandleValidation(unittest.TestCase):
"""The interface layer rejects non-handle arguments before any C call."""

def test_link_type_rejects_non_handle(self):
with self.assertRaises(amdsmi.AmdSmiParameterException):
amdsmi.amdsmi_topo_get_link_type("not_a_handle", "not_a_handle")

def test_p2p_status_rejects_non_handle(self):
with self.assertRaises(amdsmi.AmdSmiParameterException):
amdsmi.amdsmi_topo_get_p2p_status("not_a_handle", "not_a_handle")


if __name__ == "__main__":
unittest.main()
Loading