Skip to content

Commit 7a9e3de

Browse files
committed
Add Async Future status polling to CPU
1 parent 2118dd5 commit 7a9e3de

File tree

2 files changed

+16
-5
lines changed
  • accelerate-llvm-native/src

2 files changed

+16
-5
lines changed

accelerate-llvm-native/src/Data/Array/Accelerate/LLVM/Native/Execute/Async.hs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ data Future a = Future {-# UNPACK #-} !(IORef (IVar a))
7373
data IVar a
7474
= Full !a
7575
| Blocked !(Seq (a -> IO ()))
76-
| Empty
7776

7877
instance Async Native where
7978
type FutureR Native = Future
@@ -82,7 +81,7 @@ instance Async Native where
8281

8382
{-# INLINE new #-}
8483
{-# INLINE newFull #-}
85-
new = Future <$> liftIO (newIORef Empty)
84+
new = Future <$> liftIO (newIORef (Blocked Seq.empty))
8685
newFull v = Future <$> liftIO (newIORef (Full v))
8786

8887
{-# INLINE fork #-}
@@ -95,7 +94,6 @@ instance Async Native where
9594
callCC $ \k -> do
9695
native <- gets llvmTarget
9796
next <- liftIO . atomicModifyIORef' ref $ \case
98-
Empty -> (Blocked (Seq.singleton (evalParIO native . k)), reschedule)
9997
Blocked ks -> (Blocked (ks Seq.|> evalParIO native . k), reschedule)
10098
Full a -> (Full a, return a)
10199
next
@@ -108,6 +106,21 @@ instance Async Native where
108106
{-# INLINE liftPar #-}
109107
liftPar = Par . lift
110108

109+
{-# INLINE statusHandle #-}
110+
statusHandle (Future ref) = do
111+
emptyFut@(Future emptyIVar) <- new
112+
fullFut <- newFull ()
113+
liftIO $ atomicModifyIORef' ref $ \case
114+
Blocked ks -> (Blocked (ks Seq.|> const (writeIORef emptyIVar (Full ()))), emptyFut)
115+
Full v -> (Full v, fullFut)
116+
117+
{-# INLINE poll #-}
118+
poll (Future ref) = do
119+
ivar <- liftIO $ readIORef ref
120+
case ivar of
121+
Full v -> return (Just v)
122+
_ -> return Nothing
123+
111124
-- | Evaluate a continuation
112125
--
113126
{-# INLINE evalParIO #-}
@@ -122,7 +135,6 @@ evalParIO native@Native{} work =
122135
putIO :: HasCallStack => Workers -> Future a -> a -> IO ()
123136
putIO workers (Future ref) v = do
124137
ks <- atomicModifyIORef' ref $ \case
125-
Empty -> (Full v, Seq.empty)
126138
Blocked ks -> (Full v, ks)
127139
_ -> internalError "multiple put"
128140
--

accelerate-llvm-native/src/Language/Haskell/TH/Extra.hs

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)