Skip to content

Always use bulkmemory memcpy and memset when available #20144

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

Merged
merged 1 commit into from
Aug 28, 2023
Merged

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Aug 28, 2023

Unlike the JS versions of these function there is no need to only use these for small inputs.

Results of running the test_memcpy_128b test before and after this change:

v8-bulk: mean: 1.536 (+-0.071) secs  median: 1.495  range: 1.471-1.650  (noise: 4.630%)  (5 runs)
        size:   149291, compressed:    54249

->

v8-bulk: mean: 1.489 (+-0.117) secs  median: 1.535  range: 1.268-1.606  (noise: 7.871%)  (5 runs)-
        size:   148387, compressed:    53813-

See comments in #19128

@sbc100 sbc100 requested review from kripken, dschuff and tlively and removed request for dschuff August 28, 2023 17:12
Unlike the JS versions of these function there is no need to only use
these for small inputs.

Results of running the test_memcpy_128b test before and after this
change:

```
v8-bulk: mean: 1.536 (+-0.071) secs  median: 1.495  range: 1.471-1.650  (noise: 4.630%)  (5 runs)
        size:   149291, compressed:    54249
```

->

```
v8-bulk: mean: 1.489 (+-0.117) secs  median: 1.535  range: 1.268-1.606  (noise: 7.871%)  (5 runs)-
        size:   148387, compressed:    53813-
```

See comments in #19128
Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

I guess no significant code size changes since we don't measure there with bulk memory? Did you notice a code size change manually when using bulk memory?

@sbc100
Copy link
Collaborator Author

sbc100 commented Aug 28, 2023

Based on emcc ~/test/hello.c -mbulk-memory -sEXPORTED_FUNCTIONS=_memcpy,_memset,_main the wasm size goes down by around 1k (12241 to 11313 bytes). I forgot to add -Oz there.. but looks like a real saving

@kripken
Copy link
Member

kripken commented Aug 28, 2023

Nice!

@sbc100 sbc100 merged commit 60b3d4e into main Aug 28, 2023
@sbc100 sbc100 deleted the memcpy_bulkmem branch August 28, 2023 21:46
sbc100 added a commit to sbc100/emscripten that referenced this pull request Oct 26, 2023
This function was renamed in emscripten-core#20144.  This change updates/removes the
remaining references.
sbc100 added a commit that referenced this pull request Oct 27, 2023
…20548)

This function was renamed in #20144.  This change updates/removes the
remaining references.
@kg
Copy link

kg commented Mar 16, 2024

Hi,
Doing a local profile of one of our applications using chrome's devtools, emscripten's mmap is spending a bunch of time calling memset during app startup, and I don't see bulk memory operations inside of the memset from emscripten's musl libc. Is there something we should do to opt-in to the bulk memory version from this PR? It doesn't look like memcpy is using bulk memory either.
Thanks

image

@sbc100
Copy link
Collaborator Author

sbc100 commented Mar 18, 2024

Bulk memory is not enabled by default. It probably will be very soon but for now you can opt into using -mbulk-memory on the command line.

It will also automatically be enabled if you disabled support for older browser. See

Feature.BULK_MEMORY: {
'chrome': 75,
'firefox': 79,
'safari': 150000,
},

@kg
Copy link

kg commented Mar 18, 2024

Thanks, I had already tried -mbulk-memory with no success, but after your comment it occurred to me that it was probably a link-time flag, and I determined we weren't setting it on our second link, only our first.

I've now verified that we're passing -mbulk-memory during initial build and both links, and wasm-opt is also getting --enable-bulk-memory passed to it by emcc according to the stdout. But looking at memset and memcpy, I still don't see bulk operations. There are no functions in our .wasm with bulkmem in their names.

Are there other criteria I need to meet? Sorry if I'm wasting your time with something obvious, but I'm kind of stumped as to why it wouldn't get linked in unless it's being disabled by some other flag.

For reference, here's the stdout from our last link step:

