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

GPU Acceleration achieved! #1038

Merged
merged 44 commits into from
May 2, 2019
Merged

GPU Acceleration achieved! #1038

merged 44 commits into from
May 2, 2019

Conversation

harshkhandeparkar
Copy link
Member

@harshkhandeparkar harshkhandeparkar commented Apr 22, 2019

Fixes #849
Fixes #998
Fixes #260

23 April 2019 1:48AM (IST), ImageSequencer received an Alcubierre Warp Drive Ship

EDIT: It took me 20min to write the PR body so it is technically 2:08 AM

Important: Please view any screenshots/GIFs in fullscreen mode(new tab)

Changes

  1. Blur module produces an actual Gaussian kernel based on the given sigma.
    blur-better

Added

  1. Blur module is GPU accelerated.
  2. We have a new util module src/modules/_nomodule/gpuUtils.js. It exports convolve for convolution and compute for general computing on a GPU using JS!
  3. Edge Detect Uses our blur module instead of using the ndarray-gaussian-blur package. Edge Detect was bottlenecked because of ndarray-gaussian-blur.

Better

  1. Edge Detect runs much, much faster!
    edge-detect-faster
p.s: I had stopped the previews
Edge Detect is a bit more detail preserving(with the default blur value) and will need some future tweaks.
Here is a GIF of the old EdgeDetect

old-edge-det

  1. Blur no longer produces a black border! New blur module takes care of the black border by adding some padding to the pixels.

  2. Convolution module runs at 60fps
    new-conv
    This is the old one for comparison
    old-conv

Things not done

  1. Edge Detect convolution was not done on a GPU: Edge Detect convolution was already blazing fast, it was the blur module which consumed time. GPU computing requires compilation etc., overall, for edge detect which has a 3x3 kernel was actually slower on a GPU than on a CPU. Blur which currently has a 5x5 kernel is benefitted from a GPU. This kernel size can be easily bumped in the future for a higher quality of blur.
  2. I had mentioned that changePixel could have been done on a GPU, turns out, it isn't beneficial because of the reasons listed above.

Best Part: It all works in NodeJS

Screenshot from 2019-04-23 01-42-55

Make sure these boxes are checked before your pull request (PR) is ready to be reviewed and merged. Thanks!

  • tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR -- or run tests locally with npm test
  • code is in uniquely-named feature branch and has no merge conflicts
  • PR is descriptively titled
  • ask @publiclab/is-reviewers for help, in a comment below

We're happy to help you get this ready -- don't be afraid to ask for help, and don't be discouraged if your tests fail at first!

If tests do fail, click on the red X to learn why by reading the logs.

Please be sure you've reviewed our contribution guidelines at https://publiclab.org/contributing-to-public-lab-software

Thanks!

@harshkhandeparkar
Copy link
Member Author

@tech4GT @VibhorCodecianGupta @jywarren @publiclab/is-reviewers big PR!

@harshkhandeparkar harshkhandeparkar requested review from jywarren and tech4GT and removed request for jywarren April 22, 2019 20:44
@harshkhandeparkar
Copy link
Member Author

@tech4GT @VibhorCodecianGupta @jywarren this was working on my PC. Travis doesn't have the package libxi-dev installed by default. I tried to installed it but it doesn't seem to be working. Could you please help me? I don't know much about travis.

@harshkhandeparkar
Copy link
Member Author

Ok the package was successfully installed. Now it is showing a different error. I cannot track it. It says that it cannot recognise ... which I think is a spread operator.

@harshkhandeparkar
Copy link
Member Author

I didn't even add something like that.

@harshkhandeparkar
Copy link
Member Author

@jywarren why do I have merge rights?

@Divy123
Copy link
Member

Divy123 commented Apr 30, 2019

@harshkhandeparkar I will also be reviewing this in an hour. Actually my semester lab exams have started so a bit late. Will do this in an hour.

@harshkhandeparkar
Copy link
Member Author

@Divy123 thanks

src/modules/Blur/Module.js Outdated Show resolved Hide resolved
@Divy123
Copy link
Member

Divy123 commented Apr 30, 2019 via email

Copy link
Member

