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

[Build] Build for WASM with WebNN enabled and Exceptions disabled has error with gsl::narrow #22712

Closed
sevagh opened this issue Nov 4, 2024 · 3 comments
Labels
build build issues; typically submitted using template contributions welcome lower priority issues for the core ORT teams ep:WebGPU ort-web webgpu provider ep:WebNN WebNN execution provider platform:web issues related to ONNX Runtime web; typically submitted using template

Comments

@sevagh
Copy link
Contributor

sevagh commented Nov 4, 2024

Describe the issue

If you build for webassembly with --use_webnn and --disable_exceptions, there is a piece of code here:

splits.insert(splits.end(), split_count - 1, gsl::narrow<uint32_t>(input_shape[axis]) / split_count);
splits.insert(splits.end(), gsl::narrow<uint32_t>(input_shape[axis]) % split_count);

It uses gsl::narrow which fails to compile

  // Check that the splits evenly divide.
  if (split_count > 0 && splits.empty() && input_shape[axis] % split_count != 0) {
    // Divide inputs into variable size outputs:
    splits.insert(splits.end(), split_count - 1, gsl::narrow<uint32_t>(input_shape[axis]) / split_count);
    splits.insert(splits.end(), gsl::narrow<uint32_t>(input_shape[axis]) % split_count);
  }

If we check narrow.h, it says that we should use onnxruntime::narrow in the case where exceptions are disabled. Replacing gsl::narrow with onnxruntime::narrow lets my build succeed:

[ 70%] Linking CXX static library libonnxruntime_providers_webnn.a
[ 76%] Built target onnxruntime_providers_webnn
[ 76%] Linking CXX static library libonnxruntime_providers.a
[100%] Built target onnxruntime_providers
[100%] Bundling onnxruntime_webassembly
[100%] Built target bundling_target
2024-11-04 11:25:24,292 build [INFO] - Build complete

Urgency

No response

Target platform

WebAssembly

Build script

python ./vendor/onnxruntime/tools/ci_build/build.py \
--build_dir ./build/build-ort-wasm-simd-threads-webgpu-webnn \
--config=MinSizeRel \
--build_wasm_static_lib \
--parallel \
--minimal_build extended \
--disable_ml_ops \
--disable_rtti \
--include_ops_by_config ./onnx-models/required_operators_and_types.config \
--enable_reduced_operator_type_support \
--skip_tests \
--enable_wasm_simd \
--enable_wasm_threads \
--use_jsep \
--use_webnn \
--enable_wasm_exception_throwing_override \
--disable_exceptions

Error / output

[ 69%] Linking CXX static library libonnxruntime_lora.a
[ 69%] Built target onnxruntime_lora
[ 69%] Building CXX object CMakeFiles/onnxruntime_providers.dir/home/sevagh/repos/demucs.onnx-pro/vendor/onnxruntime/onnxruntime/core/providers/cpu/tensor/unique.cc.o
[ 69%] Building CXX object CMakeFiles/onnxruntime_providers.dir/op_reduction.generated/onnxruntime/contrib_ops/cpu/cpu_contrib_kernels.cc.o
/home/sevagh/repos/demucs.onnx-pro/vendor/onnxruntime/onnxruntime/core/providers/webnn/builders/impl/split_op_builder.cc:77:50: error: no template named 'narrow' in namespace 'gsl'; did you mean simply 'narrow'?
   77 |     splits.insert(splits.end(), split_count - 1, gsl::narrow<uint32_t>(input_shape[axis]) / split_count);
      |                                                  ^~~~~~~~~~~
      |                                                  narrow
/home/sevagh/repos/demucs.onnx-pro/vendor/onnxruntime/include/onnxruntime/core/common/narrow.h:38:34: note: 'narrow' declared here
   38 | GSL_SUPPRESS(type.1) constexpr T narrow(U u) noexcept {
      |                                  ^
/home/sevagh/repos/demucs.onnx-pro/vendor/onnxruntime/onnxruntime/core/providers/webnn/builders/impl/split_op_builder.cc:77:50: error: no template named 'narrow' in namespace 'gsl'; did you mean simply 'narrow'?
   77 |     splits.insert(splits.end(), split_count - 1, gsl::narrow<uint32_t>(input_shape[axis]) / split_count);
      |                                                  ^~~~~~~~~~~
      |                                                  narrow
/home/sevagh/repos/demucs.onnx-pro/vendor/onnxruntime/include/onnxruntime/core/common/narrow.h:38:34: note: 'narrow' declared here
   38 | GSL_SUPPRESS(type.1) constexpr T narrow(U u) noexcept {
      |                                  ^
/home/sevagh/repos/demucs.onnx-pro/vendor/onnxruntime/onnxruntime/core/providers/webnn/builders/impl/split_op_builder.cc:78:33: error: no template named 'narrow' in namespace 'gsl'; did you mean simply 'narrow'?
   78 |     splits.insert(splits.end(), gsl::narrow<uint32_t>(input_shape[axis]) % split_count);
      |                                 ^~~~~~~~~~~
      |                                 narrow
/home/sevagh/repos/demucs.onnx-pro/vendor/onnxruntime/include/onnxruntime/core/common/narrow.h:38:34: note: 'narrow' declared here
   38 | GSL_SUPPRESS(type.1) constexpr T narrow(U u) noexcept {
      |                                  ^
/home/sevagh/repos/demucs.onnx-pro/vendor/onnxruntime/onnxruntime/core/providers/webnn/builders/impl/split_op_builder.cc:78:33: error: no template named 'narrow' in namespace 'gsl'; did you mean simply 'narrow'?
   78 |     splits.insert(splits.end(), gsl::narrow<uint32_t>(input_shape[axis]) % split_count);
      |                                 ^~~~~~~~~~~
      |                     

Visual Studio Version

No response

GCC / Compiler Version

No response

@sevagh sevagh added the build build issues; typically submitted using template label Nov 4, 2024
@github-actions github-actions bot added ep:WebGPU ort-web webgpu provider ep:WebNN WebNN execution provider platform:web issues related to ONNX Runtime web; typically submitted using template labels Nov 4, 2024
@snnn
Copy link
Member

snnn commented Nov 4, 2024

Removing "gsl::" would be fine.

@snnn snnn added the contributions welcome lower priority issues for the core ORT teams label Nov 4, 2024
@sevagh
Copy link
Contributor Author

sevagh commented Nov 5, 2024

I made a PR for it 🙏

snnn pushed a commit that referenced this issue Nov 5, 2024
Replace use of `gsl::narrow` with `narrow` to build for WebNN @snnn 

### Description

Building for WebNN with exceptions disabled cannot use `gsl::narrow`.
Replace with `narrow`

### Motivation and Context

Address issue #22712
@snnn snnn closed this as completed Nov 5, 2024
@snnn
Copy link
Member

snnn commented Nov 5, 2024

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build build issues; typically submitted using template contributions welcome lower priority issues for the core ORT teams ep:WebGPU ort-web webgpu provider ep:WebNN WebNN execution provider platform:web issues related to ONNX Runtime web; typically submitted using template
Projects
None yet
Development

No branches or pull requests

2 participants