"/home/kate/Projects/dotnet-runtime-wasm/src/mono/browser/emsdk/node/16.20.0_64bit/bin/node" /home/kate/Projects/dotnet-runtime-wasm/src/mono/browser/emsdk/upstream/emscripten/src/compiler.js /tmp/tmpeql4v34k.json --symbols-only;"
/home/kate/Projects/dotnet-runtime-wasm/src/mono/browser/emsdk/upstream/bin/wasm-ld" -o /home/kate/Projects/dotnet-runtime-wasm/artifacts/obj/mono/RayTracer/browser.wasm.Release/browser-wasm/wasm/for-publish/dotnet.native.wasm /home/kate/Projects/dotnet-runtime-wasm/artifacts/obj/mono/RayTracer/browser.wasm.Release/browser-wasm/wasm/for-publish/pinvoke.o /home/kate/Projects/dotnet-runtime-wasm/artifacts/obj/mono/RayTracer/browser.wasm.Release/browser-wasm/wasm/for-publish/driver.o /home/kate/Projects/dotnet-runtime-wasm/artifacts/obj/mono/RayTracer/browser.wasm.Release/browser-wasm/wasm/for-publish/corebindings.o /home/kate/Projects/dotnet-runtime-wasm/artifacts/obj/mono/RayTracer/browser.wasm.Release/browser-wasm/wasm/for-publish/runtime.o /home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libicudata.a /home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libicui18n.a /home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libicuuc.a /home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libmono-component-debugger-static.a /home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libmono-component-diagnostics_tracing-stub-static.a /home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libmono-component-hot_reload-static.a /home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libmono-component-marshal-ilgen-static.a /home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libmono-ee-interp.a /home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libmono-icall-table.a /home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libmono-profiler-aot.a /home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libmono-profiler-browser.a /home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libmono-wasm-eh-wasm.a /home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libmono-wasm-simd.a /home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libmonosgen-2.0.a /home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libSystem.Globalization.Native.a /home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libSystem.IO.Compression.Native.a /home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libSystem.Native.a /home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/wasm-bundled-timezones.a -L/home/kate/Projects/dotnet-runtime-wasm/src/mono/browser/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten -lGL -lal -lhtml5 -lstubs -lc -ldlmalloc -lcompiler_rt-wasm-sjlj -lc++-except -lc++abi-except -lunwind-except -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -wasm-enable-sjlj -mllvm -disable-lsr -mllvm -wasm-enable-eh -mllvm -exception-model=wasm --allow-undefined-file=/tmp/tmp4m5_zeo6.undefined --export-if-defined=free --export-if-defined=htons --export-if-defined=malloc --export-if-defined=memalign --export-if-defined=memset --export-if-defined=ntohs --export-if-defined=stackAlloc --export-if-defined=stackRestore --export-if-defined=stackSave --export-if-defined=fmod --export-if-defined=atan2 --export-if-defined=fma --export-if-defined=pow --export-if-defined=fmodf --export-if-defined=atan2f --export-if-defined=fmaf --export-if-defined=powf --export-if-defined=asin --export-if-defined=asinh --export-if-defined=acos --export-if-defined=acosh --export-if-defined=atan --export-if-defined=atanh --export-if-defined=cbrt --export-if-defined=cos --export-if-defined=cosh --export-if-defined=exp --export-if-defined=log --export-if-defined=log2 --export-if-defined=log10 --export-if-defined=sin --export-if-defined=sinh --export-if-defined=tan --export-if-defined=tanh --export-if-defined=asinf --export-if-defined=asinhf --export-if-defined=acosf --export-if-defined=acoshf --export-if-defined=atanf --export-if-defined=atanhf --export-if-defined=cbrtf --export-if-defined=cosf --export-if-defined=coshf --export-if-defined=expf --export-if-defined=logf --export-if-defined=log2f --export-if-defined=log10f --export-if-defined=sinf --export-if-defined=sinhf --export-if-defined=tanf --export-if-defined=tanhf --export-if-defined=__get_exception_message --export-if-defined=__cpp_exception --export-if-defined=__cxa_increment_exception_refcount --export-if-defined=__cxa_decrement_exception_refcount --export-if-defined=__thrown_object_from_unwind_exception --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=fflush --export=stackSave --export=stackRestore --export=stackAlloc --export=__errno_location --export=__funcs_on_exit --export=malloc --export=free --export=__trap --export=__wasm_call_ctors --export=htonl --export=htons --export=ntohs --export=__dl_seterr --export=emscripten_builtin_memalign --export-table --growable-table -z stack-size=5242880 --initial-memory=22413312 --no-entry --max-memory=2147483648 --global-base=1024;"/home/kate/Projects/dotnet-runtime-wasm/src/mono/browser/emsdk/node/16.20.0_64bit/bin/node" /home/kate/Projects/dotnet-runtime-wasm/src/mono/browser/emsdk/upstream/emscripten/src/compiler.js /tmp/tmpv07e4tvj.json
"/home/kate/Projects/dotnet-runtime-wasm/src/mono/browser/emsdk/upstream/bin/wasm-opt" --post-emscripten -O2 --low-memory-unused --zero-filled-memory --pass-arg=directize-initial-contents-immutable --strip-producers /home/kate/Projects/dotnet-runtime-wasm/artifacts/obj/mono/RayTracer/browser.wasm.Release/browser-wasm/wasm/for-publish/dotnet.native.wasm -o /home/kate/Projects/dotnet-runtime-wasm/artifacts/obj/mono/RayTracer/browser.wasm.Release/browser-wasm/wasm/for-publish/dotnet.native.wasm -g --mvp-features --enable-bulk-memory --enable-exception-handling --enable-mutable-globals --enable-sign-ext --enable-simd;"/home/kate/Projects/dotnet-runtime-wasm/src/mono/browser/emsdk/upstream/bin/wasm-opt" --print-function-map --quiet /home/kate/Projects/dotnet-runtime-wasm/artifacts/obj/mono/RayTracer/browser.wasm.Release/browser-wasm/wasm/for-publish/dotnet.native.wasm --mvp-features --enable-bulk-memory --enable-exception-handling --enable-mutable-globals --enable-sign-ext --enable-simd

