[RFC]: add blas/ext/base/wasm/dapxsum
#5505
Labels
Accepted
RFC feature request which has been accepted.
difficulty: 3
Likely to be challenging but manageable.
Feature
Issue or pull request for adding a new feature.
Help Wanted
Extra attention is needed.
JavaScript
Issue involves or relates to JavaScript.
priority: Normal
Normal priority concern or feature request.
RFC
Request for comments. Feature requests and proposed changes.
WebAssembly
Issue involves or relates to WebAssembly.
Description
This RFC proposes adding a new package to the
blas/ext/base/wasm/*
namespace:@stdlib/blas/ext/base/wasm/dapxsum
.This package is the WebAssembly counterpart to
@stdlib/blas/ext/base/dapxsum
.Key Points
When implementing this package, you'll need to do the following:
Install the Emscripten SDK
If you have not already installed the Emscripten SDK via stdlib, run the following command to install the Emscripten SDK, which is necessary for compiling C source files to WebAssembly.
Please do not attempt to install the Emscripten SDK outside of stdlib, as we rely on specific known installation paths.
Install the WebAssembly Binary Toolkit
Similar to the step above, run the following command to install the WebAssembly binary toolkit, which is necessary for compiling a WebAssembly binary to the WebAssembly text format.
Please do not attempt to install the WebAssembly Binary Toolkit (WABT) outside of stdlib.
Create package files
To see examples of similar packages, see
@stdlib/blas/ext/base/wasm/dapxsumkbn
(returns a scalar) and@stdlib/blas/base/wasm/daxpy
(mutates and returns a vector).While the package proposed in this RFC will not match the implementations found in the above packages, those packages should provide a conceptual idea of what is desired. Do not simply copy-paste the code found in those packages without reasoning about expected behavior and API design.
When creating package files, the source directory should not include either a
main.wasm
or amain.wat
file. Both of those files will be generated during a subsequent step.Update exports file
Consult the equivalent JavaScript package
@stdlib/blas/ext/base/dapxsum
. In particular, examine thesrc
folder and determine the names of the functions which are publicly exposed in the C source files. They should be similar tostdlib_strided_foo
andstdlib_strided_foo_ndarray
.In
src/exports.json
file in the WebAssembly package, include the names of those exported functions, making sure to prefix each function name with a leading underscore.Update manifest file
In the
manifest.json
file in the WebAssembly package, update the source dependency to point to the upstream JavaScript package. This package also happens to include the C implementation which will be what is compiled to WebAssembly.Compile WebAssembly
To compile the upstream C implementation to WebAssembly, run the following command from the root stdlib repository directory (not the package folder!)
make wasm PKGS_WASM_PATTERN="blas/ext/base/wasm/dapxsum"
After running the above command, check the
src
folder to confirm that both a*.wasm
and a*.wat
file were created.If, for whatever reason, you need to recompile WebAssembly, you first need to remove any generated files using the following command
make clean-wasm PKGS_WASM_PATTERN="blas/ext/base/wasm/dapxsum"
and then rerun
make wasm PKGS_WASM_PATTERN="blas/ext/base/wasm/dapxsum"
Add a license header
In the
*.wat
file, add a license header.For reference, see
@stdlib/blas/ext/base/wasm/dapxsumkbn
.Note that, if you regenerate the
*.wat
file at any point, you'll need to manually re-add the license header above.Update all tests, documentation, and examples
Now that the WebAssembly binary has been generated, proceed to update all tests, documentation, and examples to reflect the API and expected behavior for the package. You should spend some time studying the tests in
@stdlib/blas/ext/base/dapxsum
. We expect the WebAssembly package to have equivalent and fully comprehensive tests.To see an example of what is expected, study the tests in
@stdlib/blas/ext/base/wasm/dapxsumkbn
and@stdlib/blas/ext/base/dapxsumkbn
— this is a package which returns a scalar value.@stdlib/blas/base/daxpy
and@stdlib/blas/base/wasm/daxpy
— this is a package which mutates and returns a vector.Compare and contrast the tests in those pairs of packages. As should be inferred from those packages, all tests for various strides, offsets, and other behavior should be carried over and modified for the WebAssembly package.
For each of the following commands, please run them from the root stdlib repository directory (not the package folder!).
To run unit tests,
To run examples,
make examples EXAMPLES_FILTER=".*/blas/ext/base/wasm/dapxsum/.*"
To run benchmarks,
make benchmark BENCHMARKS_FILTER=".*/blas/ext/base/wasm/dapxsum/.*"
Create pull request
Provided all tests, examples, and benchmarks successfully execute and pass and that you've updated the package's documentation, you are now ready to open a pull request!
Notes
Checklist
[RFC]:
.The text was updated successfully, but these errors were encountered: