Exemple #1
0
        public cuDoubleComplex[] PerformFFT(cuDoubleComplex[] data, int n, TransformDirection direction)
        {
            f_plan = new CudaFFTPlan2D(n, n, cufftType.Z2Z);

            CudaDeviceVariable <cuDoubleComplex> d_signal = new CudaDeviceVariable <cuDoubleComplex>(n * n);
            CudaDeviceVariable <cuDoubleComplex> o_signal = new CudaDeviceVariable <cuDoubleComplex>(n * n);

            d_signal.CopyToDevice(data);
            f_plan.Exec(d_signal.DevicePointer, o_signal.DevicePointer, direction);


            cuDoubleComplex[] result = new cuDoubleComplex[n * n];

            o_signal.CopyToHost(result);
            d_signal.Dispose();
            return(result);
        }
 public static cuDoubleComplex[] PerformFft(cuDoubleComplex[] data, int size, TransformDirection direction)
 {
     if (cudaAvailable)
     {
         return(cuHelper.PerformFFT(data, size, direction));
     }
     else
     {
         cuDoubleComplex[] result = new cuDoubleComplex[size * size];
         using (var input = new AlignedArrayComplex(16, size, size))
             using (var output = new AlignedArrayComplex(16, input.GetSize()))
             {
                 for (int i = 0; i < input.GetLength(0); i++)
                 {
                     for (int j = 0; j < input.GetLength(1); j++)
                     {
                         input[i, j] = new Complex(data[i * size + j].real, data[i * size + j].imag);
                     }
                 }
                 if (direction == TransformDirection.Forward)
                 {
                     DFT.FFT(input, output);
                 }
                 else
                 {
                     DFT.IFFT(input, output);
                 }
                 for (int i = 0; i < input.GetLength(0); i++)
                 {
                     for (int j = 0; j < input.GetLength(1); j++)
                     {
                         result[i * size + j].real = output[i, j].Real;
                         result[i * size + j].imag = output[i, j].Imaginary;
                     }
                 }
             }
         return(result);
     }
 }
		public static extern cusparseStatus cusparseZhybmv(cusparseContext handle, cusparseOperation transA, ref cuDoubleComplex alpha, cusparseMatDescr descrA, cusparseHybMat hybA, CUdeviceptr x, ref cuDoubleComplex beta, CUdeviceptr y);
		public static extern cusparseStatus cusparseZbsrxmv(cusparseContext handle,
											cusparseDirection dirA,
											cusparseOperation transA,
											int sizeOfMask,
											int mb,
											int nb,
											int nnzb,
											ref cuDoubleComplex alpha,
											cusparseMatDescr descrA,
											CUdeviceptr bsrValA,
											CUdeviceptr bsrMaskPtrA,
											CUdeviceptr bsrRowPtrA,
											CUdeviceptr bsrEndPtrA,
											CUdeviceptr bsrColIndA,
											int blockDim,
											CUdeviceptr x,
											ref cuDoubleComplex beta,
											CUdeviceptr y);
		public static extern cusparseStatus cusparseZcsrgeam(cusparseContext handle,
											int m,
											int n,
											ref cuDoubleComplex alpha,
											cusparseMatDescr descrA,
											int nnzA,
											CUdeviceptr csrValA,
											CUdeviceptr csrRowPtrA,
											CUdeviceptr csrColIndA,
											ref cuDoubleComplex beta,
											cusparseMatDescr descrB,
											int nnzB,
											CUdeviceptr csrValB,
											CUdeviceptr csrRowPtrB,
											CUdeviceptr csrColIndB,
											cusparseMatDescr descrC,
											CUdeviceptr csrValC,
											CUdeviceptr csrRowPtrC,
											CUdeviceptr csrColIndC);
		public static extern cusparseStatus cusparseZcsrgemm2_bufferSizeExt(cusparseContext handle,
															 int m,
															 int n,
															 int k,
															 ref cuDoubleComplex alpha,
															 cusparseMatDescr descrA,
															 int nnzA,
															 CUdeviceptr csrSortedRowPtrA,
															 CUdeviceptr csrSortedColIndA,
															 cusparseMatDescr descrB,
															 int nnzB,
															 CUdeviceptr csrSortedRowPtrB,
															 CUdeviceptr csrSortedColIndB,
															 ref cuDoubleComplex beta,
															 cusparseMatDescr descrD,
															 int nnzD,
															 CUdeviceptr csrSortedRowPtrD,
															 CUdeviceptr csrSortedColIndD,
															 csrgemm2Info info,
															 ref SizeT pBufferSizeInBytes);
		public static extern cusparseStatus cusparseZaxpyi(cusparseContext handle, int nnz, ref cuDoubleComplex alpha, CUdeviceptr xVal, CUdeviceptr xInd, CUdeviceptr y, cusparseIndexBase idxBase);
		public static extern cusparseStatus cusparseZbsrsm2_solve(cusparseContext handle,
												   cusparseDirection dirA,
												   cusparseOperation transA,
												   cusparseOperation transXY,
												   int mb,
												   int n,
												   int nnzb,
												   ref cuDoubleComplex alpha,
												   cusparseMatDescr descrA,
												   CUdeviceptr bsrVal,
												   CUdeviceptr bsrRowPtr,
												   CUdeviceptr bsrColInd,
												   int blockSize,
												   bsrsm2Info info,
												   CUdeviceptr X,
												   int ldx,
												   CUdeviceptr Y,
												   int ldy,
												   cusparseSolvePolicy policy,
												   CUdeviceptr pBuffer);
		public static extern cusparseStatus cusparseZcsrmm2(cusparseContext handle, cusparseOperation transa, cusparseOperation transb, int m, int n, int k, int nnz,
											ref cuDoubleComplex alpha, cusparseMatDescr descrA, CUdeviceptr csrValA, CUdeviceptr csrRowPtrA, CUdeviceptr csrColIndA, CUdeviceptr B, int ldb, ref cuDoubleComplex beta, CUdeviceptr C, int ldc);
        public static extern CublasStatus cublasZdotu_v2(CudaBlasHandle handle,
										 int n,
										 [In] CUdeviceptr x, 
										 int incx,
										 [In] CUdeviceptr y, 
										 int incy,
										 ref cuDoubleComplex result);
 public static extern cusparseStatus cusparseZnnz_compress(cusparseContext handle, 
                                   int m, 
                                   cusparseMatDescr descr,
                                   CUdeviceptr values, 
                                   CUdeviceptr rowPtr, 
                                   CUdeviceptr nnzPerRow, 
                                   CUdeviceptr nnzTotal,
                                   cuDoubleComplex tol);
        public static extern cusparseStatus cusparseZgemmi(cusparseContext handle,
                                             int m,
                                             int n,
											 int k,
											 int nnz, 
                                             ref cuDoubleComplex alpha, /* host or device pointer */
											 CUdeviceptr A,
                                             int lda,
											 CUdeviceptr cscValB,
											 CUdeviceptr cscColPtrB,
											 CUdeviceptr cscRowIndB, 
                                             ref cuDoubleComplex beta, /* host or device pointer */
											 CUdeviceptr C,
                                             int ldc);
        public static extern cusparseStatus cusparseZcsr2csr_compress(cusparseContext handle,
                                                      int m, //number of rows
                                                      int n,
                                                      cusparseMatDescr descra,
                                                      CUdeviceptr inVal, //csr values array-the elements which are below a certain tolerance will be remvoed
                                                      CUdeviceptr inColInd,
													  CUdeviceptr inRowPtr,  //corresponding input noncompressed row pointer
                                                      int inNnz,
                                                      CUdeviceptr nnzPerRow, //output: returns number of nonzeros per row 
                                                      CUdeviceptr outVal,
                                                      CUdeviceptr outColInd,
                                                      CUdeviceptr outRowPtr,
                                                      cuDoubleComplex tol);
		/// <summary/>
		public void CsreigsHost(int m, int nnz, CudaSparseMatrixDescriptor descrA, cuDoubleComplex[] csrValA, int[] csrRowPtrA, int[] csrColIndA, cuDoubleComplex left_bottom_corner, cuDoubleComplex right_upper_corner, ref int num_eigs)
		{
			res = CudaSolveNativeMethods.Sparse.cusolverSpZcsreigsHost(_handle, m, nnz, descrA.Descriptor, csrValA, csrRowPtrA, csrColIndA, left_bottom_corner, right_upper_corner, ref num_eigs);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusolverSpZcsreigsHost", res));
			if (res != cusolverStatus.Success) throw new CudaSolveException(res);
		}
		/// <summary>
		/// This function solves the simple eigenvalue problem A*x=lambda*x by shift-inverse method.
		/// </summary>
		/// <param name="m">number of rows and columns of matrix A.</param>
		/// <param name="nnz">number of nonzeros of matrix A.</param>
		/// <param name="descrA">the descriptor of matrix A. The supported matrix type is
		/// CUSPARSE_MATRIX_TYPE_GENERAL. Also, the supported index bases are CUSPARSE_INDEX_BASE_ZERO and CUSPARSE_INDEX_BASE_ONE.</param>
		/// <param name="csrValA">array of nnz (= csrRowPtrA(n) * csrRowPtrA(0)) nonzero elements of matrix A.</param>
		/// <param name="csrRowPtrA">integer array of n + 1 elements that contains the start of every row and the end of the last row plus one.</param>
		/// <param name="csrColIndA">integer array of nnz (=csrRowPtrA(n) * csrRowPtrA(0)) column indices of the nonzero elements of matrix A.</param>
		/// <param name="mu0">initial guess of eigenvalue.</param>
		/// <param name="x0">initial guess of eigenvector, a vecotr of size m.</param>
		/// <param name="maxite">maximum iterations in shift-inverse method.</param>
		/// <param name="tol">tolerance for convergence.</param>
		/// <param name="mu">approximated eigenvalue nearest mu0 under tolerance.</param>
		/// <param name="x">approximated eigenvector of size m.</param>
		public void Csreigvsi(int m, int nnz, CudaSparseMatrixDescriptor descrA, CudaDeviceVariable<cuDoubleComplex> csrValA, CudaDeviceVariable<int> csrRowPtrA, CudaDeviceVariable<int> csrColIndA, cuDoubleComplex mu0, CudaDeviceVariable<cuDoubleComplex> x0, int maxite, double tol, ref cuDoubleComplex mu, CudaDeviceVariable<cuDoubleComplex> x)
		{
			res = CudaSolveNativeMethods.Sparse.cusolverSpZcsreigvsi(_handle, m, nnz, descrA.Descriptor, csrValA.DevicePointer, csrRowPtrA.DevicePointer, csrColIndA.DevicePointer, mu0, x0.DevicePointer, maxite, tol, ref mu, x.DevicePointer);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusolverSpZcsreigvsi", res));
			if (res != cusolverStatus.Success) throw new CudaSolveException(res);
		}
		/// <summary>
		/// This function solves the simple eigenvalue problem A*x=lambda*x by shift-inverse method.
		/// </summary>
		/// <param name="m">number of rows and columns of matrix A.</param>
		/// <param name="nnz">number of nonzeros of matrix A.</param>
		/// <param name="descrA">the descriptor of matrix A. The supported matrix type is
		/// CUSPARSE_MATRIX_TYPE_GENERAL. Also, the supported index bases are CUSPARSE_INDEX_BASE_ZERO and CUSPARSE_INDEX_BASE_ONE.</param>
		/// <param name="csrValA">array of nnz (= csrRowPtrA(n) * csrRowPtrA(0)) nonzero elements of matrix A.</param>
		/// <param name="csrRowPtrA">integer array of n + 1 elements that contains the start of every row and the end of the last row plus one.</param>
		/// <param name="csrColIndA">integer array of nnz (=csrRowPtrA(n) * csrRowPtrA(0)) column indices of the nonzero elements of matrix A.</param>
		/// <param name="mu0">initial guess of eigenvalue.</param>
		/// <param name="x0">initial guess of eigenvector, a vecotr of size m.</param>
		/// <param name="maxite">maximum iterations in shift-inverse method.</param>
		/// <param name="tol">tolerance for convergence.</param>
		/// <param name="mu">approximated eigenvalue nearest mu0 under tolerance.</param>
		/// <param name="x">approximated eigenvector of size m.</param>
		public void CsreigvsiHost(int m, int nnz, CudaSparseMatrixDescriptor descrA, cuDoubleComplex[] csrValA, int[] csrRowPtrA, int[] csrColIndA, cuDoubleComplex mu0, cuDoubleComplex[] x0, int maxite, double tol, ref cuDoubleComplex mu, cuDoubleComplex[] x)
		{
			res = CudaSolveNativeMethods.Sparse.cusolverSpZcsreigvsiHost(_handle, m, nnz, descrA.Descriptor, csrValA, csrRowPtrA, csrColIndA, mu0, x0, maxite, tol, ref mu, x);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusolverSpZcsreigvsiHost", res));
			if (res != cusolverStatus.Success) throw new CudaSolveException(res);
		}
		public static extern cusparseStatus cusparseZhybsv_solve(cusparseContext handle, cusparseOperation trans, ref cuDoubleComplex alpha, cusparseMatDescr descra, cusparseHybMat hybA, cusparseSolveAnalysisInfo info, CUdeviceptr x, CUdeviceptr y);
        public static extern CublasStatus cublasZgemm3m(CudaBlasHandle handle, 
                                                      Operation transa,
                                                      Operation transb, 
                                                      int m,
                                                      int n,
                                                      int k,
													  ref cuDoubleComplex alpha, /* host or device pointer */  
                                                      CUdeviceptr A, 
                                                      int lda,
                                                      CUdeviceptr B,
                                                      int ldb,
													  ref cuDoubleComplex beta, /* host or device pointer */  
                                                      CUdeviceptr C,
                                                      int ldc);
		public static extern cusparseStatus cusparseZbsrmm(cusparseContext handle,
											cusparseDirection dirA,
											cusparseOperation transA,
											cusparseOperation transB,
											int mb,
											int n,
											int kb,
											int nnzb,
											ref cuDoubleComplex alpha,
											cusparseMatDescr descrA,
											CUdeviceptr bsrValA,
											CUdeviceptr bsrRowPtrA,
											CUdeviceptr bsrColIndA,
											int blockSize,
											CUdeviceptr B,
											int ldb,
											ref cuDoubleComplex beta,
											CUdeviceptr C,
											int ldc);
 public static extern CublasStatus cublasZgemmBatched(CudaBlasHandle handle,
                            Operation transa,
                            Operation transb, 
                            int m,
                            int n,
                            int k,
                            ref cuDoubleComplex alpha, /* host or device pointer */ 
                            CUdeviceptr Aarray, 
                            int lda,
                            CUdeviceptr Barray,
                            int ldb, 
                            ref cuDoubleComplex beta, /* host or device pointer */ 
                            CUdeviceptr Carray,
                            int ldc,
                            int batchCount);
		public static extern cusparseStatus cusparseZbsrilu02_numericBoost(cusparseContext handle,
															bsrilu02Info info,
															int enable_boost,
															ref double tol,
															ref cuDoubleComplex boost_val);
        public static extern CublasStatus cublasZgemmStridedBatched(CudaBlasHandle handle,
																 Operation transa,
																 Operation transb,
																 int m,
																 int n,
																 int k,
																 ref cuDoubleComplex alpha,  // host or device poi$
																 CUdeviceptr A,
																 int lda,
																 long strideA,   // purposely signed 
																 CUdeviceptr B,
																 int ldb,
																 long strideB,
																 ref cuDoubleComplex beta,   // host or device poi$
																 CUdeviceptr C,
																 int ldc,
																 long strideC,
																 int batchCount);
		public static extern cusparseStatus cusparseZdotci(cusparseContext handle, int nnz, CUdeviceptr xVal, CUdeviceptr xInd, CUdeviceptr y, ref cuDoubleComplex resultDevHostPtr, cusparseIndexBase idxBase);
        public static extern CublasStatus cublasZrotg_v2(CudaBlasHandle handle, 
										ref cuDoubleComplex a,  // host or device pointer
										ref cuDoubleComplex b,  // host or device pointer
										ref double c,           // host or device pointer
										ref cuDoubleComplex s);
		public static extern cusparseStatus cusparseZcsrgemm2(cusparseContext handle,
											   int m,
											   int n,
											   int k,
											   ref cuDoubleComplex alpha,
											   cusparseMatDescr descrA,
											   int nnzA,
											   CUdeviceptr csrSortedValA,
											   CUdeviceptr csrSortedRowPtrA,
											   CUdeviceptr csrSortedColIndA,
											   cusparseMatDescr descrB,
											   int nnzB,
											   CUdeviceptr csrSortedValB,
											   CUdeviceptr csrSortedRowPtrB,
											   CUdeviceptr csrSortedColIndB,
											   ref cuDoubleComplex beta,
											   cusparseMatDescr descrD,
											   int nnzD,
											   CUdeviceptr csrSortedValD,
											   CUdeviceptr csrSortedRowPtrD,
											   CUdeviceptr csrSortedColIndD,
											   cusparseMatDescr descrC,
											   CUdeviceptr csrSortedValC,
											   CUdeviceptr csrSortedRowPtrC,
											   CUdeviceptr csrSortedColIndC,
											   csrgemm2Info info,
											   CUdeviceptr pBuffer);
 public static extern CublasStatus cublasZtrsmBatched( CudaBlasHandle    handle, 
                                                   SideMode  side, 
                                                   FillMode  uplo,
                                                   Operation trans, 
                                                   DiagType  diag,
                                                   int m, 
                                                   int n, 
                                                   ref cuDoubleComplex alpha, /*Host or Device Pointer*/
                                                   CUdeviceptr A, 
                                                   int lda,
                                                   CUdeviceptr B, 
                                                   int ldb,
                                                   int batchCount);
		public static extern cusparseStatus cusparseZgemvi(cusparseContext handle,
                                    cusparseOperation transA,
                                    int m,
                                    int n,
                                    ref cuDoubleComplex alpha, /* host or device pointer */
                                    CUdeviceptr A,
                                    int lda,
                                    int nnz,
                                    CUdeviceptr xVal,
									CUdeviceptr xInd,
                                    ref cuDoubleComplex beta, /* host or device pointer */
									CUdeviceptr y,
                                    cusparseIndexBase   idxBase,
									CUdeviceptr pBuffer);
