diff --git a/arrayfire.cabal b/arrayfire.cabal index 7d636f2..0604120 100644 --- a/arrayfire.cabal +++ b/arrayfire.cabal @@ -27,6 +27,7 @@ library ArrayFire.Exception ArrayFire.Graphics ArrayFire.Image + ArrayFire.Internal ArrayFire.LAPACK ArrayFire.Random ArrayFire.Signal diff --git a/gen/Main.hs b/gen/Main.hs index 7991670..16dfb19 100644 --- a/gen/Main.hs +++ b/gen/Main.hs @@ -68,8 +68,11 @@ makeName n | otherwise = n makePath :: String -> String -makePath s = - printf "src/ArrayFire/Internal/%s.hsc" (capitalName (makeName s)) +makePath s + | s `elem` ["types", "defines"] = + printf "src/ArrayFire/Internal/%s.hsc" (capitalName (makeName s)) + | otherwise = + printf "src/ArrayFire/Internal/%s.hs" (capitalName (makeName s)) file :: String -> Text file a = T.pack $ printf @@ -81,11 +84,7 @@ file a = T.pack $ printf \import Data.Int\n\ \import Foreign.Ptr\n\ \import Foreign.C.Types\n\n\ - \#include \"af/%s.h\"\n\ - \" (capitalName a) (if lowerCase a == "exception" - then "defines" - else lowerCase a) + \" (capitalName a) -capitalName, lowerCase :: [Char] -> [Char] +capitalName :: [Char] -> [Char] capitalName (x:xs) = toUpper x : xs -lowerCase (x:xs) = map toLower (x:xs) diff --git a/src/ArrayFire/Internal.hs b/src/ArrayFire/Internal.hs new file mode 100644 index 0000000..938bccb --- /dev/null +++ b/src/ArrayFire/Internal.hs @@ -0,0 +1,37 @@ +module ArrayFire.Internal where + +import Foreign.Ptr + +import ArrayFire.Types +import ArrayFire.FFI + +import ArrayFire.Internal.Internal +import ArrayFire.Internal.Defines + +-- af_err af_create_strided_array(af_array *arr, const void *data, const dim_t offset, const unsigned ndims, const dim_t *const dims, const dim_t *const strides, const af_dtype ty, const af_source location); +-- af_err af_get_strides(dim_t *s0, dim_t *s1, dim_t *s2, dim_t *s3, const af_array arr); +getOffset + :: Array a + -> Int +getOffset = fromIntegral . (`infoFromArray` af_get_offset) + +getRawPtr + :: Array a + -> AFArray +getRawPtr = (`infoFromArray` af_get_raw_ptr) + +isLinear + :: Array a + -> Bool +isLinear = (`infoFromArray` af_is_linear) + +isOwner + :: Array a + -> Bool +isOwner = (`infoFromArray` af_is_owner) + +getAllocatedBytes + :: Array a + -> Int +getAllocatedBytes = + fromIntegral . (`infoFromArray` af_get_allocated_bytes) diff --git a/src/ArrayFire/Internal/Algorithm.hsc b/src/ArrayFire/Internal/Algorithm.hs similarity index 99% rename from src/ArrayFire/Internal/Algorithm.hsc rename to src/ArrayFire/Internal/Algorithm.hs index 50307fe..3ea611c 100644 --- a/src/ArrayFire/Internal/Algorithm.hsc +++ b/src/ArrayFire/Internal/Algorithm.hs @@ -8,7 +8,6 @@ import Data.Int import Foreign.Ptr import Foreign.C.Types -#include "af/algorithm.h" foreign import ccall unsafe "af_sum" af_sum :: Ptr AFArray -> AFArray -> Int -> IO AFErr foreign import ccall unsafe "af_sum_nan" diff --git a/src/ArrayFire/Internal/Arith.hsc b/src/ArrayFire/Internal/Arith.hs similarity index 99% rename from src/ArrayFire/Internal/Arith.hsc rename to src/ArrayFire/Internal/Arith.hs index ab16dee..1808daf 100644 --- a/src/ArrayFire/Internal/Arith.hsc +++ b/src/ArrayFire/Internal/Arith.hs @@ -8,7 +8,6 @@ import Data.Int import Foreign.Ptr import Foreign.C.Types -#include "af/arith.h" foreign import ccall unsafe "af_add" af_add :: Ptr AFArray -> AFArray -> AFArray -> Bool -> IO AFErr foreign import ccall unsafe "af_sub" diff --git a/src/ArrayFire/Internal/Array.hsc b/src/ArrayFire/Internal/Array.hs similarity index 97% rename from src/ArrayFire/Internal/Array.hsc rename to src/ArrayFire/Internal/Array.hs index 82ee4ab..74f32e3 100644 --- a/src/ArrayFire/Internal/Array.hsc +++ b/src/ArrayFire/Internal/Array.hs @@ -8,7 +8,6 @@ import Data.Int import Foreign.Ptr import Foreign.C.Types -#include "af/array.h" foreign import ccall unsafe "af_create_array" af_create_array :: Ptr AFArray -> Ptr () -> CUInt -> Ptr DimT -> AFDtype -> IO AFErr foreign import ccall unsafe "af_create_handle" @@ -72,4 +71,4 @@ foreign import ccall unsafe "af_is_sparse" foreign import ccall unsafe "af_get_scalar" af_get_scalar :: Ptr () -> AFArray -> IO AFErr foreign import ccall unsafe "&af_release_array" - af_release_array_finalizer :: FunPtr (AFArray -> IO ()) + af_release_array_finalizer :: FunPtr (AFArray -> IO ()) \ No newline at end of file diff --git a/src/ArrayFire/Internal/BLAS.hsc b/src/ArrayFire/Internal/BLAS.hs similarity index 97% rename from src/ArrayFire/Internal/BLAS.hsc rename to src/ArrayFire/Internal/BLAS.hs index 4b3a5fe..b284c4c 100644 --- a/src/ArrayFire/Internal/BLAS.hsc +++ b/src/ArrayFire/Internal/BLAS.hs @@ -8,7 +8,6 @@ import Data.Int import Foreign.Ptr import Foreign.C.Types -#include "af/blas.h" foreign import ccall unsafe "af_matmul" af_matmul :: Ptr AFArray -> AFArray -> AFArray -> AFMatProp -> AFMatProp -> IO AFErr foreign import ccall unsafe "af_dot" diff --git a/src/ArrayFire/Internal/Backend.hsc b/src/ArrayFire/Internal/Backend.hs similarity index 97% rename from src/ArrayFire/Internal/Backend.hsc rename to src/ArrayFire/Internal/Backend.hs index 6c975ee..021037f 100644 --- a/src/ArrayFire/Internal/Backend.hsc +++ b/src/ArrayFire/Internal/Backend.hs @@ -8,7 +8,6 @@ import Data.Int import Foreign.Ptr import Foreign.C.Types -#include "af/backend.h" foreign import ccall unsafe "af_set_backend" af_set_backend :: AFBackend -> IO AFErr foreign import ccall unsafe "af_get_backend_count" diff --git a/src/ArrayFire/Internal/CUDA.hsc b/src/ArrayFire/Internal/CUDA.hs similarity index 95% rename from src/ArrayFire/Internal/CUDA.hsc rename to src/ArrayFire/Internal/CUDA.hs index 06a468b..df89abb 100644 --- a/src/ArrayFire/Internal/CUDA.hsc +++ b/src/ArrayFire/Internal/CUDA.hs @@ -8,7 +8,6 @@ import Data.Int import Foreign.Ptr import Foreign.C.Types -#include "af/cuda.h" foreign import ccall unsafe "afcu_get_stream" afcu_get_stream :: Ptr CudaStreamT -> Int -> IO AFErr foreign import ccall unsafe "afcu_get_native_id" diff --git a/src/ArrayFire/Internal/Data.hsc b/src/ArrayFire/Internal/Data.hs similarity index 99% rename from src/ArrayFire/Internal/Data.hsc rename to src/ArrayFire/Internal/Data.hs index d94271e..1388965 100644 --- a/src/ArrayFire/Internal/Data.hsc +++ b/src/ArrayFire/Internal/Data.hs @@ -8,7 +8,6 @@ import Data.Int import Foreign.Ptr import Foreign.C.Types -#include "af/data.h" foreign import ccall unsafe "af_constant" af_constant :: Ptr AFArray -> Double -> CUInt -> Ptr DimT -> AFDtype -> IO AFErr foreign import ccall unsafe "af_constant_complex" diff --git a/src/ArrayFire/Internal/Defines.hsc b/src/ArrayFire/Internal/Defines.hsc deleted file mode 100644 index e7975f7..0000000 --- a/src/ArrayFire/Internal/Defines.hsc +++ /dev/null @@ -1,426 +0,0 @@ -{-# LANGUAGE GeneralizedNewtypeDeriving #-} -{-# LANGUAGE CPP #-} -{-# LANGUAGE RecordWildCards #-} -module ArrayFire.Internal.Defines where - -import Foreign.ForeignPtr -import Foreign.Ptr -import Foreign.C.Types -import Foreign.Storable - --- #include "arrayfire.h" -#include "af/defines.h" -#include "af/seq.h" -#include "af/index.h" -#include "af/complex.h" --- #include "af/opencl.h" --- #include "defines.h" - -type Batch = Bool - -afVersion = #const AF_API_VERSION - -newtype AFErr = AFErr { afError :: Int } - deriving (Show, Eq) - -#{enum AFErr, AFErr - , afSuccess = AF_SUCCESS - , afErrNoMem = AF_ERR_NO_MEM - , afErrDriver = AF_ERR_DRIVER - , afErrRuntime = AF_ERR_RUNTIME - , afErrInvalidArray = AF_ERR_INVALID_ARRAY - , afErrArg = AF_ERR_ARG - , afErrSize = AF_ERR_SIZE - , afErrType = AF_ERR_TYPE - , afErrDiffType = AF_ERR_DIFF_TYPE - , afErrBatch = AF_ERR_BATCH - , afErrDevice = AF_ERR_DEVICE - , afErrNotSupported = AF_ERR_NOT_SUPPORTED - , afErrNotConfigured = AF_ERR_NOT_CONFIGURED - , afErrNonFree = AF_ERR_NONFREE - , afErrNoDbl = AF_ERR_NO_DBL - , afErrNoGfx = AF_ERR_NO_GFX - , afErrLoadLib = AF_ERR_LOAD_LIB - , afErrLoadSym = AF_ERR_LOAD_SYM - , afErrArrBkndMismatch = AF_ERR_ARR_BKND_MISMATCH - , afErrInternal = AF_ERR_INTERNAL - , afErrUnknown = AF_ERR_UNKNOWN - } - -newtype AFDtype = AFDtype { afDType :: Int } - deriving (Show, Eq, Storable) - -#{enum AFDtype, AFDtype - , f32 = f32 - , c32 = c32 - , f64 = f64 - , c64 = c64 - , b8 = b8 - , s32 = s32 - , u32 = u32 - , u8 = u8 - , s64 = s64 - , u64 = u64 - , s16 = s16 - , u16 = u16 - } - -newtype AFSource = AFSource Int - deriving (Ord, Show, Eq) - -#{enum AFSource, AFSource - , afDevice = afDevice - , afHost = afHost - } - -afMaxDims = #const AF_MAX_DIMS - --- // A handle for an internal array object -type AFArray = Ptr () - --- // A handle for an internal array object -type AFWindow = CULLong - -newtype AFCell = AFCell (Ptr AFCell) - deriving (Storable) -newtype AFFeatures = AFFeatures (Ptr AFFeatures) - deriving (Storable) -newtype AFRandomEngine = AFRandomEngine (Ptr AFRandomEngine) - deriving (Storable) - -newtype AFInterpType = AFInterpType Int - deriving (Ord, Show, Eq, Storable) - -#{enum AFInterpType, AFInterpType - , afInterpNearest = AF_INTERP_NEAREST - , afInterpLinear = AF_INTERP_LINEAR - , afInterpBilinear = AF_INTERP_BILINEAR - , afInterpCubic = AF_INTERP_CUBIC - , afInterpLower = AF_INTERP_LOWER - , afInterpLinearCosine = AF_INTERP_LINEAR_COSINE - , afInterpBilinearCosine = AF_INTERP_BILINEAR_COSINE - , afInterpBicubic = AF_INTERP_BICUBIC - , afInterpCubicSpline = AF_INTERP_CUBIC_SPLINE - , afInterpBicubicSpline = AF_INTERP_BICUBIC_SPLINE - } - -newtype AFBorderType = AFBorderType Int - deriving (Ord, Show, Eq, Storable) - -#{enum AFBorderType, AFBorderType - , afBorderPadZero = AF_PAD_ZERO - , afPadSym = AF_PAD_SYM - } - -newtype AFConnectivity = AFConnectivity Int - deriving (Ord, Show, Eq, Storable) - -#{enum AFConnectivity, AFConnectivity - , afConnectivity4 = AF_CONNECTIVITY_4 - , afConnectivity8 = AF_CONNECTIVITY_8 - } - -newtype AFConvMode = AFConvMode Int - deriving (Ord, Show, Eq, Storable) - -#{enum AFConvMode, AFConvMode - , afConvDefault = AF_CONV_DEFAULT - , afConvExpand = AF_CONV_EXPAND - } - -newtype AFConvDomain = AFConvDomain Int - deriving (Ord, Show, Eq, Storable) - -#{enum AFConvDomain, AFConvDomain - , afConvAuto = AF_CONV_AUTO - , afConvSpatial = AF_CONV_SPATIAL - , afConvFreq = AF_CONV_FREQ -} - -newtype AFMatchType = AFMatchType Int - deriving (Ord, Show, Eq, Storable) - -#{enum AFMatchType, AFMatchType - , afSAD = AF_SAD - , afZSAD = AF_ZSAD - , afLSAD = AF_LSAD - , afSSD = AF_SSD - , afZSSD = AF_ZSSD - , afLSSD = AF_LSSD - , afNCC = AF_NCC - , afZNCC = AF_ZNCC - , afSHD = AF_SHD -} - -newtype AFYccStd = AFYccStd Int - deriving (Ord, Show, Eq, Storable) - -#{enum AFYccStd, AFYccStd - , afYcc601 = AF_YCC_601 - , afYcc709 = AF_YCC_709 - , afYcc2020 = AF_YCC_2020 - } - -newtype AFCSpace = AFCSpace Int - deriving (Ord, Show, Eq, Storable) - -#{enum AFCSpace, AFCSpace - , afGray = AF_GRAY - , afRgb = AF_RGB - , afHsv = AF_HSV - , afYCbCr = AF_YCbCr - } - -newtype AFMatProp = AFMatProp Int - deriving (Ord, Show, Eq, Storable) - -#{enum AFMatProp, AFMatProp - , afMatNone = AF_MAT_NONE - , afMatTrans = AF_MAT_TRANS - , afMatCtrans = AF_MAT_CTRANS - , afMatConj = AF_MAT_CONJ - , afMatUpper = AF_MAT_UPPER - , afMatLower = AF_MAT_LOWER - , afMatDiagUnit = AF_MAT_DIAG_UNIT - , afMatSym = AF_MAT_SYM - , afMatPosdef = AF_MAT_POSDEF - , afMatOrthog = AF_MAT_ORTHOG - , afMatTriDiag = AF_MAT_TRI_DIAG - , afMatBlockDiag = AF_MAT_BLOCK_DIAG - } - -newtype AFNormType = AFNormType Int - deriving (Ord, Show, Eq, Storable) - -#{enum AFNormType, AFNormType - , afNormVector1 = AF_NORM_VECTOR_1 - , afNormVectorInf = AF_NORM_VECTOR_INF - , afNormVector2 = AF_NORM_VECTOR_2 - , afNormVectorP = AF_NORM_VECTOR_P - , afNormMatrix1 = AF_NORM_MATRIX_1 - , afNormMatrixInf = AF_NORM_MATRIX_INF - , afNormMatrix2 = AF_NORM_MATRIX_2 - , afNormMatrixLPq = AF_NORM_MATRIX_L_PQ - , afNormEuclid = AF_NORM_VECTOR_2 -} - -newtype AFImageFormat = AFImageFormat Int - deriving (Ord, Show, Eq, Storable) - -#{enum AFImageFormat, AFImageFormat - , afFIFBmp = AF_FIF_BMP - , afFIFIco = AF_FIF_ICO - , afFIFJpeg = AF_FIF_JPEG - , afFIFJng = AF_FIF_JNG - , afFIFPng = AF_FIF_PNG - , afFIFPpm = AF_FIF_PPM - , afFIFPpmraw = AF_FIF_PPMRAW - , afFIFTiff = AF_FIF_TIFF - , afFIFPsd = AF_FIF_PSD - , afFIFHdr = AF_FIF_HDR - , afFIFExr = AF_FIF_EXR - , afFIFJp2 = AF_FIF_JP2 - , afFIFRaw = AF_FIF_RAW - } - -newtype AFMomentType = AFMomentType Int - deriving (Ord, Show, Eq, Storable) - -#{enum AFMomentType, AFMomentType - , afMomentM00 = AF_MOMENT_M00 - , afMomentM01 = AF_MOMENT_M01 - , afMomentM10 = AF_MOMENT_M10 - , afMomentM11 = AF_MOMENT_M11 - , afMomentFirstOrder = (AF_MOMENT_M00 | AF_MOMENT_M01 | AF_MOMENT_M10 | AF_MOMENT_M11) -} - -newtype AFHomographyType = AFHomographyType Int - deriving (Ord, Show, Eq, Storable) - -#{enum AFHomographyType, AFHomographyType - , afHomographyRansac = AF_HOMOGRAPHY_RANSAC - , afHomographyLmeds = AF_HOMOGRAPHY_LMEDS -} - -newtype AFBackend = AFBackend Int - deriving (Ord, Show, Eq, Storable) - -#{enum AFBackend, AFBackend - , afBackendDefault = AF_BACKEND_DEFAULT - , afBackendCpu = AF_BACKEND_DEFAULT - , afBackendCuda = AF_BACKEND_CUDA - , afBackendOpencl = AF_BACKEND_OPENCL -} - -newtype AFID = AFID Int - deriving (Ord, Show, Eq, Storable) - -#{enum AFID, AFID - afID = AF_ID -} - -newtype AFBinaryOp = AFBinaryOp Int - deriving (Ord, Show, Eq, Storable) - -#{enum AFBinaryOp, AFBinaryOp - , afBinaryAdd = AF_BINARY_ADD - , afBinaryMul = AF_BINARY_MUL - , afBinaryMin = AF_BINARY_MIN - , afBinaryMax = AF_BINARY_MAX - } - -newtype AFRandomEngineType = AFRandomEngineType Int - deriving (Ord, Show, Eq, Storable) - -#{enum AFRandomEngineType, AFRandomEngineType - , afRandomEnginePhilox4X3210 = AF_RANDOM_ENGINE_PHILOX_4X32_10 - , afRandomEngineThreefry2X3216 = AF_RANDOM_ENGINE_THREEFRY_2X32_16 - , afRandomEngineMersenneGp11213 = AF_RANDOM_ENGINE_MERSENNE_GP11213 - , afRandomEnginePhilox = AF_RANDOM_ENGINE_PHILOX_4X32_10 - , afRandomEngineThreefry = AF_RANDOM_ENGINE_THREEFRY_2X32_16 - , afRandomEngineMersenne = AF_RANDOM_ENGINE_MERSENNE_GP11213 - , afRandomEngineDefault = AF_RANDOM_ENGINE_PHILOX - } - -newtype AFColorMap = AFColorMap Int - deriving (Ord, Show, Eq, Storable) - -#{enum AFColorMap, AFColorMap - , afColormapDefault = AF_COLORMAP_DEFAULT - , afColormapSpectrum= AF_COLORMAP_SPECTRUM - , afColormapColors = AF_COLORMAP_COLORS - , afColormapRed = AF_COLORMAP_RED - , afColormapMood = AF_COLORMAP_MOOD - , afColormapHeat = AF_COLORMAP_HEAT - , afColormapBlue = AF_COLORMAP_BLUE - , afColormapInferno = AF_COLORMAP_INFERNO - , afColormapMagma = AF_COLORMAP_MAGMA - , afColormapPlasma = AF_COLORMAP_PLASMA - , afColormapViridis = AF_COLORMAP_VIRIDIS -} - -newtype AFMarkerType = AFMarkerType Int - deriving (Ord, Show, Eq, Storable) - -#{enum AFMarkerType, AFMarkerType - , afMarkerNone = AF_MARKER_NONE - , afMarkerPoint = AF_MARKER_POINT - , afMarkerCircle = AF_MARKER_CIRCLE - , afMarkerSquare = AF_MARKER_SQUARE - , afMarkerTriangle = AF_MARKER_TRIANGLE - , afMarkerCross = AF_MARKER_CROSS - , afMarkerPlus = AF_MARKER_PLUS - , afMarkerStar = AF_MARKER_STAR - } - -newtype AFCannyThreshold = AFCannyThreshold Int - deriving (Ord, Show, Eq, Storable) - -#{enum AFCannyThreshold, AFCannyThreshold - , afCannyThresholdManual = AF_CANNY_THRESHOLD_MANUAL - , afCannyThresholdAutoOtsu = AF_CANNY_THRESHOLD_AUTO_OTSU - } - -newtype AFStorage = AFStorage Int - deriving (Ord, Show, Eq, Storable) - -#{enum AFStorage, AFStorage - , afStorageDense = AF_STORAGE_DENSE - , afStorageCsr = AF_STORAGE_CSR - , afStorageCsc = AF_STORAGE_CSC - , afStorageCoo = AF_STORAGE_COO - } - -newtype AFFluxFunction = AFFluxFunction Int - deriving (Ord, Show, Eq, Storable) - -#{enum AFFluxFunction, AFFluxFunction - , afFluxQuadratic = AF_FLUX_QUADRATIC - , afFluxExponential = AF_FLUX_EXPONENTIAL - , afFluxDefault = AF_FLUX_DEFAULT - } - -newtype AFDiffusionEq = AFDiffusionEq Int - deriving (Ord, Show, Eq, Storable) - -#{enum AFDiffusionEq, AFDiffusionEq - , afDiffusionGrad = AF_DIFFUSION_GRAD - , afDiffusionMcde = AF_DIFFUSION_MCDE - , afDiffusionDefault = AF_DIFFUSION_DEFAULT - } - -newtype AFTopkFunction = AFTopkFunction Int - deriving (Ord, Show, Eq, Storable) - -#{enum AFTopkFunction, AFTopkFunction - , afTopkMin = AF_TOPK_MIN - , afTopkMax = AF_TOPK_MAX - , afTopkDefault = AF_TOPK_DEFAULT - } - -newtype AFIterativeDeconvAlgo = AFIterativeDeconvAlgo Int - deriving (Ord, Show, Eq, Storable) - --- #{enum AFIterativeDeconvAlgo, AFIterativeDeconvAlgo --- , afIterativeDeconvLandweber = AF_ITERATIVE_DECONV_LANDWEBER --- , afIterativeDeconvRichardsonlucy = AF_ITERATIVE_DECONV_RICHARDSONLUCY --- , afIterativeDeconvDefault = AF_ITERATIVE_DECONV_DEFAULT --- } - -newtype AFInverseDeconvAlgo = AFInverseDeconvAlgo Int - deriving (Ord, Show, Eq, Storable) - -#{enum AFInverseDeconvAlgo, AFInverseDeconvAlgo - afInverseDeconvTikhonov = AF_INVERSE_DECONV_TIKHONOV - afInverseDeconvDefault = AF_INVERSE_DECONV_DEFAULT - } - --- newtype AFVarBias = AFVarBias Int --- deriving (Ord, Show, Eq) - --- #{enum AFVarBias, AFVarBias --- , afVarianceDefault = AF_VARIANCE_DEFAULT --- , afVarianceSample = AF_VARIANCE_SAMPLE --- , afVariancePopulation = AF_VARIANCE_POPULATION --- } - -newtype AFSomeEnum = AFSomeEnum Int - deriving (Ord, Show, Eq, Storable) - -#{enum AFSomeEnum, AFSomeEnum - , afSomeEnum = 0 - } - -newtype DimT = DimT CLLong - deriving (Show, Eq, Storable, Num, Integral, Real, Enum, Ord) - -newtype UIntL = UIntL CULLong - deriving (Show, Eq, Storable, Num, Integral, Real, Enum, Ord) - -newtype IntL = IntL CLLong - deriving (Show, Eq, Storable, Num, Integral, Real, Enum, Ord) - --- static const af_seq af_span = {1, 1, 0}; - --- newtype AFCLPlatform = AFCLPlatform Int --- deriving (Show, Eq) - --- #{enum AFCLPlatform, AFCLPlatform --- , afclPlatformAMD = AFCL_PLATFORM_AMD --- , afclPlatformApple = AFCL_PLATFORM_APPLE --- , afclPlatformIntel = AFCL_PLATFORM_INTEL --- , afclPlatformNVIDIA = AFCL_PLATFORM_NVIDIA --- , afclPlatformBEIGNET = AFCL_PLATFORM_BEIGNET --- , afclPlatformPOCL = AFCL_PLATFORM_POCL --- , afclPlatformUnknown = AFCL_PLATFORM_UNKNOWN --- } - --- newtype DeviceType = DeviceType Int --- deriving (Show, Eq) - --- #{enum DeviceType, DeviceType --- , afCLDeviceTypeCPU = AFCL_DEVICE_TYPE_CPU --- , afCLDeviceTypeGPU = AFCL_DEVICE_TYPE_GPU --- , afCLDeviceTypeAccel = AFCL_DEVICE_TYPE_ACCEL --- , afCLDeviceTypeUnknown = AFCL_DEVICE_TYPE_UNKNOWN --- } diff --git a/src/ArrayFire/Internal/Device.hsc b/src/ArrayFire/Internal/Device.hs similarity index 99% rename from src/ArrayFire/Internal/Device.hsc rename to src/ArrayFire/Internal/Device.hs index e7655ad..9e7a6d9 100644 --- a/src/ArrayFire/Internal/Device.hsc +++ b/src/ArrayFire/Internal/Device.hs @@ -8,7 +8,6 @@ import Data.Int import Foreign.Ptr import Foreign.C.Types -#include "af/device.h" foreign import ccall unsafe "af_info" af_info :: IO AFErr foreign import ccall unsafe "af_init" diff --git a/src/ArrayFire/Internal/Exception.hsc b/src/ArrayFire/Internal/Exception.hs similarity index 94% rename from src/ArrayFire/Internal/Exception.hsc rename to src/ArrayFire/Internal/Exception.hs index 764dfe0..b26588f 100644 --- a/src/ArrayFire/Internal/Exception.hsc +++ b/src/ArrayFire/Internal/Exception.hs @@ -8,7 +8,6 @@ import Data.Int import Foreign.Ptr import Foreign.C.Types -#include "af/defines.h" foreign import ccall unsafe "af_get_last_error" af_get_last_error :: Ptr (Ptr CChar) -> Ptr DimT -> IO () foreign import ccall unsafe "af_err_to_string" diff --git a/src/ArrayFire/Internal/Features.hsc b/src/ArrayFire/Internal/Features.hs similarity index 98% rename from src/ArrayFire/Internal/Features.hsc rename to src/ArrayFire/Internal/Features.hs index a1757bc..ccf1208 100644 --- a/src/ArrayFire/Internal/Features.hsc +++ b/src/ArrayFire/Internal/Features.hs @@ -8,7 +8,6 @@ import Data.Int import Foreign.Ptr import Foreign.C.Types -#include "af/features.h" foreign import ccall unsafe "af_create_features" af_create_features :: Ptr AFFeatures -> DimT -> IO AFErr foreign import ccall unsafe "af_retain_features" diff --git a/src/ArrayFire/Internal/Graphics.hsc b/src/ArrayFire/Internal/Graphics.hs similarity index 99% rename from src/ArrayFire/Internal/Graphics.hsc rename to src/ArrayFire/Internal/Graphics.hs index b90f33e..6be9e6c 100644 --- a/src/ArrayFire/Internal/Graphics.hsc +++ b/src/ArrayFire/Internal/Graphics.hs @@ -8,7 +8,6 @@ import Data.Int import Foreign.Ptr import Foreign.C.Types -#include "af/graphics.h" foreign import ccall unsafe "af_create_window" af_create_window :: Ptr AFWindow -> Int -> Int -> Ptr CChar -> IO AFErr foreign import ccall unsafe "af_set_position" diff --git a/src/ArrayFire/Internal/Image.hsc b/src/ArrayFire/Internal/Image.hs similarity index 99% rename from src/ArrayFire/Internal/Image.hsc rename to src/ArrayFire/Internal/Image.hs index f24238a..c887639 100644 --- a/src/ArrayFire/Internal/Image.hsc +++ b/src/ArrayFire/Internal/Image.hs @@ -8,7 +8,6 @@ import Data.Int import Foreign.Ptr import Foreign.C.Types -#include "af/image.h" foreign import ccall unsafe "af_gradient" af_gradient :: Ptr AFArray -> Ptr AFArray -> AFArray -> IO AFErr foreign import ccall unsafe "af_load_image" diff --git a/src/ArrayFire/Internal/Index.hsc b/src/ArrayFire/Internal/Index.hs similarity index 98% rename from src/ArrayFire/Internal/Index.hsc rename to src/ArrayFire/Internal/Index.hs index 7dbcdd2..526cfd9 100644 --- a/src/ArrayFire/Internal/Index.hsc +++ b/src/ArrayFire/Internal/Index.hs @@ -8,7 +8,6 @@ import Data.Int import Foreign.Ptr import Foreign.C.Types -#include "af/index.h" foreign import ccall unsafe "af_index" af_index :: Ptr AFArray -> AFArray -> CUInt -> Ptr AFSeq -> IO AFErr foreign import ccall unsafe "af_lookup" diff --git a/src/ArrayFire/Internal/Internal.hsc b/src/ArrayFire/Internal/Internal.hs similarity index 97% rename from src/ArrayFire/Internal/Internal.hsc rename to src/ArrayFire/Internal/Internal.hs index dc760b2..48ba17f 100644 --- a/src/ArrayFire/Internal/Internal.hsc +++ b/src/ArrayFire/Internal/Internal.hs @@ -8,7 +8,6 @@ import Data.Int import Foreign.Ptr import Foreign.C.Types -#include "af/internal.h" foreign import ccall unsafe "af_create_strided_array" af_create_strided_array :: Ptr AFArray -> Ptr () -> DimT -> CUInt -> Ptr DimT -> Ptr DimT -> AFDtype -> AFSource -> IO AFErr foreign import ccall unsafe "af_get_strides" diff --git a/src/ArrayFire/Internal/LAPACK.hsc b/src/ArrayFire/Internal/LAPACK.hs similarity index 98% rename from src/ArrayFire/Internal/LAPACK.hsc rename to src/ArrayFire/Internal/LAPACK.hs index a4b7506..155d4ff 100644 --- a/src/ArrayFire/Internal/LAPACK.hsc +++ b/src/ArrayFire/Internal/LAPACK.hs @@ -8,7 +8,6 @@ import Data.Int import Foreign.Ptr import Foreign.C.Types -#include "af/lapack.h" foreign import ccall unsafe "af_svd" af_svd :: Ptr AFArray -> Ptr AFArray -> Ptr AFArray -> AFArray -> IO AFErr foreign import ccall unsafe "af_svd_inplace" diff --git a/src/ArrayFire/Internal/OpenCL.hsc b/src/ArrayFire/Internal/OpenCL.hs similarity index 98% rename from src/ArrayFire/Internal/OpenCL.hsc rename to src/ArrayFire/Internal/OpenCL.hs index 69b812d..25a46f8 100644 --- a/src/ArrayFire/Internal/OpenCL.hsc +++ b/src/ArrayFire/Internal/OpenCL.hs @@ -8,7 +8,6 @@ import Data.Int import Foreign.Ptr import Foreign.C.Types -#include "af/opencl.h" foreign import ccall unsafe "afcl_get_context" afcl_get_context :: Ptr ClContext -> Bool -> IO AFErr foreign import ccall unsafe "afcl_get_queue" diff --git a/src/ArrayFire/Internal/Random.hsc b/src/ArrayFire/Internal/Random.hs similarity index 98% rename from src/ArrayFire/Internal/Random.hsc rename to src/ArrayFire/Internal/Random.hs index 142dd6d..eabb7f2 100644 --- a/src/ArrayFire/Internal/Random.hsc +++ b/src/ArrayFire/Internal/Random.hs @@ -8,7 +8,6 @@ import Data.Int import Foreign.Ptr import Foreign.C.Types -#include "af/random.h" foreign import ccall unsafe "af_create_random_engine" af_create_random_engine :: Ptr AFRandomEngine -> AFRandomEngineType -> UIntL -> IO AFErr foreign import ccall unsafe "af_retain_random_engine" diff --git a/src/ArrayFire/Internal/Seq.hsc b/src/ArrayFire/Internal/Seq.hs similarity index 93% rename from src/ArrayFire/Internal/Seq.hsc rename to src/ArrayFire/Internal/Seq.hs index 67835b5..c32a0d6 100644 --- a/src/ArrayFire/Internal/Seq.hsc +++ b/src/ArrayFire/Internal/Seq.hs @@ -8,6 +8,5 @@ import Data.Int import Foreign.Ptr import Foreign.C.Types -#include "af/seq.h" foreign import ccall unsafe "af_make_seq" af_make_seq :: Double -> Double -> Double -> IO AFSeq \ No newline at end of file diff --git a/src/ArrayFire/Internal/Signal.hsc b/src/ArrayFire/Internal/Signal.hs similarity index 99% rename from src/ArrayFire/Internal/Signal.hsc rename to src/ArrayFire/Internal/Signal.hs index 10fe1f8..b75af2f 100644 --- a/src/ArrayFire/Internal/Signal.hsc +++ b/src/ArrayFire/Internal/Signal.hs @@ -8,7 +8,6 @@ import Data.Int import Foreign.Ptr import Foreign.C.Types -#include "af/signal.h" foreign import ccall unsafe "af_approx1" af_approx1 :: Ptr AFArray -> AFArray -> AFArray -> AFInterpType -> Float -> IO AFErr foreign import ccall unsafe "af_approx2" diff --git a/src/ArrayFire/Internal/Sparse.hsc b/src/ArrayFire/Internal/Sparse.hs similarity index 98% rename from src/ArrayFire/Internal/Sparse.hsc rename to src/ArrayFire/Internal/Sparse.hs index 83e1a84..ad017b9 100644 --- a/src/ArrayFire/Internal/Sparse.hsc +++ b/src/ArrayFire/Internal/Sparse.hs @@ -8,7 +8,6 @@ import Data.Int import Foreign.Ptr import Foreign.C.Types -#include "af/sparse.h" foreign import ccall unsafe "af_create_sparse_array" af_create_sparse_array :: Ptr AFArray -> DimT -> DimT -> AFArray -> AFArray -> AFArray -> AFStorage -> IO AFErr foreign import ccall unsafe "af_create_sparse_array_from_ptr" diff --git a/src/ArrayFire/Internal/Statistics.hsc b/src/ArrayFire/Internal/Statistics.hs similarity index 98% rename from src/ArrayFire/Internal/Statistics.hsc rename to src/ArrayFire/Internal/Statistics.hs index f0a941a..ab6e50a 100644 --- a/src/ArrayFire/Internal/Statistics.hsc +++ b/src/ArrayFire/Internal/Statistics.hs @@ -8,7 +8,6 @@ import Data.Int import Foreign.Ptr import Foreign.C.Types -#include "af/statistics.h" foreign import ccall unsafe "af_mean" af_mean :: Ptr AFArray -> AFArray -> DimT -> IO AFErr foreign import ccall unsafe "af_mean_weighted" diff --git a/src/ArrayFire/Internal/Types.hsc b/src/ArrayFire/Internal/Types.hsc deleted file mode 100644 index 1bf28b1..0000000 --- a/src/ArrayFire/Internal/Types.hsc +++ /dev/null @@ -1,73 +0,0 @@ -{-# LANGUAGE RecordWildCards #-} -{-# LANGUAGE CPP #-} -module ArrayFire.Internal.Types where - -#include "af/seq.h" -#include "af/complex.h" -#include "af/index.h" - -import Foreign.Storable -import ArrayFire.Internal.Defines - -data AFSeq - = AFSeq - { afSeqBegin :: {-# UNPACK #-} !Double - , afSeqEnd :: {-# UNPACK #-} !Double - , afSeqStep :: {-# UNPACK #-} !Double - } deriving (Show, Eq) - -instance Storable AFSeq where - sizeOf _ = #{size af_seq} - alignment _ = #{alignment af_seq} - peek ptr = do - afSeqBegin <- #{peek af_seq, begin} ptr - afSeqEnd <- #{peek af_seq, end} ptr - afSeqStep <- #{peek af_seq, step} ptr - pure AFSeq {..} - poke ptr AFSeq{..} = do - #{poke af_seq, begin} ptr afSeqBegin - #{poke af_seq, end} ptr afSeqEnd - #{poke af_seq, step} ptr afSeqStep - -data AFIndex - = AFIndex - { afIdx :: !(Either AFArray AFSeq) - , afIsSeq :: !Bool - , afIsBatch :: !Bool - } -instance Storable AFIndex where - sizeOf _ = #{size af_index_t} - alignment _ = #{alignment af_index_t} - peek ptr = do - afIsSeq <- #{peek af_index_t, isSeq} ptr - afIsBatch <- #{peek af_index_t, isBatch} ptr - afIdx <- - if afIsSeq - then Left <$> #{peek af_index_t, idx.arr} ptr - else Right <$> #{peek af_index_t, idx.seq} ptr - pure AFIndex{..} - poke ptr AFIndex{..} = do - case afIdx of - Left afarr -> #{poke af_index_t, idx.arr} ptr afarr - Right afseq -> #{poke af_index_t, idx.seq} ptr afseq - #{poke af_index_t, isSeq} ptr afIsSeq - #{poke af_index_t, isBatch} ptr afIsBatch - -data AFCFloat - = AFCFloat - { afcReal :: {-# UNPACK #-} !Float - , afcImag :: {-# UNPACK #-} !Float - } deriving (Eq, Show) - -instance Storable AFCFloat where - sizeOf _ = #{size af_cfloat} - alignment _ = #{alignment af_cfloat} - peek ptr = do - afcReal <- #{peek af_cfloat, real} ptr - afcImag <- #{peek af_cfloat, imag} ptr - pure AFCFloat{..} - poke ptr AFCFloat{..} = do - #{poke af_cfloat, real} ptr afcReal - #{poke af_cfloat, imag} ptr afcImag - - diff --git a/src/ArrayFire/Internal/Util.hsc b/src/ArrayFire/Internal/Util.hs similarity index 98% rename from src/ArrayFire/Internal/Util.hsc rename to src/ArrayFire/Internal/Util.hs index 200b237..7699e36 100644 --- a/src/ArrayFire/Internal/Util.hsc +++ b/src/ArrayFire/Internal/Util.hs @@ -8,7 +8,6 @@ import Data.Int import Foreign.Ptr import Foreign.C.Types -#include "af/util.h" foreign import ccall unsafe "af_print_array" af_print_array :: AFArray -> IO AFErr foreign import ccall unsafe "af_print_array_gen" diff --git a/src/ArrayFire/Internal/Vision.hsc b/src/ArrayFire/Internal/Vision.hs similarity index 98% rename from src/ArrayFire/Internal/Vision.hsc rename to src/ArrayFire/Internal/Vision.hs index d21fed8..ecec04b 100644 --- a/src/ArrayFire/Internal/Vision.hsc +++ b/src/ArrayFire/Internal/Vision.hs @@ -8,7 +8,6 @@ import Data.Int import Foreign.Ptr import Foreign.C.Types -#include "af/vision.h" foreign import ccall unsafe "af_fast" af_fast :: Ptr AFFeatures -> AFArray -> Float -> CUInt -> Bool -> Float -> CUInt -> IO AFErr foreign import ccall unsafe "af_harris"