C# wrapper for cusparse.h
        /// <summary>
        /// Returns matrix fill mode
        /// </summary>
        /// <returns></returns>
        public cusparseFillMode GetMatFillMode()
        {
            cusparseFillMode fillMode = CudaSparseNativeMethods.cusparseGetMatFillMode(_descr);

            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseGetMatFillMode", res));
            return(fillMode);
        }
        /// <summary>
        /// Returns matrix diagonal type
        /// </summary>
        /// <returns></returns>
        public cusparseDiagType GetMatDiagType()
        {
            cusparseDiagType diagType = CudaSparseNativeMethods.cusparseGetMatDiagType(_descr);

            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseGetMatDiagType", res));
            return(diagType);
        }
        /// <summary>
        /// Returns matrix index base.
        /// </summary>
        /// <returns></returns>
        public IndexBase GetMatIndexBase()
        {
            IndexBase indexBase = CudaSparseNativeMethods.cusparseGetMatIndexBase(_descr);

            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseGetMatIndexBase", res));
            return(indexBase);
        }
예제 #4
0
 /// <summary>
 /// SetColorAlgs
 /// </summary>
 public void SetColorAlgs(cusparseColorAlg alg)
 {
     res = CudaSparseNativeMethods.cusparseSetColorAlgs(_info, alg);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseSetColorAlgs", res));
     if (res != cusparseStatus.Success)
     {
         throw new CudaSparseException(res);
     }
 }
예제 #5
0
 /// <summary>
 ///
 /// </summary>
 public void GetSize()
 {
     res = CudaSparseNativeMethods.cusparseSpMatGetSize(descr, ref rows, ref cols, ref nnz);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseSpMatGetSize", res));
     if (res != cusparseStatus.Success)
     {
         throw new CudaSparseException(res);
     }
 }
예제 #6
0
 /// <summary>
 ///
 /// </summary>
 public void SetStridedBatch(int batchCount)
 {
     res = CudaSparseNativeMethods.cusparseSpMatSetStridedBatch(descr, batchCount);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseSpMatSetStridedBatch", res));
     if (res != cusparseStatus.Success)
     {
         throw new CudaSparseException(res);
     }
 }
예제 #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="data"></param>
 public void SetValues(CudaDeviceVariable <dataT> data)
 {
     res = CudaSparseNativeMethods.cusparseDnVecSetValues(descr, data.DevicePointer);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseDnVecSetValues", res));
     if (res != cusparseStatus.Success)
     {
         throw new CudaSparseException(res);
     }
 }
 /// <summary>
 /// Sets matrix index base
 /// </summary>
 /// <param name="indexBase"></param>
 public void SetMatIndexBase(IndexBase indexBase)
 {
     res = CudaSparseNativeMethods.cusparseSetMatIndexBase(_descr, indexBase);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseSetMatIndexBase", res));
     if (res != cusparseStatus.Success)
     {
         throw new CudaSparseException(res);
     }
 }
예제 #9
0
 public void SetAttribute(cusparseDiagType diagType)
 {
     res = CudaSparseNativeMethods.cusparseSpMatSetAttribute(descr, cusparseSpMatAttribute.DiagType, ref diagType, sizeof(cusparseDiagType));
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseSpMatSetAttribute", res));
     if (res != cusparseStatus.Success)
     {
         throw new CudaSparseException(res);
     }
 }
예제 #10
0
 /// <summary>
 /// </summary>
 public CudaSparseHybMat()
 {
     _hyb = new cusparseHybMat();
     res  = CudaSparseNativeMethods.cusparseCreateHybMat(ref _hyb);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseCreateHybMat", res));
     if (res != cusparseStatus.Success)
     {
         throw new CudaSparseException(res);
     }
 }
예제 #11
0
 /// <summary>
 /// </summary>
 public CudaSparseCsrsm2Info()
 {
     _info = new csrsm2Info();
     res   = CudaSparseNativeMethods.cusparseCreateCsrsm2Info(ref _info);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseCreateCsrsm2Info", res));
     if (res != cusparseStatus.Success)
     {
         throw new CudaSparseException(res);
     }
 }
