XNNPACK
XNNPACK copied to clipboard
Add CMake support for Emscripten builds
It seems that it would be as simple as updating CMake to add the file list in PROD_SCALAR_WASM_MICROKERNEL_SRCS
, ALL_WASM_MICROKERNEL_SRCS
, etc... from BUILD.bazel
Emscripten's CMake toolchain doesn't support targeting WAsm Atomics / WAsm SIMD / WAsm Relaxed SIMD specifications used in XNNPack, which is the reason why we don't support WebAssembly builds with CMake. If you want to have it supported, I suggest to refactor Emscripten's CMake toolchain and add options to target these WAsm specifications.
Wasm SIMD can be enabled with a compiler flag from what I understand:
IF(EMSCRIPTEN)
IF(XNNPACK_ENABLE_WASMSIMD)
SET_PROPERTY(SOURCE ${PROD_MICROKERNEL_SRCS} APPEND_STRING PROPERTY COMPILE_FLAGS " -msimd128 ")
SET_PROPERTY(SOURCE ${ALL_MICROKERNEL_SRCS} APPEND_STRING PROPERTY COMPILE_FLAGS " -msimd128 ")
SET_PROPERTY(TARGET XNNPACK APPEND_STRING PROPERTY COMPILE_FLAGS " -msimd128 ")
ENDIF()
ENDIF()
Relaxed SIMD and atomics I think are just at the proposal level, but even without simd128 I think it would be nice to support whatever can give a boost in WebAssembly. I currently have this commit on a branch from the reference of tflite 2.10.0 and it's compiling without issues, still haven't tested it though.
WAsm extensions work differently than native extensions in that they "taint" the whole WAsm binary. E.g. if a WAsm binary contains even a single WAsm SIMD instruction, the whole binary will be rejected by WAsm engines which don't support WAsm SIMD. Thus, these flags should be set at toolchain level, not at the level of individual projects.
the whole binary will be rejected by WAsm engines which don't support WAsm SIMD
aka Safari 🤣
And I don't think wasm works that different to native binaries, all it takes is one shared object with an instruction not supported by the running CPU for the whole process to be killed by illegal instruction.
But seriously, having basic support for WASM MVP and/or WASM simd128 would be great - that way tflite can be compiled with CMake for WebAssembly.
all it takes is one shared object with an instruction not supported by the running CPU for the whole process to be killed by illegal instruction
Only if the unsupported instruction is being executed. In WAsm the whole module is rejected even if unsupported instructions never execute, so it is impossible to do runtime ISA extension detection.
Hello sir , I am new to open source contribution. I already know java , my tech stacks & tools includes C, C++ , Python , Java, JavaScript , HTML , CSS , SQL , Bootstrap, ReactJS, ExpressJS, NodeJS & Git . I need a little help from your side to contribute to these amazing projects.
It's a bad news! Does it's possible to build xnnpack wasm library with bazel, and then integrate it to another cmake wasm project? @Maratyszcza
It's a bad news! i need build into libtensorflowlite_c.a (Emscripten static library archive) for work with my C project and build them to wasm
@xbwee1024 Should work in theory, but we haven't really tried that.
so how to build xnnpack wasm library??