feat: add Enflame GCU TOPSPTI profiler integration - #142
Draft
lvyufeng wants to merge 1 commit into
Draft
Conversation
Add an optional TOPSPTI-backed DeviceTracer for Enflame GCU, including activity decoding, timestamp calibration, runtime correlation mapping, CMake detection, integration coverage, and architecture documentation.\n\nThe implementation gracefully falls back when the SDK is unavailable. Physical GCU validation remains pending because the current environment lacks the required Torch build and hardware.\n\nCo-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
lvyufeng
force-pushed
the
feat/gcu-rng-unified
branch
from
August 19, 2026 08:34
63f8808 to
083c616
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AI Agent Information
Summary
This PR adds an optional TOPSPTI-backed
DeviceTracerfor Enflame GCU and connects it to the existing vendor-neutral Kineto profiler adapter. The implementation decodes kernel, memcpy, memset, runtime, and driver activities, calibrates TOPSPTI timestamps to realtime, and preserves vendor correlation flow data plus best-effort Kineto external correlation. It also adds CMake SDK detection, unavailable fallbacks, a GCU integration test, and architecture documentation.Change Type
Platforms Affected
Problem Analysis
What was broken/missing?
The GCU backend had no implementation of the profiler
DeviceTracercontract. A Kineto session could not collect GCU device activities, runtime-to-device flow relationships, or GCU-specific activity metadata through the existing PrivateUse1 profiler path.Why did it happen?
The repository already had vendor-specific tracers for CUDA-compatible and other accelerator runtimes, but Enflame's TOPSPTI activity API had not been adapted to the shared
DeviceTracerabstraction. TOPSPTI also does not expose the CUPTI-style external-correlation push/pop API, so its correlation behavior requires a platform-specific mapping strategy.Investigation process:
csrc/profiler/device_tracer.h, the generic Kineto adapter, and existing CUDA, MSPTI, and MUPTI tracer implementations./opt/tops, identifying the asynchronous activity API intopspti_activity.handlibtopspti.soas the appropriate online tracing interface.flagos/main, resolved the RNG and operator-support conflicts while retaining both local and upstream changes, and checked that GCU source selection leaves exactly one tracer factory.Solution Design
Implementation approach:
gcu_topspti_device_tracer.ccimplementing the sharedDeviceTracerinterface.topspti_shim.hwith optional header declarations and lazydlopen/dlsymbinding.FLAGOS_HAVE_TOPSPTIonly when available.Key design decisions:
DeviceEventvalues.topsptiGetTimestamp()andCLOCK_REALTIME.External idattribution when callback ordering supports it.Code changes by file:
csrc/CMakeLists.txt: Select the GCU tracer exclusively and detect optional TOPSPTI headers.csrc/profiler/flagos_kineto_profiler.cc: Register the generic Kineto adapter forFLAGOS_HAVE_TOPSPTIbuilds.csrc/profiler/gcu_topspti_device_tracer.cc: Decode TOPSPTI activity buffers, calibrate timestamps, map correlations, and implement the GCU tracer factory.csrc/profiler/topspti_shim.h: Provide lazy runtime symbol binding and no-SDK fallback declarations.tests/integration/conftest.py: Register thegcupytest marker.tests/integration/test_profiler_gcu.py: Add physical-GCU TOPSPTI activity and Chrome trace assertions.docs/architecture/profiler.md: Document the GCU integration, correlation limitations, and current validation status.Changes by commit:
083c616-feat: add GCU TOPSPTI profiler integration: Add the tracer, runtime shim, build wiring, test, and documentation on top of the latest upstreammain.Verification
Pre-submission Checklist
ruff checkandruff format --check)pytestis unavailable in this environment)FLAGOS_TOPSPTI_DEBUG)Linting Results
Targeted checks for the changed Python files:
$ ruff check tests/integration/conftest.py tests/integration/test_profiler_gcu.py All checks passed! $ ruff format --check tests/integration/conftest.py tests/integration/test_profiler_gcu.py 2 files already formattedRepository-wide checks were also attempted:
Test Results
The GCU integration test therefore has not been run. It is designed to skip when
ACCELERATOR=gcu, the FlagOS backend, or the TOPSPTI runtime is unavailable, and requires physical GCU validation before this PR is marked ready for review.Manual Verification
The C++ source-level checks completed successfully. The only diagnostic is the existing unused-parameter warning from
DeviceTracer::pushCorrelationindevice_tracer.h:$ g++ -std=c++17 -Wall -Wextra -fsyntax-only \ -DUSE_GCU -DFLAGOS_HAVE_TOPSPTI \ -Icsrc/profiler -I/opt/tops/extras/TOPSPTI/include \ csrc/profiler/gcu_topspti_device_tracer.cc # Exit code: 0 # Warning: existing unused parameter `id` in device_tracer.h $ g++ -std=c++17 -Wall -Wextra -fsyntax-only \ -DUSE_GCU -Icsrc/profiler \ csrc/profiler/gcu_topspti_device_tracer.cc # Exit code: 0 $ g++ -std=c++17 -Wall -Wextra -fsyntax-only \ -Icsrc/profiler \ csrc/profiler/gcu_topspti_device_tracer.cc # Exit code: 0 $ git diff --check # No output; passedA complete CMake configure/build was attempted but is blocked because the active Python environment has no PyTorch installation or Torch CMake package:
Code Quality Verification
Style Consistency
DeviceTracerpatternsEdge Cases Considered
Potential Risks
External idattribution may require adjustment for a particular SDK release.Rollback Plan
Revert commit
63f8808. This removes the GCU TOPSPTI tracer, CMake detection, test, registration condition, and documentation without changing the existing CUDA, MetaX, Ascend, or MUSA tracer implementations.Related Work
Explicitly Not Included
Human Review Notes
Areas needing special attention:
External idattribution on physical GCU hardware.Questions for reviewer:
Additional Context
The installed SDK was inspected under
/opt/tops; the implementation uses the public asynchronous activity API from/opt/tops/extras/TOPSPTI/includeand resolveslibtopspti.solazily. Runtime lookup can be overridden withFLAGOS_TOPSPTI_LIBRARY, and diagnostics can be enabled withFLAGOS_TOPSPTI_DEBUG=1.🤖 Generated with Claude Code