コード例 #1
0
ファイル: MatrixApp.java プロジェクト: Tradunsky/rootbeer1
 private void cpuRun() {
   int num_cores = Runtime.getRuntime().availableProcessors();
   m_cpuWatch.start();
   List<MatrixCpuThread> threads = new ArrayList<MatrixCpuThread>();
   for (int i = 0; i < num_cores; ++i) {
     MatrixCpuThread thread =
         new MatrixCpuThread(
             m_a, m_b, m_ccpu, i, m_blockSize, m_gridSize * m_blockIters, num_cores);
     threads.add(thread);
   }
   for (int i = 0; i < num_cores; ++i) {
     MatrixCpuThread thread = threads.get(i);
     thread.join();
   }
   m_cpuWatch.stop();
   System.out.println("avg cpu time: " + m_cpuWatch.getAverageTime() + " ms");
 }
コード例 #2
0
ファイル: MatrixApp.java プロジェクト: Tradunsky/rootbeer1
  private void gpuRun() {
    m_gpuWatch.start();
    MatrixKernel matrix_kernel =
        new MatrixKernel(m_a, m_b, m_cgpu, m_blockSize, m_gridSize, m_blockIters);
    Rootbeer rootbeer = new Rootbeer();
    rootbeer.setThreadConfig(1024, m_gridSize);
    rootbeer.runAll(matrix_kernel);
    m_gpuWatch.stop();
    System.out.println("avg gpu time: " + m_gpuWatch.getAverageTime() + " ms");

    /*
        int sum = 0;
        for(Calculation calc : matrix_kernel.m_calcs){
          if(calc == null){
            continue;
          }
          System.out.println("  calc:");
          System.out.println("    k: "+calc.m_invalidIndexK);
          System.out.println("    row: "+calc.m_invalidIndexRow);
          System.out.println("    col: "+calc.m_invalidIndexCol);
          System.out.println("    a_value: "+calc.m_invalidAValue);
          System.out.println("    b_value: "+calc.m_invalidBValue);
          System.out.println("    prev_a: "+calc.m_invalidPrevA);
          System.out.println("    prev_b: "+calc.m_invalidPrevB);
          System.out.println("    m: "+calc.m_invalidIndexM);
          System.out.println("    sub_matrix_row: "+calc.m_invalidSubMatrixRow);
          System.out.println("    sub_matrix_col: "+calc.m_invalidSubMatrixCol);
          sum += (calc.m_invalidAValue * calc.m_invalidBValue);
        }
        System.out.println("SUM: "+sum);
    */

    List<StatsRow> stats = rootbeer.getStats();
    for (StatsRow row : stats) {
      System.out.println("  StatsRow:");
      System.out.println("    init time: " + row.getInitTime());
      System.out.println("    serial time: " + row.getSerializationTime());
      System.out.println("    exec time: " + row.getExecutionTime());
      System.out.println("    deserial time: " + row.getDeserializationTime());
      System.out.println("    num blocks: " + row.getNumBlocks());
      System.out.println("    num threads: " + row.getNumThreads());
    }
  }