======================================================================
Round 42 -- RTX 4060 Laptop fp64 Diagnosis Summary
======================================================================
PyTorch        : 2.5.1+cu121
GPU            : NVIDIA GeForce RTX 4060 Laptop GPU
Compute cap    : sm_89
VRAM           : 8.6 GB

-- Test 1: Isolated fp64 vs fp32 penalty for core operations --------
          op      size     fp32_ms     fp64_ms     ratio
-------------------------------------------------------
        rfft    16,384    0.012288    0.149504   12.1667x
       irfft    16,384    0.017408    0.155648    8.9412x
         exp    16,384    0.010240    0.026400    2.5781x
         mul    16,384    0.008192    0.009216    1.1250x
         sum    16,384    0.008192    0.012288    1.5000x
   histogram    16,384    0.019456    0.028960    1.4885x
        rfft    32,768    0.020480    0.061440    3.0000x
       irfft    32,768    0.026624    0.065536    2.4615x
         exp    32,768    0.034944    0.017408    0.4982x
         mul    32,768    0.008192    0.027648    3.3750x
         sum    32,768    0.012192    0.020480    1.6798x
   histogram    32,768    0.019520    0.029696    1.5213x

  Worst fp64 penalty: rfft at size=16,384  ratio=12.1667x
  RTX 4060 fp64 TFLOPS ~ 0.25 (1/32 of fp32 8 TFLOPS = compute bottleneck)

-- Test 2: DCB forward phase breakdown (n=50K bimodal, fp64) --------
  Full forward fp64 : 74.546 ms
  Full forward fp32 : 237.196 ms
  fp64/fp32 ratio   : 0.31x
  (Round 38 baseline was 134ms -- this run should be similar)

  precompute_fft fp64 : 0.547 ms  (0.7% of forward)
  trisection 16R fp64 : 7.426 ms  (10.0% of forward)  = 0.464 ms/round
  _refine_hcrit fp64  : 1.715 ms  (2.3% of forward)

-- Test 3: forward_batched breakdown (K=16, n=50K, fp64) ------------
  serial   K=16: 3913.158 ms  (244.572 ms/dist)
  batched  K=16: 868.690 ms  (54.293 ms/dist)
  speedup      : 4.50x  (P100 baseline: 10.7x at K=16)

  forward_batched_total                   : 868.6899 ms
  serial_total                            : 3913.1577 ms
  speedup                                 : 4.5047 ms
  precompute_fft_batch_f32                : 23.4957 ms
  precompute_fft_batch_f64                : 31.4592 ms
  mode_count_K_batch_1round               : 2.8570 ms
  trisection_16R_estimate                 : 45.7114 ms

-- Test 4: Memory bandwidth saturation ------------------------------
  fp32 copy 100MB: 0.9216 ms  -> 227.6 GB/s  (83.7% of 272 GB/s spec)
  fp64 copy 100MB: 0.9185 ms  -> 228.3 GB/s  (83.9% of 272 GB/s spec)
  fp64/fp32 copy ratio: 1.00x
  -> Memory-bound: fp64 copy is fast -> bottleneck is COMPUTE, not BW
    (RTX 4060 fp64 compute = 0.25 TFLOPS = 1/32 of fp32)

-- Test 5: fp32 drop-in accuracy ------------------------------------
  fp64 batch K=16: 868.690 ms  (reference)
  fp32 batch K=16: 272.758 ms  speedup=3.18x
  fp32 accuracy: max |err%|=0.0001%  mean=0.0000%
  fp32 on fp64 data accuracy: max |err%|=0.0000%  mean=0.0000%
  fp32 PASS (<0.1%): YES

-- Practical Recommendation -----------------------------------------
RTX 4060 Laptop fp64 TFLOPS = 0.25 TFLOPS (1/32 of 8 TFLOPS fp32).
The irfft inner loop in mode_count_from_C / mode_count_K_batch
is executed in fp64 (complex128) for numerical correctness.
On RTX 4060 this gives ~30x compute penalty per irfft vs fp32.

fp32 forward_batched is accurate to <0.1% -- ACCEPTABLE for training.
RECOMMENDATION: Use fp32 internally for CUDA training (fft_dtype=float32)
and only verify final mode count in fp64 (C_mc separate compute).
This is already the design of DCBLayer (fft_dtype=float32 default)
but forward_batched up-casts C_batch to complex128 for mode counting.
A CUDA-fp32 mode counting path (with 1e-6 relative threshold) could
recover the 30x penalty while staying within <0.1% accuracy.

======================================================================