Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to utilise GPU Acceleration #19

Open
5 tasks
ajatprabha opened this issue Jul 29, 2019 · 11 comments
Open
5 tasks

Add ability to utilise GPU Acceleration #19

ajatprabha opened this issue Jul 29, 2019 · 11 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@ajatprabha
Copy link
Member

ajatprabha commented Jul 29, 2019

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

@ajatprabha ajatprabha added enhancement New feature or request help wanted Extra attention is needed labels Jul 29, 2019
@anubhavp28
Copy link
Contributor

anubhavp28 commented Jul 30, 2019

Do you guys mind if I take up this issue? I am thinking to add GoCV support in Darkroom. GoCV has CUDA support. It is still in experimental phase, but a lot of functionalities seems to work fine.

Do you guys want to see some benchmark results comparing performance improvements possible by using GoCV instead of Bild?

@ajatprabha
Copy link
Member Author

ajatprabha commented Jul 30, 2019

@anubhavp28 Sure, go ahead. Although I'd like to see a working prototype first with GoCV before we can take the decision to opt for it.

@anubhavp28
Copy link
Contributor

Unfortunately, GoCV lacks support for image processing using cuda currently. I couldn't find a alternative to GoCV. Let me know if you guys know of something. I am currently thinking of adding that support to GoCV, but this could take a long time (I don't have any experience of calling C/C++ code from Go). I hope that's not a problem.

Sorry for updating you guys so late. I had been busy in the previous week due to my coursework.

@anubhavp28
Copy link
Contributor

Update : I am working on adding the necessary functionality to GoCV - link to pull request. The author of GoCV @deadprogram is looking for some members from GoCV community to verify that the code in my pull request is working for their hardware. If any of you could help with this, it would expedite the whole process.

@ajatprabha
Copy link
Member Author

@anubhavp28 Commented on your GoCV PR. 👍

@baskarap
Copy link
Member

baskarap commented Aug 26, 2019

@anubhavp28 thanks anubhav, i checked your PR on GoCV and it looks promising

@baskarap
Copy link
Member

I can see that the PR on gocv has been merged @anubhavp28 awesome work 🎊 hybridgroup/gocv#494

@deadprogram
Copy link

The new release of GoCV that includes this code should be out by next week.

@jspeedluk
Copy link

I would like to take up the issue for blur of image using cuda

@ajatprabha
Copy link
Member Author

@anubhavp28 @jspeedluk Any updates on this?

@anubhavp28
Copy link
Contributor

I'm currently not working on this. I don't think I would be able to resume work this month. I am currently looking for Internship, and busy with hiring contests and interviews rounds. If @jspeedluk or anyone else wants to take the work forward, feel free too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants