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"); }
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()); } }
private void test(TestSerialization creator) { int i = 0; try { Rootbeer rootbeer = new Rootbeer(); List<Kernel> known_good_items = creator.create(); List<Kernel> testing_items = creator.create(); Stopwatch watch = new Stopwatch(); watch.start(); rootbeer.runAll(testing_items); m_passed = true; watch.stop(); m_gpuTime = watch.elapsedTimeMillis(); watch.start(); for (i = 0; i < known_good_items.size(); ++i) { Kernel known_good_item = known_good_items.get(i); known_good_item.gpuMethod(); } watch.stop(); m_cpuTime = watch.elapsedTimeMillis(); for (i = 0; i < known_good_items.size(); ++i) { Kernel known_good_item = known_good_items.get(i); Kernel testing_item = testing_items.get(i); if (!creator.compare(known_good_item, testing_item)) { m_message = "Compare failed at: " + i; m_passed = false; return; } } } catch (Throwable ex) { ex.printStackTrace(); m_message = "Exception thrown at index: " + i + "\n"; ByteArrayOutputStream os = new ByteArrayOutputStream(); PrintWriter writer = new PrintWriter(os); ex.printStackTrace(writer); writer.flush(); writer.close(); m_message += os.toString(); m_passed = false; } }