module Foreign.OpenCL.Bindings.Device (
getDeviceIDs,
deviceAddressBits, deviceAvailable, deviceCompilerAvailable,
deviceEndianLittle, deviceErrorCorrectionSupport,
deviceExecutionCapabilities,
deviceExtensions, deviceGlobalMemCacheSize, deviceGlobalMemCacheLineSize,
deviceGlobalMemSize, deviceGlobalMemCacheType,
deviceLocalMemSize, deviceLocalMemType,
deviceImageSupport, deviceImage2DMaxSize, deviceImage3DMaxSize,
deviceMaxClockFrequency, deviceMaxComputeUnits, deviceMaxConstantArgs,
deviceMaxConstantBufferSize, deviceMaxMemAllocSize, deviceMaxParameterSize,
deviceMaxReadImageArgs, deviceMaxSamplers, deviceMaxWorkGroupSize,
deviceMaxWorkItemDimensions, deviceMaxWorkItemSizes,
deviceMaxWriteImageArgs, deviceMemBaseAddrAlign, deviceMinDataTypeAlignSize,
deviceName, devicePlatform, devicePreferredVectorWidthChar,
devicePreferredVectorWidthShort, devicePreferredVectorWidthInt,
devicePreferredVectorWidthLong, devicePreferredVectorWidthFloat,
deviceProfile, deviceProfilingTimerResolution,
deviceQueueProperties, deviceSingleFPConfig,
deviceType, deviceVendor, deviceVendorID, deviceVersion, deviceDriverVersion
) where
import Control.Monad
import Control.Applicative
import Data.Word
import Foreign.C.Types
import Foreign.Ptr
import Foreign.Storable
import Foreign.Marshal
import Foreign.OpenCL.Bindings.Internal.Types
import Foreign.OpenCL.Bindings.Internal.Error
import Foreign.OpenCL.Bindings.Internal.Util
import Foreign.OpenCL.Bindings.Internal.Logging as Log
getDeviceIDs :: [DeviceType]
-> PlatformID
-> IO [DeviceID]
getDeviceIDs typ platform = do
Log.debug "Invoking clGetDeviceIDs"
getList (clGetDeviceIDs_ platform (enumToBitfield typ))
where
clGetDeviceIDs_ pform devtype num_entries devs num_devs =
checkClError "clGetDeviceIDs" =<<
clGetDeviceIDs pform devtype num_entries devs num_devs
getDeviceInfo device info =
getInfo (clGetDeviceInfo_ device) info
clGetDeviceInfo_ device name size value size_ret =
checkClError "clGetDeviceInfo" =<<
clGetDeviceInfo device name size value size_ret
deviceAddressBits :: DeviceID -> IO Word32
deviceAddressBits dev = fromIntegral `fmap` (getDeviceInfo dev DeviceAddressBits :: IO ClUInt)
deviceAvailable :: DeviceID -> IO Bool
deviceAvailable dev = getDeviceInfo dev DeviceAvailable
deviceCompilerAvailable :: DeviceID -> IO Bool
deviceCompilerAvailable dev = getDeviceInfo dev DeviceCompilerAvailable
deviceEndianLittle :: DeviceID -> IO Bool
deviceEndianLittle dev = getDeviceInfo dev DeviceEndianLittle
deviceErrorCorrectionSupport :: DeviceID -> IO Bool
deviceErrorCorrectionSupport dev = getDeviceInfo dev DeviceErrorCorrectionSupport
deviceExecutionCapabilities :: DeviceID -> IO [DeviceExecCapabilities]
deviceExecutionCapabilities dev =
enumFromBitfield caps <$>
(getDeviceInfo dev DeviceExecutionCapabilities :: IO (CULLong))
where
caps = [ExecKernel, ExecNativeKernel]
deviceExtensions :: DeviceID -> IO [String]
deviceExtensions dev = return . words =<< getDeviceInfo dev DeviceExtensions
deviceGlobalMemCacheSize :: DeviceID -> IO ClULong
deviceGlobalMemCacheSize dev = getDeviceInfo dev DeviceGlobalMemCacheSize
deviceGlobalMemCacheLineSize :: DeviceID -> IO ClUInt
deviceGlobalMemCacheLineSize dev = getDeviceInfo dev DeviceGlobalMemCachelineSize
deviceGlobalMemSize :: DeviceID -> IO ClULong
deviceGlobalMemSize dev = getDeviceInfo dev DeviceGlobalMemSize
deviceGlobalMemCacheType :: DeviceID -> IO DeviceMemCacheType
deviceGlobalMemCacheType dev = do
typ <- getDeviceInfo dev DeviceGlobalMemCacheType :: IO (CUInt)
return . toEnum $ fromIntegral typ
deviceImageSupport :: DeviceID -> IO Bool
deviceImageSupport dev = getDeviceInfo dev DeviceImageSupport
deviceImage2DMaxSize :: DeviceID -> IO (CSize, CSize)
deviceImage2DMaxSize dev = do
w <- getDeviceInfo dev DeviceImage2DMaxWidth
h <- getDeviceInfo dev DeviceImage2DMaxHeight
return (w,h)
deviceImage3DMaxSize :: DeviceID -> IO (CSize, CSize, CSize)
deviceImage3DMaxSize dev = do
w <- getDeviceInfo dev DeviceImage3DMaxWidth
h <- getDeviceInfo dev DeviceImage3DMaxHeight
d <- getDeviceInfo dev DeviceImage3DMaxDepth
return (w, h, d)
deviceLocalMemSize :: DeviceID -> IO ClULong
deviceLocalMemSize dev = getDeviceInfo dev DeviceLocalMemSize
deviceLocalMemType :: DeviceID -> IO DeviceLocalMemType
deviceLocalMemType dev = do
typ <- getDeviceInfo dev DeviceLocalMemType :: IO (CUInt)
return . toEnum $ fromIntegral typ
deviceMaxClockFrequency :: DeviceID -> IO Word32
deviceMaxClockFrequency dev = fromIntegral `fmap` (getDeviceInfo dev DeviceMaxClockFrequency :: IO ClUInt)
deviceMaxComputeUnits :: DeviceID -> IO Word32
deviceMaxComputeUnits dev = fromIntegral `fmap` (getDeviceInfo dev DeviceMaxComputeUnits :: IO ClUInt)
deviceMaxConstantArgs :: DeviceID -> IO ClUInt
deviceMaxConstantArgs dev = getDeviceInfo dev DeviceMaxConstantArgs
deviceMaxConstantBufferSize :: DeviceID -> IO ClULong
deviceMaxConstantBufferSize dev = getDeviceInfo dev DeviceMaxConstantBufferSize
deviceMaxMemAllocSize :: DeviceID -> IO ClULong
deviceMaxMemAllocSize dev = getDeviceInfo dev DeviceMaxMemAllocSize
deviceMaxParameterSize :: DeviceID -> IO CSize
deviceMaxParameterSize dev = getDeviceInfo dev DeviceMaxParameterSize
deviceMaxReadImageArgs :: DeviceID -> IO ClUInt
deviceMaxReadImageArgs dev = getDeviceInfo dev DeviceMaxReadImageArgs
deviceMaxSamplers :: DeviceID -> IO ClUInt
deviceMaxSamplers dev = getDeviceInfo dev DeviceMaxSamplers
deviceMaxWorkGroupSize :: DeviceID -> IO CSize
deviceMaxWorkGroupSize dev = getDeviceInfo dev DeviceMaxWorkGroupSize
deviceMaxWorkItemDimensions :: DeviceID -> IO ClUInt
deviceMaxWorkItemDimensions dev = getDeviceInfo dev DeviceMaxWorkItemDimensions
deviceMaxWorkItemSizes :: DeviceID -> IO [CSize]
deviceMaxWorkItemSizes dev = do
dim <- fromIntegral `fmap` deviceMaxWorkItemDimensions dev
let array_size = fromIntegral $ dim * (fromIntegral $ sizeOf (undefined :: CSize))
alloca $ \psize ->
allocaArray dim $ \arr -> do
_ <- clGetDeviceInfo_ dev (fromIntegral $ fromEnum DeviceMaxWorkItemSizes)
array_size (castPtr arr) psize
size' <- peek psize
when (array_size /= size') $ error "Size mismatch in element size array"
mapM (peekElemOff arr) [0 .. dim 1]
deviceMaxWriteImageArgs :: DeviceID -> IO ClUInt
deviceMaxWriteImageArgs dev = getDeviceInfo dev DeviceMaxWriteImageArgs
deviceMemBaseAddrAlign :: DeviceID -> IO ClUInt
deviceMemBaseAddrAlign dev = getDeviceInfo dev DeviceMemBaseAddrAlign
deviceMinDataTypeAlignSize :: DeviceID -> IO ClUInt
deviceMinDataTypeAlignSize dev = getDeviceInfo dev DeviceMinDataTypeAlignSize
deviceName :: DeviceID -> IO String
deviceName dev = getDeviceInfo dev DeviceName
devicePlatform :: DeviceID -> IO PlatformID
devicePlatform dev = getDeviceInfo dev DevicePlatform
devicePreferredVectorWidthChar :: DeviceID -> IO ClUInt
devicePreferredVectorWidthChar dev = getDeviceInfo dev DevicePreferredVectorWidthChar
devicePreferredVectorWidthShort :: DeviceID -> IO ClUInt
devicePreferredVectorWidthShort dev = getDeviceInfo dev DevicePreferredVectorWidthShort
devicePreferredVectorWidthInt :: DeviceID -> IO ClUInt
devicePreferredVectorWidthInt dev = getDeviceInfo dev DevicePreferredVectorWidthInt
devicePreferredVectorWidthLong :: DeviceID -> IO ClUInt
devicePreferredVectorWidthLong dev = getDeviceInfo dev DevicePreferredVectorWidthLong
devicePreferredVectorWidthFloat :: DeviceID -> IO ClUInt
devicePreferredVectorWidthFloat dev = getDeviceInfo dev DevicePreferredVectorWidthFloat
deviceProfile :: DeviceID -> IO String
deviceProfile dev = getDeviceInfo dev DeviceProfile :: IO String
deviceProfilingTimerResolution :: DeviceID -> IO CSize
deviceProfilingTimerResolution dev = getDeviceInfo dev DeviceProfilingTimerResolution
deviceQueueProperties :: DeviceID -> IO [CommandQueueProperties]
deviceQueueProperties dev =
enumFromBitfield queue_props <$>
(getDeviceInfo dev DeviceQueueProperties :: IO (CULLong))
where
queue_props = [QueueOutOfOrderExecModeEnable,
QueueProfilingEnable]
deviceSingleFPConfig :: DeviceID -> IO [DeviceFPConfig]
deviceSingleFPConfig dev =
enumFromBitfield fps <$>
(getDeviceInfo dev DeviceSingleFPConfig :: IO (CULLong))
where
fps = [FpDenorm,
FpInfNan,
FpRoundToNearest,
FpRoundToZero,
FpRoundToInf,
FpFma,
FpSoftFloat]
deviceType :: DeviceID -> IO [DeviceType]
deviceType dev =
enumFromBitfield device_types <$>
(getDeviceInfo dev DeviceType :: IO (CULLong))
where
device_types = [DeviceTypeDefault,
DeviceTypeCpu,
DeviceTypeGpu,
DeviceTypeAccelerator,
DeviceTypeAll]
deviceVendor :: DeviceID -> IO String
deviceVendor dev = getDeviceInfo dev DeviceVendor
deviceVendorID :: DeviceID -> IO ClUInt
deviceVendorID dev = getDeviceInfo dev DeviceVendorID
deviceVersion :: DeviceID -> IO String
deviceVersion dev = getDeviceInfo dev DeviceVersion
deviceDriverVersion :: DeviceID -> IO String
deviceDriverVersion dev = getDeviceInfo dev DriverVersion
foreign import ccall unsafe "Foreign/OpenCL/Bindings/Device.chs.h clGetDeviceIDs"
clGetDeviceIDs :: ((PlatformID) -> (CULLong -> (CUInt -> ((Ptr (DeviceID)) -> ((Ptr CUInt) -> (IO CInt))))))
foreign import ccall unsafe "Foreign/OpenCL/Bindings/Device.chs.h clGetDeviceInfo"
clGetDeviceInfo :: ((DeviceID) -> (CUInt -> (CULong -> ((Ptr ()) -> ((Ptr CULong) -> (IO CInt))))))