opencv: shared:ERROR: If pthreads and memory growth are enabled, WASM_MEM_MAX must be set

/home/z/emsdk/emscripten/incoming/em++ -s WASM=1 -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -pthread -Qunused-arguments -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -DNDEBUG -O2 -DNDEBUG -Wl,--gc-sections -O2 --memory-init-file 0 -s TOTAL_MEMORY=134217728 -s ALLOW_MEMORY_GROWTH=1 -s MODULARIZE=1 -s SINGLE_FILE=1 -s EXPORT_NAME="'cv'" -s DEMANGLE_SUPPORT=1 -s FORCE_FILESYSTEM=1 --use-preload-plugins --bind --post-js /home/z/opencv/modules/js/src/helpers.js -Wno-missing-prototypes @CMakeFiles/opencv_js.dir/objects1.rsp -o ../../bin/opencv_js.js @CMakeFiles/opencv_js.dir/linklibs.rsp root:WARNING: USE_PTHREADS + ALLOW_MEMORY_GROWTH may run non-wasm code slowly, see https://github.com/WebAssembly/design/issues/1271 shared:ERROR: If pthreads and memory growth are enabled, WASM_MEM_MAX must be set modules/js/CMakeFiles/opencv_js.dir/build.make:179: recipe for target 'bin/opencv_js.js' failed make[3]: *** [bin/opencv_js.js] Error 1 make[3]: Leaving directory '/home/z/opencv/build_wasm' CMakeFiles/Makefile2:1514: recipe for target 'modules/js/CMakeFiles/opencv_js.dir/all' failed make[2]: *** [modules/js/CMakeFiles/opencv_js.dir/all] Error 2 make[2]: Leaving directory '/home/z/opencv/build_wasm' CMakeFiles/Makefile2:1479: recipe for target 'modules/js/CMakeFiles/opencv.js.dir/rule' failed make[1]: *** [modules/js/CMakeFiles/opencv.js.dir/rule] Error 2 make[1]: Leaving directory '/home/z/opencv/build_wasm' Makefile:390: recipe for target 'opencv.js' failed make: *** [opencv.js] Error 2 Traceback (most recent call last): File "./platforms/js/build_js.py", line 235, in <module> builder.build_opencvjs() File "./platforms/js/build_js.py", line 170, in build_opencvjs execute(["make", "-j", str(multiprocessing.cpu_count()), "opencv.js"]) File "./platforms/js/build_js.py", line 23, in execute raise Fail("Child returned: %s" % retcode) __main__.Fail: Child returned: 2 z@z:~/opencv$

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 3
  • Comments: 25 (9 by maintainers)

Most upvoted comments

@Wenzhao-Xiang, Can you please also experiment with flags += "-s USE_PTHREADS=0 " at get_build_flags in build_js.py?

    def get_build_flags(self):
        flags = ""
        flags += "-s USE_PTHREADS=0 "
        if self.options.build_wasm:
            flags += "-s WASM=1 "
        elif self.options.disable_wasm:
            flags += "-s WASM=0 "
        if self.options.enable_exception:
            flags += "-s DISABLE_EXCEPTION_CATCHING=0 "
        return flags

Using just this flag helped me to build opencv.js with the latest emscripten. It’s interesting if performance is the same or not.

@dkurt Here is the data:

Opencv version: 4.1.0-dev Emscripten version: latest

Test environment: System: Ubuntu 16.04 CPU: Intel® Core™ i7-4790 CPU @ 3.60GHz Chrome version: Version 75.0.3770.90 (Official Build) unknown (64-bit)

Kernel \ Build Type Type1 Type2
GaussianBlur 3.356ms 3.334ms
cvtColor 0.518ms 0.513ms
threshold 0.202ms 0.211ms
integral2 0.769ms 0.743ms

Type 1: -s ALLOW_MEMORY_GROWTH=1 + -s DEMANGLE_SUPPORT=0 (+ -s USE_PTHREADS=1 ) (latest version of emscripten enable pthreads building option by default) Type 2: -s ALLOW_MEMORY_GROWTH=1 + -s DEMANGLE_SUPPORT=0 + -s USE_PTHREADS=0

According to the data, seems there is no performance issue when only testing kernels if I enable pthread+allow_memory_growth. But I’m not sure whether there are performance issues for real case, because I still get the warning “USE_PTHREADS + ALLOW_MEMORY_GROWTH may run non-wasm code slowly, see https://github.com/WebAssembly/design/issues/1271”.

@dkurt Thanks for the input! I think the performance will be affected only when the pthread and allow_memory_growth are both enabled. With my investigation, the latest version of emscripten seems to enable pthread by default, which is also the root cause of this issue. Anyway, I will test the performance with my benchmark. I’m now working with opencv.js performance optimization. I will also test the performance if both pthread and allow_memory_growth are enabled.

@Santhosh-KS @lawsonfulton I change the flag here:

    def get_build_flags(self):
        flags = "-s WASM_MEM_MAX=512MB -s DEMANGLE_SUPPORT=0 "  # SEE HERE!!!!!!!
        if self.options.build_wasm:
            flags += "-s WASM=1 "
        elif self.options.disable_wasm:
            flags += "-s WASM=0 "
        if self.options.enable_exception:
            flags += "-s DISABLE_EXCEPTION_CATCHING=0 "
        return flags

But also get the error: shared:ERROR: invalid forced library: libc++abi