--------------------------------------------------------------------------------
-- |
-- Module      : ArrayFire.Backend
  Copyright    :   ( c ) 2019 - 2020
  License      : BSD 3
  Maintainer   :   <  >
-- Stability   : Experimental
  Portability : GHC
--
  Set and get available ArrayFire ' Backend 's .
--
-- @
-- module Main where
--
  import ArrayFire
--
-- main :: IO ()
-- main = print =<< getAvailableBackends
-- @
--
-- @
  [ CPU , OpenCL ]
-- @
--------------------------------------------------------------------------------
module ArrayFire.Backend where

import ArrayFire.FFI
import ArrayFire.Internal.Backend
import ArrayFire.Internal.Types

-- | Set specific 'Backend' to use
--
-- >>> setBackend OpenCL
-- ()
setBackend
  :: Backend
  -- ^ 'Backend' to use for 'Array' construction
  -> IO ()
setBackend = afCall . af_set_backend . toAFBackend

-- | Retrieve count of Backends available
--
  > > > getBackendCount
  2
--
getBackendCount :: IO Int
getBackendCount =
  fromIntegral <$>
    afCall1 af_get_backend_count

-- | Retrieve available 'Backend's
--
-- >>> mapM_ print =<< getAvailableBackends
-- CPU
  OpenCL
getAvailableBackends :: IO [Backend]
getAvailableBackends =
  toBackends . fromIntegral <$>
    afCall1 af_get_available_backends

-- | Retrieve 'Backend' that specific 'Array' was created from
--
  > > > getBackend ( scalar @Double 2.0 )
  OpenCL
getBackend :: Array a -> Backend
getBackend = toBackend . flip infoFromArray af_get_backend_id

-- | Retrieve active 'Backend'
--
-- >>> getActiveBackend
  OpenCL
getActiveBackend :: IO Backend
getActiveBackend = toBackend <$> afCall1 af_get_active_backend

-- | Retrieve Device ID that 'Array' was created from
--
-- >>> getDeviceID (scalar \@Double 2.0)
  1
getDeviceID :: Array a -> Int
getDeviceID = fromIntegral . flip infoFromArray af_get_device_id

------------------------------------------------------------------------------
 |
 Module      : ArrayFire.Backend
 Stability   : Experimental


 @
 module Main where


 main :: IO ()
 main = print =<< getAvailableBackends
 @

 @
 @
------------------------------------------------------------------------------
 | Set specific 'Backend' to use

 >>> setBackend OpenCL
 ()
 ^ 'Backend' to use for 'Array' construction
 | Retrieve count of Backends available


 | Retrieve available 'Backend's

 >>> mapM_ print =<< getAvailableBackends
 CPU
 | Retrieve 'Backend' that specific 'Array' was created from

 | Retrieve active 'Backend'

 >>> getActiveBackend
 | Retrieve Device ID that 'Array' was created from

 >>> getDeviceID (scalar \@Double 2.0)
  Copyright    :   ( c ) 2019 - 2020
  License      : BSD 3
  Maintainer   :   <  >
  Portability : GHC
  Set and get available ArrayFire ' Backend 's .
  import ArrayFire
  [ CPU , OpenCL ]
module ArrayFire.Backend where

import ArrayFire.FFI
import ArrayFire.Internal.Backend
import ArrayFire.Internal.Types

setBackend
  :: Backend
  -> IO ()
setBackend = afCall . af_set_backend . toAFBackend

  > > > getBackendCount
  2
getBackendCount :: IO Int
getBackendCount =
  fromIntegral <$>
    afCall1 af_get_backend_count

  OpenCL
getAvailableBackends :: IO [Backend]
getAvailableBackends =
  toBackends . fromIntegral <$>
    afCall1 af_get_available_backends

  > > > getBackend ( scalar @Double 2.0 )
  OpenCL
getBackend :: Array a -> Backend
getBackend = toBackend . flip infoFromArray af_get_backend_id

  OpenCL
getActiveBackend :: IO Backend
getActiveBackend = toBackend <$> afCall1 af_get_active_backend

  1
getDeviceID :: Array a -> Int
getDeviceID = fromIntegral . flip infoFromArray af_get_device_id
