{-# LANGUAGE BangPatterns #-}
module Data.Array.Accelerate.LLVM.PTX.Array.Table (
MemoryTable,
new,
) where
import Data.Array.Accelerate.LLVM.PTX.Context ( Context, withContext )
import qualified Data.Array.Accelerate.Array.Remote as Remote
import qualified Data.Array.Accelerate.LLVM.PTX.Debug as Debug
import {-# SOURCE #-} Data.Array.Accelerate.LLVM.PTX.Execute.Event
import qualified Foreign.CUDA.Ptr as CUDA
import qualified Foreign.CUDA.Driver as CUDA
import Text.Printf
type MemoryTable = Remote.MemoryTable CUDA.DevicePtr (Maybe Event)
{-# INLINEABLE new #-}
new :: Context -> IO MemoryTable
new !ctx = Remote.new freeRemote
where
freeRemote :: CUDA.DevicePtr a -> IO ()
freeRemote !ptr = do
message (printf "freeRemote %s" (show ptr))
withContext ctx (CUDA.free ptr)
{-# INLINE trace #-}
trace :: String -> IO a -> IO a
trace msg next = Debug.traceIO Debug.dump_gc ("gc: " ++ msg) >> next
{-# INLINE message #-}
message :: String -> IO ()
message s = s `trace` return ()