Skip to content

Commit 2e11b56

Browse files
Merge pull request #864 from dfinity/andriy/run-975-simd-example
feat: RUN-975: Add WebAssembly SIMD example
2 parents 27e0e78 + 55ce7df commit 2e11b56

File tree

12 files changed

+1313
-0
lines changed

12 files changed

+1313
-0
lines changed

Diff for: .github/workflows/rust-simd-example.yaml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: rust-simd
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
paths:
8+
- rust/simd/**
9+
- .github/workflows/provision-darwin.sh
10+
- .github/workflows/provision-linux.sh
11+
- .github/workflows/rust-simd-example.yaml
12+
- .ic-commit
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: true
16+
jobs:
17+
rust-simd-example-darwin:
18+
runs-on: macos-12
19+
steps:
20+
- uses: actions/checkout@v1
21+
- name: Provision Darwin
22+
run: DFX_VERSION="0.20.2-beta.0" bash .github/workflows/provision-darwin.sh
23+
- name: Remove networks.json
24+
run: rm -f ~/.config/dfx/networks.json
25+
- name: Rust SIMD Darwin
26+
run: |
27+
dfx start --background
28+
pushd rust/simd
29+
make test
30+
popd
31+
rust-simd-example-linux:
32+
runs-on: ubuntu-20.04
33+
steps:
34+
- uses: actions/checkout@v1
35+
- name: Provision Linux
36+
run: DFX_VERSION="0.20.2-beta.0" bash .github/workflows/provision-linux.sh
37+
- name: Remove networks.json
38+
run: rm -f ~/.config/dfx/networks.json
39+
- name: Rust SIMD Linux
40+
run: |
41+
dfx start --background
42+
pushd rust/simd
43+
make test
44+
popd

Diff for: rust/simd/.cargo/config.toml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[build]
2+
target = ["wasm32-unknown-unknown"]
3+
4+
[target.wasm32-unknown-unknown]
5+
# This example compares the performance of the same function compiled
6+
# with and without WebAssembly SIMD support. SIMD instructions are
7+
# globally disabled, and enabled just for specific functions using
8+
# the `target_feature` attribute:
9+
#
10+
# ```rust
11+
# #[target_feature(enable = "simd128")]
12+
# #[ic_cdk_macros::query]
13+
# fn auto_vectorized_f32() -> u64 {
14+
# ```
15+
#
16+
# In most cases, there's no need to annotate functions or even change
17+
# the source code. To enable WebAssembly SIMD instructions globally,
18+
# for the whole workspace and all its dependencies, just uncomment
19+
# the following line:
20+
#
21+
# rustflags = ["-C", "target-feature=+simd128"]
22+
#
23+
# Note, enabling WebAssembly SIMD instructions enables Rust loop
24+
# auto-vectorization. This option might be enabled by default in future
25+
# `dfx` versions.

0 commit comments

Comments
 (0)