adjusted tests and initialization phase
This commit is contained in:
@@ -13,7 +13,12 @@ import de.unidue.nes.gpu.events.ApplicationFinishedEvent;
|
||||
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,9 @@ 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 = 50;
|
||||
|
||||
public static boolean initPhase = false;
|
||||
|
||||
static {
|
||||
Initializer.init();
|
||||
@@ -48,16 +55,17 @@ public class GpuTestSystem {
|
||||
GpuEventBus.INSTANCE.stopListening();
|
||||
LOG.info("Running tasks so dlls get loaded");
|
||||
muteLogger();
|
||||
initPhase = true;
|
||||
|
||||
// run tasks for the first time to load dlls and initialize everything
|
||||
// tasks.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
|
||||
|
||||
resetLogger();
|
||||
|
||||
initPhase = false;
|
||||
LOG.info("Now starting tasks to measure performance");
|
||||
// now run tasks to get the runtime performance
|
||||
GpuEventBus.INSTANCE.startListening();
|
||||
@@ -82,13 +90,13 @@ public class GpuTestSystem {
|
||||
private List<Task> getTasks() {
|
||||
|
||||
return Arrays.asList(//
|
||||
// new UploadDownloadTask(), //
|
||||
// new PageLockedUploadDownloadTask(), //
|
||||
// new PixelWiseTask(), //
|
||||
new KernelTask() //
|
||||
// new ImgProcTask(),//
|
||||
// new PipelineTask(),//
|
||||
// new FeatureBasedTask() //
|
||||
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 = 100;
|
||||
public static final int TEST_RUNS = GpuTestSystem.TEST_RUNS;
|
||||
|
||||
@Override
|
||||
public void runTask() {
|
||||
|
||||
@@ -2,11 +2,13 @@ package de.unidue.nes.gpu.events;
|
||||
|
||||
import static de.unidue.nes.gpu.events.TaskType.CPU_CANNY;
|
||||
import static de.unidue.nes.gpu.events.TaskType.CPU_DILATE;
|
||||
import static de.unidue.nes.gpu.events.TaskType.CPU_ERODE;
|
||||
import static de.unidue.nes.gpu.events.TaskType.CPU_FEATURE_DETECTION1;
|
||||
import static de.unidue.nes.gpu.events.TaskType.CPU_FEATURE_DETECTION2;
|
||||
import static de.unidue.nes.gpu.events.TaskType.CPU_GAUSSIAN_BLUR;
|
||||
import static de.unidue.nes.gpu.events.TaskType.CPU_GRAYSCALE;
|
||||
import static de.unidue.nes.gpu.events.TaskType.CPU_HOUGH_CIRCLE;
|
||||
import static de.unidue.nes.gpu.events.TaskType.CPU_MEDIAN_BLUR;
|
||||
import static de.unidue.nes.gpu.events.TaskType.CPU_PIPELINE;
|
||||
import static de.unidue.nes.gpu.events.TaskType.CPU_STEREO_MATCHING;
|
||||
import static de.unidue.nes.gpu.events.TaskType.CPU_THRESHOLD;
|
||||
@@ -14,11 +16,13 @@ import static de.unidue.nes.gpu.events.TaskType.GPU_CANNY;
|
||||
import static de.unidue.nes.gpu.events.TaskType.GPU_COMBINED;
|
||||
import static de.unidue.nes.gpu.events.TaskType.GPU_DILATE;
|
||||
import static de.unidue.nes.gpu.events.TaskType.GPU_DOWNLOAD;
|
||||
import static de.unidue.nes.gpu.events.TaskType.GPU_ERODE;
|
||||
import static de.unidue.nes.gpu.events.TaskType.GPU_FEATURE_DETECTION1;
|
||||
import static de.unidue.nes.gpu.events.TaskType.GPU_FEATURE_DETECTION2;
|
||||
import static de.unidue.nes.gpu.events.TaskType.GPU_GAUSSIAN_BLUR;
|
||||
import static de.unidue.nes.gpu.events.TaskType.GPU_GRAYSCALE;
|
||||
import static de.unidue.nes.gpu.events.TaskType.GPU_HOUGH_CIRCLE;
|
||||
import static de.unidue.nes.gpu.events.TaskType.GPU_MEDIAN_BLUR;
|
||||
import static de.unidue.nes.gpu.events.TaskType.GPU_PIPELINE;
|
||||
import static de.unidue.nes.gpu.events.TaskType.GPU_STEREO_MATCHING;
|
||||
import static de.unidue.nes.gpu.events.TaskType.GPU_THRESHOLD;
|
||||
@@ -109,7 +113,8 @@ public class EventHandler {
|
||||
}
|
||||
|
||||
private void printKernelTasks() {
|
||||
printTable("kernel table", new TaskType[] { CPU_GAUSSIAN_BLUR, GPU_GAUSSIAN_BLUR, CPU_DILATE, GPU_DILATE });
|
||||
printTable("kernel table",
|
||||
new TaskType[] { CPU_MEDIAN_BLUR, GPU_MEDIAN_BLUR, CPU_GAUSSIAN_BLUR, GPU_GAUSSIAN_BLUR, CPU_DILATE, GPU_DILATE, CPU_ERODE, GPU_ERODE });
|
||||
}
|
||||
|
||||
private void printPixelwiseStuff() {
|
||||
|
||||
@@ -15,7 +15,7 @@ public enum TaskType {
|
||||
CPU_FEATURE_MATCHING("CPU feature matching"), GPU_FEATURE_MATCHING("GPU feature matching"), //
|
||||
CPU_STEREO_MATCHING("CPU stereo matching"), GPU_STEREO_MATCHING("GPU stereo matching"), CPU_FEATURE_DETECTION1("CPU feature detection"),
|
||||
CPU_FEATURE_DETECTION2("CPU feature detection"), GPU_FEATURE_DETECTION1("GPU feature detection"), GPU_FEATURE_DETECTION2("GPU feature detection"), //
|
||||
CPU_DILATE("CPU dilate"), GPU_DILATE("GPU dilate");
|
||||
CPU_DILATE("CPU dilate"), GPU_DILATE("GPU dilate"), CPU_ERODE("CPU erode"), GPU_ERODE("GPU erode");
|
||||
|
||||
private String title;
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ public class CPUFiltering {
|
||||
|
||||
TimeDto time = TimingService.testPerformance(() -> Imgproc.GaussianBlur(img, dst, size, 0, 0), KernelTask.TEST_RUNS);
|
||||
|
||||
LOG.info(() -> "gaussian filter on size: " + img.size() + " took " + time + "ms");
|
||||
GpuEventBus.INSTANCE.post(new TaskResultEvent("", KernelTask.TEST_RUNS, img.size(), TaskType.CPU_GAUSSIAN_BLUR, time));
|
||||
}
|
||||
|
||||
|
||||
+12
-2
@@ -1,5 +1,7 @@
|
||||
package de.unidue.nes.gpu.tasks.cputasks;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.Size;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
@@ -15,14 +17,22 @@ import de.unidue.nes.gpu.utils.TimingService;
|
||||
* @author Roch P., Shahbaz Nejad B.
|
||||
*
|
||||
*/
|
||||
public class CPUDilation {
|
||||
public class CPUMorph {
|
||||
|
||||
public void dilate(Mat img) {
|
||||
private static final Logger LOG = LogManager.getLogger(CPUMorph.class);
|
||||
|
||||
public void morph(Mat img) {
|
||||
|
||||
Mat dst = new Mat();
|
||||
Mat kernel = Imgproc.getStructuringElement(Imgproc.CV_SHAPE_RECT, new Size(15, 15));
|
||||
TimeDto time = TimingService.testPerformance(() -> Imgproc.dilate(img, dst, kernel), KernelTask.TEST_RUNS);
|
||||
|
||||
LOG.info(() -> "dilate on size: " + img.size() + " took " + time + "ms");
|
||||
GpuEventBus.INSTANCE.post(new TaskResultEvent("", KernelTask.TEST_RUNS, img.size(), TaskType.CPU_DILATE, time));
|
||||
|
||||
TimeDto time2 = TimingService.testPerformance(() -> Imgproc.erode(img, dst, kernel), KernelTask.TEST_RUNS);
|
||||
|
||||
LOG.info(() -> "erode on size: " + img.size() + " took " + time2 + "ms");
|
||||
GpuEventBus.INSTANCE.post(new TaskResultEvent("", KernelTask.TEST_RUNS, img.size(), TaskType.CPU_ERODE, time2));
|
||||
}
|
||||
}
|
||||
+15
-2
@@ -1,5 +1,7 @@
|
||||
package de.unidue.nes.gpu.tasks.gputasks;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.bytedeco.opencv.global.opencv_core;
|
||||
import org.bytedeco.opencv.global.opencv_cudafilters;
|
||||
import org.bytedeco.opencv.global.opencv_imgproc;
|
||||
@@ -20,12 +22,17 @@ import de.unidue.nes.gpu.utils.TimingService;
|
||||
* @author Roch P., Shahbaz Nejad B.
|
||||
*
|
||||
*/
|
||||
public class GPUDilation {
|
||||
public class GPUMorph {
|
||||
|
||||
public void dilate(org.opencv.core.Mat img) {
|
||||
private static final Logger LOG = LogManager.getLogger(GPUMorph.class);
|
||||
|
||||
public void morph(org.opencv.core.Mat img) {
|
||||
|
||||
Mat kernel = opencv_imgproc.getStructuringElement(opencv_imgproc.CV_SHAPE_RECT, new Size(15, 15));
|
||||
|
||||
Filter filter = opencv_cudafilters.createMorphologyFilter(opencv_imgproc.MORPH_DILATE, opencv_core.CV_8U, kernel);
|
||||
Filter filter2 = opencv_cudafilters.createMorphologyFilter(opencv_imgproc.MORPH_ERODE, opencv_core.CV_8U, kernel);
|
||||
|
||||
GpuMat dst = new GpuMat();
|
||||
GpuMat src = new GpuMat();
|
||||
MatConverter converter = new MatConverter();
|
||||
@@ -36,6 +43,12 @@ public class GPUDilation {
|
||||
// Mat kernel = Imgproc.getStructuringElement(Imgproc.CV_SHAPE_RECT, new Size(15, 15));
|
||||
TimeDto time = TimingService.testPerformance(() -> filter.apply(src, dst), KernelTask.TEST_RUNS);
|
||||
|
||||
LOG.info(() -> "dilate on size: " + img.size() + " took " + time + "ms");
|
||||
GpuEventBus.INSTANCE.post(new TaskResultEvent("", KernelTask.TEST_RUNS, img.size(), TaskType.GPU_DILATE, time));
|
||||
|
||||
TimeDto time2 = TimingService.testPerformance(() -> filter2.apply(src, dst), KernelTask.TEST_RUNS);
|
||||
|
||||
LOG.info(() -> "erode on size: " + img.size() + " took " + time2 + "ms");
|
||||
GpuEventBus.INSTANCE.post(new TaskResultEvent("", KernelTask.TEST_RUNS, img.size(), TaskType.GPU_ERODE, time2));
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ public class GpuFeatureTask {
|
||||
GpuMat imgDescriptors = new GpuMat();
|
||||
ORB orb = ORB.create();
|
||||
KeyPointVector keypoints = new KeyPointVector()) {
|
||||
|
||||
orb.setBlurForDescriptor(true);
|
||||
gpuImg.upload(first);
|
||||
TimeDto time = TimingService.testPerformance(() -> {
|
||||
orb.detectAndCompute(gpuImg, mask, keypoints, imgDescriptors);
|
||||
@@ -63,6 +63,7 @@ public class GpuFeatureTask {
|
||||
ORB orb = ORB.create();
|
||||
KeyPointVector keypoints = new KeyPointVector()) {
|
||||
|
||||
orb.setBlurForDescriptor(true);
|
||||
gpuImg.upload(first);
|
||||
TimeDto time = TimingService.testPerformance(() -> {
|
||||
orb.detectAndCompute(gpuImg, mask, keypoints, imgDescriptors);
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.apache.logging.log4j.Logger;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
|
||||
import de.unidue.nes.gpu.GpuTestSystem;
|
||||
import de.unidue.nes.gpu.tasks.Task;
|
||||
import de.unidue.nes.gpu.tasks.cputasks.CPUStereoMatching;
|
||||
import de.unidue.nes.gpu.tasks.cputasks.CpuFeatureTask;
|
||||
@@ -21,7 +22,7 @@ import de.unidue.nes.gpu.utils.ImageLoader;
|
||||
*/
|
||||
public class FeatureBasedTask implements Task {
|
||||
|
||||
public static final int TEST_RUNS = 2;
|
||||
public static final int TEST_RUNS = GpuTestSystem.TEST_RUNS;
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(FeatureBasedTask.class);
|
||||
|
||||
@@ -29,10 +30,7 @@ public class FeatureBasedTask implements Task {
|
||||
public void runTask() {
|
||||
Mat[][] stereoimages = ImageLoader.getStereoImages();
|
||||
Mat[] featureimages = ImageLoader.getFeatureImages();
|
||||
// for (int i = 0; i < stereoimages.length; i++) {
|
||||
// Imgproc.cvtColor(stereoimages[i][0], stereoimages[i][0], Imgproc.COLOR_BGR2GRAY);
|
||||
// Imgproc.cvtColor(stereoimages[i][1], stereoimages[i][1], Imgproc.COLOR_BGR2GRAY);
|
||||
// }
|
||||
|
||||
Stream.concat(Arrays.stream(stereoimages).flatMap(Stream::of), Arrays.stream(featureimages))
|
||||
.forEach(mat -> Imgproc.cvtColor(mat, mat, Imgproc.COLOR_BGR2GRAY));
|
||||
|
||||
@@ -52,10 +50,6 @@ public class FeatureBasedTask implements Task {
|
||||
gpuTask.detectAndCompute2(featureimages[i + 1]);
|
||||
}
|
||||
|
||||
// Arrays.stream(featureimages).forEach(gpuTask::detectAndCompute);
|
||||
// Arrays.stream(images).forEach(cpuTask::match);
|
||||
// Arrays.stream(images).forEach(gpuTask::match);
|
||||
|
||||
Arrays.stream(stereoimages).forEach(arr -> cpuStereo.matchImages(arr[0], arr[1]));
|
||||
Arrays.stream(stereoimages).forEach(arr -> gpuStereo.matchImages(arr[0], arr[1]));
|
||||
}
|
||||
|
||||
@@ -29,9 +29,9 @@ public class FilteringTask implements Task {
|
||||
Mat[] images = ImageLoader.getTestImagesForKernelOperations();
|
||||
Arrays.stream(images).forEach(img -> Imgproc.cvtColor(img, img, Imgproc.COLOR_BGR2GRAY));
|
||||
|
||||
// Arrays.stream(images).forEach(this.cpuTask::runMedianFiltering);
|
||||
Arrays.stream(images).forEach(this.cpuTask::runMedianFiltering);
|
||||
Arrays.stream(images).forEach(this.cpuTask::runGaussianBlur);
|
||||
// Arrays.stream(images).forEach(this.gpuTask::runMedianFiltering);
|
||||
Arrays.stream(images).forEach(this.gpuTask::runMedianFiltering);
|
||||
Arrays.stream(images).forEach(this.gpuTask::runGaussianBlur);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.unidue.nes.gpu.tasks.taskdefinitions;
|
||||
|
||||
import de.unidue.nes.gpu.GpuTestSystem;
|
||||
import de.unidue.nes.gpu.tasks.Task;
|
||||
|
||||
/**
|
||||
@@ -7,7 +8,7 @@ import de.unidue.nes.gpu.tasks.Task;
|
||||
*/
|
||||
public class ImgProcTask implements Task {
|
||||
|
||||
public static final int TEST_RUNS = 100;
|
||||
public static final int TEST_RUNS = GpuTestSystem.TEST_RUNS;
|
||||
|
||||
@Override
|
||||
public void runTask() {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.unidue.nes.gpu.tasks.taskdefinitions;
|
||||
|
||||
import de.unidue.nes.gpu.GpuTestSystem;
|
||||
import de.unidue.nes.gpu.tasks.Task;
|
||||
|
||||
/**
|
||||
@@ -7,15 +8,15 @@ import de.unidue.nes.gpu.tasks.Task;
|
||||
*/
|
||||
public class KernelTask implements Task {
|
||||
|
||||
public static final int TEST_RUNS = 100;
|
||||
public static final int TEST_RUNS = GpuTestSystem.TEST_RUNS;
|
||||
|
||||
@Override
|
||||
public void runTask() {
|
||||
FilteringTask task = new FilteringTask();
|
||||
task.runTask();
|
||||
|
||||
DilateTask diltask = new DilateTask();
|
||||
diltask.runTask();
|
||||
MorphTask morph = new MorphTask();
|
||||
morph.runTask();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+7
-7
@@ -6,26 +6,26 @@ import org.opencv.core.Mat;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
|
||||
import de.unidue.nes.gpu.tasks.Task;
|
||||
import de.unidue.nes.gpu.tasks.cputasks.CPUDilation;
|
||||
import de.unidue.nes.gpu.tasks.gputasks.GPUDilation;
|
||||
import de.unidue.nes.gpu.tasks.cputasks.CPUMorph;
|
||||
import de.unidue.nes.gpu.tasks.gputasks.GPUMorph;
|
||||
import de.unidue.nes.gpu.utils.ImageLoader;
|
||||
|
||||
/**
|
||||
* @author Roch P., Shahbaz Nejad B.
|
||||
*
|
||||
*/
|
||||
public class DilateTask implements Task {
|
||||
public class MorphTask implements Task {
|
||||
|
||||
@Override
|
||||
public void runTask() {
|
||||
Mat[] images = ImageLoader.getTestImagesForKernelOperations();
|
||||
Arrays.stream(images).forEach(img -> Imgproc.cvtColor(img, img, Imgproc.COLOR_BGR2GRAY));
|
||||
|
||||
CPUDilation cpuTask = new CPUDilation();
|
||||
GPUDilation gpuTask = new GPUDilation();
|
||||
CPUMorph cpuTask = new CPUMorph();
|
||||
GPUMorph gpuTask = new GPUMorph();
|
||||
|
||||
Arrays.stream(images).forEach(cpuTask::dilate);
|
||||
Arrays.stream(images).forEach(gpuTask::dilate);
|
||||
Arrays.stream(images).forEach(cpuTask::morph);
|
||||
Arrays.stream(images).forEach(gpuTask::morph);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.unidue.nes.gpu.tasks.taskdefinitions;
|
||||
|
||||
import de.unidue.nes.gpu.GpuTestSystem;
|
||||
import de.unidue.nes.gpu.tasks.Task;
|
||||
|
||||
/**
|
||||
@@ -7,7 +8,7 @@ import de.unidue.nes.gpu.tasks.Task;
|
||||
*/
|
||||
public class PixelWiseTask implements Task {
|
||||
|
||||
public static final int TEST_RUNS = 1000;
|
||||
public static final int TEST_RUNS = GpuTestSystem.TEST_RUNS;
|
||||
|
||||
@Override
|
||||
public void runTask() {
|
||||
|
||||
@@ -2,6 +2,8 @@ package de.unidue.nes.gpu.utils;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import de.unidue.nes.gpu.GpuTestSystem;
|
||||
|
||||
/**
|
||||
* @author Roch P., Shahbaz Nejad B.
|
||||
*/
|
||||
@@ -10,7 +12,13 @@ public class TimingService {
|
||||
private TimingService() {
|
||||
}
|
||||
|
||||
public static long measureTime(Runnable run, int iterations, TimeUnit unit) {
|
||||
private static long measureTime(Runnable run, int iterations, TimeUnit unit) {
|
||||
if (GpuTestSystem.initPhase) {
|
||||
for (int i = 0; i < 5; i++) {// only run 5 times in initialization phase
|
||||
run.run();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
long start = System.nanoTime();
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
run.run();
|
||||
|
||||
Reference in New Issue
Block a user