Skip to content

[rocprofiler-sdk] Introduce TopologyProvider abstraction - #6352

Closed
bgopesh wants to merge 2 commits into
ROCm:developfrom
bgopesh:users/bgopesh/topology-provider
Closed

bgopesh wants to merge 2 commits into
ROCm:developfrom
bgopesh:users/bgopesh/topology-provider

Conversation

@bgopesh

@bgopesh bgopesh commented May 21, 2026

Copy link
Copy Markdown
Contributor

Factor GPU/CPU agent discovery behind a polymorphic TopologyProvider interface so the existing Linux/KFD path is preserved verbatim while WSL and native Windows gain dedicated backends.

  • topology/linux_kfd_provider: byte-identical move of read_topology() and its helpers (parse_cpu_info, read_map, read_property, etc.) out of agent.cpp. Linux behaviour is unchanged.
  • topology/dxg_provider: WSL backend skeleton. Dlopens libdxcore.so and probes CreateDXCoreAdapterFactory; full DXCore-to-agent enumeration is left as a follow-up.
  • topology/d3dkmt_provider: native Windows backend skeleton. All D3DKMT calls are #ifdef _WIN32 guarded so the class still links on Linux (stubs return empty + warning). The full enumeration body is left as a follow-up.
  • topology/topology_provider: factory make_default_provider() with runtime selection precedence: ROCPROFILER_FORCE_DXG -> ROCPROFILER_FORCE_D3DKMT -> sysfs -> libdxcore.so loadable -> WIN32 -> LinuxKfd fallback. The ROCPROFILER_FORCE* env vars are new and intended for triage.
  • agent.cpp: read_topology() and its helpers deleted. The singleton accessor and internal_refresh_topology() now go through the provider. No other public function changed.
  • agent_internal.hpp: minimal forward declaration of update_agent_runtime_visibility so providers can call it without touching the public header.

Motivation

Technical Details

JIRA ID

Test Plan

Test Result

Submission Checklist

Factor GPU/CPU agent discovery behind a polymorphic TopologyProvider
interface so the existing Linux/KFD path is preserved verbatim while
WSL and native Windows gain dedicated backends.

  - topology/linux_kfd_provider: byte-identical move of read_topology()
    and its helpers (parse_cpu_info, read_map, read_property, etc.) out
    of agent.cpp. Linux behaviour is unchanged.
  - topology/dxg_provider: WSL backend skeleton. Dlopens libdxcore.so
    and probes CreateDXCoreAdapterFactory; full DXCore-to-agent
    enumeration is left as a follow-up.
  - topology/d3dkmt_provider: native Windows backend skeleton. All
    D3DKMT calls are #ifdef _WIN32 guarded so the class still links on
    Linux (stubs return empty + warning). The full enumeration body
    is left as a follow-up.
  - topology/topology_provider: factory make_default_provider() with
    runtime selection precedence:
      ROCPROFILER_FORCE_DXG -> ROCPROFILER_FORCE_D3DKMT -> sysfs ->
      libdxcore.so loadable -> _WIN32 -> LinuxKfd fallback.
    The ROCPROFILER_FORCE_* env vars are new and intended for triage.
  - agent.cpp: read_topology() and its helpers deleted. The singleton
    accessor and internal_refresh_topology() now go through the
    provider. No other public function changed.
  - agent_internal.hpp: minimal forward declaration of
    update_agent_runtime_visibility so providers can call it without
    touching the public header.
Copilot AI review requested due to automatic review settings May 21, 2026 15:43
@bgopesh
bgopesh requested review from a team as code owners May 21, 2026 15:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a TopologyProvider abstraction to decouple agent (CPU/GPU) discovery from agent.cpp, preserving the existing Linux/KFD enumeration while adding skeleton backends for WSL (DXCore) and native Windows (D3DKMT).

Changes:

  • Adds a polymorphic TopologyProvider interface and a runtime-selected factory (make_default_provider()).
  • Moves the existing Linux/KFD sysfs topology parsing/enumeration into LinuxKfdProvider (verbatim refactor).
  • Introduces WSL (DxgProvider) and Windows (D3dkmtProvider) backend skeletons and routes agent.cpp topology refresh through the provider.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/topology/topology_provider.hpp Defines the provider interface, unique_agent_t, and documents selection precedence.
projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/topology/topology_provider.cpp Implements provider selection (make_default_provider) based on env/filesystem probes.
projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/topology/linux_kfd_provider.hpp Declares the Linux/KFD provider implementation.
projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/topology/linux_kfd_provider.cpp Contains the extracted Linux/KFD sysfs parsing + agent materialization logic.
projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/topology/dxg_provider.hpp Declares the WSL/DXCore provider skeleton and availability probe.
projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/topology/dxg_provider.cpp Implements libdxcore probing via dlopen/dlsym and a TODO enumerator.
projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/topology/d3dkmt_provider.hpp Declares the Windows D3DKMT provider skeleton and helper stubs.
projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/topology/d3dkmt_provider.cpp Provides Windows/non-Windows stub implementations and logging.
projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/topology/CMakeLists.txt Adds topology sources/headers to the object library build.
projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/CMakeLists.txt Adds the new topology/ subdirectory to the library build.
projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/agent.cpp Removes embedded topology enumeration and routes through TopologyProvider.
projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/agent_internal.hpp Introduces an internal declaration for update_agent_runtime_visibility() for providers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +7 to +9
set(ROCPROFILER_TOPOLOGY_SOURCES topology_provider.cpp linux_kfd_provider.cpp
dxg_provider.cpp d3dkmt_provider.cpp)

Comment on lines +57 to +82
} // namespace

std::unique_ptr<TopologyProvider>
make_default_provider()
{
const bool force_dxg = common::get_env("ROCPROFILER_FORCE_DXG", false);
const bool force_d3dkmt = common::get_env("ROCPROFILER_FORCE_D3DKMT", false);

if(force_dxg)
{
ROCP_INFO << "TopologyProvider: forced DxgProvider via ROCPROFILER_FORCE_DXG";
return std::make_unique<DxgProvider>();
}
if(force_d3dkmt)
{
ROCP_INFO << "TopologyProvider: forced D3dkmtProvider via ROCPROFILER_FORCE_D3DKMT";
return std::make_unique<D3dkmtProvider>();
}
if(sysfs_topology_present())
{
ROCP_INFO << "TopologyProvider: selected LinuxKfdProvider (sysfs present)";
return std::make_unique<LinuxKfdProvider>();
}
if(DxgProvider::is_available())
{
ROCP_INFO << "TopologyProvider: selected DxgProvider (libdxcore.so present)";
Comment on lines +109 to +113
while(std::getline(ifs, line))
{
if(ifs.eof())
{
if(!current_block.empty()) blocks.emplace_back(std::move(current_block));
Fixes probe_libdxcore() to look up D3DKMTEnumAdapters3 (the symbol
actually called) instead of CreateDXCoreAdapterFactory. Fills in
DxgProvider::enumerate() using D3DKMTEnumAdapters3 +
D3DKMTQueryAdapterInfo (PHYSICALADAPTERDEVICEIDS, ADAPTERADDRESS,
ADAPTERREGISTRYINFO, GETSEGMENTSIZE). Filters AMD adapters only,
packs PCI BDF into location_id, converts wide adapter names to UTF-8,
and closes every adapter handle. Fields DXCore cannot supply
(gfx_target_version, CU/SDMA counts, mem_banks/caches/io_links) are
left zero/empty rather than fabricated.

Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
@bgopesh

bgopesh commented May 25, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #6399

@bgopesh bgopesh closed this May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants