 
 -- Friends
 import C2HS
+import Time
 import RandomVector
 
 -- System


--
-- Note that this requires two memory copies: once from a Haskell list to the C
-- heap, and from there into the graphics card memory.
--
foldCUDA :: [Float] -> IO Float
foldCUDA xs =
  let len = length xs in
  CUDA.withListArray xs $ \d_xs -> fold_plusf d_xs len

{# fun unsafe fold_plusf
  { withDP* `CUDA.DevicePtr Float'


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!"