@kg
Copy link

kg commented Mar 18, 2024

If I'm reading https://github.com/emscripten-core/emscripten/blob/918e131fae0b5c7b1d05a5c75d7e8e676c377713/tools/system_libs.py#L1307C7-L1307C16 correctly, it looks like -Oz may be unintentionally disabling bulk memory, since it passes its own version of memcpy/memmove?

We do use -Oz sometimes, but I tried replacing all our references to it with -O2 and didn't see a change. I'll keep experimenting...

@sbc100
Copy link
Collaborator Author

sbc100 commented Mar 18, 2024

You should see libbulkmemory being included on the link line (e.g. -lbulkmemory).

See

if settings.BULK_MEMORY:
add_library('libbulkmemory')

@kg
Copy link

kg commented Mar 18, 2024

So from looking at my build logs, I'm running:

emcc "@/home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/src/emcc-default.rsp" -msimd128 "@/home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/src/emcc-link.rsp" "@/home/kate/Projects/dotnet-runtime-wasm/artifacts/obj/mono/RayTracer/browser.wasm.Release/browser-wasm/wasm/for-publish/emcc-link.rsp"

and if i cat the relevant rsp file:

kate@reeir-debian2:~/Projects/dotnet-runtime-wasm/src/mono/sample/wasm/dotnet-wasm-raytracer-simd$ cat "/home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/src/emcc-default.rsp"
-mbulk-memory

So the switch should be getting seen by emcc, and it seems like at some level it is being seen because --enable-bulk-memory is making it through to the link step. But as you point out, -lbulkmemory is missing from the link arguments. Is it not supported to use response files in this way? As you may notice we have a raw -msimd128 in the command line there; I previously had to add that to get things working so maybe we've been having rsp file problems this whole time without my notice...

For reference, here are the other two rsp files. You can see bulk-memory is in another one too, since I tried adding it there earlier:

kate@reeir-debian2:~/Projects/dotnet-runtime-wasm/src/mono/sample/wasm/dotnet-wasm-raytracer-simd$ cat /home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/src/emcc-link.rsp
-s INITIAL_MEMORY=16777216
-s STACK_SIZE=5MB
-s ALLOW_MEMORY_GROWTH=1
-s ALLOW_TABLE_GROWTH=1
-s NO_EXIT_RUNTIME=0
-s FORCE_FILESYSTEM=1
-s DEFAULT_LIBRARY_FUNCS_TO_INCLUDE="[]"
-s EXPORTED_RUNTIME_METHODS="['FS','out','err','ccall','cwrap','setValue','getValue','UTF8ToString','UTF8ArrayToString','stringToUTF8Array','FS_createPath','FS_createDataFile','removeRunDependency','addRunDependency','addFunction','safeSetTimeout','runtimeKeepalivePush','runtimeKeepalivePop','maybeExit','abort']"
-s EXPORTED_FUNCTIONS=_free,_htons,_malloc,_memalign,_memset,_ntohs,stackAlloc,stackRestore,stackSave,_fmod,_atan2,_fma,_pow,_fmodf,_atan2f,_fmaf,_powf,_asin,_asinh,_acos,_acosh,_atan,_atanh,_cbrt,_cos,_cosh,_exp,_log,_log2,_log10,_sin,_sinh,_tan,_tanh,_asinf,_asinhf,_acosf,_acoshf,_atanf,_atanhf,_cbrtf,_cosf,_coshf,_expf,_logf,_log2f,_log10f,_sinf,_sinhf,_tanf,_tanhf
--source-map-base http://example.com
-s WASM_BIGINT=1
-s EXPORT_NAME="'createDotnetRuntime'"
-s MODULARIZE=1
-s ENVIRONMENT="web,webview,worker,node,shell"
-Wno-limited-postlink-optimizations
--profiling-funcs
kate@reeir-debian2:~/Projects/dotnet-runtime-wasm/src/mono/sample/wasm/dotnet-wasm-raytracer-simd$ cat /home/kate/Projects/dotnet-runtime-wasm/artifacts/obj/mono/RayTracer/browser.wasm.Release/browser-wasm/wasm/for-publish/emcc-link.rsp
-O2
-mbulk-memory
-g
-v
-fwasm-exceptions
-s EXPORT_ES6=1 -lexports.js
-s EXPORT_EXCEPTION_HANDLING_HELPERS=1
-s LLD_REPORT_UNDEFINED
-s ERROR_ON_UNDEFINED_SYMBOLS=1
-s INITIAL_MEMORY=22413312
-s STACK_SIZE=5MB
-s WASM_BIGINT=1
--emit-symbol-map
--pre-js "/home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/src/es6/dotnet.es6.pre.js"
--js-library "/home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/src/es6/dotnet.es6.lib.js"
--extern-post-js "/home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/src/es6/dotnet.es6.extpost.js"
"/home/kate/Projects/dotnet-runtime-wasm/artifacts/obj/mono/RayTracer/browser.wasm.Release/browser-wasm/wasm/for-publish/pinvoke.o"
"/home/kate/Projects/dotnet-runtime-wasm/artifacts/obj/mono/RayTracer/browser.wasm.Release/browser-wasm/wasm/for-publish/driver.o"
"/home/kate/Projects/dotnet-runtime-wasm/artifacts/obj/mono/RayTracer/browser.wasm.Release/browser-wasm/wasm/for-publish/corebindings.o"
"/home/kate/Projects/dotnet-runtime-wasm/artifacts/obj/mono/RayTracer/browser.wasm.Release/browser-wasm/wasm/for-publish/runtime.o"
"/home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libicudata.a"
"/home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libicui18n.a"
"/home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libicuuc.a"
"/home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libmono-component-debugger-static.a"
"/home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libmono-component-diagnostics_tracing-stub-static.a"
"/home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libmono-component-hot_reload-static.a"
"/home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libmono-component-marshal-ilgen-static.a"
"/home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libmono-ee-interp.a"
"/home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libmono-icall-table.a"
"/home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libmono-profiler-aot.a"
"/home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libmono-profiler-browser.a"
"/home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libmono-wasm-eh-wasm.a"
"/home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libmono-wasm-simd.a"
"/home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libmonosgen-2.0.a"
"/home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libSystem.Globalization.Native.a"
"/home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libSystem.IO.Compression.Native.a"
"/home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/libSystem.Native.a"
"/home/kate/Projects/dotnet-runtime-wasm/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Release/runtimes/browser-wasm/native/wasm-bundled-timezones.a"
-o "/home/kate/Projects/dotnet-runtime-wasm/artifacts/obj/mono/RayTracer/browser.wasm.Release/browser-wasm/wasm/for-publish/dotnet.native.js"
-s DEFAULT_LIBRARY_FUNCS_TO_INCLUDE="[]"
-s EXPORTED_RUNTIME_METHODS="['FS','out','err','ccall','cwrap','setValue','getValue','UTF8ToString','UTF8ArrayToString','stringToUTF8Array','FS_createPath','FS_createDataFile','removeRunDependency','addRunDependency','addFunction','safeSetTimeout','runtimeKeepalivePush','runtimeKeepalivePop','maybeExit','abort']"
-s EXPORTED_FUNCTIONS=_free,_htons,_malloc,_memalign,_memset,_ntohs,stackAlloc,stackRestore,stackSave,_fmod,_atan2,_fma,_pow,_fmodf,_atan2f,_fmaf,_powf,_asin,_asinh,_acos,_acosh,_atan,_atanh,_cbrt,_cos,_cosh,_exp,_log,_log2,_log10,_sin,_sinh,_tan,_tanh,_asinf,_asinhf,_acosf,_acoshf,_atanf,_atanhf,_cbrtf,_cosf,_coshf,_expf,_logf,_log2f,_log10f,_sinf,_sinhf,_tanf,_tanhf

@sbc100
Copy link
Collaborator Author

sbc100 commented Mar 18, 2024

--enable-bulk-memory is being passed to wasm-opt because one of more object files enabled it.

I can't see why -mbulk-memory would not work fine in a .rsp file.

Can you try adding adding assert setting.BULK_MEMORY at the end of parse_args in emcc.py?

@kg
Copy link

kg commented Mar 18, 2024

setting.BULK_MEMORY doesn't seem to be defined. I tried settings.BULK_MEMORY but:

AttributeError: no such setting: 'BULK_MEMORY'

options.BULK_MEMORY seems wrong too:

AttributeError: 'EmccOptions' object has no attribute 'BULK_MEMORY'

I see BULK_MEMORY in feature_matrix.py in my local copy of emsdk, but I don't see it in system_libs.py. So my error is that somehow our install of emscripten is missing this stuff even though it was merged last year, in which case I've wasted your time. :( This explains why the flag is making it through to wasm-opt; it's working, but it's not doing what I expected it to do.

@sbc100
Copy link
Collaborator Author

sbc100 commented Mar 18, 2024

It should be settings.BULK_MEMORY. What version of emscripten are you using?

@sbc100
Copy link
Collaborator Author

sbc100 commented Mar 18, 2024

You can see the setting getting set in the arg_parse function:

emscripten/emcc.py

Lines 1349 to 1352 in 1201861

elif arg == '-mbulk-memory':
settings.BULK_MEMORY = 1
elif arg == '-mno-bulk-memory':
settings.BULK_MEMORY = 0

@kg
Copy link

kg commented Mar 18, 2024

You can see the setting getting set in the arg_parse function:

emscripten/emcc.py

Lines 1349 to 1352 in 1201861

elif arg == '-mbulk-memory':
settings.BULK_MEMORY = 1
elif arg == '-mno-bulk-memory':
settings.BULK_MEMORY = 0

I'm confident that our emscripten is just too old since the commit(s) that added this bulkmem optimization aren't in it. I found an emscripten_revision.txt that, if accurate, indicates I wasted your time by misreading what version we're on (it looks like we're in the .34 range, which is definitely too old). Good lesson for the future to grep the actual files I have in my emsdk folder if something isn't working before I come here for help :)

@sbc100
Copy link
Collaborator Author

sbc100 commented Mar 18, 2024

No worries! Glad it worked out.

PetarKirov added a commit to metacraft-labs/DendrETH that referenced this pull request Mar 22, 2024
Emscripten expect the JS-host to provide this import since v3.1.46 and this PR:
emscripten-core/emscripten#20144
PetarKirov added a commit to metacraft-labs/DendrETH that referenced this pull request Mar 22, 2024
Emscripten expect the JS-host to provide this import since v3.1.46 and this PR:
emscripten-core/emscripten#20144
PetarKirov added a commit to metacraft-labs/DendrETH that referenced this pull request Mar 22, 2024
Emscripten expect the JS-host to provide this import since v3.1.46 and this PR:
emscripten-core/emscripten#20144
PetarKirov added a commit to metacraft-labs/DendrETH that referenced this pull request Mar 22, 2024
Emscripten expect the JS-host to provide this import since v3.1.46 and this PR:
emscripten-core/emscripten#20144
PetarKirov added a commit to metacraft-labs/DendrETH that referenced this pull request Mar 22, 2024
Emscripten expect the JS-host to provide this import since v3.1.46 and this PR:
emscripten-core/emscripten#20144
github-merge-queue bot pushed a commit to metacraft-labs/DendrETH that referenced this pull request Mar 22, 2024
Emscripten expect the JS-host to provide this import since v3.1.46 and this PR:
emscripten-core/emscripten#20144
PetarKirov added a commit to metacraft-labs/DendrETH that referenced this pull request Mar 22, 2024
Emscripten expect the JS-host to provide this import since v3.1.46 and this PR:
emscripten-core/emscripten#20144
kkirkov pushed a commit to metacraft-labs/DendrETH that referenced this pull request Mar 25, 2024
Emscripten expect the JS-host to provide this import since v3.1.46 and this PR:
emscripten-core/emscripten#20144
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants