Пример #1
0
 public static void cudaTransposeAndMultiply(ref MathNet.Numerics.LinearAlgebra.Double.DenseMatrix dm)
 {
     Cudafy.CudafyModule km = Cudafy.Translator.CudafyTranslator.Cudafy();
     km.Serialize();
     GPGPU gpu = CudafyHost.GetDevice(eGPUType.Cuda);
     int cols = dm.ColumnCount, rows = dm.RowCount;
     dm.Storage.ToColumnMajorArray();
     double[] a = dm.ToColumnWiseArray();
     dm = new MathNet.Numerics.LinearAlgebra.Double.DenseMatrix(1, 1);
     double[] dev_a = gpu.Allocate<double>(a.Length);
     GPGPUBLAS blas = GPGPUBLAS.Create(gpu);
     double[] a_d = gpu.CopyToDevice<double>(a);
     double[] c_d = gpu.Allocate<double>(cols * cols);
     gpu.StartTimer();
     blas.GEMM(cols, rows, cols, 1, a_d, a_d, 0, c_d, Cudafy.Maths.BLAS.Types.cublasOperation.T);
     a = new double[cols * cols];
     gpu.CopyFromDevice<double>(c_d, a);
     gpu.FreeAll();
     dm = new MathNet.Numerics.LinearAlgebra.Double.DenseMatrix(cols, cols, a);
 }
Пример #2
0
 public static void writeMatrixToFile(MathNet.Numerics.LinearAlgebra.Double.DenseMatrix matrix, string file, System.Windows.Forms.RichTextBox tb1, MainForm frm)
 {
     System.IO.Stream fileStream = new System.IO.FileStream(file,System.IO.FileMode.Create);
     System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fileStream, System.Text.Encoding.Default);
     double[] arr =  matrix.ToColumnWiseArray();
     System.IO.TextWriter tr = new System.IO.StreamWriter(file + ".metainfo");
     tr.WriteLine("Column count");
     tr.WriteLine(matrix.ColumnCount);
     tr.WriteLine("Row count");
     tr.WriteLine(matrix.RowCount);
     tr.Flush();
     tr.Close();
     int len = arr.Length;
     matrix = null;
     int index=0;
     byte[] bytes = new byte[arr.Length*8];
     foreach (double item in arr)
     {
         BitConverter.GetBytes(item).CopyTo(bytes,index);
         if (index / 8 / 500D == Math.Round(index / 8 / 500D)) { tb1.BeginInvoke(new MainForm.setProgressDel(frm.addVal), new object[] { (int)index / 8, len, "Записано" }); }
         index+=8;
     }
     bw.Write(bytes);
     bw.Flush();
     tb1.BeginInvoke(new MainForm.setProgressDel(frm.addVal), new object[] { (int)0, len, "" });
     bw.Flush();
     bw.Close();
     fileStream.Close();
 }