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

[wasm] Add test checking that disabiling SIMD actually disables it #89302

Open
2 of 7 tasks
radekdoulik opened this issue Jul 21, 2023 · 29 comments
Open
2 of 7 tasks

[wasm] Add test checking that disabiling SIMD actually disables it #89302

radekdoulik opened this issue Jul 21, 2023 · 29 comments
Assignees
Labels
arch-wasm WebAssembly architecture area-Build-mono
Milestone

Comments

@radekdoulik
Copy link
Member

radekdoulik commented Jul 21, 2023

The SIMD cannot be disabled anymore. These are the 2 parts we need to fix:

  • do not put -msimd128 to emcc-default.rsp, otherwise we compile with SIMD even when WasmEnableSIMD is false. Instead add it conditionally in src/mono/wasm/wasm.proj, src/mono/wasm/runtime/CMakeLists.txt and src/mono/wasm/build/WasmApp.Native.targets
  • do not build our mono runtime with -msimd128 or provide multiple native libraries versions

optionally:

  • do not pass '--enable-simd' to wasm-opt. I think this doesn't add any SIMD instructions, so we probably don't need it. We should check it though.

following step:

  • add WBT test to check that build with SIMD disabled produces .wasm files without SIMD instructions. This can be done easily once we have the wa-info tool in the runtime repo.
  • Run SIMD WBT with older Firefox (88) or Chrome to check it works on runtime
  • Disable SIMD and WASM EH in Jiterpreter if it was disabled during build
  • AOT complication produces some SIMD althought it was disabled
@radekdoulik
Copy link
Member Author

@kg do we need add_compile_options(-msimd128) in the src/mono/CMakeLists.txt for the interpreter to work with SIMD? if not, we can probably remove it. I think the performance will not be affected much by this. Otherwise we would need multiple versions of mono native libs I think.

@vargaz
Copy link
Contributor

vargaz commented Jul 21, 2023

I think --enable-simd is needed by wasm-opt to be able to read an input file which uses simd opcodes.

@kg
Copy link
Member

kg commented Jul 21, 2023

@kg do we need add_compile_options(-msimd128) in the src/mono/CMakeLists.txt for the interpreter to work with SIMD? if not, we can probably remove it. I think the performance will not be affected much by this. Otherwise we would need multiple versions of mono native libs I think.

Without -msimd128 no code that uses wasm intrinsics will compile, even if we don't run it. So we would need to ifdef everything relevant out I think.

Part of the problem is that -msimd128 isn't just an 'enable support' flag, unfortunately it turns a bunch of other stuff on by default and that's probably the source of the sections or opcodes that are breaking things for people.

I don't think the switch specifically needs to be there; I tried a bunch of things to try and get SIMD to work and that was the only simple solution I found that worked.

@radical radical added the arch-wasm WebAssembly architecture label Jul 23, 2023
@ghost
Copy link

ghost commented Jul 23, 2023

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

The SIMD cannot be disabled anymore. These are the 2 parts we need to fix:

  • do not put -msimd128 to emcc-default.rsp, otherwise we compile with SIMD even when WasmEnableSIMD is false. Instead add it conditionally in src/mono/wasm/wasm.proj, src/mono/wasm/runtime/CMakeLists.txt and src/mono/wasm/build/WasmApp.Native.targets
  • do not build our mono runtime with -msimd128 or provide multiple native libraries versions

optionally:

  • do not pass '--enable-simd' to wasm-opt. I think this doesn't add any SIMD instructions, so we probably don't need it. We should check it though.

following step:

  • add WBT test to check that build with SIMD disabled produces .wasm files without SIMD instructions. This can be done easily once we have the wa-info tool in the runtime repo.
Author: radekdoulik
Assignees: radekdoulik
Labels:

arch-wasm, area-Build-mono

Milestone: 8.0.0

radekdoulik added a commit to radekdoulik/runtime that referenced this issue Jul 25, 2023
This is the first part of changes to make wasm/SIMD optional again,
dotnet#89302
@radekdoulik
Copy link
Member Author

For mono libs and src/mono/CMakeLists.txt I will try to extract the interp simd code to a separate library, similar to what we do for exception handling, and link it conditionally.

radekdoulik added a commit that referenced this issue Jul 26, 2023
* [wasm] Do not set -msimd128 in the default rsp

This is the first part of changes to make wasm/SIMD optional again,
#89302

* Feedback

* Feedback

* Update the tests, we force relink with SIMD disabled now
@radekdoulik
Copy link
Member Author

remaining parts can be done in net9

@radekdoulik radekdoulik modified the milestones: 8.0.0, 9.0.0 Aug 30, 2023
@KubaGluszkiewicz
Copy link

KubaGluszkiewicz commented Sep 10, 2023

Hello,
since our browser wasm application is deployed into various TV Systems like Tizen or WebOS which are internally baked by older chromium versions, disabling SIMD support is crucial for us.
I'm trying to follow issues here (at least 2 were open related to enabling SIMD by default), and i see you are trying to fix it.
I'm using version .net8 preview 7 and i'm not able to switch off SIMD support using csproj settings.
Question is it possible in Preview7 to fully disable SIMD? If not, it will be possible in upcoming RC1 version?

My project settings:

<TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
<OutputType>Exe</OutputType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<WasmEnableExceptionHandling>False</WasmEnableExceptionHandling>
<WasmEnableSIMD>False</WasmEnableSIMD>
<WasmBuildNative>True</WasmBuildNative>

At program launch i'm getting bunch of errors like this:

MONO_WASM: instantiate_wasm_module() failed CompileError: WebAssembly.instantiateStreaming(): Compiling function #104:"19" failed: Invalid opcode (enable with --experimental-wasm-simd) @+28002
nt @ dotnet.runtime.js:3
dotnet.js:3 MONO_WASM: CompileError: WebAssembly.instantiateStreaming(): Compiling function #104:"19" failed: Invalid opcode (enable with --experimental-wasm-simd) @+28002
l @ dotnet.js:3
main.js:26 Error initializing dotnet: CompileError: WebAssembly.instantiateStreaming(): Compiling function #104:"19" failed: Invalid opcode (enable with --experimental-wasm-simd) @+28002
(anonymous) @ main.js:26
dotnet.js:3 Error in mono_download_assets: CompileError: WebAssembly.instantiateStreaming(): Compiling function #104:"19" failed: Invalid opcode (enable with --experimental-wasm-simd) @+28002
(anonymous) @ dotnet.js:3
4dotnet.js:3 Uncaught (in promise) CompileError: WebAssembly.instantiateStreaming(): Compiling function #104:"19" failed: Invalid opcode (enable with --experimental-wasm-simd) @+28002
dotnet.runtime.js:3 Uncaught (in promise) CompileError: WebAssembly.instantiateStreaming(): Compiling function #104:"19" failed: Invalid opcode (enable with --experimental-wasm-simd) @+28002
2index.html:1 Uncaught (in promise) CompileError: WebAssembly.instantiateStreaming(): Compiling function #104:"19" failed: Invalid opcode (enable with --experimental-wasm-simd) @+28002

not sure what i can do more to get rid of SIMD support in .Net8

@maraf
Copy link
Member

maraf commented Sep 18, 2023

@KubaGluszkiewicz Just a note, use lower case true/false in MSBuild properties.

@lewing
Copy link
Member

lewing commented Oct 5, 2023

<WasmEnableSIMD>false</WasmEnableSIMD> should be the only thing required to disable simd (and eh since it defaults to the simd setting) and the setting is fully functional now.

@lewing lewing changed the title [wasm] SIMD cannot be disabled [wasm] Add test checking that disabiling SIMD actually disables it Oct 5, 2023
@maraf
Copy link
Member

maraf commented Oct 5, 2023

<WasmEnableSIMD>false</WasmEnableSIMD> should be the only thing required to disable simd (and eh since it defaults to the simd setting) and the setting is fully functional now.

I have it on my list. Using chrome 85 on CI should be enough

@lewing
Copy link
Member

lewing commented Nov 21, 2023

add WBT test to check that build with SIMD disabled produces .wasm files without SIMD instructions. This can be done easily once we have the wa-info tool in the runtime repo.

Running wasm-opt without --enable- is an easy way to see what is in use

@paulguz-datapa
Copy link

We have customers hitting this on Windows 10 machines. What is the timescale for the fix?

@maraf
Copy link
Member

maraf commented Jan 9, 2024

@paulguz-datapa Disabling SIMD should be working, they this issue open only to make an automated test. Are you setting both WasmEnableExceptionHandling and WasmEnableSIMD to false? I have published a simple with disabled SIMD here https://maraf.github.io/dotnet-wasm-nosimd/. Can you check it works in your environment?

@paulguz-datapa
Copy link

@maraf Yes, those flags work, thanks.

@lewing
Copy link
Member

lewing commented Feb 9, 2024

Closing as completed if this is incorrect please reopen

@lewing lewing closed this as completed Feb 9, 2024
@luccawilli
Copy link

@maraf unfortunately your fix does not fix our problem.
We got a small project running on blazor webassemly and after the update to .net8, we received feedback that the website was no longer working for them.
As mentioned in this Issue, we decided to disable SIMD (the error message also pointed it out) via adding the Wasm Section to our project file.

<WasmEnableSIMD>false</WasmEnableSIMD>
<WasmEnableExceptionHandling>false</WasmEnableExceptionHandling>

Unfortunately, this does not solve the actual problem.
We received still the same error.
grafik

Our test environment runs on "Microsoft Windows Server 2019 Standard - 10.0.17763" is a Virtual Machine with the processor "Intel64 Family 6 Model 85 Stepping 7 GenuineIntel" (Unfortunately without SIMD support).
Hosting seems to be unrelated, I get the error in the IIS as well as in the Docker Image hosted Variant.

Unfortunately, I am not allowed to share the project code with you, so I have created a sample application that at least also outputs a SIMD error message. Unfortunately I can't get the same error as in the project above.
https://github.com/luccawilli/dotnet-wasm-nosimd

grafik

It works on my personal machine ;)
grafik

Nevertheless, I suspect that SIMD is still included in the published Version somewhere.
Do you have an idea what could go wrong?

@maraf
Copy link
Member

maraf commented Feb 9, 2024

@luccawilli If I understand it correctly, you are able to reproduce the error in your test environment, right? Can we please verify that https://maraf.github.io/dotnet-wasm-nosimd/ works on the machine without SIMD?

@luccawilli
Copy link

@maraf correct, your example works without an error. But it does not use any Pages or Components.

@maraf
Copy link
Member

maraf commented Feb 9, 2024

But it does not use any Pages or Components.

It's plain WebAssembly without blazor.

And your sample with Blazor doesn't work https://github.com/luccawilli/dotnet-wasm-nosimd, right?
Do you have wasm-tools workload installed? (dotnet workload install wasm-tools)

@luccawilli
Copy link

luccawilli commented Feb 9, 2024

@maraf Yes correct, mine does not work. And yes i installed wasm-tools.

@maraf
Copy link
Member

maraf commented Feb 9, 2024

Thanks! I'm getting the same "AllowRange" error on my machine. I'll investigate it

@LostBeard
Copy link

I have created demonstration projects showing how to build Blazor WASM apps with both SIMD enabled and disabled. And then loading the appropriate build at runtime based on the environment.

Blazor Web App SIMD Detect Example
BlazorWebAppSIMDDetectExample

Blazor WebAssembly Standalone SIMD Detect Example
BlazorWASMSIMDDetectExample

@maraf
Copy link
Member

maraf commented Feb 9, 2024

@luccawilli The "AllowRange" error comes from the Jiterpreter that is testing what capabilities it can use. We'll prepare a fix for it not to test SIMD on runtime when it was disabled during compilation.

Anyway, with disable SIMD during build (WasmEnableSIMD=false and WasmEnableExceptionHandling=false) the app works despite it prints error to the console (the Blazor UI renders and all interactions work). You can get rid of the error with the following setting

<BlazorWebAssemblyRuntimeOptions>--no-jiterpreter-simd-enabled --no-jiterpreter-wasm-eh-enabled</BlazorWebAssemblyRuntimeOptions>

@maraf maraf reopened this Feb 9, 2024
@LostBeard
Copy link

LostBeard commented Feb 9, 2024

My comment here

Interesting note. I have noticed that my devices or browsers that do not support SIMD also throw an error MONO_WASM: Disabling jiterpreter after 2 failures if BlazorWebAssemblyJiterpreter is not also disabled. (The app still runs with the error.) Disabling both SIMD and the jiterpreter when SIMD is not supported works without any further issues on my test devices.

I found that disabling SIMD without also disabling BlazorWebAssemblyJiterpreter gave an error but still allowed the app to run.

@maraf You "cc@kg" my above comment on that thread. maraf quoting my above comment

@maraf
Copy link
Member

maraf commented Feb 9, 2024

I found that disabling SIMD without also disabling BlazorWebAssemblyJiterpreter gave an error but still allowed the app to run.

You actually don't need to disable the whole jiterpreter, just the SIMD and EH

@luccawilli
Copy link

@maraf Thank you for the investigation. As i see the error in my test app has vanished :)

Unfortunately, the change does not yet solve any problems in our main project. I will try to improve my test app, so that i can show you my main problem.

@luccawilli
Copy link

So I have improved my example. It now shows the same error that we get in our main project.
https://github.com/luccawilli/dotnet-wasm-nosimd-try2

I also added the publish result and the folder publish profile.

The error shown in my test system:
grafik

No errors on my system (with SIMD support) (except for the missing icon)
grafik

@maraf Can you also investigate this one? Thanks alot :)

@maraf
Copy link
Member

maraf commented Feb 12, 2024

Why are you setting WasmBuildNative=false? This setting disables relinking .NET runtime and thus makes all the other settings void. We are improving the experience in 9 to produce an error when incompatible settings are used

@luccawilli
Copy link

Oh damn, okay alright. I didn't know that.
I had to add it because my build agent (a linux machine) had thrown the following error:
WasmApp.Native.targets(737,5): error : MarshalingPInvokeScanner.Assemblies cannot be empty

But I think I can ignore that, since it only needs to be published in my Docker-Image.
Btw. to build and publish it in a Docker-Image, i had to install python3. (Maybe that also a problem on my build agent.)
RUN apt-get update RUN apt-get install -y python3

Thank you once again
Best regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-wasm WebAssembly architecture area-Build-mono
Projects
None yet
Development

No branches or pull requests

10 participants