@Divy123 Divy123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have given some reviews. Looking into detail further.
Also awesome testing @harshkhandeparkar !!

src/modules/Convolution/Convolution.js Outdated Show resolved Hide resolved
src/modules/Blur/Blur.js Show resolved Hide resolved
@Divy123
Copy link
Member

Divy123 commented Apr 30, 2019 via email

@harshkhandeparkar
Copy link
Member Author

Or I can just delete the comments if not needed. Saving in a different file doesn't really do much. Should I delete them?

@Divy123
Copy link
Member

Divy123 commented Apr 30, 2019 via email

@harshkhandeparkar
Copy link
Member Author

@Divy123 committed the changes you had requested.

@harshkhandeparkar harshkhandeparkar requested review from jywarren, Divy123 and a team and removed request for jywarren May 1, 2019 07:39
@jywarren
Copy link
Member

jywarren commented May 1, 2019

Hi @harshkhandeparkar - would you be able to add a simple test for Convolution and Edge Detect, to keep our coverage from falling? Neither of those two modules have tests, and CodeCov is pointing it out:

#1038 (comment)

What do you think? With that, i'd be very happy to merge this!

@jywarren
Copy link
Member

jywarren commented May 1, 2019

Also, @harshkhandeparkar this is so cool. 🎉

Do you think it would be worth refactoring Webgl-distort to use this? would it be faster in a server-node environment than starting up a puppeteer instance? https://github.com/tech4GT/image-sequencer/blob/a3f1b016dacfee38b55966cab63c917094dd3d1e/src/modules/WebglDistort/Module.js#L154

@harshkhandeparkar
Copy link
Member Author

Hi @harshkhandeparkar - would you be able to add a simple test for Convolution and Edge Detect, to keep our coverage from falling? Neither of those two modules have tests, and CodeCov is pointing it out:

#1038 (comment)

What do you think? With that, i'd be very happy to merge this!

I want to add tests for modules, all the remaining ones in a followup as soon as this is merged. Is this ok?

@harshkhandeparkar
Copy link
Member Author

Also, @harshkhandeparkar this is so cool. tada

Do you think it would be worth refactoring Webgl-distort to use this? would it be faster in a server-node environment than starting up a puppeteer instance? https://github.com/tech4GT/image-sequencer/blob/a3f1b016dacfee38b55966cab63c917094dd3d1e/src/modules/WebglDistort/Module.js#L154

Maybe, but we will have to write the distort code in JS rather than GLSL and also the compilation takes a while, a long while. The bigger the kernel, longer the time. Also, if the output image can be bigger than the input image, handling that will also require more computation. The decision is up to the community. I have just added a General Purpose GPU computation utility method called compute in src/modules/_nomodule/gpuUtils.js. That one can be used if we ever decide to do so.

@jywarren
Copy link
Member

jywarren commented May 2, 2019

Hi, @harshkhandeparkar I would really like to see the tests associated within a single PR, and our coverage monitoring would appreciate it too! We can wait on this one for the time being if you are busy, but I think we should start accepting tests + new code together as a matter of policy, in order to really ratchet up our coverage and stability. I hope you understand! ❤️ Thank you for your fantastic work!

@harshkhandeparkar
Copy link
Member Author

harshkhandeparkar commented May 2, 2019 via email

@jywarren
Copy link
Member

jywarren commented May 2, 2019

I hear you, @harshkhandeparkar, and I really empathize with your desire to close this very large PR up. I do want to note that you've changed the internals of those modules, and I worry a little bit that without tests, we can't see that they are working in Travis. Although, without tests before, we couldn't see that they were working before either!

So, because this is a gradual process, I'm going to merge this, and I think we'll all feel great about it 🙌

However, I think we will be getting more and more committed to always asking for tests with any module changes at all as time goes on. I'd LOVE it if you would consider filing a follow-up quickly to help improve our coverage over these modules specifically! Thank you so much! ❤️ 👍 🎉

@jywarren jywarren merged commit b0096a1 into publiclab:main May 2, 2019
@harshkhandeparkar
Copy link
Member Author

@jywarren thanks a lot. I will open a follow-up PR as soon as I can. If it is possible today then today or tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants