added pipeline task
This commit is contained in:
@@ -13,7 +13,6 @@ 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.ImgProcTask;
|
||||
|
||||
/**
|
||||
* Class containing the main method of this project.
|
||||
@@ -86,7 +85,8 @@ public class GpuTestSystem {
|
||||
// new PageLockedUploadDownloadTask(), //
|
||||
// new PixelWiseTask(), //
|
||||
// new KernelTask(), //
|
||||
new ImgProcTask()//
|
||||
// new ImgProcTask(),//
|
||||
// new PipelineTask()//
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package de.unidue.nes.gpu;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.opencv.core.Mat;
|
||||
|
||||
import de.unidue.nes.gpu.tasks.Task;
|
||||
import de.unidue.nes.gpu.tasks.taskdefinitions.CpuPipeline;
|
||||
import de.unidue.nes.gpu.tasks.taskdefinitions.GpuPipeline;
|
||||
import de.unidue.nes.gpu.utils.ImageLoader;
|
||||
|
||||
/**
|
||||
* @author Roch P., Shahbaz Nejad B.
|
||||
*/
|
||||
public class PipelineTask implements Task {
|
||||
|
||||
public static final int TEST_RUNS = 100;
|
||||
|
||||
@Override
|
||||
public void runTask() {
|
||||
CpuPipeline cpuTask = new CpuPipeline();
|
||||
GpuPipeline gpuTask = new GpuPipeline();
|
||||
|
||||
Mat[] images = ImageLoader.getTestImagesForPipeline();
|
||||
|
||||
Arrays.stream(images).forEach(cpuTask::doStuff);
|
||||
Arrays.stream(images).forEach(gpuTask::doStuff);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,6 +5,7 @@ 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_THRESHOLD;
|
||||
import static de.unidue.nes.gpu.events.TaskType.GPU_CANNY;
|
||||
import static de.unidue.nes.gpu.events.TaskType.GPU_COMBINED;
|
||||
@@ -13,6 +14,7 @@ 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_THRESHOLD;
|
||||
import static de.unidue.nes.gpu.events.TaskType.GPU_UPLOAD;
|
||||
import static de.unidue.nes.gpu.events.TaskType.PAGE_LOCKED_GPU_COMBINED;
|
||||
@@ -71,14 +73,19 @@ public class EventHandler {
|
||||
printPixelwiseStuff();
|
||||
printKernelTasks();
|
||||
printImageProcTasks();
|
||||
printPipelineTasks();
|
||||
|
||||
List<TaskResultEvent> notTested = this.events.stream().filter(evt -> !this.testedTasks.contains(evt.getType())).collect(Collectors.toList());
|
||||
if (!notTested.isEmpty()) {
|
||||
LOG.warn("Following were not tested:");
|
||||
LOG.warn("Following were not printed:");
|
||||
notTested.stream().map(TaskResultEvent::getType).distinct().forEach(t -> LOG.warn(t::toString));
|
||||
}
|
||||
}
|
||||
|
||||
private void printPipelineTasks() {
|
||||
printTable("pipeline table", new TaskType[] { CPU_PIPELINE, GPU_PIPELINE });
|
||||
}
|
||||
|
||||
private void printImageProcTasks() {
|
||||
printTable("imgproc table", new TaskType[] { CPU_CANNY, GPU_CANNY, CPU_HOUGH_CIRCLE, GPU_HOUGH_CIRCLE });
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@ public enum TaskType {
|
||||
CPU_THRESHOLD("CPU threshold"), GPU_THRESHOLD("GPU threshold"), CPU_GRAYSCALE("CPU grayscale"), GPU_GRAYSCALE("GPU grayscale"), //
|
||||
CPU_MEDIAN_BLUR("CPU median filter"), GPU_MEDIAN_BLUR("GPU median filter"), //
|
||||
CPU_GAUSSIAN_BLUR("CPU gaussian filter"), GPU_GAUSSIAN_BLUR("GPU gaussian filter"), //
|
||||
CPU_CANNY("CPU edge detection"), GPU_CANNY("GPU edge detection"), CPU_HOUGH_CIRCLE("CPU circle detection"), GPU_HOUGH_CIRCLE("GPU circle detection");
|
||||
CPU_CANNY("CPU edge detection"), GPU_CANNY("GPU edge detection"), CPU_HOUGH_CIRCLE("CPU circle detection"), GPU_HOUGH_CIRCLE("GPU circle detection"), //
|
||||
CPU_PIPELINE("CPU pipeline"), GPU_PIPELINE("GPU pipeline");
|
||||
|
||||
private String title;
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package de.unidue.nes.gpu.tasks.taskdefinitions;
|
||||
|
||||
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;
|
||||
|
||||
import de.unidue.nes.gpu.PipelineTask;
|
||||
import de.unidue.nes.gpu.events.GpuEventBus;
|
||||
import de.unidue.nes.gpu.events.TaskResultEvent;
|
||||
import de.unidue.nes.gpu.events.TaskType;
|
||||
import de.unidue.nes.gpu.utils.TimeDto;
|
||||
import de.unidue.nes.gpu.utils.TimingService;
|
||||
|
||||
/**
|
||||
* @author Roch P., Shahbaz Nejad B.
|
||||
*/
|
||||
public class CpuPipeline {
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(CpuPipeline.class);
|
||||
|
||||
public void doStuff(Mat img) {
|
||||
Mat edges = new Mat();
|
||||
Mat gray = new Mat();
|
||||
Size ksize = new Size(15, 15);
|
||||
TimeDto time = TimingService.testPerformance(() -> {
|
||||
Imgproc.cvtColor(img, gray, Imgproc.COLOR_BGR2GRAY);
|
||||
Imgproc.GaussianBlur(gray, edges, ksize, 0, 0);
|
||||
Imgproc.Canny(edges, edges, 35, 100);
|
||||
}, PipelineTask.TEST_RUNS);
|
||||
|
||||
LOG.info(() -> "cpu execution time for image of size " + img.size() + ": " + time + "ms");
|
||||
GpuEventBus.INSTANCE.post(new TaskResultEvent("", PipelineTask.TEST_RUNS, img.size(), TaskType.CPU_PIPELINE, time));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package de.unidue.nes.gpu.tasks.taskdefinitions;
|
||||
|
||||
import static org.bytedeco.opencv.global.opencv_core.CV_8UC1;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.bytedeco.opencv.global.opencv_cudafilters;
|
||||
import org.bytedeco.opencv.global.opencv_cudaimgproc;
|
||||
import org.bytedeco.opencv.global.opencv_imgproc;
|
||||
import org.bytedeco.opencv.opencv_core.GpuMat;
|
||||
import org.bytedeco.opencv.opencv_core.Mat;
|
||||
import org.bytedeco.opencv.opencv_cudafilters.Filter;
|
||||
import org.bytedeco.opencv.opencv_cudaimgproc.CannyEdgeDetector;
|
||||
|
||||
import de.unidue.nes.gpu.PipelineTask;
|
||||
import de.unidue.nes.gpu.events.GpuEventBus;
|
||||
import de.unidue.nes.gpu.events.TaskResultEvent;
|
||||
import de.unidue.nes.gpu.events.TaskType;
|
||||
import de.unidue.nes.gpu.utils.MatConverter;
|
||||
import de.unidue.nes.gpu.utils.TimeDto;
|
||||
import de.unidue.nes.gpu.utils.TimingService;
|
||||
|
||||
/**
|
||||
* @author Roch P., Shahbaz Nejad B.
|
||||
*/
|
||||
public class GpuPipeline {
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(GpuPipeline.class);
|
||||
|
||||
public void doStuff(org.opencv.core.Mat img) {
|
||||
MatConverter converter = new MatConverter();
|
||||
Mat javacvimg = converter.convert2Javacv(img);
|
||||
|
||||
GpuMat image = new GpuMat();
|
||||
GpuMat gray = new GpuMat();
|
||||
GpuMat edges = new GpuMat();
|
||||
Filter filter = opencv_cudafilters.createGaussianFilter(CV_8UC1, CV_8UC1, new org.bytedeco.opencv.opencv_core.Size(15, 15), 0);
|
||||
CannyEdgeDetector detector = opencv_cudaimgproc.createCannyEdgeDetector(35, 100);
|
||||
Mat res = new Mat();
|
||||
TimeDto time = TimingService.testPerformance(() -> {
|
||||
image.upload(javacvimg);
|
||||
opencv_cudaimgproc.cvtColor(image, gray, opencv_imgproc.COLOR_BGR2GRAY);
|
||||
filter.apply(gray, edges);
|
||||
detector.detect(edges, edges);
|
||||
edges.download(res);
|
||||
}, PipelineTask.TEST_RUNS);
|
||||
|
||||
LOG.info(() -> "gpu execution time for image of size " + img.size() + ": " + time + "ms");
|
||||
GpuEventBus.INSTANCE.post(new TaskResultEvent("", PipelineTask.TEST_RUNS, img.size(), TaskType.GPU_PIPELINE, time));
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import de.unidue.nes.gpu.tasks.Task;
|
||||
*/
|
||||
public class ImgProcTask implements Task {
|
||||
|
||||
public static final int TEST_RUNS = 2;
|
||||
public static final int TEST_RUNS = 100;
|
||||
|
||||
@Override
|
||||
public void runTask() {
|
||||
|
||||
@@ -7,7 +7,7 @@ import de.unidue.nes.gpu.tasks.Task;
|
||||
*/
|
||||
public class KernelTask implements Task {
|
||||
|
||||
public static final int TEST_RUNS = 2;
|
||||
public static final int TEST_RUNS = 100;
|
||||
|
||||
@Override
|
||||
public void runTask() {
|
||||
|
||||
@@ -55,4 +55,8 @@ public class ImageLoader {
|
||||
public static Mat[] getImgprocImages() {
|
||||
return getLargeImageDataset();
|
||||
}
|
||||
|
||||
public static Mat[] getTestImagesForPipeline() {
|
||||
return getLargeImageDataset();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user