beatreichenbach / realflare

Physically-Based Lens Flare Tool
57 stars 3 forks source link

Failing to run on an Intel MacOS machine. #51

Closed alexfry closed 1 year ago

alexfry commented 1 year ago

Hey Beat

Just tried to get it running on an Intel Mac running Monterey. Running into some OpenCL errors.

Not sure if I'm running into a user error or a platform issue here?

Traceback (most recent call last):
  File "/Users/afry/.pyenv/versions/3.10.8/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/afry/.pyenv/versions/3.10.8/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/afry/.pyenv/versions/3.10.8/lib/python3.10/site-packages/flare/__main__.py", line 88, in <module>
    main()
  File "/Users/afry/.pyenv/versions/3.10.8/lib/python3.10/site-packages/flare/__main__.py", line 82, in main
    gui_app.exec_()
  File "/Users/afry/.pyenv/versions/3.10.8/lib/python3.10/site-packages/flare/gui/app.py", line 518, in exec_
    window = MainWindow()
  File "/Users/afry/.pyenv/versions/3.10.8/lib/python3.10/site-packages/flare/gui/app.py", line 55, in __init__
    self._init_engine()
  File "/Users/afry/.pyenv/versions/3.10.8/lib/python3.10/site-packages/flare/gui/app.py", line 64, in _init_engine
    self.engine = Engine()
  File "/Users/afry/.pyenv/versions/3.10.8/lib/python3.10/site-packages/flare/api/engine.py", line 42, in __init__
    self._init_tasks()
  File "/Users/afry/.pyenv/versions/3.10.8/lib/python3.10/site-packages/flare/api/engine.py", line 68, in _init_tasks
    self.starburst_task = StarburstTask(self.queue)
  File "/Users/afry/.pyenv/versions/3.10.8/lib/python3.10/site-packages/flare/api/tasks/starburst.py", line 26, in __init__
    self.build()
  File "/Users/afry/.pyenv/versions/3.10.8/lib/python3.10/site-packages/flare/api/tasks/opencl.py", line 180, in build
    self.program = cl.Program(self.context, self.source).build(*args, **kwargs)
  File "/Users/afry/.pyenv/versions/3.10.8/lib/python3.10/site-packages/pyopencl/__init__.py", line 532, in build
    self._prg, was_cached = self._build_and_catch_errors(
  File "/Users/afry/.pyenv/versions/3.10.8/lib/python3.10/site-packages/pyopencl/__init__.py", line 580, 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) Core(TM) i7-9750H CPU @ 2.60GHz' on 'Apple' at 0xffffffff>:

<program source>:1:11: error: global variables must have a constant address space qualifier
const int LAMBDA_MIN = 390;
          ^
<program source>:2:11: error: global variables must have a constant address space qualifier
const int LAMBDA_MAX = 700;
          ^
<program source>:3:11: error: global variables must have a constant address space qualifier
const int LAMBDA_MID = 545.0;
          ^

(options: -I /Users/afry/.pyenv/versions/3.10.8/lib/python3.10/site-packages/pyopencl/cl)
(source saved as /var/folders/vz/jp4x9bwx171cz6x6t1vnq214000jp5/T/tmpp7gtif4h.cl)
beatreichenbach commented 1 year ago

Thank you for the report, just some back story:

So the cool thing about OpenCL is that it can run on any CPU or GPU. However my code is definitely not build for CPU. The code architecture is expecting thousands of cores so it would probably be incredibly slow. It looks like on your end it tries to run on the CPU, which definitely is possible as I didn't built anything to check for / prefer the GPU. I'm just picking the first device available which in your case is a CPU.

Regarding your error, I need to replace const with __constant per https://stackoverflow.com/questions/27547974/what-is-a-constant-address-space-qualifier-in-opencl

Additionally I need to figure out a way to automatically choose the GPU / allow the user to select if multiple devices are available.

alexfry commented 1 year ago

Ahh brilliant!

Looking forward to trying it out, will have a play with it on my Windows box later.

beatreichenbach commented 1 year ago

I played around with different ways of exposing the available devices but since the tool doesn't even run on the CPU I figured it'd be best to just throw up an error about CPU's not being supported.

For now I'd say if you want to play around with it, try it on a machine that has a dedicated GPU and it should automatically pick that one. Unfortunately adding CPU support is a bit further down the road (but definitely doable and a big reason for choosing openCL).

alexfry commented 1 year ago

I should flag, this machine does have a dedicated GPU. Not a big one, but it is there, Radeon Pro 5500M 8GB.

I have however had some more success running it on a Windows 11 machine with an Nvidia GPU.

beatreichenbach commented 1 year ago

Great info! This means I still will have to figure out how to make it easy for the user to select a device. Thank you for the feedback :)

beatreichenbach commented 1 year ago

Added a new section "System" to manually select an opencl device. That section can later be used for memory management etc. You can find this feature in the latest release.

alexfry commented 1 year ago

Device selection works!

image

But flare rendering is still failing.

INFO:root:ApertureTask.run:                           0.166ms
INFO:root:StarburstTask.run:                          0.430ms
INFO:root:ApertureTask.run:                           0.133ms
INFO:root:GhostTask.run:                              0.013ms
ERROR:root:'NoneType' object has no attribute 'array'
Traceback (most recent call last):
  File "/Users/afry/.pyenv/versions/3.10.8/lib/python3.10/site-packages/realflare/api/engine.py", line 227, in render
    render_func(project)
  File "/Users/afry/.pyenv/versions/3.10.8/lib/python3.10/site-packages/realflare/api/engine.py", line 116, in flare
    path_indexes = self.preprocess_task.run(project.flare, project.render)
  File "/Users/afry/.pyenv/versions/3.10.8/lib/python3.10/site-packages/realflare/api/tasks/preprocessing.py", line 76, in run
    areas = self.update_areas(rays)
  File "/Users/afry/.pyenv/versions/3.10.8/lib/python3.10/site-packages/realflare/api/tasks/preprocessing.py", line 46, in update_areas
    path_count, wavelength_count, ray_count = rays.array.shape
AttributeError: 'NoneType' object has no attribute 'array'
INFO:root:Engine.render:                              9.101ms