PR09: DSP/Graph Execution (C++)#10442
Open
agibsonccc wants to merge 11 commits into
Open
Conversation
Part of the 22-PR split of ag_new_release_updates_2 branch. Merge layer: 3 (native features) Files: 169 See pr-plans/00-master-plan.md for the full split plan and merge order.
This was referenced Jun 15, 2026
…s with constants - Remove build-workaround comment from NativeDynamicShapePlan.cpp - Define DIAGNOSTIC_SRC_SENTINEL_OFFSET and DIAGNOSTIC_OUT_SENTINEL_OFFSET constants in OneDnnGraphBackend.cpp to replace bare 50000/60000 magic numbers
…yet-implemented Add explicit runtime warning in setGraphExecutionMode() when GEM_TVM (16) is requested: sd_printf logs that TVM was removed and execution falls back to SLOT_BY_SLOT. Expand the ModeContract case 16 comment to direct users to GEM_TRITON or GEM_NVRTC_JIT. Add a prominent stub comment block to PjrtClientManager.h and .cpp making clear that all PJRT/TPU methods return false/nullptr and must not be called in production. Document what is needed for real TPU integration and reference ADR 0072 for the roadmap.
Delete libnd4j/profiler-output.txt.ncu-rep — a profiler report binary that was accidentally committed to the repo with zero references.
Contributor
Author
Architecture OverviewThis PR is the DSP (Dynamic Shape Plan) execution engine — the core C++ runtime that compiles, captures, and replays computation graphs. It implements the full dispatch priority chain: Triton MLIR → NVRTC JIT → PTX templates → CUDA Graphs → slot-by-slot, with thread-isolated plan caches and dual-stream execution (DSP stream + gap stream). Highlights
|
Refactor MetalReplayHandle to support Indirect Command Buffer replay integration with the DSP framework on macOS ARM64.
DSP logging consolidation: - Context.cpp: fix 8 diagnostic blocks from || to && gating - NativeDynamicShapePlan.cpp: remove isVerbose() gates on DSP_DIAG, add DSP_DIAG companions to error sd_printf calls - NativeDynamicShapePlan_gpubackend.cu: change stats gate to isDebug() - TritonIRBuilder_module.cpp: sd_debug → DSP_DIAG(COMPILE,...) Diagnostics gating (sd_printf → sd_debug): - Graph.cpp, Variable.cpp, VariableSpace.cpp, VariableProxy.cpp, Stash.cpp, NativeDynamicShapePlan_slotexec.cpp, NativeDynamicShapePlan_gpubackend.cpp CUDA macros: - MegaKernelInterpreter.cu: __global__→SD_KERNEL, __device__→SD_DEVICE
Apply THROW_EXCEPTION macro consolidation to graph/DSP execution files.
Add DspSegmentHelpers.h, sync Node.h
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.
Summary
PR 09 of 22 PRs in the
ag_new_release_updates_2branch split. Merge after Layer 2 (native core ops + helpers)..cpp/.cufiles + 40 new headers implementing the full native plan executorsetGraphExecutionMode()g_captureActive[16]) serialize concurrent captures;CaptureStateGuardRAII prevents illegalcudaStreamQuerycalls during capture (avoids CUDA error 900)NativePlanCachekeys on(outputSetHash, phShapeContentHash, phCount, graphExecutionMode, threadId); each thread gets its own plan instance, mutable slot state never sharedplanCacheBudgetFraction * freeDeviceMem); pin/unpin prevents eviction of active plansDspDiagEventring buffer; FULL level echoes every event to stderr in real timeGraphReplayFactoryselects from 8GraphReplayHandlesubclasses: CUDA, HIP/ROCm, Metal, Vulkan, Level Zero, TPU, Hexagon/QNN, CPU functionalLogicXxxfiles (LogicWhile, LogicSwitch, etc.) deleted; TF-graph-style control flow replaced by plan-based compilation (resolved at Java level before serialization)tl_dspExecutionStreamroutes H2D through DSP stream;tl_dspGapStream(viaScopedDspGapStreamRAII) routes cuBLAS gap ops onto the same stream as island replayWhat Changed
Core DSP execution engine — graph/impl/ (35 new files, 10 modified)
NativeDynamicShapePlan.cpp— main executor: plan deserialization, NativeSlot construction,executeSlot()dispatcher routing to slot-by-slot/CUDA graph/NVRTC/Triton;DSP_BUF(arr)macro for portable CUDA/CPU buffer accessNativeDynamicShapePlan_segments.cpp— segment shape key hashing, CPU graph backend dispatch, slot-by-slot fallbackNativeDynamicShapePlan_cudagraph.cu— CUDA graph state machine: warmup→capture→instantiate→replay; per-GPU atomics for concurrent capture serialization;ScopedDspGapStreamRAIINativeDynamicShapePlan_cuda.cu— device-side slot execution;tl_dspExecutionStreamandtl_dspGapStreamthread-local stream management; cuBLAS workspace gate for graph captureNativeDynamicShapePlan_slotexec.cpp/_slotexec_cuda.cu— op-by-op dispatch using LegacyTransformSameOp, LegacyScalarOp, LegacyReduceFloatOp, etc.NativeDynamicShapePlan_cublas.cu— batched GEMM via cublasSgemmStridedBatched; cuBLASLt matmul with workspace; stream-capture-safe allocationNativeDynamicShapePlan_batchgemm.cu— groups consecutive matmul slots into single cublasGemmStridedBatchedEx callNativeDynamicShapePlan_batchzero.cu— zeros output buffers via cudaMemsetAsync before segment executionNativeDynamicShapePlan_gpubackend.cpp/.cu— GPU backend selection: Triton→NVRTC→PTX→CUDA Graphs; handles segment splitting for register pressure limitsNativeDynamicShapePlan_prereplay.cu— pointer stability validation, placeholder H2D sync, argTableStable fast-path detectionNativeDynamicShapePlan_cuda_stubs.cpp— CPU-side stubs so CPU build links cleanlyNativePlanCache.cpp— LRU with content-based key; dual eviction: hard count cap + memory soft cap; pin/unpin supportNativePlanCompiler.cpp— deserializes FlatBuffers from Java, constructs NativeSlot array, resolves variable referencesPlanDefinition.cpp,PlanTopology.cpp— plan data model and topological orderingSegmentExecutor.cpp— segment lifecycle: build→seal→replace for FrozenPlan segmentsSlotArray.cpp,SlotBufferOwnership.cpp— slot array management and buffer ownership for CUDA graph address stabilityFrozenPlan.cpp— pointer table captured at freeze; validated on each replay attemptFusionPass.cpp— identity elimination, cast chain collapsing, element-wise chain groupingGraphAnalysisUtils.cpp— convex subgraph detection, segment boundary inferenceGraphReplayFactory.cpp— selects correctGraphReplayHandlesubclass based on detected hardwareReplayCacheManager.cpp— per-segment compiled graph handles with LRU evictionResourceBinder.cpp— binds placeholders/variables/constants to native slot pointers pre-executionDspBufferColorMap.cpp,DspDiagnostics.cpp— buffer reuse analysis and diagnostics frameworkDspBufferPool.cpp— reusable intermediate buffer poolExecutionState.cpp/.cu,DeviceExecutionContext.cpp/.cu— per-execution mutable state, per-device contextSdnbReader.cpp,SdzReader.cpp— plan bundle deserializers (single bytes and zip format)Node.cpp,Graph.cpp,Context.cpp,FlatUtils.cppand others — updated for DSP compatibilityCore DSP headers — graph/ (40 new, 6 modified, 12 deleted)
NativeDynamicShapePlan.h—GraphExecutionModeenum (19 modes);JitModeenum;NativeSlotstruct; plan lifecycle methodsNativePlanCache.h— LRU cache with content-based key; thread-per-plan isolationDspDiagnostics.h— 20-category bitfield (all → DSP_DIAG_ALL=0xFFFFF); SUMMARY/DETAILED/FULL levels;DspDiagEventring buffer (65,536 entries)GraphBackend.h— abstract backend interface:isAvailable(),canFuseSegment(),compileSegment(),executeSegment(),invalidateCache(),getLastCompilationAudit()GraphReplayHandle.h— abstract replay handle:ReplayStateenum,ReplayStatistics, workspace management APIDspGraphTypes.h—GraphSegmentstruct,NativeSlotstruct with op classification and buffer pointersDspPhaseUtils.h— phase transition guards; SLOT_BY_SLOT→SHAPES_FROZEN→REPLAYING lifecycle checksCaptureStateGuard.h— RAII guard settingstreamCaptureActiveflag to block illegal API calls during CUDA graph captureDspDiagnostics.h,DspBufferColorMap.h,DspBufferPool.h,DspExecutionTrace.h,DspStreamGuard.h,DspThreadState.h,FrozenPlan.h,FusionPass.h,PlanDefinition.h,PlanTopology.h,ReplayCacheManager.h,ResourceBinder.h,SegmentExecutor.h,SlotArray.h,DeviceExecutionContext.h,SdnbReader.h,SdzReader.h— supporting subsystem headersFlowPath.h,GraphExecutioner.h,GraphHolder.h, all 10LogicXxx.h/.cppfiles (LogicConditional, LogicWhile, LogicSwitch, etc.)Multi-backend GraphReplayHandle — graph/ (12 new files)
cuda/CudaGraphReplayHandle.h/.cu— wraps CudaGraphHandle; beginCapture/endCapture/finalize/replay via CUDA graph APIhip/HipGraphReplayHandle.h/.cpp— HIP (ROCm) graph capture/replay mirrormetal/MetalReplayHandle.h/.mm— Metal command buffer capture/replayvulkan/VulkanReplayHandle.h/.cpp— Vulkan command buffer recording/replaylevelzero/LevelZeroReplayHandle.h/.cpp— Intel Level Zero graph backendtpu/TpuReplayHandle.h/.cpp,TpuGraphBackend.h/.cpp,HloIRBuilder.h/.cpp,PjrtClientManager.h/.cpp— TPU via PJRT; HloIRBuilder generates XLA HLO from NativeSlotshexagon/HexagonGraphBackend.h/.cpp,HexagonIRBuilder.h/.cpp,HexagonReplayHandle.h/.cpp,HexagonRuntimeManager.h/.cpp— Qualcomm Hexagon/QNN backendCPU graph backends — graph/cpu/ (14 new files)
OneDnnGraphBackend.h/.cpp— oneDNN Graph API: builds and executes compiled_partition from segment slotsAclGraphBackend.h/.cpp— ARM Compute Library Dynamic Fusion backendMlxGraphBackend.h/.cpp,MlxIRBuilder.h/.cpp— Apple MLX compute graph backendMlirCpuGraphBackend.h/.cpp— MLIR Linalg/arith JIT for CPUArmHybridGraphBackend.h/.cpp— MLIR CPU + Vulkan for Android/AArch64NnapiGraphBackend.h/.cpp— Android NNAPI backendOpenVinoGraphBackend.h/.cpp— Intel OpenVINO backendFunctionalReplayHandle.h/.cpp— CPU fallback: re-runs compiled segment function on replayCpuIRBuilder.h/.cpp— platform-neutral IR generator for CPU backendsProfiling
profiling/OpTimingTracker.h/.cpp— per-op timing with CSV export; integrates with TIMING diagnostic categoryprofiling/impl/GraphProfile.cpp— updated to use OpTimingTrackerprofiling/impl/GraphProfilingHelper.cpp— replaced by OpTimingTrackerDependencies
Merge Order
These 22 PRs must merge in layer order. Each layer depends on the layers above it being merged first. PRs within the same layer are independent and can merge in parallel.