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 all 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ module.exports = function ModuleName(options,UI) {

The `progressObj` parameter of `draw()` is not consumed unless a custom progress bar needs to be drawn, for which this default spinner should be stopped with `progressObj.stop()` and image-sequencer is informed about the custom progress bar with `progressObj.overrideFlag = true;` following which this object can be overriden with custom progress object.

The pixelManipulation API can draw progress bars internally using the `pace` npm package. The option is disabled by default but can be enabled by passing `ui: true` in the options for pixelManipulation. The recommended way is to use `ui: options.step.ui`. This will only show the progress if the ui is set to true by the user, while creating the sequencer object.

### Module example

Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -578,3 +578,24 @@ 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

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](https://github.com/publiclab/image-sequencer/blob/main/test/core/sequencer/benchmark.js).

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](https://travis-ci.org/publiclab/image-sequencer/jobs/544415673#L1931).


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.


`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:

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

let sequencer = ImageSequencer() // also for wasm mode i.e. default mode

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

```
Binary file added dist/manipulation.wasm
Binary file not shown.
6 changes: 3 additions & 3 deletions examples/lib/defaultHtmlStepUi.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function DefaultHtmlStepUi(_sequencer, options) {
var inputDesc = isInput ? mapHtmlTypes(inputs[paramName]) : {};
if (!isInput) {
html += '<span class="output"></span>';
}
}
else if (inputDesc.type.toLowerCase() == 'select') {

html += '<select class="form-control target" name="' + paramName + '">';
Expand All @@ -94,7 +94,7 @@ function DefaultHtmlStepUi(_sequencer, options) {
let paramVal = step.options[paramName] || inputDesc.default;

if (inputDesc.id == 'color-picker') { // separate input field for color-picker
html +=
html +=
'<div id="color-picker" class="input-group colorpicker-component">' +
'<input class="form-control target" type="' +
inputDesc.type +
Expand Down Expand Up @@ -122,7 +122,7 @@ function DefaultHtmlStepUi(_sequencer, options) {
'"max="' +
inputDesc.max +
'"step="' +
(inputDesc.step ? inputDesc.step : 1)+ '">' + '<span>' + paramVal + '</span>';
(inputDesc.step ? inputDesc.step : 1) + '">' + '<span>' + paramVal + '</span>';

}
else html += '">';
Expand Down
Loading