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

Enable WebAssembly SIMD #2760

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ target-dir = "rust/target"

[target.wasm32-unknown-unknown]
runner = 'wasm-bindgen-test-runner'
rustflags = [
"--cfg=web_sys_unstable_apis",
"-Ctarget-feature=+bulk-memory,+simd128",
]

[target.i686-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static", "--cfg=web_sys_unstable_apis"]

[target.x86_64-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static", "--cfg=web_sys_unstable_apis"]


[future-incompat-report]
frequency = 'never'

Expand Down
4 changes: 1 addition & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ members = [
"rust/perspective-js",
"rust/perspective-python",
"rust/perspective-server",
"examples/rust-axum",
"examples/rust-axum",
]

[profile.dev]
Expand All @@ -36,3 +36,6 @@ opt-level = "z"
codegen-units = 1
lto = true
strip = true

[patch.crates-io]
simd-adler32 = { git = "https://github.com/mcountryman/simd-adler32.git", rev = "140cde033e8b9a12d4de840648c65ccd5320bcc5" }
3 changes: 1 addition & 2 deletions cmake/modules/FindInstallDependency.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ function(psp_build_dep name cmake_file)
endif()

if(${name} STREQUAL arrow)
set(ARROW_SIMD_LEVEL "NONE")
set(ARROW_DEFINE_OPTIONS ON)
set(ARROW_RUNTIME_SIMD_LEVEL "NONE")
set(ARROW_BUILD_SHARED OFF)
set(ARROW_BUILD_STATIC ON)
set(ARROW_BUILD_INTEGRATION OFF)
Expand All @@ -49,6 +47,7 @@ function(psp_build_dep name cmake_file)
set(ARROW_WITH_ZSTD ON)
set(ARROW_WITH_LZ4 ON)
set(ARROW_NO_EXPORT ON)
set(ARROW_SIMD_LEVEL "SSE4_2")
if(PSP_WASM_BUILD)
set(ARROW_ENABLE_THREADING OFF)
else()
Expand Down
37 changes: 14 additions & 23 deletions cpp/perspective/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -235,17 +235,20 @@ if(PSP_WASM_BUILD)
")
endif()
else()
# Pyodide RELEASE block
set(OPT_FLAGS " \
-O3 \
-g0 \
set(OPT_FLAGS " -O3 -g0 ")
if(NOT PSP_PYODIDE)
set(OPT_FLAGS " \
${OPT_FLAGS} \
-mbulk-memory \
-msimd128 \
-msse4.2 \
")
endif()

if (PSP_WASM_EXCEPTIONS)
set(OPT_FLAGS "${OPT_FLAGS} -fwasm-exceptions ")
endif()
endif()

set(ASYNC_MODE_FLAGS "")
elseif(PSP_CPP_BUILD OR PSP_PYTHON_BUILD)
if(WIN32)
if(CMAKE_BUILD_TYPE_LOWER STREQUAL debug)
Expand All @@ -272,7 +275,7 @@ elseif(PSP_CPP_BUILD OR PSP_PYTHON_BUILD)
-Wover-aligned \
")
else ()
set(OPT_FLAGS " \
set(OPT_FLAGS " \
-O0 \
-fexceptions \
-g3 \
Expand All @@ -293,8 +296,6 @@ elseif(PSP_CPP_BUILD OR PSP_PYTHON_BUILD)
endif()
endif()

set(ASYNC_MODE_FLAGS "")

# Boost is a system dependency and must be present and built on the system.
if(PSP_PYODIDE)
set(CMAKE_FIND_ROOT_PATH "${CMAKE_FIND_ROOT_PATH};/usr/local/")
Expand Down Expand Up @@ -323,27 +324,18 @@ elseif(PSP_CPP_BUILD OR PSP_PYTHON_BUILD)
endif()
endif()

set(RAPIDJSON_SSE42 ON CACHE BOOL "Enable RapidJSON SIMD")
set(RAPIDJSON_BUILD_TESTS OFF CACHE BOOL "Disable rapidjson tests")


set(CMAKE_C_FLAGS " \
-O3 \
")
set(CMAKE_C_FLAGS " -O3 ${OPT_FLAGS} ")
if (PSP_WASM_EXCEPTIONS)
set(CMAKE_CXX_FLAGS " -fwasm-exceptions \
-O3 \
-g0 \
")
set(CMAKE_CXX_FLAGS " -fwasm-exceptions ${OPT_FLAGS} ")
else()
set(CMAKE_CXX_FLAGS " \
-O3 \
")

set(CMAKE_CXX_FLAGS " -O3 ")
endif()

if(PSP_PYODIDE)
set(RELOCATABLE_FLAGS "-sRELOCATABLE=1 -sSIDE_MODULE=2 -sWASM_BIGINT=1")

string(APPEND CMAKE_EXE_LINKER_FLAGS "${RELOCATABLE_FLAGS}")
string(APPEND CMAKE_C_FLAGS "${RELOCATABLE_FLAGS}")
string(APPEND CMAKE_CXX_FLAGS "${RELOCATABLE_FLAGS}")
Expand Down Expand Up @@ -557,7 +549,6 @@ else()
-s TEXTDECODER=2 \
-s STANDALONE_WASM=1 \
-s DYNAMIC_EXECUTION=0 \
-s BINARYEN_EXTRA_PASSES=--one-caller-inline-max-function-size=19306 \
-s EXPORT_NAME=\"load_perspective\" \
-s MAXIMUM_MEMORY=4gb \
-s ERROR_ON_UNDEFINED_SYMBOLS=0 \
Expand Down
13 changes: 9 additions & 4 deletions rust/bootstrap-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ test = false

[dependencies]
talc = "4.4.1"
simd-adler32 = { version = "0.3.7", default-features = false }
zune-inflate = { version = "0.2", default-features = false, features = [
"zlib",
] }

[dependencies.zune-inflate]
version = "0.2"
default-features = false
features = ["zlib"]

[features]
env_target = []
default_features = []

# This crate needs a patch for wasm32
[patch.crates-io]
simd-adler32 = { git = "https://github.com/mcountryman/simd-adler32.git", rev = "140cde033e8b9a12d4de840648c65ccd5320bcc5" }
2 changes: 2 additions & 0 deletions rust/bootstrap/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ fn main() {

OptimizationOptions::new_optimize_for_size()
.one_caller_inline_max_size(19306)
.enable_feature(wasm_opt::Feature::BulkMemory)
.enable_feature(wasm_opt::Feature::Simd)
.run(inpath.clone(), args.output.unwrap_or(args.input))
.unwrap();
}
Expand Down
10 changes: 7 additions & 3 deletions rust/bundle/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ struct BundleArgs {
features: Option<String>,
}

use wasm_bindgen_cli_support::Bindgen;
use wasm_opt::OptimizationOptions;
use wasm_bindgen_cli_support::{Bindgen, EncodeInto};
use wasm_opt::{Feature, OptimizationOptions};

/// Run the packages `build` task with the appropriate flags. These can't be
/// defined in the `/.cargo/config.toml` because they would define this build
Expand Down Expand Up @@ -68,7 +68,9 @@ fn bindgen(outdir: &Path, artifact: &str, is_release: bool) {
.web(true)
.unwrap()
.input_path(input)
.encode_into(EncodeInto::Always)
.typescript(true)
.reference_types(true)
.out_name(&format!("{}.wasm", artifact.replace('_', "-")))
.generate(outdir)
.unwrap();
Expand All @@ -78,7 +80,9 @@ fn bindgen(outdir: &Path, artifact: &str, is_release: bool) {
fn opt(outpath: &Path, is_release: bool) {
if is_release {
OptimizationOptions::new_optimize_for_size_aggressively()
.one_caller_inline_max_size(19306)
.enable_feature(Feature::BulkMemory)
.enable_feature(Feature::ReferenceTypes)
.enable_feature(Feature::Simd)
.run(outpath, outpath)
.unwrap();
}
Expand Down
3 changes: 3 additions & 0 deletions rust/perspective-js/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,6 @@ features = [
"VisibilityState",
"Window",
]

[patch.crates-io]
simd-adler32 = { git = "https://github.com/mcountryman/simd-adler32.git", rev = "140cde033e8b9a12d4de840648c65ccd5320bcc5" }
Loading