# GPU Implementation Deduplication Plan

> Post-candle-elimination cleanup. Consolidate duplicate GPU tensor, linear, activation, and optimizer implementations.

**Goal:** Single canonical implementation per GPU primitive in ml-core, with ml-ppo CudaLinear kept for its distinct ownership model.

---

## Phase 1: Delete ml-supervised GpuTensor/GpuLinear (CRITICAL)

- DELETE `crates/ml-supervised/src/gpu_tensor.rs` GpuTensor + GpuLinear definitions
- Re-export `ml_core::cuda_autograd::{GpuTensor, GpuLinear}` in ml-supervised
- Update all ml-supervised imports
- ~200 LOC reduction

## Phase 2: Consolidate activations into ml-core

- MERGE `crates/ml-ppo/src/cuda_nn/activations.rs` CUDA kernels into ml-core
- DELETE `crates/ml-ppo/src/cuda_nn/activations.rs`
- Add thin wrapper in ml-ppo returning CudaVec for PPO compat
- ~400 LOC reduction

## Phase 3: Merge AdamW kernels

- MERGE `crates/ml-ppo/src/cuda_nn/adam.rs` kernel source into ml-core GpuAdamW
- Keep wrapper in ml-ppo for flat param group interface
- ~200 LOC reduction

## Phase 4: GPU-ify host-side workarounds

Priority order:
1. `gpu_clone()` — cudaMemcpyDtoDAsync (trivial, HIGH frequency)
2. `add/sub/mul()` — 3 element-wise CUDA kernels (~10 lines each)
3. `broadcast_mul/div()` — strided CUDA kernel
4. `softmax` — standard CUDA softmax kernel for attention
5. `narrow(dim>0)` — 2D copy kernel
6. `argmax/mean_all` — CUB reductions (LOW frequency)

## Phase 5: Consolidate pointer helpers

- Define `raw_ptr()`/`raw_ptr_mut()` once in ml-core, re-export
- Delete 3 duplicate definitions