예제 #12
0
 /// <summary>
 /// </summary>
 public SpGEMMDescr()
 {
     descr = new cusparseSpGEMMDescr();
     res   = CudaSparseNativeMethods.cusparseSpGEMM_createDescr(ref descr);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseSpGEMM_createDescr", res));
     if (res != cusparseStatus.Success)
     {
         throw new CudaSparseException(res);
     }
 }
 /// <summary>
 /// When the matrix descriptor is created, its fields are initialized to:
 /// CUSPARSE_MATRIXYPE_GENERAL
 /// CUSPARSE_INDEX_BASE_ZERO
 /// All other fields are uninitialized
 /// </summary>
 public CudaSparseMatrixDescriptor()
 {
     _descr = new cusparseMatDescr();
     res    = CudaSparseNativeMethods.cusparseCreateMatDescr(ref _descr);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseCreateMatDescr", res));
     if (res != cusparseStatus.Success)
     {
         throw new CudaSparseException(res);
     }
 }
예제 #14
0
 /// <summary>
 ///
 /// </summary>
 public void SetStridedBatchCsr(int batchCount,
                                long offsetsBatchStride, long columnsValuesBatchStride)
 {
     res = CudaSparseNativeMethods.cusparseCsrSetStridedBatch(descr, batchCount, offsetsBatchStride, columnsValuesBatchStride);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseCsrSetStridedBatch", res));
     if (res != cusparseStatus.Success)
     {
         throw new CudaSparseException(res);
     }
 }
예제 #15
0
 public void GetAttribute(out cusparseFillMode fillMode)
 {
     fillMode = cusparseFillMode.Lower;
     res      = CudaSparseNativeMethods.cusparseSpMatGetAttribute(descr, cusparseSpMatAttribute.FillMode, ref fillMode, sizeof(cusparseFillMode));
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseSpMatGetAttribute", res));
     if (res != cusparseStatus.Success)
     {
         throw new CudaSparseException(res);
     }
 }
