ndtatbristol / arim

A Python library for array imaging in ultrasonic testing.
MIT License
25 stars 13 forks source link

Arim das.py is not adaptable for 32-bit raspbian system #12

Closed ultrasunix closed 1 year ago

ultrasunix commented 1 year ago

There is a @numba:jit function which cannot be adaptable for 32 bit raspbian system (Linux) due to the 'parallel=True' option. There are several places of this issue in the das.py script.

Traceback (most recent call last):
  File "/home/pi/arim/arim-master/examples/contact_tfm.py", line 70, in <module>
    tfm = arim.im.tfm.contact_tfm(frame, grid, speed)
  File "/home/pi/.local/lib/python3.7/site-packages/arim/im/tfm.py", line 331, in contact_tfm
    res = das.delay_and_sum(frame, focal_law, **kwargs_delay_and_sum)
  File "/home/pi/.local/lib/python3.7/site-packages/arim/im/das.py", line 940, in delay_and_sum
    return delay_and_sum_numba_noamp(frame, focal_law, *args, **kwargs)
  File "/home/pi/.local/lib/python3.7/site-packages/arim/im/das.py", line 463, in delay_and_sum_numba_noamp
    result
  File "/home/pi/.local/lib/python3.7/site-packages/numba/core/dispatcher.py", line 487, in _compile_for_args
    raise e
  File "/home/pi/.local/lib/python3.7/site-packages/numba/core/dispatcher.py", line 420, in _compile_for_args
    return_val = self.compile(tuple(argtypes))
  File "/home/pi/.local/lib/python3.7/site-packages/numba/core/dispatcher.py", line 965, in compile
    cres = self._compiler.compile(args, return_type)
  File "/home/pi/.local/lib/python3.7/site-packages/numba/core/dispatcher.py", line 125, in compile
    status, retval = self._compile_cached(args, return_type)
  File "/home/pi/.local/lib/python3.7/site-packages/numba/core/dispatcher.py", line 139, in _compile_cached
    retval = self._compile_core(args, return_type)
  File "/home/pi/.local/lib/python3.7/site-packages/numba/core/dispatcher.py", line 157, in _compile_core
    pipeline_class=self.pipeline_class)
  File "/home/pi/.local/lib/python3.7/site-packages/numba/core/compiler.py", line 716, in compile_extra
    return pipeline.compile_extra(func)
  File "/home/pi/.local/lib/python3.7/site-packages/numba/core/compiler.py", line 452, in compile_extra
    return self._compile_bytecode()
  File "/home/pi/.local/lib/python3.7/site-packages/numba/core/compiler.py", line 520, in _compile_bytecode
    return self._compile_core()
  File "/home/pi/.local/lib/python3.7/site-packages/numba/core/compiler.py", line 499, in _compile_core
    raise e
  File "/home/pi/.local/lib/python3.7/site-packages/numba/core/compiler.py", line 486, in _compile_core
    pm.run(self.state)
  File "/home/pi/.local/lib/python3.7/site-packages/numba/core/compiler_machinery.py", line 368, in run
    raise patched_exception
  File "/home/pi/.local/lib/python3.7/site-packages/numba/core/compiler_machinery.py", line 356, in run
    self._runPass(idx, pass_inst, state)
  File "/home/pi/.local/lib/python3.7/site-packages/numba/core/compiler_lock.py", line 35, in _acquire_compile_lock
    return func(*args, **kwargs)
  File "/home/pi/.local/lib/python3.7/site-packages/numba/core/compiler_machinery.py", line 311, in _runPass
    mutated |= check(pss.run_pass, internal_state)
  File "/home/pi/.local/lib/python3.7/site-packages/numba/core/compiler_machinery.py", line 273, in check
    mangled = func(compiler_state)
  File "/home/pi/.local/lib/python3.7/site-packages/numba/core/typed_passes.py", line 394, in run_pass
    lower.lower()
  File "/home/pi/.local/lib/python3.7/site-packages/numba/core/lowering.py", line 168, in lower
    self.lower_normal_function(self.fndesc)
  File "/home/pi/.local/lib/python3.7/site-packages/numba/core/lowering.py", line 222, in lower_normal_function
    entry_block_tail = self.lower_function_body()
  File "/home/pi/.local/lib/python3.7/site-packages/numba/core/lowering.py", line 251, in lower_function_body
    self.lower_block(block)
  File "/home/pi/.local/lib/python3.7/site-packages/numba/core/lowering.py", line 265, in lower_block
    self.lower_inst(inst)
  File "/home/pi/.local/lib/python3.7/site-packages/numba/core/lowering.py", line 567, in lower_inst
    func(self, inst)
  File "/home/pi/.local/lib/python3.7/site-packages/numba/parfors/parfor_lowering.py", line 58, in _lower_parfor_parallel
    ensure_parallel_support()
  File "/home/pi/.local/lib/python3.7/site-packages/numba/parfors/parfor.py", line 5016, in ensure_parallel_support
    raise errors.UnsupportedParforsError(msg)
numba.core.errors.UnsupportedParforsError: Failed in nopython mode pipeline (step: native lowering)
The 'parallel' target is not currently supported on 32 bit hardware.


During: lowering "id=0[LoopNest(index_variable = parfor_index.22, range = (0, $numpoints.27, 1))]{130: <ir.Block at /home/pi/.local/lib/python3.7/site-packages/arim/im/das.py (497)>, 164: <ir.Block at /home/pi/.local/lib/python3.7/site-packages/arim/im/das.py (497)>, 36: <ir.Block at /home/pi/.local/lib/python3.7/site-packages/arim/im/das.py (485)>, 112: <ir.Block at /home/pi/.local/lib/python3.7/site-packages/arim/im/das.py (494)>, 148: <ir.Block at /home/pi/.local/lib/python3.7/site-packages/arim/im/das.py (488)>, 52: <ir.Block at /home/pi/.local/lib/python3.7/site-packages/arim/im/das.py (488)>, 54: <ir.Block at /home/pi/.local/lib/python3.7/site-packages/arim/im/das.py (488)>, 120: <ir.Block at /home/pi/.local/lib/python3.7/site-packages/arim/im/das.py (495)>}Var(parfor_index.22, das.py:485)" at /home/pi/.local/lib/python3.7/site-packages/arim/im/das.py (485)
mgchandler commented 1 year ago

It looks as though this is the same problem, as it has a 32-bit OS installed on 64-bit hardware, and they report no obvious solution to the problem. https://github.com/numba/numba/issues/9027

nbud commented 1 year ago

Does it work when using parallel=False? If so, we could rely on an environment variable (ARIM_USE_PARALLEL or similar) to override the value of parallel. If the environment variable if not set, the default would be True.

Edit: by any chance, does setting the environment variable NUMBA_NUM_THREADS=1 fix the issue on raspberry?

mgchandler commented 1 year ago

Setting the NUMBA_NUM_THREADS environment variable doesn't work unfortunately. I think setting our own environment variable route would work, as setting parallel=False does work. The ensure_parallel_support() function which is causes the error relies on numba.core.config.IS_32BITS, which we could use.

nbud commented 1 year ago

Fixed by #13