 
 --
 -- Note that this requires two memory copies: once from a Haskell list to the C
--- heap, and from there into the graphics card memory.
+-- heap, and from there into the graphics card memory. See the `bandwidthTest'
+-- example for the atrocious performance of this operation.
+--
+-- For this test, cheat a little and just time the pure computation.
 --
 foldCUDA :: [Float] -> IO Float
-foldCUDA xs =
-  let len = length xs in
-  CUDA.withListArray xs $ \d_xs -> fold_plusf d_xs len
+foldCUDA xs = do
+  let len = length xs
+  CUDA.withListArray xs $ \d_xs -> do
+    (t,r) <- benchmark 100 (fold_plusf d_xs len) CUDA.sync
+    putStrLn $ "== CUDA: " ++ show (timeIn millisecond t) ++ "ms"
+    return r
 
 {# fun unsafe fold_plusf
   { withDP* `CUDA.DevicePtr Float'


-- Friends
import C2HS
import RandomVector

-- System


main :: IO ()
main = do
  dev   <- CUDA.get
  props <- CUDA.props dev
  putStrLn $ "Using device " ++ show dev ++ ": " ++ CUDA.deviceName props

  xs   <- randomList 30000
  ref  <- foldRef xs
  cuda <- foldCUDA xs

  putStrLn $ "== Validating: " ++ if ((ref-cuda)/ref) < 0.0001 then "Ok!" else "INVALID!"

