{-# LANGUAGE CPP #-} {-# LANGUAGE ForeignFunctionInterface #-} -- | -- Module : Foreign.CUDA.BLAS.Sparse.Matrix.Descriptor -- Copyright : [2017] Trevor L. McDonell -- License : BSD3 -- -- Maintainer : Trevor L. McDonell -- Stability : experimental -- Portability : non-portable (GHC extensions) -- module Foreign.CUDA.BLAS.Sparse.Matrix.Descriptor ( MatrixDescriptor(..), MatrixType(..), IndexBase(..), Diagonal(..), Fill(..), createMatDescr, destroyMatDescr, -- Querying properties getDiagonal, getFillMode, getIndexBase, getMatrixType, -- Setting properties setDiagonal, setFillMode, setIndexBase, setMatrixType, ) where -- Friends import Foreign.CUDA.BLAS.Sparse.Error import Foreign.CUDA.BLAS.Sparse.Internal.C2HS -- System import Foreign import Foreign.C import Control.Monad ( liftM ) #include "cbits/stubs.h" {# context lib="cusparse" #} -- | An opaque type used to describe the shape and properties of a matrix. -- -- -- newtype MatrixDescriptor = MatrixDescriptor { useMatDescr :: {# type cusparseMatDescr_t #}} -- | Indicates whether the diagonal elements of the matrix are unity. The -- diagonal elements are always assumed to be present, but if 'Unit' is passed -- to an API routine, then the routine assumes that all diagonal entries are -- unity and will not read or modify those entries. -- -- -- {# enum cusparseDiagType_t as Diagonal { underscoreToCase } with prefix="CUSPARSE_DIAG_TYPE" deriving (Eq, Show) #} -- | Indicates whether the upper or lower part of the sparse matrix is stored. -- -- -- {# enum cusparseFillMode_t as Fill { underscoreToCase } with prefix="CUSPARSE_FILL_MODE" deriving (Eq, Show) #} -- | Indicates whether indexing of matrix elements starts at zero or one. -- -- -- {# enum cusparseIndexBase_t as IndexBase { underscoreToCase } with prefix="CUSPARSE_INDEX_BASE" deriving (Eq, Show) #} -- | Indicates the type of matrix. -- -- -- {# enum cusparseMatrixType_t as MatrixType { underscoreToCase } with prefix="CUSPARSE_MATRIX_TYPE" deriving (Eq, Show) #} -- | Create a new matrix descriptor, with matrix type 'General' and index base -- 'Zero', while leaving other fields uninitialised. -- -- -- {-# INLINEABLE createMatDescr #-} {# fun unsafe cusparseCreateMatDescr as createMatDescr { alloca- `MatrixDescriptor' peekMD* } -> `()' checkStatus*- #} where peekMD = liftM MatrixDescriptor . peek -- | Release memory associated with a matrix descriptor. -- -- -- {-# INLINEABLE destroyMatDescr #-} {# fun unsafe cusparseDestroyMatDescr as destroyMatDescr { useMatDescr `MatrixDescriptor' } -> `()' checkStatus* #} -- | Get the 'Diagonal' type field of the matrix descriptor. -- -- -- {-# INLINEABLE getDiagonal #-} {# fun unsafe cusparseGetMatDiagType as getDiagonal { useMatDescr `MatrixDescriptor' } -> `Diagonal' cToEnum #} -- | Get the 'Fill' mode of the matrix descriptor. -- -- -- {-# INLINEABLE getFillMode #-} {# fun unsafe cusparseGetMatFillMode as getFillMode { useMatDescr `MatrixDescriptor' } -> `Fill' cToEnum #} -- | Get the 'IndexBase' mode of the matrix descriptor. -- -- -- {-# INLINEABLE getIndexBase #-} {# fun unsafe cusparseGetMatIndexBase as getIndexBase { useMatDescr `MatrixDescriptor' } -> `IndexBase' cToEnum #} -- | Get the 'MatrixType' mode of the matrix descriptor. -- -- -- {-# INLINEABLE getMatrixType #-} {# fun unsafe cusparseGetMatType as getMatrixType { useMatDescr `MatrixDescriptor' } -> `MatrixType' cToEnum #} -- | Set the 'Diagonal' type field of the matrix descriptor. -- -- -- {-# INLINEABLE setDiagonal #-} {# fun unsafe cusparseSetMatDiagType as setDiagonal { useMatDescr `MatrixDescriptor', cFromEnum `Diagonal' } -> `()' checkStatus* #} -- | Set the 'Fill' mode of the matrix descriptor. -- -- -- {-# INLINEABLE setFillMode #-} {# fun unsafe cusparseSetMatFillMode as setFillMode { useMatDescr `MatrixDescriptor', cFromEnum `Fill' } -> `()' checkStatus* #} -- | Set the 'IndexBase' mode of the matrix descriptor. -- -- -- {-# INLINEABLE setIndexBase #-} {# fun unsafe cusparseSetMatIndexBase as setIndexBase { useMatDescr `MatrixDescriptor', cFromEnum `IndexBase' } -> `()' checkStatus* #} -- | Set the 'MatrixType' mode of the matrix descriptor. -- -- -- {-# INLINEABLE setMatrixType #-} {# fun unsafe cusparseSetMatType as setMatrixType { useMatDescr `MatrixDescriptor', cFromEnum `MatrixType' } -> `()' checkStatus* #}