PR14: Java Backend Implementations (CUDA + CPU)#10447
Open
agibsonccc wants to merge 8 commits into
Open
Conversation
Part of the 22-PR split of ag_new_release_updates_2 branch. Merge layer: 4 (java core) Files: 117 See pr-plans/00-master-plan.md for the full split plan and merge order.
…impls # Conflicts: # nd4j/nd4j-backends/nd4j-backend-impls/nd4j-cuda/src/main/java/org/nd4j/linalg/jcublas/context/CudaContext.java
This was referenced Jun 15, 2026
…ent, SleepyTrainingListener)
…-cpu-backend-common)
…date production imports
Contributor
Author
Architecture OverviewThis PR implements the Java backend layer for CUDA and CPU, plus scaffolding for 4 new target platforms. The key architectural change is Highlights
|
…onUID, property centralization
- Add Info entries for SD_VALIDATE_PTR/OpTraits in CPU and CUDA presets - Fix nd4j-native pom.xml: disable --release to resolve --add-exports conflict
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 14 of 22 PRs in the
ag_new_release_updates_2branch split. Merge after Layer 3 (native platform backends + DSP engine).CudaDeviceContextProvider: New single canonical path for device-switching; replaces 15+ duplicated sequences (update affinity map →nativeOps.setDevice()→ resetCudaZeroHandlerThreadLocal → fetch stream pointers) acrossCudaAffinityManager,AtomicAllocator,CudaZeroHandler, and multiple executioner pathsBaseCudaDataBuffertracksCoherenceStateper buffer;syncToHost()/syncToDevice()are no-ops when state is already valid; all 14 typed CUDA buffer subclasses updatedAtomicAllocatorintegration:allocateMemory()now callsDeviceMemoryManager.trackAllocation()before native allocation; enables cap enforcement and eviction callbacks without pollingpriority=50), Hexagon (SNPE/QNN dispatch), ZLUDA (AMD GPUs via HIP→CUDA translation, reuses existing JCublas backend), SDX (Snapdragon X Elite NPU, early-stage scaffold)jni-config.json,reflect-config.json,resource-config.json,native-image.propertiesadded to CPU backend underMETA-INF/native-image/DeviceContextProviderdelegation,DeviceMemoryManagerregistration,OpaqueDataBufferDeallocator,MultiBackendWorkspaceinterfaceAllocationPoint: AddedgetCoherenceState()/setCoherenceState()methods; deallocation unified viaOpaqueNDArrayDeallocatorWhat Changed
CPU Backend — nd4j-cpu-backend-common (18 files)
CpuAffinityManager.java— delegates thread affinity toCpuDeviceContextProviderCpuMemoryManager.java— registers withDeviceMemoryManager; honors memory capsCpuNDArrayFactory.java— routes throughDeviceAwareNDArrayFactoryBaseCpuDataBuffer.java— coherence state tracking;OpaqueDataBufferDeallocatorNativeOpExecutioner.java— integratesDeviceAwareOpExecutioner,BackendRoutingStrategy,HelperRouter; DSP plan path updatedCpuWorkspace.java— implementsMultiBackendWorkspaceinterfaceCpuTADManager.java,DirectShapeInfoProvider.java,CpuLapack.java,CpuLevel1.java,DefaultDataBufferFactory.java,CpuDeallocator.java,ConstantBuffersCache.java,CpuOpContext.java,CpuOpContextDeallocator.java,CpuNativeRandom.java— API alignment and coherence/deallocator updatesmodule-info.java— Java 9 module descriptorCUDA Backend — nd4j-cuda (40+ files)
CudaDeviceContextProvider.java— single canonical device-switch path: updates affinity map, traces viaMultiGpuTracer, callsnativeOps.setDevice()(triggers C++ContextBuffers::release()+ lazy reinit), resetsCudaZeroHandlerThreadLocal, fetches stream pointers viabuildContext(); replaces 15+ duplicated call sitesAllocationPoint.java—getCoherenceState()/setCoherenceState()methodsAtomicAllocator.java—allocateMemory()andfree()updateDeviceMemoryManageratomics for cap enforcementCudaAffinityManager.java— now delegates toCudaDeviceContextProvider; retains only high-level APIBaseCudaDataBuffer.java— coherence state per buffer;syncToHost()/syncToDevice()guarded byCoherenceState;OpaqueDataBufferDeallocatorCudaFloatDataBuffer.java,CudaHalfDataBuffer.java,CudaBfloat16DataBuffer.java,CudaDoubleDataBuffer.java,CudaIntDataBuffer.java,CudaLongDataBuffer.java,CudaByteDataBuffer.java,CudaBoolDataBuffer.java,CudaShortDataBuffer.java,CudaUByteDataBuffer.java,CudaUInt16DataBuffer.java,CudaUInt32DataBuffer.java,CudaUInt64DataBuffer.java,CudaUtf8Buffer.java— all updated for coherence tracking and new deallocator chainCudaDataBufferFactory.java— produces coherence-aware buffersMemoryHandler.java,CudaZeroHandler.java— reset context viaCudaDeviceContextProvideron device switchCudaMemoryManager.java— registers allocations inDeviceMemoryManager; checks device caps before allocatingSynchronousFlowController.java— usestl_dspGapStreamfor gap op stream synchronizationCudaWorkspace.java— implementsMultiBackendWorkspacewith coherence-aware buffer managementCudaExecutioner.java— integratesDeviceAwareOpExecutioner,MultiBackendExecutioner; DSP execution path updatedCudaEnvironment.java,JCublasBackend.java— updated forEnvironmentsubsystem config classesJCublasNDArray.java,JCublasNDArrayFactory.java— coherence tracking; device-routed factoryJcublasLapack.java,JcublasLevel1.java— routed throughDeviceAwareOpExecutionerCudaDeallocator.java,CudaContext.java,CudaOpContext.java,CudaOpContextDeallocator.java— updated deallocator chain and device context propagationConfiguration.java— extended with multi-device routing, FP8 support, Triton section fusion propertiesBasicTADManager.java,DeviceTADManager.java— updated for device descriptor abstractionNd4jCudaPresets.java— updated preset annotations for FP8/Triton/paged attention entry pointsmodule-info.java,nd4j-jcublas.properties— module exports and properties updatedCUDA Platform and Presets
nd4j-cuda-platform/pom.xml,nd4j-cuda-preset/pom.xml— updated platform BOM and preset buildNd4jMinimalPresets.java,Nd4jMinimal.java,CpuStatisticsProvider.java— updated minimizer backendNew: TPU Backend — nd4j-tpu (7 files)
JTpuBackend.java— PJRT (Portable Runtime) for Cloud TPU v4/v5; auto-detects TPU via JNI probe;priority=50JTpuNDArray.java— NDArray backed by XLA buffer handlesJTpuNDArrayFactory.java— producesJTpuNDArrayinstancesTpuEnvironment.java— HLO compilation caching, BF16 defaultsTpuExecutioner.java— routes ops to PJRT XLA executionTpuOpContext.java,nd4j-jtpu.propertiesNew: TPU Preset — nd4j-tpu-preset (2 files)
Nd4jTpuPresets.java/Nd4jTpuHelper.java— JavaCPP preset and helper for PJRT bindingsNew: Hexagon Backend — nd4j-hexagon (6 files)
HexagonBackend.java,HexagonEnvironment.java,HexagonExecutioner.java,HexagonOpContext.java— Qualcomm Hexagon DSP via SNPE/QNNMETA-INF/services/org.nd4j.linalg.factory.Nd4jBackend— service registrationnd4j-hexagon-preset/Nd4jHexagonPresets.java— JavaCPP preset for SNPE/QNN bindingsNew: ZLUDA Backend — nd4j-zluda (4 files)
JZludaBackend.java— CUDA-compatible backend via ZLUDA HIP→CUDA translation for AMD GPUs; reuses JCublas backend without Java-layer changesZludaEnvironment.java,module-info.java,nd4j-jzluda.propertiesNew: SDX Backend — nd4j-sdx (1 file)
SdxRuntime.java— Snapdragon X Elite NPU integration (early-stage scaffold)GraalVM Native Image — nd4j-native/META-INF/native-image/ (4 files)
jni-config.json,reflect-config.json,resource-config.json,native-image.properties— GraalVM Native Image configuration for CPU backend AOT compilationBuild Infrastructure
nd4j-backend-impls/pom.xml— adds tpu, hexagon, zluda, sdx modulesnd4j-presets-common/pom.xml,nd4j-native-platform/pom.xml— updated dependenciesDependencies
DeviceContextProvider,DeviceMemoryManager,DeviceDescriptor,CoherenceState,MultiBackendWorkspaceinterfaces); PR13 (new op impls tested through updated executioners)CudaExecutionerandNativeOpExecutioner), PR16 (DSP runtime usesCudaDeviceContextProviderfor stream management)Merge Order
This PR is in Layer 4 (Java backend implementations — parallel with PR12/PR13/PR15, all needed before PR16).