Skip to content

[RFC]: add blas/ext/base/wasm/dapxsum #5505

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

Closed
3 tasks done
kgryte opened this issue Feb 28, 2025 · 1 comment · Fixed by #5634
Closed
3 tasks done

[RFC]: add blas/ext/base/wasm/dapxsum #5505

kgryte opened this issue Feb 28, 2025 · 1 comment · Fixed by #5634
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.

Comments

@kgryte
Copy link
Member

kgryte commented Feb 28, 2025

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.

make install-deps-emsdk

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.

make install-deps-wabt

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 a main.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 the src folder and determine the names of the functions which are publicly exposed in the C source files. They should be similar to stdlib_strided_foo and stdlib_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.

+     "dependencies": [
+        "@stdlib/blas/ext/base/dapxsum"
+      ]

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.

;; @license Apache-2.0
;;
;; Copyright (c) 2025 The Stdlib Authors.
;;
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
;; You may obtain a copy of the License at
;;
;;    http://www.apache.org/licenses/LICENSE-2.0
;;
;; Unless required by applicable law or agreed to in writing, software
;; distributed under the License is distributed on an "AS IS" BASIS,
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;; See the License for the specific language governing permissions and
;; limitations under the License.

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

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,

make test TESTS_FILTER=".*/blas/ext/base/wasm/dapxsum/.*"

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

  • If you are interested in contributing a PR which addresses this RFC and still getting familiar with our project conventions, please do not submit LLM-generated code. Please consult our contributing guidelines and the associated development guide. Failure to respect project conventions will result in your PR being rejected without review. Thank you for understanding!

Checklist

  • I have read and understood the Code of Conduct.
  • Searched for existing issues and pull requests.
  • The issue name begins with [RFC]:.
@kgryte kgryte added 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. labels Feb 28, 2025
@vivekmaurya001
Copy link
Contributor

working on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants