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

Using wasm to accelerate PixelManipulation.js #1093

Merged
merged 43 commits into from
Jun 21, 2019
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
2019622
Add wasm code
May 29, 2019
1ea2d20
Merge remote-tracking branch 'upstream/main' into wasm
May 29, 2019
f7f8f3a
First working model
May 31, 2019
2f4066f
Add PixelManipulation web assembly code to browser and node
Jun 3, 2019
6a60840
Tests corrected for modules
Jun 3, 2019
f6a4104
Corrected test script
Jun 5, 2019
8c22f33
Resolve merge conflicts
Jun 5, 2019
b640aaf
Add wasm bechmarks
Jun 11, 2019
7f2fadb
Resolve merge conflicts
Jun 11, 2019
d78c587
Update Readme
Jun 11, 2019
c41bb33
Merge branch 'main' into wasm
jywarren Jun 13, 2019
9da895f
Applies toggling functionality and refactored PixelManipulation code
Jun 13, 2019
afc42c5
Merge remote-tracking branch 'upstream/main' into wasm
Jun 13, 2019
15c495e
Merge remote-tracking branch 'origin/wasm' into wasm
Jun 13, 2019
0ea5419
Added documentation and corrected wasm toggling
Jun 13, 2019
6b21435
Merge remote-tracking branch 'upstream/main' into wasm
Jun 13, 2019
c129de1
change noise reduction module to use wasm code
Jun 13, 2019
adca670
Corrected formatting and removed extra comments
Jun 14, 2019
5b8b365
Merge branch 'main' into wasm
Divy123 Jun 14, 2019
5c7c2ba
Add default wasm option and made README changes
Jun 15, 2019
4ae1d4a
Resolve merge conflicts
Jun 15, 2019
a3821c0
Merge remote-tracking branch 'upstream/main' into wasm
Jun 15, 2019
320dcb3
Merge remote-tracking branch 'origin/wasm' into wasm
Jun 15, 2019
371b11d
Merge branch 'main' into wasm
Divy123 Jun 15, 2019
133673a
Fixed negative test timings
Jun 15, 2019
466ecf8
Merge remote-tracking branch 'origin/wasm' into wasm
Jun 15, 2019
8e2c1dc
combined benchmarks file
jywarren Jun 17, 2019
4419730
Merge branch 'main' into wasm
jywarren Jun 17, 2019
cf91655
Update benchmark.js
jywarren Jun 17, 2019
1e9f741
Resolve merge conflicts
Jun 17, 2019
5c19488
Removed copies of wasm file and corrected test format
Jun 17, 2019
c89bfe4
Merge branch 'main' into wasm
jywarren Jun 18, 2019
317c2ae
Resolve merge conflicts
Jun 18, 2019
bafdfcb
Update package.json
Divy123 Jun 18, 2019
e45da7d
Added wasm file and removed redundant code
Jun 18, 2019
11f24a5
Removed earlier benchmarks
Jun 18, 2019
4aefec1
move test/core/sequencer/benchmark.js to its own test command, not pa…
jywarren Jun 19, 2019
0358835
Solves memory leaks and blank lines
Jun 20, 2019
32ec906
Solves memory leaks and blank lines
Jun 20, 2019
1e4ba0d
Added handler for node code
Jun 20, 2019
1e1ac72
Modify test script
Jun 20, 2019
14ea03f
Modify test script
Jun 20, 2019
6f4fc3b
Correct doc and removed pace fuctionality
Jun 21, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -578,3 +578,22 @@ sequencer2.run();
This method returns an object which defines the name and inputs of the modules. If a module name (hyphenated) is passed in the method, then only the details of that module are returned.

The `notify` function takes two parameters `msg` and `id`, former being the message to be displayed on console (in case of CLI and node ) and a HTML component(in browser). The id is optional and is useful for HTML interface to give appropriate IDs.

## Using WebAssembly for heavy pixel processing