Exemple #28
0
 public static extern CUResult cuMemcpyDtoH_v2(ref cuDoubleComplex dstHost, CUdeviceptr srcDevice, SizeT ByteCount);
		public static extern cusparseStatus cusparseZcsrmv(cusparseContext handle, cusparseOperation transA, int m, int n, int nnz, ref cuDoubleComplex alpha, cusparseMatDescr descrA, CUdeviceptr csrValA, CUdeviceptr csrRowPtrA, CUdeviceptr csrColIndA, CUdeviceptr x, ref cuDoubleComplex beta, CUdeviceptr y);
		public static extern cusparseStatus cusparseZcsrsv2_solve(cusparseContext handle,
												   cusparseOperation transA,
												   int m,
												   int nnz,
												   ref cuDoubleComplex alpha,
												   cusparseMatDescr descra,
												   CUdeviceptr csrValA,
												   CUdeviceptr csrRowPtrA,
												   CUdeviceptr csrColIndA,
												   csrsv2Info info,
												   CUdeviceptr x,
												   CUdeviceptr y,
												   cusparseSolvePolicy policy,
												   CUdeviceptr pBuffer);
		public static extern cusparseStatus cusparseZcsrsv_solve(cusparseContext handle, cusparseOperation transA, int m, ref cuDoubleComplex alpha, cusparseMatDescr descrA, CUdeviceptr csrValA, CUdeviceptr csrRowPtrA, CUdeviceptr csrColIndA, cusparseSolveAnalysisInfo info, CUdeviceptr x, CUdeviceptr y);
		/// <summary>
		/// This function solves the following least-square problem x = argmin||A*z-b||
		/// </summary>
		/// <param name="m">number of rows of matrix A.</param>
		/// <param name="n">number of columns of matrix A.</param>
		/// <param name="nnz">number of nonzeros of matrix A.</param>
		/// <param name="descrA">the descriptor of matrix A. The supported matrix type is
		/// CUSPARSE_MATRIX_TYPE_GENERAL. Also, the supported index bases are CUSPARSE_INDEX_BASE_ZERO and CUSPARSE_INDEX_BASE_ONE.</param>
		/// <param name="csrValA">array of nnz (= csrRowPtrA(n) * csrRowPtrA(0)) nonzero elements of matrix A.</param>
		/// <param name="csrRowPtrA">integer array of n + 1 elements that contains the start of every row and the end of the last row plus one.</param>
		/// <param name="csrColIndA">integer array of nnz (=csrRowPtrA(n) * csrRowPtrA(0)) column indices of the nonzero elements of matrix A.</param>
		/// <param name="b">right hand side vector of size m.</param>
		/// <param name="tol">tolerance to decide rank of A.</param>
		/// <param name="rankA">numerical rank of A.</param>
		/// <param name="x">solution vector of size n, x=pinv(A)*b.</param>
		/// <param name="p">a vector of size n, which represents the permuation matrix P satisfying A*P^T=Q*R.</param>
		/// <param name="min_norm">||A*x-b||, x=pinv(A)*b.</param>
		public void CsrlsqvqrHost(int m, int n, int nnz, CudaSparseMatrixDescriptor descrA, cuDoubleComplex[] csrValA, int[] csrRowPtrA, int[] csrColIndA, cuDoubleComplex[] b, double tol, ref int rankA, cuDoubleComplex[] x, int[] p, ref double min_norm)
		{
			res = CudaSolveNativeMethods.Sparse.cusolverSpZcsrlsqvqrHost(_handle, m, n, nnz, descrA.Descriptor, csrValA, csrRowPtrA, csrColIndA, b, tol, ref rankA, x, p, ref min_norm);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusolverSpZcsrlsqvqrHost", res));
			if (res != cusolverStatus.Success) throw new CudaSolveException(res);
		}