예제 #16
0
 /// <summary>
 /// </summary>
 public DenseVector(long aSize, CudaDeviceVariable <dataT> values)
 {
     size     = aSize;
     descr    = new cusparseDnVecDescr();
     typeData = CudaDataTypeTranslator.GetType(typeof(dataT));
     res      = CudaSparseNativeMethods.cusparseCreateDnVec(ref descr, size, values.DevicePointer, typeData);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseCreateDnVec", res));
     if (res != cusparseStatus.Success)
     {
         throw new CudaSparseException(res);
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public CudaSparseMatrixDescriptor Copy()
        {
            CudaSparseMatrixDescriptor retVal = new CudaSparseMatrixDescriptor();

            res = CudaSparseNativeMethods.cusparseCopyMatDescr(retVal.Descriptor, _descr);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseCopyMatDescr", res));
            if (res != cusparseStatus.Success)
            {
                throw new CudaSparseException(res);
            }
            return(retVal);
        }
예제 #18
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public CudaDeviceVariable <dataT> GetValues()
        {
            CUdeviceptr devPtr = new CUdeviceptr();

            res = CudaSparseNativeMethods.cusparseDnVecGetValues(descr, ref devPtr);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseDnVecGetValues", res));
            if (res != cusparseStatus.Success)
            {
                throw new CudaSparseException(res);
            }
            return(new CudaDeviceVariable <dataT>(devPtr));
        }
예제 #19
0
        /// <summary>
        /// GetColorAlgs
        /// </summary>
        public cusparseColorAlg GetColorAlgs()
        {
            cusparseColorAlg retVal = new cusparseColorAlg();

            res = CudaSparseNativeMethods.cusparseGetColorAlgs(_info, ref retVal);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseGetColorAlgs", res));
            if (res != cusparseStatus.Success)
            {
                throw new CudaSparseException(res);
            }
            return(retVal);
        }
예제 #20
0
        /// <summary>
        ///
        /// </summary>
        public void CooSet(CudaDeviceVariable <indexT> cooRows,
                           CudaDeviceVariable <indexT> cooColumns,
                           CudaDeviceVariable <dataT> cooValues)
        {
            res = CudaSparseNativeMethods.cusparseCooSetPointers(descr, cooRows.DevicePointer,
                                                                 cooColumns.DevicePointer, cooValues.DevicePointer);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseCooSetPointers", res));

            if (res != cusparseStatus.Success)
            {
                throw new CudaSparseException(res);
            }
        }
예제 #21
0
        /// <summary>
        ///
        /// </summary>
        public CudaDeviceVariable <dataT> Get()
        {
            CUdeviceptr ptrValues = new CUdeviceptr();

            res = CudaSparseNativeMethods.cusparseDnMatGet(descr, ref rows, ref cols, ref ld, ref ptrValues, ref typeData, ref order);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseDnMatGet", res));
            if (res != cusparseStatus.Success)
            {
                throw new CudaSparseException(res);
            }

            return(new CudaDeviceVariable <dataT>(ptrValues));
        }
 /// <summary>
 /// Creates a new CudaSparseMatrixDescriptor
 /// </summary>
 public CudaSparseMatrixDescriptor(cusparseMatrixType matrixType, cusparseFillMode fillMode, cusparseDiagType diagType, IndexBase indexBase)
 {
     _descr = new cusparseMatDescr();
     res    = CudaSparseNativeMethods.cusparseCreateMatDescr(ref _descr);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseCreateMatDescr", res));
     if (res != cusparseStatus.Success)
     {
         throw new CudaSparseException(res);
     }
     SetMatType(matrixType);
     SetMatFillMode(fillMode);
     SetMatDiagType(diagType);
     SetMatIndexBase(indexBase);
 }
예제 #23
0
 /// <summary>
 /// For IDisposable
 /// </summary>
 /// <param name="fDisposing"></param>
 protected virtual void Dispose(bool fDisposing)
 {
     if (fDisposing && !disposed)
     {
         //Ignore if failing
         res = CudaSparseNativeMethods.cusparseDestroyCsrsm2Info(_info);
         Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseDestroyCsrsm2Info", res));
         disposed = true;
     }
     if (!fDisposing && !disposed)
     {
         Debug.WriteLine(String.Format("ManagedCUDA not-disposed warning: {0}", this.GetType()));
     }
 }
예제 #24
0
        /// <summary>
        ///
        /// </summary>
        public void Get(out CudaDeviceVariable <indexT> indices, out CudaDeviceVariable <dataT> values)
        {
            CUdeviceptr ptrIndices = new CUdeviceptr();
            CUdeviceptr ptrValues  = new CUdeviceptr();

            res = CudaSparseNativeMethods.cusparseSpVecGet(descr, ref size, ref nnz, ref ptrIndices, ref ptrValues, ref typeIndices, ref idxBase, ref typeData);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseSpVecGet", res));
            if (res != cusparseStatus.Success)
            {
                throw new CudaSparseException(res);
            }

            indices = new CudaDeviceVariable <indexT>(ptrIndices);
            values  = new CudaDeviceVariable <dataT>(ptrValues);
        }
예제 #25
0
 /// <summary>
 /// </summary>
 public SparseVector(long aSize, long aNnz, CudaDeviceVariable <indexT> indices, CudaDeviceVariable <dataT> values, IndexBase aIdxBase)
 {
     size        = aSize;
     nnz         = aNnz;
     idxBase     = aIdxBase;
     descr       = new cusparseSpVecDescr();
     typeIndices = IndexTypeTranslator.GetType(typeof(indexT));
     typeData    = CudaDataTypeTranslator.GetType(typeof(dataT));
     res         = CudaSparseNativeMethods.cusparseCreateSpVec(ref descr, size, nnz, indices.DevicePointer, values.DevicePointer, typeIndices, idxBase, typeData);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseCreateSpVec", res));
     if (res != cusparseStatus.Success)
     {
         throw new CudaSparseException(res);
     }
 }
예제 #26
0
 /// <summary>
 /// </summary>
 public DenseMatrix(long aRows, long aCols, long aLd, Order aOrder, CudaDeviceVariable <dataT> values)
 {
     rows     = aRows;
     cols     = aCols;
     ld       = aLd;
     order    = aOrder;
     descr    = new cusparseDnMatDescr();
     typeData = CudaDataTypeTranslator.GetType(typeof(dataT));
     res      = CudaSparseNativeMethods.cusparseCreateDnMat(ref descr, rows, cols, ld, values.DevicePointer, typeData, order);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseCreateDnMat", res));
     if (res != cusparseStatus.Success)
     {
         throw new CudaSparseException(res);
     }
 }
예제 #27
0
        public void CooAoSGet(out CudaDeviceVariable <indexT> cooInd,
                              out CudaDeviceVariable <dataT> cooValues)
        {
            CUdeviceptr ptrIdx    = new CUdeviceptr();
            CUdeviceptr ptrValues = new CUdeviceptr();

            res = CudaSparseNativeMethods.cusparseCooAoSGet(descr, ref rows, ref cols, ref nnz, ref ptrIdx, ref ptrValues, ref typeIndices, ref idxBase, ref typeData);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseCooAoSGet", res));

            if (res != cusparseStatus.Success)
            {
                throw new CudaSparseException(res);
            }

            cooInd    = new CudaDeviceVariable <indexT>(ptrIdx);
            cooValues = new CudaDeviceVariable <dataT>(ptrValues);
        }
예제 #28
0
 /// <summary>
 /// </summary>
 private SparseMatrix(cusparseSpMatDescr aDescr, long aRows, long aCols, long aNnz, IndexBase aIdxBase, IndexType aTypeIndices, cudaDataType aTypeData)
 {
     rows        = aRows;
     cols        = aCols;
     nnz         = aNnz;
     idxBase     = aIdxBase;
     descr       = aDescr;
     typeIndices = aTypeIndices;
     typeData    = aTypeData;
     format      = Format.COO;
     res         = CudaSparseNativeMethods.cusparseSpMatGetFormat(descr, ref format);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseSpMatGetFormat", res));
     if (res != cusparseStatus.Success)
     {
         throw new CudaSparseException(res);
     }
 }
예제 #29
0
        /// <summary>
        ///
        /// </summary>
        public void BlockedEllGet(out CudaDeviceVariable <indexT> ellColInd,
                                  out CudaDeviceVariable <dataT> ellValue, out long ellBlockSize, out long ellCols)
        {
            ellBlockSize = 0;
            ellCols      = 0;
            CUdeviceptr ptrIdx    = new CUdeviceptr();
            CUdeviceptr ptrValues = new CUdeviceptr();

            res = CudaSparseNativeMethods.cusparseBlockedEllGet(descr, ref rows, ref cols, ref ellBlockSize, ref ellCols, ref ptrIdx, ref ptrValues, ref typeIndices, ref idxBase, ref typeData);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseBlockedEllGet", res));

            if (res != cusparseStatus.Success)
            {
                throw new CudaSparseException(res);
            }

            ellColInd = new CudaDeviceVariable <indexT>(ptrIdx);
            ellValue  = new CudaDeviceVariable <dataT>(ptrValues);
        }
예제 #30
0
        /// <summary>
        ///
        /// </summary>
        public void CsrGet(out CudaDeviceVariable <indexT> csrRowOffsets,
                           out CudaDeviceVariable <indexT> csrColInd,
                           out CudaDeviceVariable <dataT> csrValues)
        {
            CUdeviceptr ptrRowOffsets   = new CUdeviceptr();
            CUdeviceptr ptrColIdx       = new CUdeviceptr();
            CUdeviceptr ptrValues       = new CUdeviceptr();
            IndexType   indexTypeOffset = IndexType.Index32I;

            res = CudaSparseNativeMethods.cusparseCsrGet(descr, ref rows, ref cols, ref nnz, ref ptrRowOffsets,
                                                         ref ptrColIdx, ref ptrValues, ref indexTypeOffset, ref typeIndices, ref idxBase, ref typeData);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseCsrGet", res));

            if (res != cusparseStatus.Success)
            {
                throw new CudaSparseException(res);
            }

            csrRowOffsets = new CudaDeviceVariable <indexT>(ptrRowOffsets);
            csrColInd     = new CudaDeviceVariable <indexT>(ptrColIdx);
            csrValues     = new CudaDeviceVariable <dataT>(ptrValues);
        }