public static void cudaTranspose(ref MathNet.Numerics.LinearAlgebra.Double.DenseMatrix dm)
        {
            GPGPU gpu = CudafyHost.GetDevice(eGPUType.Cuda);

            GPGPUBLAS blas = GPGPUBLAS.Create(gpu);

            int cols = dm.ColumnCount, rows = dm.RowCount;
            int restRows = rows - cols;
            //double[] a = dm.Storage.ToColumnMajorArray();
            double[] a = dm.SubMatrix(0, cols, 0, cols).Storage.ToColumnMajorArray();
            double[] b = dm.SubMatrix(cols, restRows, 0, cols).Storage.ToColumnMajorArray();
            dm = null;

            double[] a_d = gpu.CopyToDevice<double>(a);
            a = null;
            double[] c_d = gpu.Allocate<double>(cols * cols);
            double[] x_d = gpu.CopyToDevice<double>(new double[] { 1 });
            blas.GEMV(cols, cols, 1, c_d, x_d, 0, x_d, Cudafy.Maths.BLAS.Types.cublasOperation.T);
            a = new double[cols * rows];
            gpu.CopyFromDevice<double>(c_d, 0, a, 0, cols * cols);
            gpu.FreeAll();
            a_d = gpu.CopyToDevice<double>(b);
            b = null;
            c_d = gpu.Allocate<double>(restRows * cols);
            x_d = gpu.CopyToDevice<double>(new double[] { 1 });
            blas.GEMV(restRows, cols, 1, c_d, x_d, 0, x_d, Cudafy.Maths.BLAS.Types.cublasOperation.T);
            gpu.CopyFromDevice<double>(c_d, 0, a, cols * cols, restRows * cols);
            gpu.FreeAll();
            dm = new MathNet.Numerics.LinearAlgebra.Double.DenseMatrix(cols, rows, a);
        }
Example #2
0
 public static void writeMatrixToTxtFile(MathNet.Numerics.LinearAlgebra.Double.DenseMatrix dm, string file)
 {
     StringBuilder sb = new StringBuilder();
     for (int i = 0; i < dm.RowCount; i++)
     {
         foreach (var item in dm.SubMatrix(i,1,0,dm.ColumnCount).ToColumnWiseArray())
             {
                 sb.AppendFormat("{0,5:0.0000000000000e+00};",item);
             }
         sb.Append("\r\n");
     }
     System.IO.File.WriteAllText(file, sb.ToString());
 }