Exemplo n.º 1
0
        public CudaMatrixDouble Add(CudaMatrixDouble matrix)
        {
            int rows = Math.Max(_Rows, matrix._Rows);
            int cols = Math.Max(_Cols, matrix._Cols);
            CudaMatrixDouble result = new CudaMatrixDouble(rows, cols);

            UpdateDeviceMemory();
            matrix.UpdateDeviceMemory();

            IntPtr handle = cuBLAS.Create_v2();

            cuBLAS.Dgeam(
                handle,
                cublasOperation.CUBLAS_OP_N,
                cublasOperation.CUBLAS_OP_N,
                _Rows, _Cols,
                1d,
                _Device, _Rows,
                1d,
                matrix._Device, _Rows,
                result._Device, _Rows
                );
            cuBLAS.Destroy_v2(handle);

            result.UpdateHostMemory();
            return(result);
        }
Exemplo n.º 2
0
        public CudaMatrixDouble Dot(CudaMatrixDouble matrix)
        {
            CudaMatrixDouble result = new CudaMatrixDouble(_Rows, matrix._Cols);

            UpdateDeviceMemory();
            matrix.UpdateDeviceMemory();

            IntPtr handle = cuBLAS.Create_v2();

            cuBLAS.Dgemm_v2(
                handle,
                cublasOperation.CUBLAS_OP_N,
                cublasOperation.CUBLAS_OP_N,
                _Rows, matrix._Cols, _Cols,
                1f,
                _Device, _Rows,
                matrix._Device, matrix._Rows,
                1f,
                result._Device, _Rows
                );
            cuBLAS.Destroy_v2(handle);

            result.UpdateHostMemory();
            return(result);
        }
Exemplo n.º 3
0
        public CudaMatrixDouble Mul(double value)
        {
            CudaMatrixDouble result = new CudaMatrixDouble(_Rows, _Cols);

            UpdateDeviceMemory();

            IntPtr handle = cuBLAS.Create_v2();

            cuBLAS.Dgeam(
                handle,
                cublasOperation.CUBLAS_OP_N,
                cublasOperation.CUBLAS_OP_N,
                _Rows, _Cols,
                value,
                _Device, _Rows,
                0f,
                IntPtr.Zero, _Rows,
                result._Device, _Rows
                );
            cuBLAS.Destroy_v2(handle);

            result.UpdateHostMemory();
            return(result);
        }
Exemplo n.º 4
0
        public CudaMatrixDouble Mul(CudaMatrixDouble matrix)
        {
            int rows = Math.Max(_Rows, matrix._Rows);
            int cols = Math.Max(_Cols, matrix._Cols);
            CudaMatrixDouble result = new CudaMatrixDouble(_Rows, matrix._Cols);

            UpdateDeviceMemory();
            matrix.UpdateDeviceMemory();

            IntPtr handle = cuBLAS.Create_v2();

            cuBLAS.Ddgmm(
                handle,
                cublasSideMode.CUBLAS_SIDE_LEFT,
                _Rows, _Cols,
                _Device, _Rows,
                matrix._Device, _Rows,
                result._Device, _Rows
                );
            cuBLAS.Destroy_v2(handle);

            result.UpdateHostMemory();
            return(result);
        }