ufo-kit / syris

X-ray imaging simulation
GNU Lesser General Public License v3.0
32 stars 19 forks source link

Can't run Syris on macOS 11.1 #11

Closed kaminetzky closed 3 years ago

kaminetzky commented 3 years ago

Hello there!

I'm having issues running Syris on macOS Big Sur 11.1 and Python 3.9.4.

After installing PyOpenCL, this simple example works properly. However, when running python -m examples.simple I get the following error:

2021-04-27 19:22:07,493 - syris.gpu.util - ERROR - Platform None not found, using first one which can be found
/Users/ak/Documents/Universidad/Magíster/Code/syris/venv/lib/python3.9/site-packages/pyopencl/__init__.py:230: CompilerWarning: Non-empty compiler output encountered. Set the environment variable PYOPENCL_COMPILER_OUTPUT=1 to see more.
  warn("Non-empty compiler output encountered. Set the "
/Users/ak/Documents/Universidad/Magíster/Code/syris/venv/lib/python3.9/site-packages/pyopencl/cache.py:491: UserWarning: PyOpenCL compiler caching failed with an exception:
[begin exception]
Traceback (most recent call last):
  File "/Users/ak/Documents/Universidad/Magíster/Code/syris/venv/lib/python3.9/site-packages/pyopencl/cache.py", line 474, in create_built_program_from_source_cached
    _create_built_program_from_source_cached(
  File "/Users/ak/Documents/Universidad/Magíster/Code/syris/venv/lib/python3.9/site-packages/pyopencl/cache.py", line 421, in _create_built_program_from_source_cached
    result = _cl._Program(ctx, devices, binaries)
pyopencl._cl.LogicError: clCreateProgramWithBinary failed: INVALID_VALUE
[end exception]
  warn("PyOpenCL compiler caching failed with an exception:\n"
Traceback (most recent call last):
  File "/Users/ak/Documents/Universidad/Magíster/Code/syris/venv/lib/python3.9/site-packages/pyopencl/tools.py", line 97, in first_arg_dependent_memoize
    return ctx_dict[cl_object][args]
KeyError: <pyopencl.Context at 0x7ffd810d57f0 on <pyopencl.Device 'Intel(R) HD Graphics 530' on 'Apple' at 0x1024500>, <pyopencl.Device 'AMD Radeon Pro 460 Compute Engine' on 'Apple' at 0x1021c00>, <pyopencl.Device 'Intel(R) Core(TM) i7-6920HQ CPU @ 2.90GHz' on 'Apple' at 0xffffffff>>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/ak/Documents/Universidad/Magíster/Code/syris/examples/simple.py", line 28, in <module>
    main()
  File "/Users/ak/Documents/Universidad/Magíster/Code/syris/examples/simple.py", line 21, in main
    image = propagate([sample], (n, n), energies, distance, pixel_size).get()
  File "/Users/ak/Documents/Universidad/Magíster/Code/syris/syris/physics.py", line 267, in propagate
    u.fill(0)
  File "/Users/ak/Documents/Universidad/Magíster/Code/syris/venv/lib/python3.9/site-packages/pyopencl/array.py", line 1204, in fill
    self._fill(self, value, queue=queue, wait_for=wait_for))
  File "/Users/ak/Documents/Universidad/Magíster/Code/syris/venv/lib/python3.9/site-packages/pyopencl/array.py", line 139, in kernel_runner
    knl = kernel_getter(*args, **kwargs)
  File "/Users/ak/Documents/Universidad/Magíster/Code/syris/venv/lib/python3.9/site-packages/pyopencl/array.py", line 790, in _fill
    return elementwise.get_fill_kernel(result.context, result.dtype)
  File "/Users/ak/Documents/Universidad/Magíster/Code/syris/venv/lib/python3.9/site-packages/decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
  File "/Users/ak/Documents/Universidad/Magíster/Code/syris/venv/lib/python3.9/site-packages/pyopencl/tools.py", line 100, in first_arg_dependent_memoize
    result = func(cl_object, *args)
  File "/Users/ak/Documents/Universidad/Magíster/Code/syris/venv/lib/python3.9/site-packages/pyopencl/elementwise.py", line 707, in get_fill_kernel
    return get_elwise_kernel(context,
  File "/Users/ak/Documents/Universidad/Magíster/Code/syris/venv/lib/python3.9/site-packages/pyopencl/elementwise.py", line 176, in get_elwise_kernel
    func, arguments = get_elwise_kernel_and_types(
  File "/Users/ak/Documents/Universidad/Magíster/Code/syris/venv/lib/python3.9/site-packages/pyopencl/elementwise.py", line 158, in get_elwise_kernel_and_types
    prg = get_elwise_program(
  File "/Users/ak/Documents/Universidad/Magíster/Code/syris/venv/lib/python3.9/site-packages/pyopencl/elementwise.py", line 111, in get_elwise_program
    return Program(context, source).build(options)
  File "/Users/ak/Documents/Universidad/Magíster/Code/syris/venv/lib/python3.9/site-packages/pyopencl/__init__.py", line 503, in build
    self._prg, was_cached = self._build_and_catch_errors(
  File "/Users/ak/Documents/Universidad/Magíster/Code/syris/venv/lib/python3.9/site-packages/pyopencl/__init__.py", line 551, in _build_and_catch_errors
    raise err
pyopencl._cl.RuntimeError: clBuildProgram failed: BUILD_PROGRAM_FAILURE - clBuildProgram failed: BUILD_PROGRAM_FAILURE - clBuildProgram failed: BUILD_PROGRAM_FAILURE

Build on <pyopencl.Device 'Intel(R) HD Graphics 530' on 'Apple' at 0x1024500>:

<program source>:2:18: fatal error: 'pyopencl-complex.h' file not found
        #include <pyopencl-complex.h>
                 ^
===========================================================================
Build on <pyopencl.Device 'AMD Radeon Pro 460 Compute Engine' on 'Apple' at 0x1021c00>:

<program source>:4:18: fatal error: 'pyopencl-complex.h' file not found
        #include <pyopencl-complex.h>
                 ^
===========================================================================
Build on <pyopencl.Device 'Intel(R) Core(TM) i7-6920HQ CPU @ 2.90GHz' on 'Apple' at 0xffffffff>:

<program source>:2:18: fatal error: 'pyopencl-complex.h' file not found
        #include <pyopencl-complex.h>
                 ^

(options: -I /Users/ak/Documents/Universidad/Magíster/Code/syris/venv/lib/python3.9/site-packages/pyopencl/cl)
(source saved as /var/folders/9v/jxm3fqpd7qg0sc8hrq1hpg9c0000gn/T/tmprye8tugv.cl)

I've spent hours trying to find a solution but have had no luck. Any idea on what could be going on?

Cheers! Alex

tfarago commented 3 years ago

I think I will just disable the support of other than NVIDIA platform for now, for which it has been developed. Various implementations omit various parts of the standard and then you get similar errors. I strongly advise to use an NVIDIA GPU because to make things run really cross-HW-platform will be tricky.

kaminetzky commented 3 years ago

Hey Tomas!

That's what I thought. Looks like macOS hasn't supported OpenCL for a while. Do you know if it's possible to run Syris on my CPU? Maybe that way it could work.

By the way, I ran your code on Google Colab and everything went great. ;)

tfarago commented 3 years ago

I think the problem is not mac but the opencl installation. If you stick an nvidia vard in your mac and install cuda chances are it will work.

kaminetzky commented 3 years ago

Alright. Thanks!

kaminetzky commented 3 years ago

I tried installing it with conda and it worked. :)