diff --git a/cbits/stubs.c b/cbits/stubs.c index 3b363ee..67f9280 100644 --- a/cbits/stubs.c +++ b/cbits/stubs.c @@ -22,17 +22,6 @@ cudaError_t cudaConfigureCall_simple(unsigned int gridX, unsigned int gridY, uns } #endif -CUresult cuTexRefSetAddress2D_simple(CUtexref tex, CUarray_format format, unsigned int numChannels, CUdeviceptr dptr, size_t width, size_t height, size_t pitch) -{ - CUDA_ARRAY_DESCRIPTOR desc; - desc.Format = format; - desc.NumChannels = numChannels; - desc.Width = width; - desc.Height = height; - - return cuTexRefSetAddress2D(tex, &desc, dptr, pitch); -} - CUresult cuMemcpy2DHtoD(CUdeviceptr dstDevice, unsigned int dstPitch, unsigned int dstXInBytes, unsigned int dstY, void* srcHost, unsigned int srcPitch, unsigned int srcXInBytes, unsigned int srcY, unsigned int widthInBytes, unsigned int height) { CUDA_MEMCPY2D desc; @@ -284,11 +273,6 @@ CUresult CUDAAPI cuMemsetD32(CUdeviceptr dstDevice, unsigned int ui, size_t N) { return cuMemsetD32_v2(dstDevice, ui, N); } - -CUresult CUDAAPI cuTexRefSetAddress(size_t *ByteOffset, CUtexref hTexRef, CUdeviceptr dptr, size_t bytes) -{ - return cuTexRefSetAddress_v2(ByteOffset, hTexRef, dptr, bytes); -} #endif #if CUDA_VERSION >= 4000 diff --git a/cuda.cabal b/cuda.cabal index e401bda..f6e1a25 100644 --- a/cuda.cabal +++ b/cuda.cabal @@ -1,7 +1,7 @@ cabal-version: 1.24 Name: cuda -Version: 0.11.0.1 +Version: 0.12.2.0 Synopsis: FFI binding to the CUDA interface for programming NVIDIA GPUs Description: The CUDA library provides a direct, general purpose C-like SPMD programming @@ -121,7 +121,6 @@ Library Foreign.CUDA.Driver.Module.Query Foreign.CUDA.Driver.Profiler Foreign.CUDA.Driver.Stream - Foreign.CUDA.Driver.Texture Foreign.CUDA.Driver.Unified Foreign.CUDA.Driver.Utils @@ -133,7 +132,6 @@ Library Foreign.CUDA.Runtime.Exec Foreign.CUDA.Runtime.Marshal Foreign.CUDA.Runtime.Stream - Foreign.CUDA.Runtime.Texture Foreign.CUDA.Runtime.Utils -- Extras diff --git a/src/Foreign/CUDA/Driver/Graph/Capture.chs b/src/Foreign/CUDA/Driver/Graph/Capture.chs index 8876542..b116977 100644 --- a/src/Foreign/CUDA/Driver/Graph/Capture.chs +++ b/src/Foreign/CUDA/Driver/Graph/Capture.chs @@ -149,17 +149,15 @@ status = requireSDK 'status 10.0 -- -- @since 0.10.1.0 -- -#if CUDA_VERSION < 10010 -info :: Stream -> IO (Status, Int64) -info = requireSDK 'info 10.1 -#else -{# fun unsafe cuStreamGetCaptureInfo as info +{# fun unsafe cuStreamGetCaptureInfo_v2 as info { useStream `Stream' , alloca- `Status' peekEnum* , alloca- `Int64' peekIntConv* + , alloca- `Graph' + , alloca- `Node' + , alloca- `CSize' } -> `()' checkStatus*- #} -#endif -- | Set the stream capture interaction mode for this thread. Return the previous value. diff --git a/src/Foreign/CUDA/Driver/Module/Query.chs b/src/Foreign/CUDA/Driver/Module/Query.chs index 0998b3a..e484d8e 100644 --- a/src/Foreign/CUDA/Driver/Module/Query.chs +++ b/src/Foreign/CUDA/Driver/Module/Query.chs @@ -16,7 +16,7 @@ module Foreign.CUDA.Driver.Module.Query ( -- ** Querying module inhabitants - getFun, getPtr, getTex, + getFun, getPtr, ) where @@ -28,7 +28,6 @@ import Foreign.CUDA.Driver.Error import Foreign.CUDA.Driver.Exec import Foreign.CUDA.Driver.Marshal ( peekDeviceHandle ) import Foreign.CUDA.Driver.Module.Base -import Foreign.CUDA.Driver.Texture import Foreign.CUDA.Internal.C2HS import Foreign.CUDA.Ptr @@ -92,26 +91,6 @@ getPtr !mdl !name = do -> `Status' cToEnum #} --- | --- Return a handle to a texture reference. This texture reference handle --- should not be destroyed, as the texture will be destroyed automatically --- when the module is unloaded. --- --- --- -{-# INLINEABLE getTex #-} -getTex :: Module -> ShortByteString -> IO Texture -getTex !mdl !name = resultIfFound "texture" name =<< cuModuleGetTexRef mdl name - -{-# INLINE cuModuleGetTexRef #-} -{# fun unsafe cuModuleGetTexRef - { alloca- `Texture' peekTex* - , useModule `Module' - , useAsCString* `ShortByteString' - } - -> `Status' cToEnum #} - - -------------------------------------------------------------------------------- -- Internal -------------------------------------------------------------------------------- diff --git a/src/Foreign/CUDA/Driver/Stream.chs b/src/Foreign/CUDA/Driver/Stream.chs index b85dc9a..fa3a21d 100644 --- a/src/Foreign/CUDA/Driver/Stream.chs +++ b/src/Foreign/CUDA/Driver/Stream.chs @@ -331,10 +331,10 @@ write32 :: DevicePtr Word32 -> Word32 -> Stream -> [StreamWriteFlag] -> IO () #if CUDA_VERSION < 8000 write32 _ _ _ _ = requireSDK 'write32 8.0 #else -write32 ptr val stream flags = nothingIfOk =<< cuStreamWriteValue32 stream ptr val flags +write32 ptr val stream flags = nothingIfOk =<< cuStreamWriteValue32_v2 stream ptr val flags -{-# INLINE cuStreamWriteValue32 #-} -{# fun unsafe cuStreamWriteValue32 +{-# INLINE cuStreamWriteValue32_v2 #-} +{# fun unsafe cuStreamWriteValue32_v2 { useStream `Stream' , useDeviceHandle `DevicePtr Word32' , `Word32' @@ -348,10 +348,10 @@ write64 :: DevicePtr Word64 -> Word64 -> Stream -> [StreamWriteFlag] -> IO () #if CUDA_VERSION < 9000 write64 _ _ _ _ = requireSDK 'write64 9.0 #else -write64 ptr val stream flags = nothingIfOk =<< cuStreamWriteValue64 stream ptr val flags +write64 ptr val stream flags = nothingIfOk =<< cuStreamWriteValue64_v2 stream ptr val flags -{-# INLINE cuStreamWriteValue64 #-} -{# fun unsafe cuStreamWriteValue64 +{-# INLINE cuStreamWriteValue64_v2 #-} +{# fun unsafe cuStreamWriteValue64_v2 { useStream `Stream' , useDeviceHandle `DevicePtr Word64' , `Word64' @@ -385,10 +385,10 @@ wait32 :: DevicePtr Word32 -> Word32 -> Stream -> [StreamWaitFlag] -> IO () #if CUDA_VERSION < 8000 wait32 _ _ _ _ = requireSDK 'wait32 8.0 #else -wait32 ptr val stream flags = nothingIfOk =<< cuStreamWaitValue32 stream ptr val flags +wait32 ptr val stream flags = nothingIfOk =<< cuStreamWaitValue32_v2 stream ptr val flags -{-# INLINE cuStreamWaitValue32 #-} -{# fun unsafe cuStreamWaitValue32 +{-# INLINE cuStreamWaitValue32_v2 #-} +{# fun unsafe cuStreamWaitValue32_v2 { useStream `Stream' , useDeviceHandle `DevicePtr Word32' , `Word32' @@ -401,10 +401,10 @@ wait64 :: DevicePtr Word64 -> Word64 -> Stream -> [StreamWaitFlag] -> IO () #if CUDA_VERSION < 9000 wait64 _ _ _ _ = requireSDK 'wait64 9.0 #else -wait64 ptr val stream flags = nothingIfOk =<< cuStreamWaitValue64 stream ptr val flags +wait64 ptr val stream flags = nothingIfOk =<< cuStreamWaitValue64_v2 stream ptr val flags -{-# INLINE cuStreamWaitValue64 #-} -{# fun unsafe cuStreamWaitValue64 +{-# INLINE cuStreamWaitValue64_v2 #-} +{# fun unsafe cuStreamWaitValue64_v2 { useStream `Stream' , useDeviceHandle `DevicePtr Word64' , `Word64' diff --git a/src/Foreign/CUDA/Driver/Texture.chs b/src/Foreign/CUDA/Driver/Texture.chs deleted file mode 100644 index c06a768..0000000 --- a/src/Foreign/CUDA/Driver/Texture.chs +++ /dev/null @@ -1,308 +0,0 @@ -{-# LANGUAGE BangPatterns #-} -{-# LANGUAGE ForeignFunctionInterface #-} -{-# OPTIONS_HADDOCK prune #-} --------------------------------------------------------------------------------- --- | --- Module : Foreign.CUDA.Driver.Texture --- Copyright : [2009..2023] Trevor L. McDonell --- License : BSD --- --- Texture management for low-level driver interface --- --------------------------------------------------------------------------------- - -module Foreign.CUDA.Driver.Texture ( - - -- * Texture Reference Management - Texture(..), Format(..), AddressMode(..), FilterMode(..), ReadMode(..), - bind, bind2D, - getAddressMode, getFilterMode, getFormat, - setAddressMode, setFilterMode, setFormat, setReadMode, - - -- Deprecated - create, destroy, - - -- Internal - peekTex - -) where - -#include "cbits/stubs.h" -{# context lib="cuda" #} - --- Friends -import Foreign.CUDA.Ptr -import Foreign.CUDA.Driver.Error -import Foreign.CUDA.Driver.Marshal -import Foreign.CUDA.Internal.C2HS - --- System -import Foreign -import Foreign.C -import Control.Monad - -#if CUDA_VERSION >= 3020 -{-# DEPRECATED create, destroy "as of CUDA version 3.2" #-} -#endif - - --------------------------------------------------------------------------------- --- Data Types --------------------------------------------------------------------------------- - --- | --- A texture reference --- -newtype Texture = Texture { useTexture :: {# type CUtexref #}} - deriving (Eq, Show) - -instance Storable Texture where - sizeOf _ = sizeOf (undefined :: {# type CUtexref #}) - alignment _ = alignment (undefined :: {# type CUtexref #}) - peek p = Texture `fmap` peek (castPtr p) - poke p t = poke (castPtr p) (useTexture t) - --- | --- Texture reference addressing modes --- -{# enum CUaddress_mode as AddressMode - { underscoreToCase } - with prefix="CU_TR_ADDRESS_MODE" deriving (Eq, Show) #} - --- | --- Texture reference filtering mode --- -{# enum CUfilter_mode as FilterMode - { underscoreToCase } - with prefix="CU_TR_FILTER_MODE" deriving (Eq, Show) #} - --- | --- Texture read mode options --- -#c -typedef enum CUtexture_flag_enum { - CU_TEXTURE_FLAG_READ_AS_INTEGER = CU_TRSF_READ_AS_INTEGER, - CU_TEXTURE_FLAG_NORMALIZED_COORDINATES = CU_TRSF_NORMALIZED_COORDINATES, - CU_TEXTURE_FLAG_SRGB = CU_TRSF_SRGB -} CUtexture_flag; -#endc - -{# enum CUtexture_flag as ReadMode - { underscoreToCase - , CU_TEXTURE_FLAG_SRGB as SRGB } - with prefix="CU_TEXTURE_FLAG" deriving (Eq, Show) #} - --- | --- Texture data formats --- -{# enum CUarray_format as Format - { underscoreToCase - , UNSIGNED_INT8 as Word8 - , UNSIGNED_INT16 as Word16 - , UNSIGNED_INT32 as Word32 - , SIGNED_INT8 as Int8 - , SIGNED_INT16 as Int16 - , SIGNED_INT32 as Int32 } - with prefix="CU_AD_FORMAT" deriving (Eq, Show) #} - - --------------------------------------------------------------------------------- --- Texture management --------------------------------------------------------------------------------- - --- | --- Create a new texture reference. Once created, the application must call --- 'setPtr' to associate the reference with allocated memory. Other texture --- reference functions are used to specify the format and interpretation to be --- used when the memory is read through this reference. --- --- --- -{-# INLINEABLE create #-} -create :: IO Texture -create = resultIfOk =<< cuTexRefCreate - -{-# INLINE cuTexRefCreate #-} -{# fun unsafe cuTexRefCreate - { alloca- `Texture' peekTex* } -> `Status' cToEnum #} - - --- | --- Destroy a texture reference. --- --- --- -{-# INLINEABLE destroy #-} -destroy :: Texture -> IO () -destroy !tex = nothingIfOk =<< cuTexRefDestroy tex - -{-# INLINE cuTexRefDestroy #-} -{# fun unsafe cuTexRefDestroy - { useTexture `Texture' } -> `Status' cToEnum #} - - --- | --- Bind a linear array address of the given size (bytes) as a texture --- reference. Any previously bound references are unbound. --- --- --- -{-# INLINEABLE bind #-} -bind :: Texture -> DevicePtr a -> Int64 -> IO () -bind !tex !dptr !bytes = nothingIfOk =<< cuTexRefSetAddress tex dptr bytes - -{-# INLINE cuTexRefSetAddress #-} -{# fun unsafe cuTexRefSetAddress - { alloca- `Int' - , useTexture `Texture' - , useDeviceHandle `DevicePtr a' - , `Int64' } -> `Status' cToEnum #} - - --- | --- Bind a linear address range to the given texture reference as a --- two-dimensional arena. Any previously bound reference is unbound. Note that --- calls to 'setFormat' can not follow a call to 'bind2D' for the same texture --- reference. --- --- --- -{-# INLINEABLE bind2D #-} -bind2D :: Texture -> Format -> Int -> DevicePtr a -> (Int,Int) -> Int64 -> IO () -bind2D !tex !fmt !chn !dptr (!width,!height) !pitch = - nothingIfOk =<< cuTexRefSetAddress2D_simple tex fmt chn dptr width height pitch - -{-# INLINE cuTexRefSetAddress2D_simple #-} -{# fun unsafe cuTexRefSetAddress2D_simple - { useTexture `Texture' - , cFromEnum `Format' - , `Int' - , useDeviceHandle `DevicePtr a' - , `Int' - , `Int' - , `Int64' } -> `Status' cToEnum #} - - --- | --- Get the addressing mode used by a texture reference, corresponding to the --- given dimension (currently the only supported dimension values are 0 or 1). --- --- --- -{-# INLINEABLE getAddressMode #-} -getAddressMode :: Texture -> Int -> IO AddressMode -getAddressMode !tex !dim = resultIfOk =<< cuTexRefGetAddressMode tex dim - -{-# INLINE cuTexRefGetAddressMode #-} -{# fun unsafe cuTexRefGetAddressMode - { alloca- `AddressMode' peekEnum* - , useTexture `Texture' - , `Int' } -> `Status' cToEnum #} - - --- | --- Get the filtering mode used by a texture reference. --- --- --- -{-# INLINEABLE getFilterMode #-} -getFilterMode :: Texture -> IO FilterMode -getFilterMode !tex = resultIfOk =<< cuTexRefGetFilterMode tex - -{-# INLINE cuTexRefGetFilterMode #-} -{# fun unsafe cuTexRefGetFilterMode - { alloca- `FilterMode' peekEnum* - , useTexture `Texture' } -> `Status' cToEnum #} - - --- | --- Get the data format and number of channel components of the bound texture. --- --- --- -{-# INLINEABLE getFormat #-} -getFormat :: Texture -> IO (Format, Int) -getFormat !tex = do - (!status,!fmt,!dim) <- cuTexRefGetFormat tex - resultIfOk (status,(fmt,dim)) - -{-# INLINE cuTexRefGetFormat #-} -{# fun unsafe cuTexRefGetFormat - { alloca- `Format' peekEnum* - , alloca- `Int' peekIntConv* - , useTexture `Texture' } -> `Status' cToEnum #} - - --- | --- Specify the addressing mode for the given dimension of a texture reference. --- --- --- -{-# INLINEABLE setAddressMode #-} -setAddressMode :: Texture -> Int -> AddressMode -> IO () -setAddressMode !tex !dim !mode = nothingIfOk =<< cuTexRefSetAddressMode tex dim mode - -{-# INLINE cuTexRefSetAddressMode #-} -{# fun unsafe cuTexRefSetAddressMode - { useTexture `Texture' - , `Int' - , cFromEnum `AddressMode' } -> `Status' cToEnum #} - - --- | --- Specify the filtering mode to be used when reading memory through a texture --- reference. --- --- --- -{-# INLINEABLE setFilterMode #-} -setFilterMode :: Texture -> FilterMode -> IO () -setFilterMode !tex !mode = nothingIfOk =<< cuTexRefSetFilterMode tex mode - -{-# INLINE cuTexRefSetFilterMode #-} -{# fun unsafe cuTexRefSetFilterMode - { useTexture `Texture' - , cFromEnum `FilterMode' } -> `Status' cToEnum #} - - --- | --- Specify additional characteristics for reading and indexing the texture --- reference. --- --- --- -{-# INLINEABLE setReadMode #-} -setReadMode :: Texture -> ReadMode -> IO () -setReadMode !tex !mode = nothingIfOk =<< cuTexRefSetFlags tex mode - -{-# INLINE cuTexRefSetFlags #-} -{# fun unsafe cuTexRefSetFlags - { useTexture `Texture' - , cFromEnum `ReadMode' } -> `Status' cToEnum #} - - --- | --- Specify the format of the data and number of packed components per element to --- be read by the texture reference. --- --- --- -{-# INLINEABLE setFormat #-} -setFormat :: Texture -> Format -> Int -> IO () -setFormat !tex !fmt !chn = nothingIfOk =<< cuTexRefSetFormat tex fmt chn - -{-# INLINE cuTexRefSetFormat #-} -{# fun unsafe cuTexRefSetFormat - { useTexture `Texture' - , cFromEnum `Format' - , `Int' } -> `Status' cToEnum #} - - --------------------------------------------------------------------------------- --- Internal --------------------------------------------------------------------------------- - -{-# INLINE peekTex #-} -peekTex :: Ptr {# type CUtexref #} -> IO Texture -peekTex = liftM Texture . peek - diff --git a/src/Foreign/CUDA/Runtime/Device.chs b/src/Foreign/CUDA/Runtime/Device.chs index fa58f9e..ebb3325 100644 --- a/src/Foreign/CUDA/Runtime/Device.chs +++ b/src/Foreign/CUDA/Runtime/Device.chs @@ -216,10 +216,10 @@ count = resultIfOk =<< cudaGetDeviceCount -- {-# INLINEABLE props #-} props :: Device -> IO DeviceProperties -props !n = resultIfOk =<< cudaGetDeviceProperties n +props !n = resultIfOk =<< cudaGetDeviceProperties_v2 n -{-# INLINE cudaGetDeviceProperties #-} -{# fun unsafe cudaGetDeviceProperties +{-# INLINE cudaGetDeviceProperties_v2 #-} +{# fun unsafe cudaGetDeviceProperties_v2 { alloca- `DeviceProperties' peek* , `Int' } -> `Status' cToEnum #} diff --git a/src/Foreign/CUDA/Runtime/Texture.chs b/src/Foreign/CUDA/Runtime/Texture.chs deleted file mode 100644 index 94e8db9..0000000 --- a/src/Foreign/CUDA/Runtime/Texture.chs +++ /dev/null @@ -1,203 +0,0 @@ -{-# LANGUAGE BangPatterns #-} -{-# LANGUAGE ForeignFunctionInterface #-} --------------------------------------------------------------------------------- --- | --- Module : Foreign.CUDA.Runtime.Texture --- Copyright : [2009..2023] Trevor L. McDonell --- License : BSD --- --- Texture references --- --------------------------------------------------------------------------------- - -module Foreign.CUDA.Runtime.Texture ( - - -- * Texture Reference Management - Texture(..), FormatKind(..), AddressMode(..), FilterMode(..), FormatDesc(..), - bind, bind2D - -) where - --- Friends -import Foreign.CUDA.Ptr -import Foreign.CUDA.Runtime.Error -import Foreign.CUDA.Internal.C2HS - --- System -import Data.Int -import Foreign -import Foreign.C - -#include "cbits/stubs.h" -{# context lib="cudart" #} - -#c -typedef struct textureReference textureReference; -typedef struct cudaChannelFormatDesc cudaChannelFormatDesc; -#endc - --------------------------------------------------------------------------------- --- Data Types --------------------------------------------------------------------------------- - --- |A texture reference --- -{# pointer *textureReference as ^ -> Texture #} - -data Texture = Texture - { - normalised :: !Bool, -- ^ access texture using normalised coordinates [0.0,1.0) - filtering :: !FilterMode, - addressing :: !(AddressMode, AddressMode, AddressMode), - format :: !FormatDesc - } - deriving (Eq, Show) - --- |Texture channel format kind --- -{# enum cudaChannelFormatKind as FormatKind - { } - with prefix="cudaChannelFormatKind" deriving (Eq, Show) #} - --- |Texture addressing mode --- -{# enum cudaTextureAddressMode as AddressMode - { } - with prefix="cudaAddressMode" deriving (Eq, Show) #} - --- |Texture filtering mode --- -{# enum cudaTextureFilterMode as FilterMode - { } - with prefix="cudaFilterMode" deriving (Eq, Show) #} - - --- |A description of how memory read through the texture cache should be --- interpreted, including the kind of data and the number of bits of each --- component (x,y,z and w, respectively). --- -{# pointer *cudaChannelFormatDesc as ^ foreign -> FormatDesc nocode #} - -data FormatDesc = FormatDesc - { - depth :: !(Int,Int,Int,Int), - kind :: !FormatKind - } - deriving (Eq, Show) - -instance Storable FormatDesc where - sizeOf _ = {# sizeof cudaChannelFormatDesc #} - alignment _ = alignment (undefined :: Ptr ()) - - peek p = do - dx <- cIntConv `fmap` {# get cudaChannelFormatDesc.x #} p - dy <- cIntConv `fmap` {# get cudaChannelFormatDesc.y #} p - dz <- cIntConv `fmap` {# get cudaChannelFormatDesc.z #} p - dw <- cIntConv `fmap` {# get cudaChannelFormatDesc.w #} p - df <- cToEnum `fmap` {# get cudaChannelFormatDesc.f #} p - return $ FormatDesc (dx,dy,dz,dw) df - - poke p (FormatDesc (x,y,z,w) k) = do - {# set cudaChannelFormatDesc.x #} p (cIntConv x) - {# set cudaChannelFormatDesc.y #} p (cIntConv y) - {# set cudaChannelFormatDesc.z #} p (cIntConv z) - {# set cudaChannelFormatDesc.w #} p (cIntConv w) - {# set cudaChannelFormatDesc.f #} p (cFromEnum k) - - -instance Storable Texture where - sizeOf _ = {# sizeof textureReference #} - alignment _ = alignment (undefined :: Ptr ()) - - peek p = do - norm <- cToBool `fmap` {# get textureReference.normalized #} p - fmt <- cToEnum `fmap` {# get textureReference.filterMode #} p - dsc <- peek . castPtr =<< {# get textureReference.channelDesc #} p - [x,y,z] <- peekArrayWith cToEnum 3 =<< {# get textureReference.addressMode #} p - return $ Texture norm fmt (x,y,z) dsc - - poke p (Texture norm fmt (x,y,z) dsc) = do - {# set textureReference.normalized #} p (cFromBool norm) - {# set textureReference.filterMode #} p (cFromEnum fmt) - withArray (map cFromEnum [x,y,z]) ({# set textureReference.addressMode #} p) - - -- c2hs is returning the wrong type for structs-within-structs - dscptr <- {# get textureReference.channelDesc #} p - poke (castPtr dscptr) dsc - - --------------------------------------------------------------------------------- --- Texture References --------------------------------------------------------------------------------- - --- |Bind the memory area associated with the device pointer to a texture --- reference given by the named symbol. Any previously bound references are --- unbound. --- -{-# INLINEABLE bind #-} -bind :: String -> Texture -> DevicePtr a -> Int64 -> IO () -bind !name !tex !dptr !bytes = do - ref <- getTex name - poke ref tex - nothingIfOk =<< cudaBindTexture ref dptr (format tex) bytes - -{-# INLINE cudaBindTexture #-} -{# fun unsafe cudaBindTexture - { alloca- `Int' - , id `TextureReference' - , dptr `DevicePtr a' - , with_* `FormatDesc' - , `Int64' } -> `Status' cToEnum #} - where dptr = useDevicePtr . castDevPtr - --- |Bind the two-dimensional memory area to the texture reference associated --- with the given symbol. The size of the area is constrained by (width,height) --- in texel units, and the row pitch in bytes. Any previously bound references --- are unbound. --- -{-# INLINEABLE bind2D #-} -bind2D :: String -> Texture -> DevicePtr a -> (Int,Int) -> Int64 -> IO () -bind2D !name !tex !dptr (!width,!height) !bytes = do - ref <- getTex name - poke ref tex - nothingIfOk =<< cudaBindTexture2D ref dptr (format tex) width height bytes - -{-# INLINE cudaBindTexture2D #-} -{# fun unsafe cudaBindTexture2D - { alloca- `Int' - , id `TextureReference' - , dptr `DevicePtr a' - , with_* `FormatDesc' - , `Int' - , `Int' - , `Int64' } -> `Status' cToEnum #} - where dptr = useDevicePtr . castDevPtr - - --- |Returns the texture reference associated with the given symbol --- -{-# INLINEABLE getTex #-} -getTex :: String -> IO TextureReference -getTex !name = resultIfOk =<< cudaGetTextureReference name - -{-# INLINE cudaGetTextureReference #-} -{# fun unsafe cudaGetTextureReference - { alloca- `Ptr Texture' peek* - , withCString_* `String' } -> `Status' cToEnum #} - - --------------------------------------------------------------------------------- --- Internal --------------------------------------------------------------------------------- - -{-# INLINE with_ #-} -with_ :: Storable a => a -> (Ptr a -> IO b) -> IO b -with_ = with - - --- CUDA 5.0 changed the types of some attributes from char* to void* --- -{-# INLINE withCString_ #-} -withCString_ :: String -> (Ptr a -> IO b) -> IO b -withCString_ !str !fn = withCString str (fn . castPtr) -