Repository navigation
[WIP] [ROCm] Migrate SMI device queries from rocm_smi to amd_smi - #1113
nurmukhametov wants to merge 1 commit into
Conversation
1cba3a7 to
1d0de6d
Compare
| uint16_t width; | ||
| }; | ||
|
|
||
| #if (TF_ROCM_VERSION >= 71300) |
There was a problem hiding this comment.
this macro guarad on rocm version will be challenged by upstream to change as the runtime check..
There was a problem hiding this comment.
I don't think so. Why should they challenge that?
There was a problem hiding this comment.
they against these new added #ifdef e.g., openxla#47447 (review) and openxla#46895 (comment)
There was a problem hiding this comment.
they against these new added
#ifdefe.g., openxla#47447 (review) and openxla#46895 (comment)
IMO, these are completely different cases.
There was a problem hiding this comment.
Split the implementation into separate files and choose the impl via bazel.
There was a problem hiding this comment.
I'm not sure how this will play with you work to use amd_smi to get memory bandwidth. Not sure what we have here is simpler than just moving to amd_smi and having dlopen workaround for pre 7.14.
There was a problem hiding this comment.
Split the implementation into separate files and choose the impl via bazel.
Done.
I'm not sure how this will play with you work to use amd_smi to get memory bandwidth. Not sure what we have here is simpler than just moving to amd_smi and having dlopen workaround for pre 7.14.
I will implement it for amd_smi only. Below 7.13, it will just keep today's behavior, the per-gfx constant.
1d0de6d to
8b44a37
Compare
| // amd_smi reports pcie_speed directly in MT/s, unlike rocm_smi below. | ||
| return PcieLinkStatus{pcie_info.pcie_metric.pcie_speed, | ||
| pcie_info.pcie_metric.pcie_width}; |
There was a problem hiding this comment.
nit / fragility: The comment says amd_smi reports speed "directly in MT/s." Could you add a reference to the specific amd_smi header or doc that confirms this? The rocm_smi path below documents its 0.1 GT/s unit, which is great — having the same clarity here would protect against silent regressions if the semantics ever change across amd_smi versions.
A sanity check (e.g., LOG_IF(WARNING, speed > 128000)) would also catch unexpected unit changes early, but that's optional.
There was a problem hiding this comment.
Put the reference to amd_smi header.
There was a problem hiding this comment.
Resolved - the amdsmi.h reference in rocm_smi_util_amd_smi.cc:132 documents the unit clearly.
There was a problem hiding this comment.
Resolved — amd_smi header reference added. Thanks.
| amdsmi_bdf_t bdf = {}; | ||
| bdf.bdf.domain_number = target_bdf.domain; | ||
| bdf.bdf.bus_number = target_bdf.bus; | ||
| bdf.bdf.device_number = target_bdf.device; | ||
| bdf.bdf.function_number = target_bdf.function; |
There was a problem hiding this comment.
nit: BdfComponents uses uint64_t for all fields (domain, bus, device, function), but amdsmi_bdf_t's internal fields are narrower (typically uint32_t/uint16_t/bitfields). The assignments here involve implicit narrowing conversions. While PCI BDF values are always small enough in practice, explicit static_casts would make the assumption visible and prevent compiler warnings under stricter settings.
There was a problem hiding this comment.
The field types match at uint64_t, and static_cast neither documents nor silences anything
There was a problem hiding this comment.
Resolved - understood, BdfComponents fields are uint64_t and the amdsmi_bdf_t accessors return matching types, so no narrowing occurs.
There was a problem hiding this comment.
Resolved — agreed, the field types already match at uint64_t so no narrowing occurs and a static_cast would be noise.
|
|
||
| // Returns true if src reaches dst over an xGMI link. | ||
| bool IsXgmiPeer(SmiDeviceHandle src, SmiDeviceHandle dst) { | ||
| uint64_t hops = 0; |
There was a problem hiding this comment.
nit: hops is written by both amdsmi_topo_get_link_type and rsmi_topo_get_link_type but is never read afterward. Moving it inside each #if/#else block (or at minimum annotating with [[maybe_unused]]) would be cleaner.
There was a problem hiding this comment.
It is not unused, it is used. Made a comment about it.
There was a problem hiding this comment.
Resolved - the comment at line 148 makes clear hops is a required out-parameter. Thanks for clarifying.
There was a problem hiding this comment.
Resolved — hops is a required out-parameter for both amdsmi_topo_get_link_type and rsmi_topo_get_link_type. Clarifying comment added.
| data = glob([ | ||
| "%{rocm_root}/lib/libamd_smi.so*" if _use_amd_smi else "%{rocm_root}/lib/librocm_smi64.so*", |
There was a problem hiding this comment.
observation: glob() will silently produce an empty list if the expected library is missing from the ROCm installation (e.g., ROCm 7.13 installed but libamd_smi.so not present). The error would only surface at runtime. This is inherent to glob-based patterns and not new to this PR — just flagging in case a more explicit fail-fast check (e.g., a Starlark fail() when the glob returns empty) is desired.
There was a problem hiding this comment.
The glob is indeed silent when empty (XLA sets --incompatible_disallow_empty_glob=false in .bazelrc:5), but it is not what gates this. rocm_lib_import passes interface_library to cc_import(shared_library = ...) as a bare label, never through a glob, so a missing library is a build-time error naming the exact path, not a runtime surprise.
There was a problem hiding this comment.
Resolved - correct, interface_library is a bare label so a missing .so is a build-time error, not a silent runtime issue.
There was a problem hiding this comment.
Resolved — good point about interface_library in cc_import making a missing .so a build-time error regardless of the glob behavior. The safety net is at the right layer.
Review SummaryClean migration from One item worth verifying before merge: the The remaining inline comments are minor (implicit narrowing, unused variable, documentation asks). |
8b44a37 to
0ce954d
Compare
| static_library = "%{rocm_root}/lib/libhsakmt.a", | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
| # RCCL links librocm_smi64 below ROCm 7.13 and libamd_smi from 7.13 on. XLA |
There was a problem hiding this comment.
leave both libs and use alias at point of usage in xla/stream_executor/rocm/BUILD. The point of adding both is to not care which one is actuality used.
Re-review SummaryAll 5 previous findings have been addressed by the developer:
No new issues found. The refactoring cleanly splits the SMI backends into separate compilation units with correct build-time selection via |
| // Returns std::nullopt if not found. | ||
| std::optional<uint32_t> FindDeviceIndex(const BdfComponents& target_bdf); | ||
| // Returns handles for every SMI visible GPU, in SMI enumeration order. Empty | ||
| // on failure. Callers must hold rocm_smi_mutex. |
There was a problem hiding this comment.
Good comment on mutex. Maybe use TF_EXCLUSIVE_LOCKS_REQUIRED here. Not that we check of it. But it is somewhat selfdocumenting.
|
|
||
| // Finds the SMI device that matches the given PCI bus ID. | ||
| // Returns std::nullopt if not found. Callers must hold rocm_smi_mutex. | ||
| std::optional<SmiDeviceHandle> FindDevice(const BdfComponents& target_bdf); |
There was a problem hiding this comment.
Does it make sense for this to be StatusOr? I guess that would avoid most of the need for kSmiLibraryName and caller can chose if to just vlog the message or treat it as something serious. Also we can ensure we only log the message once per device. I won't hold of PR on this. This can be a follow up. This std::optional somehow passed the initial review on upstream.
There was a problem hiding this comment.
Yes, it makes sense. I have removed kSmiLibraryName completely as well.
927e3cc to
40dd19d
Compare
| << pci_bus_id; | ||
| return std::nullopt; | ||
| } | ||
| absl::StatusOr<SmiDeviceHandle> device = FindDevice(*bdf); |
There was a problem hiding this comment.
*ASIGN_OR_RETURN macro?
There was a problem hiding this comment.
Actually this reminders me @nurmukhametov shall we rm this part https://github.com/ROCm/xla/blob/rocm-dev-infra/.claude/skills/review-xla-pr/SKILL.md#11-xla-project-specific-c-conventions due to openxla@eb278d3 ?
These stale skills might hurt claude code review quality? Instead of giving the specific instruction, maybe we just let Claude to follow other existing error handle APIs in the codebase.
In addition, we're still using opus-4.6, wondering can we use opus-4.8?
There was a problem hiding this comment.
*ASIGN_OR_RETURN macro?
Done.
Actually this reminders me @nurmukhametov shall we rm this part https://github.com/ROCm/xla/blob/rocm-dev-infra/.claude/skills/review-xla-pr/SKILL.md#11-xla-project-specific-c-conventions due to openxla@eb278d3 ?
These stale skills might hurt claude code review quality? Instead of giving the specific instruction, maybe we just let Claude to follow other existing error handle APIs in the codebase.
Yeah, could be. The stale things need to be removed for sure.
In addition, we're still using opus-4.6, wondering can we use opus-4.8?
We need to use the latest model.
|
|
||
| if (!InitRocmSmi()) return std::nullopt; | ||
| if (!InitSmi()) return absl::UnavailableError("SMI is not available"); |
There was a problem hiding this comment.
Maybe make InitSmi return status.
Cherry-pick of #1113 (02298de) with SMI-only Bazel changes on this release branch. Unblocks JAX wheel builds when librocm_smi64 is absent from the ROCm SDK (ROCm/TheRock#6852).
Cherry-pick of #1113 (02298de) with SMI-only Bazel changes on this release branch. Unblocks JAX wheel builds when librocm_smi64 is absent from the ROCm SDK (ROCm/TheRock#6852).
Cherry-pick of #1113 (02298de) with SMI-only Bazel changes on this release branch. Unblocks JAX wheel builds when librocm_smi64 is absent from the ROCm SDK (ROCm/TheRock#6852).
Cherry-pick of #1113 (02298de) with SMI-only Bazel changes on this release branch. Unblocks JAX wheel builds when librocm_smi64 is absent from the ROCm SDK (ROCm/TheRock#6852).
Cherry-pick of #1113 (02298de) with SMI-only Bazel changes on this release branch. Unblocks JAX wheel builds when librocm_smi64 is absent from the ROCm SDK (ROCm/TheRock#6852).
Cherry-pick of #1113 (02298de) with SMI-only Bazel changes on this release branch. Unblocks JAX wheel builds when librocm_smi64 is absent from the ROCm SDK (ROCm/TheRock#6852).
Cherry-pick of #1113 (02298de) with SMI-only Bazel changes on this release branch. Unblocks JAX wheel builds when librocm_smi64 is absent from the ROCm SDK (ROCm/TheRock#6852).
Cherry-pick of #1113 (02298de) with SMI-only Bazel changes on this release branch. Unblocks JAX wheel builds when librocm_smi64 is absent from the ROCm SDK (ROCm/TheRock#6852).
Cherry-pick of #1113 (02298de) with SMI-only Bazel changes on this release branch. Unblocks JAX wheel builds when librocm_smi64 is absent from the ROCm SDK (ROCm/TheRock#6852).
Cherry-pick of #1113 (02298de) with SMI-only Bazel changes on this release branch. Unblocks JAX wheel builds when librocm_smi64 is absent from the ROCm SDK (ROCm/TheRock#6852).
Cherry-pick of #1113 (02298de) with SMI-only Bazel changes on this release branch. Unblocks JAX wheel builds when librocm_smi64 is absent from the ROCm SDK (ROCm/TheRock#6852).
Cherry-pick of #1113 (02298de) with SMI-only Bazel changes on this release branch. Unblocks JAX wheel builds when librocm_smi64 is absent from the ROCm SDK (ROCm/TheRock#6852).
Cherry-pick of #1113 (02298de) with SMI-only Bazel changes on this release branch. Unblocks JAX wheel builds when librocm_smi64 is absent from the ROCm SDK (ROCm/TheRock#6852).
Cherry-pick of #1113 (02298de) with SMI-only Bazel changes on this release branch. Unblocks JAX wheel builds when librocm_smi64 is absent from the ROCm SDK (ROCm/TheRock#6852).
Cherry-pick of #1113 (02298de) with SMI-only Bazel changes on this release branch. Unblocks JAX wheel builds when librocm_smi64 is absent from the ROCm SDK (ROCm/TheRock#6852).
Cherry-pick of #1113 (02298de) with SMI-only Bazel changes on this release branch. Unblocks JAX wheel builds when librocm_smi64 is absent from the ROCm SDK (ROCm/TheRock#6852).
Cherry-pick of #1113 (02298de) with SMI-only Bazel changes on this release branch. Unblocks JAX wheel builds when librocm_smi64 is absent from the ROCm SDK (ROCm/TheRock#6852).
Cherry-pick of #1113 (02298de) with SMI-only Bazel changes on this release branch. Unblocks JAX wheel builds when librocm_smi64 is absent from the ROCm SDK (ROCm/TheRock#6852).
Cherry-pick of #1113 (02298de) with SMI-only Bazel changes on this release branch. Unblocks JAX wheel builds when librocm_smi64 is absent from the ROCm SDK (ROCm/TheRock#6852).
Cherry-pick of #1113 (02298de) with SMI-only Bazel changes on this release branch. Unblocks JAX wheel builds when librocm_smi64 is absent from the ROCm SDK (ROCm/TheRock#6852).
Cherry-pick of #1113 (02298de) with SMI-only Bazel changes on this release branch. Unblocks JAX wheel builds when librocm_smi64 is absent from the ROCm SDK (ROCm/TheRock#6852).
Cherry-pick of #1113 (02298de) with SMI-only Bazel changes on this release branch. Unblocks JAX wheel builds when librocm_smi64 is absent from the ROCm SDK (ROCm/TheRock#6852).
Cherry-pick of #1113 (02298de) with SMI-only Bazel changes on this release branch. Unblocks JAX wheel builds when librocm_smi64 is absent from the ROCm SDK (ROCm/TheRock#6852).
Cherry-pick of #1113 (02298de) with SMI-only Bazel changes on this release branch. Unblocks JAX wheel builds when librocm_smi64 is absent from the ROCm SDK (ROCm/TheRock#6852).
Cherry-pick of #1113 (02298de) with SMI-only Bazel changes on this release branch. Unblocks JAX wheel builds when librocm_smi64 is absent from the ROCm SDK (ROCm/TheRock#6852). (cherry picked from commit 45f7885)
) Cherry-pick of ROCm#1113 (02298de) with SMI-only Bazel changes on this release branch. Unblocks JAX wheel builds when librocm_smi64 is absent from the ROCm SDK (ROCm/TheRock#6852). (cherry picked from commit 45f7885)
) Cherry-pick of ROCm#1113 (02298de) with SMI-only Bazel changes on this release branch. Unblocks JAX wheel builds when librocm_smi64 is absent from the ROCm SDK (ROCm/TheRock#6852). (cherry picked from commit 45f7885)
|
It was merged upstream in openxla@ca92135 |
Motivation
To get review.
Technical Details
RCCL dropped librocm_smi64 in ROCm 7.13 and links libamd_smi instead. The two libraries cannot coexist in one process. XLA now switches SMI libraries at the same boundary RCCL does, so only one is ever present. Selection is compile and link time only, via a version gated :smi target in BUILD.tpl and #if (TF_ROCM_VERSION >= 71300) in the three existing sources. The ROCm floor stays at 7.1; bumping it to 7.13 later reduces to deleting the #else branches.
Submission Checklist