refactored some stuff
This commit is contained in:
@@ -14,6 +14,11 @@ import de.unidue.nes.gpu.events.GpuEventBus;
|
||||
import de.unidue.nes.gpu.initialization.Initializer;
|
||||
import de.unidue.nes.gpu.tasks.Task;
|
||||
import de.unidue.nes.gpu.tasks.taskdefinitions.FeatureBasedTask;
|
||||
import de.unidue.nes.gpu.tasks.taskdefinitions.ImgProcTask;
|
||||
import de.unidue.nes.gpu.tasks.taskdefinitions.KernelTask;
|
||||
import de.unidue.nes.gpu.tasks.taskdefinitions.PageLockedUploadDownloadTask;
|
||||
import de.unidue.nes.gpu.tasks.taskdefinitions.PixelWiseTask;
|
||||
import de.unidue.nes.gpu.tasks.taskdefinitions.UploadDownloadTask;
|
||||
|
||||
/**
|
||||
* Class containing the main method of this project.
|
||||
@@ -24,7 +29,11 @@ public class GpuTestSystem {
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(GpuTestSystem.class);
|
||||
|
||||
public static final int TEST_RUNS = 100;
|
||||
public static final int TEST_RUNS_PER_TEST = 2;
|
||||
|
||||
public static final int TEST_RUNS_ITERATIONS = 2;
|
||||
|
||||
public static final int TEST_RUNS_WARMUP = 5;
|
||||
|
||||
public static boolean initPhase = false;
|
||||
|
||||
@@ -58,12 +67,10 @@ public class GpuTestSystem {
|
||||
|
||||
// run tasks for the first time to load dlls and initialize everything
|
||||
tasks.stream().peek(t -> System.out.println("starting " + t.getClass().getSimpleName())).forEach(Task::runTask);
|
||||
tasks.stream().peek(t -> System.out.println("starting " + t.getClass().getSimpleName())).forEach(Task::runTask);
|
||||
tasks.stream().peek(t -> System.out.println("starting " + t.getClass().getSimpleName())).forEach(Task::runTask);
|
||||
|
||||
// run again to be sure that nothing is loaded anymore
|
||||
// 1 run should already be sufficient
|
||||
// tasks.forEach(Task::runTask);// I'm not sure if this is necessary
|
||||
tasks.forEach(Task::runTask);
|
||||
|
||||
resetLogger();
|
||||
initPhase = false;
|
||||
@@ -91,12 +98,12 @@ public class GpuTestSystem {
|
||||
private List<Task> getTasks() {
|
||||
|
||||
return Arrays.asList(//
|
||||
// new UploadDownloadTask(), //
|
||||
// new PageLockedUploadDownloadTask(), //
|
||||
// new PixelWiseTask(), //
|
||||
// new KernelTask(), //
|
||||
// new ImgProcTask(), //
|
||||
// new PipelineTask() //
|
||||
new UploadDownloadTask(), //
|
||||
new PageLockedUploadDownloadTask(), //
|
||||
new PixelWiseTask(), //
|
||||
new KernelTask(), //
|
||||
new ImgProcTask(), //
|
||||
new PipelineTask(), //
|
||||
new FeatureBasedTask() //
|
||||
);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import de.unidue.nes.gpu.utils.ImageLoader;
|
||||
*/
|
||||
public class PipelineTask implements Task {
|
||||
|
||||
public static final int TEST_RUNS = GpuTestSystem.TEST_RUNS;
|
||||
public static final int TEST_RUNS = GpuTestSystem.TEST_RUNS_PER_TEST;
|
||||
|
||||
@Override
|
||||
public void runTask() {
|
||||
|
||||
@@ -38,7 +38,7 @@ public class CPUFeatureMatching {
|
||||
orb.detectAndCompute(images[0], mask, imageKeypoints, imageDescriptors);
|
||||
orb.detectAndCompute(images[1], mask, testKeyPoints, testDescriptors);
|
||||
matcher.match(testDescriptors, imageDescriptors, matches);
|
||||
}, GpuTestSystem.TEST_RUNS);
|
||||
}, GpuTestSystem.TEST_RUNS_PER_TEST);
|
||||
// Just for debugging
|
||||
// List<DMatch> matchList = matches.toList();
|
||||
// matchList = matchList.stream().sorted((match1, match2) -> Float.compare(match1.distance, match2.distance)).limit(25).collect(Collectors.toList());
|
||||
|
||||
@@ -28,7 +28,7 @@ public class CPUHistogramming {
|
||||
MatOfFloat ranges = new MatOfFloat(0, 256);
|
||||
List<Mat> images = Collections.singletonList(img);
|
||||
|
||||
long time = TimingService.measureTime(() -> Imgproc.calcHist(images, channels, mask, hist, histSize, ranges), GpuTestSystem.TEST_RUNS);
|
||||
long time = TimingService.measureTime(() -> Imgproc.calcHist(images, channels, mask, hist, histSize, ranges), GpuTestSystem.TEST_RUNS_PER_TEST);
|
||||
|
||||
LOG.info(() -> "histogram for image of size " + img.size() + ": " + time + "ms");
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public class CPUResizing {
|
||||
// LOG.debug(() -> "resizing image from size " + img.size() + " to size " + size);
|
||||
|
||||
Mat dst = new Mat();
|
||||
long time = TimingService.measureTime(() -> Imgproc.resize(img, dst, size), GpuTestSystem.TEST_RUNS);
|
||||
long time = TimingService.measureTime(() -> Imgproc.resize(img, dst, size), GpuTestSystem.TEST_RUNS_PER_TEST);
|
||||
|
||||
LOG.info(() -> "resizing image from size " + img.size() + " to size " + size + " took " + time + "ms.");
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class GPUFeatureMatching {
|
||||
orb.detectAndCompute(gpuImg, mask, keypoints, imgDescriptors);
|
||||
orb.detectAndCompute(gpuImg2, mask, testKeyPoints, testDescriptors);
|
||||
matcher.match(testDescriptors, imgDescriptors, matches);
|
||||
}, GpuTestSystem.TEST_RUNS);
|
||||
}, GpuTestSystem.TEST_RUNS_PER_TEST);
|
||||
|
||||
// Just for debugging
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ public class GPUHistogramming {
|
||||
this.converter.convert(img, m);
|
||||
gpuMat.upload(m);
|
||||
|
||||
long time = TimingService.measureTime(() -> opencv_cudaimgproc.calcHist(gpuMat, hist), GpuTestSystem.TEST_RUNS);
|
||||
long time = TimingService.measureTime(() -> opencv_cudaimgproc.calcHist(gpuMat, hist), GpuTestSystem.TEST_RUNS_PER_TEST);
|
||||
LOG.info(() -> "histogram for image of size " + img.size() + ": " + time + "ms");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class GPUResizing {
|
||||
LOG.trace("uploading done");
|
||||
|
||||
LOG.trace("resizing now");
|
||||
long time = TimingService.measureTime(() -> opencv_cudawarping.resize(gpuImg, dst, javacvSize), GpuTestSystem.TEST_RUNS);
|
||||
long time = TimingService.measureTime(() -> opencv_cudawarping.resize(gpuImg, dst, javacvSize), GpuTestSystem.TEST_RUNS_PER_TEST);
|
||||
LOG.trace("resizing done");
|
||||
|
||||
// org.bytedeco.opencv.opencv_core.Mat res = new org.bytedeco.opencv.opencv_core.Mat();
|
||||
|
||||
@@ -18,7 +18,7 @@ public class ConvertingTask implements Task {
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(ConvertingTask.class);
|
||||
|
||||
private static final int CONVERT_RUNS = GpuTestSystem.TEST_RUNS;
|
||||
private static final int CONVERT_RUNS = GpuTestSystem.TEST_RUNS_PER_TEST;
|
||||
|
||||
@Override
|
||||
public void runTask() {
|
||||
|
||||
@@ -19,7 +19,7 @@ import de.unidue.nes.gpu.utils.ImageLoader;
|
||||
*/
|
||||
public class FeatureBasedTask implements Task {
|
||||
|
||||
public static final int TEST_RUNS = GpuTestSystem.TEST_RUNS;
|
||||
public static final int TEST_RUNS = GpuTestSystem.TEST_RUNS_PER_TEST;
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(FeatureBasedTask.class);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import de.unidue.nes.gpu.tasks.Task;
|
||||
*/
|
||||
public class ImgProcTask implements Task {
|
||||
|
||||
public static final int TEST_RUNS = GpuTestSystem.TEST_RUNS;
|
||||
public static final int TEST_RUNS = GpuTestSystem.TEST_RUNS_PER_TEST;
|
||||
|
||||
@Override
|
||||
public void runTask() {
|
||||
|
||||
@@ -8,7 +8,7 @@ import de.unidue.nes.gpu.tasks.Task;
|
||||
*/
|
||||
public class KernelTask implements Task {
|
||||
|
||||
public static final int TEST_RUNS = GpuTestSystem.TEST_RUNS;
|
||||
public static final int TEST_RUNS = GpuTestSystem.TEST_RUNS_PER_TEST;
|
||||
|
||||
@Override
|
||||
public void runTask() {
|
||||
|
||||
+2
-2
@@ -33,7 +33,7 @@ public class PageLockedUploadDownloadTask implements Task {
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(PageLockedUploadDownloadTask.class);
|
||||
|
||||
private static final int ITERATIONS = GpuTestSystem.TEST_RUNS;
|
||||
private static final int ITERATIONS = GpuTestSystem.TEST_RUNS_PER_TEST;
|
||||
|
||||
@Override
|
||||
public void runTask() {
|
||||
@@ -43,7 +43,7 @@ public class PageLockedUploadDownloadTask implements Task {
|
||||
matList.forEach(opencv_core::registerPageLocked);
|
||||
matList.forEach(this::testUpload);
|
||||
matList.forEach(this::testDownload);
|
||||
matList.forEach(this::testUploadAndDownload);
|
||||
// matList.forEach(this::testUploadAndDownload);
|
||||
matList.forEach(opencv_core::unregisterPageLocked);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import de.unidue.nes.gpu.tasks.Task;
|
||||
*/
|
||||
public class PixelWiseTask implements Task {
|
||||
|
||||
public static final int TEST_RUNS = GpuTestSystem.TEST_RUNS;
|
||||
public static final int TEST_RUNS = GpuTestSystem.TEST_RUNS_PER_TEST;
|
||||
|
||||
@Override
|
||||
public void runTask() {
|
||||
|
||||
+2
-2
@@ -32,7 +32,7 @@ public class UploadDownloadTask implements Task {
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(UploadDownloadTask.class);
|
||||
|
||||
private static final int ITERATIONS = GpuTestSystem.TEST_RUNS;
|
||||
private static final int ITERATIONS = GpuTestSystem.TEST_RUNS_PER_TEST;
|
||||
|
||||
@Override
|
||||
public void runTask() {
|
||||
@@ -42,7 +42,7 @@ public class UploadDownloadTask implements Task {
|
||||
|
||||
matList.forEach(this::testUpload);
|
||||
matList.forEach(this::testDownload);
|
||||
matList.forEach(this::testUploadAndDownload);
|
||||
// matList.forEach(this::testUploadAndDownload);
|
||||
}
|
||||
|
||||
private void testUpload(Mat m) {
|
||||
|
||||
@@ -14,7 +14,7 @@ public class TimingService {
|
||||
|
||||
private static long measureTime(Runnable run, int iterations, TimeUnit unit) {
|
||||
if (GpuTestSystem.initPhase) {
|
||||
for (int i = 0; i < 25; i++) {// only run 25 times in initialization phase
|
||||
for (int i = 0; i < GpuTestSystem.TEST_RUNS_WARMUP; i++) {// only run 25 times in initialization phase
|
||||
run.run();
|
||||
}
|
||||
return -1;
|
||||
@@ -32,7 +32,7 @@ public class TimingService {
|
||||
}
|
||||
|
||||
public static TimeDto testPerformance(Runnable run, int iterations) {
|
||||
final int iterations2 = 10;
|
||||
final int iterations2 = GpuTestSystem.TEST_RUNS_ITERATIONS;
|
||||
long[] times = new long[iterations2];
|
||||
for (int i = 0; i < iterations2; i++) {
|
||||
times[i] = measureTime(run, iterations);
|
||||
|
||||
Reference in New Issue
Block a user