adjusted all test cases to use TimingService

This commit is contained in:
2020-02-26 10:15:06 +01:00
parent 261316cca7
commit 8202db8c3c
13 changed files with 103 additions and 180 deletions
@@ -11,6 +11,11 @@ import org.apache.logging.log4j.core.config.Configuration;
import de.unidue.nes.gpu.initialization.Initializer;
import de.unidue.nes.gpu.tasks.Task;
import de.unidue.nes.gpu.tasks.taskdefinitions.ColoringTask;
import de.unidue.nes.gpu.tasks.taskdefinitions.ConvertingTask;
import de.unidue.nes.gpu.tasks.taskdefinitions.EdgeDetectionTask;
import de.unidue.nes.gpu.tasks.taskdefinitions.FeatureMatchingTask;
import de.unidue.nes.gpu.tasks.taskdefinitions.FilteringTask;
import de.unidue.nes.gpu.tasks.taskdefinitions.HistogramTask;
/**
@@ -51,7 +56,8 @@ public class GpuTestSystem {
private List<Task> getTasks() {
return Arrays.asList(new HistogramTask());
return Arrays.asList(new HistogramTask(), new FilteringTask(), new FeatureMatchingTask(), new EdgeDetectionTask(), new ConvertingTask(),
new ColoringTask());
}
}
@@ -5,6 +5,8 @@ import org.apache.logging.log4j.Logger;
import org.opencv.core.Mat;
import org.opencv.imgproc.Imgproc;
import de.unidue.nes.gpu.utils.TimingService;
/**
* @author Roch P., Shahbaz Nejad B.
*/
@@ -15,13 +17,10 @@ public class CPUColoring {
public void grayScale(Mat image) {
LOG.debug(() -> "grayscaling an image of size " + image.size().toString());
Mat gray = new Mat();
long time = System.currentTimeMillis();
for (int i = 0; i < 1000; i++) {
Imgproc.cvtColor(image, gray, Imgproc.COLOR_BGR2GRAY);
}
long time2 = System.currentTimeMillis();
LOG.info(() -> "Grayscaling took " + (time2 - time) + "ms");
long time = TimingService.measureTime(() -> Imgproc.cvtColor(image, gray, Imgproc.COLOR_BGR2GRAY), 1000);
LOG.info(() -> "Grayscaling took " + time + "ms");
}
}
@@ -5,6 +5,8 @@ import org.apache.logging.log4j.Logger;
import org.opencv.core.Mat;
import org.opencv.imgproc.Imgproc;
import de.unidue.nes.gpu.utils.TimingService;
/**
* @author Roch P., Shahbaz Nejad B.
*/
@@ -15,13 +17,9 @@ public class CPUEdgeDetection {
public void findEdges(Mat img) {
Mat edges = new Mat();
long time = System.currentTimeMillis();
for (int i = 0; i < 1000; i++) {
Imgproc.Canny(img, edges, 20, 60);
}
long time2 = System.currentTimeMillis();
long time = TimingService.measureTime(() -> Imgproc.Canny(img, edges, 20, 60), 1000);
LOG.info(() -> "execution time: " + (time2 - time) + "ms");
LOG.info(() -> "execution time: " + time + "ms");
}
}
@@ -14,6 +14,8 @@ import org.opencv.features2d.ORB;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import de.unidue.nes.gpu.utils.TimingService;
/**
* @author Roch P., Shahbaz Nejad B.
*/
@@ -46,8 +48,7 @@ public class CPUFeatureMatching {
Mat testDescriptors = new Mat();
MatOfDMatch matches = new MatOfDMatch();
long time = System.currentTimeMillis();
for (int i = 0; i < 50; i++) {
long time = TimingService.measureTime(() -> {
orb.detectAndCompute(originalImage, mask, imageKeypoints, imageDescriptors);
orb.detectAndCompute(wrongImage, mask, testKeyPoints, testDescriptors);
matcher.match(testDescriptors, imageDescriptors, matches);
@@ -67,10 +68,9 @@ public class CPUFeatureMatching {
} else {
// second image is the correct one
}
}
long time2 = System.currentTimeMillis();
}, 50);
LOG.info(() -> "execution time: " + (time2 - time) + "ms");
LOG.info(() -> "execution time: " + time + "ms");
}
}
@@ -7,6 +7,8 @@ import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import de.unidue.nes.gpu.utils.TimingService;
/**
* @author Roch P., Shahbaz Nejad B.
*/
@@ -33,28 +35,15 @@ public class CPUFiltering {
public void runMedianFiltering() {
Mat dst = new Mat();
long time1 = System.currentTimeMillis();
for (int i = 0; i < 10; i++) {
Imgproc.medianBlur(this.testImages[0], dst, 15);
}
long time2 = System.currentTimeMillis();
for (int i = 0; i < 10; i++) {
Imgproc.medianBlur(this.testImages[1], dst, 15);
}
long time3 = System.currentTimeMillis();
for (int i = 0; i < 10; i++) {
Imgproc.medianBlur(this.testImages[2], dst, 15);
}
long time4 = System.currentTimeMillis();
for (int i = 0; i < 10; i++) {
Imgproc.medianBlur(this.testImages[3], dst, 15);
}
long time5 = System.currentTimeMillis();
long time1 = TimingService.measureTime(() -> Imgproc.medianBlur(this.testImages[0], dst, 15), 10);
long time2 = TimingService.measureTime(() -> Imgproc.medianBlur(this.testImages[1], dst, 15), 10);
long time3 = TimingService.measureTime(() -> Imgproc.medianBlur(this.testImages[2], dst, 15), 10);
long time4 = TimingService.measureTime(() -> Imgproc.medianBlur(this.testImages[3], dst, 15), 10);
LOG.info(() -> "original image median filter: " + (time2 - time1) + "ms");
LOG.info(() -> "2.5x image median filter: " + (time3 - time2) + "ms");
LOG.info(() -> "5x image median filter: " + (time4 - time3) + "ms");
LOG.info(() -> "10x image median filter: " + (time5 - time4) + "ms");
LOG.info(() -> "original image median filter: " + time1 + "ms");
LOG.info(() -> "2.5x image median filter: " + time2 + "ms");
LOG.info(() -> "5x image median filter: " + time3 + "ms");
LOG.info(() -> "10x image median filter: " + time4 + "ms");
}
@@ -62,28 +51,15 @@ public class CPUFiltering {
Mat dst = new Mat();
Size size = new Size(15, 15);
long time1 = System.currentTimeMillis();
for (int i = 0; i < 100; i++) {
Imgproc.GaussianBlur(this.testImages[0], dst, size, 0, 0);
}
long time2 = System.currentTimeMillis();
for (int i = 0; i < 100; i++) {
Imgproc.GaussianBlur(this.testImages[1], dst, size, 0, 0);
}
long time3 = System.currentTimeMillis();
for (int i = 0; i < 100; i++) {
Imgproc.GaussianBlur(this.testImages[2], dst, size, 0, 0);
}
long time4 = System.currentTimeMillis();
for (int i = 0; i < 100; i++) {
Imgproc.GaussianBlur(this.testImages[3], dst, size, 0, 0);
}
long time5 = System.currentTimeMillis();
long time1 = TimingService.measureTime(() -> Imgproc.GaussianBlur(this.testImages[0], dst, size, 0, 0), 100);
long time2 = TimingService.measureTime(() -> Imgproc.GaussianBlur(this.testImages[1], dst, size, 0, 0), 100);
long time3 = TimingService.measureTime(() -> Imgproc.GaussianBlur(this.testImages[2], dst, size, 0, 0), 100);
long time4 = TimingService.measureTime(() -> Imgproc.GaussianBlur(this.testImages[3], dst, size, 0, 0), 100);
LOG.info(() -> "original image gaussian filter: " + (time2 - time1) + "ms");
LOG.info(() -> "2.5x image gaussian filter: " + (time3 - time2) + "ms");
LOG.info(() -> "5x image gaussian filter: " + (time4 - time3) + "ms");
LOG.info(() -> "10x image gaussian filter: " + (time5 - time4) + "ms");
LOG.info(() -> "original image gaussian filter: " + time1 + "ms");
LOG.info(() -> "2.5x image gaussian filter: " + time2 + "ms");
LOG.info(() -> "5x image gaussian filter: " + time3 + "ms");
LOG.info(() -> "10x image gaussian filter: " + time4 + "ms");
}
}
@@ -11,6 +11,8 @@ import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import de.unidue.nes.gpu.utils.TimingService;
/**
* @author Roch P., Shahbaz Nejad B.
*/
@@ -41,27 +43,19 @@ public class CPUHistogramming {
MatOfInt histSize = new MatOfInt(256);
MatOfFloat ranges = new MatOfFloat(0, 256);
long time1 = System.currentTimeMillis();
for (int i = 0; i < 100; i++) {
Imgproc.calcHist(Collections.singletonList(this.testImages[0]), channels, mask, hist, histSize, ranges);
}
long time2 = System.currentTimeMillis();
for (int i = 0; i < 100; i++) {
Imgproc.calcHist(Collections.singletonList(this.testImages[1]), channels, mask, hist, histSize, ranges);
}
long time3 = System.currentTimeMillis();
for (int i = 0; i < 100; i++) {
Imgproc.calcHist(Collections.singletonList(this.testImages[2]), channels, mask, hist, histSize, ranges);
}
long time4 = System.currentTimeMillis();
for (int i = 0; i < 100; i++) {
Imgproc.calcHist(Collections.singletonList(this.testImages[3]), channels, mask, hist, histSize, ranges);
}
long time5 = System.currentTimeMillis();
LOG.info(() -> "original image histogram: " + (time2 - time1) + "ms");
LOG.info(() -> "2.5x image histogram: " + (time3 - time2) + "ms");
LOG.info(() -> "5x image histogram: " + (time4 - time3) + "ms");
LOG.info(() -> "10x image histogram: " + (time5 - time4) + "ms");
long time1 = TimingService.measureTime(() -> Imgproc.calcHist(Collections.singletonList(this.testImages[0]), channels, mask, hist, histSize, ranges),
100);
long time2 = TimingService.measureTime(() -> Imgproc.calcHist(Collections.singletonList(this.testImages[1]), channels, mask, hist, histSize, ranges),
100);
long time3 = TimingService.measureTime(() -> Imgproc.calcHist(Collections.singletonList(this.testImages[2]), channels, mask, hist, histSize, ranges),
100);
long time4 = TimingService.measureTime(() -> Imgproc.calcHist(Collections.singletonList(this.testImages[3]), channels, mask, hist, histSize, ranges),
100);
LOG.info(() -> "original image histogram: " + time1 + "ms");
LOG.info(() -> "2.5x image histogram: " + time2 + "ms");
LOG.info(() -> "5x image histogram: " + time3 + "ms");
LOG.info(() -> "10x image histogram: " + time4 + "ms");
}
}
@@ -8,6 +8,7 @@ import org.bytedeco.opencv.opencv_core.GpuMat;
import org.opencv.core.Mat;
import de.unidue.nes.gpu.utils.MatConverter;
import de.unidue.nes.gpu.utils.TimingService;
/**
* @author Roch P., Shahbaz Nejad B.
@@ -27,17 +28,12 @@ public class GPUColoring {
org.bytedeco.opencv.opencv_core.Mat javacvMat = new org.bytedeco.opencv.opencv_core.Mat();
this.converter.convert(image, javacvMat);
long time1;
long time2;
long time;
try (GpuMat gpuImg = new GpuMat(); GpuMat grayImg = new GpuMat()) {
gpuImg.upload(javacvMat);
time1 = System.currentTimeMillis();
for (int i = 0; i < 1000; i++) {
opencv_cudaimgproc.cvtColor(gpuImg, grayImg, opencv_imgproc.COLOR_BGR2GRAY);
}
time2 = System.currentTimeMillis();
time = TimingService.measureTime(() -> opencv_cudaimgproc.cvtColor(gpuImg, grayImg, opencv_imgproc.COLOR_BGR2GRAY), 1000);
}
LOG.info(() -> "grayscaling took " + (time2 - time1) + "ms");
LOG.info(() -> "grayscaling took " + time + "ms");
}
}
@@ -8,6 +8,7 @@ import org.bytedeco.opencv.opencv_cudaimgproc.CannyEdgeDetector;
import org.opencv.core.Mat;
import de.unidue.nes.gpu.utils.MatConverter;
import de.unidue.nes.gpu.utils.TimingService;
/**
* @author Roch P., Shahbaz Nejad B.
@@ -25,18 +26,13 @@ public class GPUEdgeDetection {
org.bytedeco.opencv.opencv_core.Mat javacvMat = new org.bytedeco.opencv.opencv_core.Mat();
this.converter.convert(img, javacvMat);
long time;
long time2;
try (GpuMat gpuImg = new GpuMat(); GpuMat gpuEdges = new GpuMat(); CannyEdgeDetector detector = opencv_cudaimgproc.createCannyEdgeDetector(20, 60)) {
gpuImg.upload(javacvMat);
time = System.currentTimeMillis();
for (int i = 0; i < 1000; i++) {
detector.detect(gpuImg, gpuEdges);
}
time2 = System.currentTimeMillis();
time = TimingService.measureTime(() -> detector.detect(gpuImg, gpuEdges), 1000);
gpuEdges.download(javacvMat);
}
LOG.info(() -> "gpu execution time: " + (time2 - time) + "ms");
LOG.info(() -> "gpu execution time: " + time + "ms");
}
}
@@ -19,6 +19,7 @@ import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import de.unidue.nes.gpu.utils.MatConverter;
import de.unidue.nes.gpu.utils.TimingService;
/**
* @author Roch P., Shahbaz Nejad B.
@@ -71,8 +72,7 @@ public class GPUFeatureMatching {
KeyPointVector testKeyPoints = new KeyPointVector();
DMatchVector matches = new DMatchVector();
long time = System.currentTimeMillis();
for (int i = 0; i < 50; i++) {
long time = TimingService.measureTime(() -> {
orb.detectAndCompute(gpuImg, mask, keypoints, imgDescriptors);
orb.detectAndCompute(gpuWrongImg, mask, testKeyPoints, testDescriptors);
matcher.match(testDescriptors, imgDescriptors, matches);
@@ -89,10 +89,9 @@ public class GPUFeatureMatching {
} else {
// second image is the correct one
}
}
}, 50);
long time2 = System.currentTimeMillis();
LOG.info(() -> "execution time: " + (time2 - time) + "ms");
LOG.info(() -> "execution time: " + time + "ms");
}
}
@@ -13,6 +13,7 @@ import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import de.unidue.nes.gpu.utils.MatConverter;
import de.unidue.nes.gpu.utils.TimingService;
/**
* @author Roch P., Shahbaz Nejad B.
@@ -55,28 +56,16 @@ public class GPUFiltering {
img4.upload(mat4);
GpuMat dst = new GpuMat();
Filter filter = opencv_cudafilters.createMedianFilter(CV_8UC1, 15);
long time1 = System.currentTimeMillis();
for (int i = 0; i < 10; i++) {
filter.apply(img1, dst);
}
long time2 = System.currentTimeMillis();
for (int i = 0; i < 10; i++) {
filter.apply(img2, dst);
}
long time3 = System.currentTimeMillis();
for (int i = 0; i < 10; i++) {
filter.apply(img3, dst);
}
long time4 = System.currentTimeMillis();
for (int i = 0; i < 10; i++) {
filter.apply(img4, dst);
}
long time5 = System.currentTimeMillis();
LOG.info(() -> "original image median filter: " + (time2 - time1) + "ms");
LOG.info(() -> "2.5x image median filter: " + (time3 - time2) + "ms");
LOG.info(() -> "5x image median filter: " + (time4 - time3) + "ms");
LOG.info(() -> "10x image median filter: " + (time5 - time4) + "ms");
long time1 = TimingService.measureTime(() -> filter.apply(img1, dst), 10);
long time2 = TimingService.measureTime(() -> filter.apply(img2, dst), 10);
long time3 = TimingService.measureTime(() -> filter.apply(img3, dst), 10);
long time4 = TimingService.measureTime(() -> filter.apply(img4, dst), 10);
LOG.info(() -> "original image median filter: " + time1 + "ms");
LOG.info(() -> "2.5x image median filter: " + time2 + "ms");
LOG.info(() -> "5x image median filter: " + time3 + "ms");
LOG.info(() -> "10x image median filter: " + time4 + "ms");
}
public void runGaussianBlur() {
@@ -95,28 +84,15 @@ public class GPUFiltering {
GpuMat dst = new GpuMat();
Filter filter = opencv_cudafilters.createGaussianFilter(CV_8UC1, CV_8UC1, new org.bytedeco.opencv.opencv_core.Size(15, 15), 0);
long time1 = System.currentTimeMillis();
for (int i = 0; i < 100; i++) {
filter.apply(img1, dst);
}
long time2 = System.currentTimeMillis();
for (int i = 0; i < 100; i++) {
filter.apply(img2, dst);
}
long time3 = System.currentTimeMillis();
for (int i = 0; i < 100; i++) {
filter.apply(img3, dst);
}
long time4 = System.currentTimeMillis();
for (int i = 0; i < 100; i++) {
filter.apply(img4, dst);
}
long time5 = System.currentTimeMillis();
long time1 = TimingService.measureTime(() -> filter.apply(img1, dst), 100);
long time2 = TimingService.measureTime(() -> filter.apply(img2, dst), 100);
long time3 = TimingService.measureTime(() -> filter.apply(img3, dst), 100);
long time4 = TimingService.measureTime(() -> filter.apply(img4, dst), 100);
LOG.info(() -> "original image gaussian filter: " + (time2 - time1) + "ms");
LOG.info(() -> "2.5x image gaussian filter: " + (time3 - time2) + "ms");
LOG.info(() -> "5x image gaussian filter: " + (time4 - time3) + "ms");
LOG.info(() -> "10x image gaussian filter: " + (time5 - time4) + "ms");
LOG.info(() -> "original image gaussian filter: " + time1 + "ms");
LOG.info(() -> "2.5x image gaussian filter: " + time2 + "ms");
LOG.info(() -> "5x image gaussian filter: " + time3 + "ms");
LOG.info(() -> "10x image gaussian filter: " + time4 + "ms");
}
}
@@ -10,6 +10,7 @@ import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import de.unidue.nes.gpu.utils.MatConverter;
import de.unidue.nes.gpu.utils.TimingService;
/**
* @author Roch P., Shahbaz Nejad B.
@@ -56,27 +57,14 @@ public class GPUHistogramming {
gpuMat3.upload(this.testImages[2]);
gpuMat4.upload(this.testImages[3]);
long time1 = System.currentTimeMillis();
for (int i = 0; i < 100; i++) {
opencv_cudaimgproc.calcHist(gpuMat1, hist);
}
long time2 = System.currentTimeMillis();
for (int i = 0; i < 100; i++) {
opencv_cudaimgproc.calcHist(gpuMat2, hist);
}
long time3 = System.currentTimeMillis();
for (int i = 0; i < 100; i++) {
opencv_cudaimgproc.calcHist(gpuMat3, hist);
}
long time4 = System.currentTimeMillis();
for (int i = 0; i < 100; i++) {
opencv_cudaimgproc.calcHist(gpuMat4, hist);
}
long time5 = System.currentTimeMillis();
LOG.info(() -> "original image histogram: " + (time2 - time1) + "ms");
LOG.info(() -> "2.5x image histogram: " + (time3 - time2) + "ms");
LOG.info(() -> "5x image histogram: " + (time4 - time3) + "ms");
LOG.info(() -> "10x image histogram: " + (time5 - time4) + "ms");
long time1 = TimingService.measureTime(() -> opencv_cudaimgproc.calcHist(gpuMat1, hist), 100);
long time2 = TimingService.measureTime(() -> opencv_cudaimgproc.calcHist(gpuMat2, hist), 100);
long time3 = TimingService.measureTime(() -> opencv_cudaimgproc.calcHist(gpuMat3, hist), 100);
long time4 = TimingService.measureTime(() -> opencv_cudaimgproc.calcHist(gpuMat4, hist), 100);
LOG.info(() -> "original image histogram: " + time1 + "ms");
LOG.info(() -> "2.5x image histogram: " + time2 + "ms");
LOG.info(() -> "5x image histogram: " + time3 + "ms");
LOG.info(() -> "10x image histogram: " + time4 + "ms");
}
}
@@ -10,6 +10,7 @@ import org.opencv.imgproc.Imgproc;
import de.unidue.nes.gpu.tasks.Task;
import de.unidue.nes.gpu.utils.MatConverter;
import de.unidue.nes.gpu.utils.TimingService;
/**
* @author Roch P., Shahbaz Nejad B.
@@ -33,23 +34,13 @@ public class ConvertingTask implements Task {
try (org.bytedeco.opencv.opencv_core.Mat smallJavacvMat = new org.bytedeco.opencv.opencv_core.Mat();
org.bytedeco.opencv.opencv_core.Mat smallJavacvImage = new org.bytedeco.opencv.opencv_core.Mat();
org.bytedeco.opencv.opencv_core.Mat bigJavacvImage = new org.bytedeco.opencv.opencv_core.Mat()) {
long time1 = System.currentTimeMillis();
for (int i = 0; i < CONVERT_RUNS; i++) {
converter.convert(smallMat, smallJavacvMat);
}
long time2 = System.currentTimeMillis();
for (int i = 0; i < CONVERT_RUNS; i++) {
converter.convert(smallImage, smallJavacvImage);
}
long time3 = System.currentTimeMillis();
for (int i = 0; i < CONVERT_RUNS; i++) {
converter.convert(bigImage, bigJavacvImage);
}
long time4 = System.currentTimeMillis();
long time1 = TimingService.measureTime(() -> converter.convert(smallMat, smallJavacvMat), CONVERT_RUNS);
long time2 = TimingService.measureTime(() -> converter.convert(smallImage, smallJavacvImage), CONVERT_RUNS);
long time3 = TimingService.measureTime(() -> converter.convert(bigImage, bigJavacvImage), CONVERT_RUNS);
LOG.info(() -> "converting small mat: " + (time2 - time1) + "ms");
LOG.info(() -> "converting small image: " + (time3 - time2) + "ms");
LOG.info(() -> "converting big image: " + (time4 - time3) + "ms");
LOG.info(() -> "converting small mat: " + time1 + "ms");
LOG.info(() -> "converting small image: " + time2 + "ms");
LOG.info(() -> "converting big image: " + time3 + "ms");
}
}
@@ -18,4 +18,8 @@ public class TimingService {
long end = System.nanoTime();
return unit.convert(end - start, TimeUnit.NANOSECONDS);
}
public static long measureTime(Runnable run, int iterations) {
return measureTime(run, iterations, TimeUnit.MILLISECONDS);
}
}