As of now, any of the modules, which uses changePixel function uses wasm as well. Both node and browser code use WebAssembly and the only region of fallback to the initial code is the one under browserified unit tests.
Copy link
Member

Choose a reason for hiding this comment

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

Can you link to the browerified unit tests you're referring to?

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
As of now, any of the modules, which uses changePixel function uses wasm as well. Both node and browser code use WebAssembly and the only region of fallback to the initial code is the one under browserified unit tests.
Any module which uses the `changePixel` function gets WebAssembly acceleration (`wasm`). Both node and browser code use WebAssembly and the only code which falls back to non-`wasm` code is the [browserified unit tests](...).

Copy link
Member Author

Choose a reason for hiding this comment

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

Doing now!!


The main advantage we get using wasm is blazing fast speed attained in processing pixels for many modules that is very clear from the benchmarks itself.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
The main advantage we get using wasm is blazing fast speed attained in processing pixels for many modules that is very clear from the benchmarks itself.
The main advantage we get using `wasm` is blazing fast speed attained in processing pixels for many modules that is very clear from [checking module benchmarks](...).

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks!!


The only limitation encountered was that the browser and node code for implementing wasm had to be written separately. This is because in browser we use ```fetch``` and in node we use ```fs``` module which both can't be used in other environment.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
The only limitation encountered was that the browser and node code for implementing wasm had to be written separately. This is because in browser we use ```fetch``` and in node we use ```fs``` module which both can't be used in other environment.
The only limitation is that browser and node code for `wasm` had to be written separately, and switched between. This is because in browser we use `fetch` to retrieve the compiled `wasm` program while in node we use the `fs` module, each of which cannot be used in the other's environment.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks!!


Also, one can toggle between the two modes, the wasm one and the non-wasm in the following way:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Also, one can toggle between the two modes, the wasm one and the non-wasm in the following way:
`wasm` mode is enabled by default. If you need to force this mode to be on or off, you can use the `useWasm` option when initializing ImageSequencer:

Copy link
Member

Choose a reason for hiding this comment

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

^ this is accurate, right? Or have we made it default off? I think probably best to have it default on, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

Doing now!!


```js
let sequencer = ImageSequencer({useWasm:true}) // for wasm mode or

let sequencer = ImageSequencer({useWasm:false}) //for non-wasm mode or simply

let sequencer = ImageSequencer() // also for non-wasm mode
Copy link
Member

Choose a reason for hiding this comment

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

If we make the default on then this section will have to be modified.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok sure!!


```
2 changes: 1 addition & 1 deletion examples/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var defaultHtmlSequencerUi = require('./lib/defaultHtmlSequencerUi.js'),
insertPreview = require('./lib/insertPreview.js');

window.onload = function() {
sequencer = ImageSequencer();
sequencer = ImageSequencer({useWasm:true});

function refreshOptions() {
// Load information of all modules (Name, Inputs, Outputs)
Expand Down
2 changes: 1 addition & 1 deletion examples/lib/insertPreview.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function generatePreview(previewStepName, customValues, path, selector) {

var previewSequencer = ImageSequencer();
var previewSequencer = ImageSequencer({useWasm:true});
function insertPreview(src) {
var img = document.createElement('img');
img.classList.add('img-thumbnail');
Expand Down
Binary file added examples/manipulation.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/replace.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ <h4>sequencer.replaceImage('#pencils','invert');</h4>

<script>

var sequencer = ImageSequencer();
var sequencer = ImageSequencer({useWasm:true});
document.querySelector('#pencils').onclick = function() {
sequencer.replaceImage('#pencils','invert');
}
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

require('./src/ImageSequencer');
sequencer = ImageSequencer({ ui: false });
sequencer = ImageSequencer({ ui: false,useWasm:true });
var fs = require('fs');
var program = require('commander');
var utils = require('./src/CliUtils');
Expand Down
Binary file added manipulation.wasm
Binary file not shown.