-
Notifications
You must be signed in to change notification settings - Fork 41
Open
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed
Description
What would you like to be added
It would be really great if Darkroom starts to support GPU acceleration for the image processing whenever possible.
Why is this needed
The performance of the application server can be greatly improved if we utilize GPU for processing images when available.
Attaching some benchmarks performed by @sohamkamani to support this feature request.
- Machine details
Machine Type | CPU Platform | GPUs |
---|---|---|
n1-standard-1 (1 vCPU, 3.75 GB memory) | Intel Ivy Bridge | 1 x NVIDIA Tesla K80 |
- Code used
#include <opencv2/highgui.hpp>
#include "cuda.hpp"
#include <opencv2/cudawarping.hpp>
#include <opencv2/imgproc.hpp>
#include "core.hpp"
#include <iostream>
#include <ctime>
using namespace std;
int main(int argc, char ** argv) {
string input_file = "sample.jpg";
string output_file = "out.jpg";
//Read input image from the disk
cv::Mat inputCpu = cv::imread(input_file, 1);
cv::cuda::GpuMat input(inputCpu);
if (input.empty()) {
cout << "Image Not Found: " << input_file << endl;
return -1;
}
//Create output image
cv::cuda::GpuMat output;
clock_t start = clock();
for (int i = 0; i < 20; i++) {
cv::cuda::resize(input, output, cv::Size(0, 0), .25, 0.25, 3); // downscale 4x on both x and y
}
clock_t d1 = clock() - start;
cout << "OpenCv Gpu code ran. Time:" << d1 << "\n";
cv::Mat outputCpu;
output.download(outputCpu);
cv::imwrite(output_file, outputCpu);
cv::Mat inputCpu2 = cv::imread(input_file, 1);
cv::Mat outputCpu2;
start = clock();
for (int i = 0; i < 20; i++) {
cv::resize(inputCpu, outputCpu, cv::Size(0, 0), .25, 0.25, 3);
}
clock_t d2 = clock() - start;
cout << "OpenCv Cpu code ran. Time:" << d2 << "\n";
input.release();
output.release();
return 0;
}
- Results
user@localhost:~$ ./a.out
OpenCv Gpu code ran. Time:226962
OpenCv Cpu code ran. Time:3231722
user@localhost:~$ ./a.out
OpenCv Gpu code ran. Time:226377
OpenCv Cpu code ran. Time:3277886
user@localhost:~$ ./a.out
OpenCv Gpu code ran. Time:217269
OpenCv Cpu code ran. Time:3254524
user@localhost:~$ ./a.out
OpenCv Gpu code ran. Time:184617
OpenCv Cpu code ran. Time:3342405
This shows that resizing an image with the GPU is 14-16 times
faster than with the CPU.
Feature Status
- Resize (
@anubhavp28@ajatprabha) - Crop
- Rotate
- Grayscale
- Blur (
@jspeedluk)
imjuanleonard
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed