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_cc_binary with tensorflow lite minimal example failed #1424

Open
Yongle-Fu opened this issue Jul 10, 2024 · 7 comments
Open

wasm_cc_binary with tensorflow lite minimal example failed #1424

Yongle-Fu opened this issue Jul 10, 2024 · 7 comments

Comments

@Yongle-Fu
Copy link

tensorflow lite minimal example

wasm_cc_binary(
    name = "wasm-minimal",
    cc_target = ":minimal",
)

tensorflow/tensorflow/lite/examples/minimal/BUILD:13:10: Linking tensorflow/lite/examples/minimal/minimal failed: (Exit 1): emcc_link.sh failed: error executing command (from target //tensorflow/lite/examples/minimal:minimal) external/emsdk/emscripten_toolchain/emcc_link.sh @bazel-out/wasm-opt-ST-b4dbd4a2bfc4/bin/tensorflow/lite/examples/minimal/minimal-2.params
wasm-ld: error: --shared-memory is disallowed by bazel-out/wasm-opt-ST-b4dbd4a2bfc4/bin/tensorflow/lite/examples/minimal/_objs/minimal/minimal.o because it was not compiled with 'atomics' or 'bulk-memory' features.
emcc: error: '/private/var/tmp/_bazel_yongle/fd2da45fc7b2786266a27e6e6c87cfd0/execroot/org_tensorflow/external/emscripten_bin_mac/bin/wasm-ld @/var/folders/sh/vmbfsw6x5fv2mn91h60r1jj00000gn/T/emscripten_qe8ad8zr.rsp.utf-8' failed (returned 1)
Target //tensorflow/lite/examples/minimal:wasm-minimal failed to build

@walkingeyerobot
Copy link
Collaborator

The error message is complaining about atomics, so maybe it needs to be built with threads. Try adding threads = "emscripten", to your wasm_cc_binary

@Yongle-Fu
Copy link
Author

Thank you very much. Build completed successfully now

@Yongle-Fu
Copy link
Author

The error message is complaining about atomics, so maybe it needs to be built with threads. Try adding threads = "emscripten", to your wasm_cc_binary

I am using WebAssembly (Wasm) in a WeChat Mini Program environment, but it does not support Web Workers.

worker=new Worker(pthreadMainJs,workerOptions)

Would you like additional information or suggestions on how to handle WebAssembly in WeChat Mini Programs without Web Workers? @walkingeyerobot

like without option threads = "emscripten" in wasm_cc_binary,

thank you so much !~

@Yongle-Fu Yongle-Fu reopened this Jul 17, 2024
@walkingeyerobot
Copy link
Collaborator

Are you able to get tensorflow lite to compile without threads outside of bazel and run in your environment? If yes, I'm happy to help dig into this further. If no, I think that's a question for hte tensorflow lite folks.

@Yongle-Fu
Copy link
Author

Yongle-Fu commented Jul 25, 2024

Thank you very much for your help.

According to the advice from a TensorFlow Lite team member, I tried remove the -pthread lines in the emlink params file and ran emcc_link.sh. It was successful, although the generated wasm-loader.js is larger than usual. Are there any unfinished tasks that need to be completed after running emcc_link.sh?

generated wasm-loader.js file
tensorflow isuse help which build wasm_cc_binary without pthread

@mattsoulanille
Copy link
Contributor

Are you able to get tensorflow lite to compile without threads outside of bazel and run in your environment? If yes, I'm happy to help dig into this further. If no, I think that's a question for hte tensorflow lite folks.

This works internally in google3 (you can ping me in chat for a link) for building @tensorflow/tfjs-tflite, so I think the Bazel wasm tooling probably supports it. My guess is there's something misconfigured in the oss build, possibly before anything gets passed to wasm_cc_binary, that's causing it to use threads even when threads are not requested. If that's the case, then this is a TFLite issue.

@Yongle-Fu
Copy link
Author

Yongle-Fu commented Jul 26, 2024

The error message is complaining about atomics, so maybe it needs to be built with threads. Try adding threads = "emscripten", to your wasm_cc_binary

I found a solution to fix the emcc_link issue by threads = "off" and adding -s USE_PTHREADS=0

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

No branches or pull requests

3 participants