OpenCL on Apple M1

I’ve got Cycles Metal working on my M1 Max (32 core). It’s rather impressive as well.

I built Blender from source on my MBP15 i9 with VEGA 20 dGPU and applied the diff for the unreviewed patch. That gave me an X86 build of Blender that showed the Metal GPU options on the Intel Mac but alas didn’t render (kernel internal error).

I then tried to set the ARM flag to compile again but that didn’t work.

So as a last ditch I took the built X86 version over to my M1 Max and low and behold it renders on the GPU.

BMW in 43 seconds on the 32 core GPU - so not 30% faster than the 24 core version but it is an X86 build.

However, every scene I tried the live viewport performance is rather wonderful.

I’d never built Blender from source until today. I’ll keep this build now to play with until the proper one lands.

The only slightly difficult bit was getting the new patch added, which I did like this:
patch -p1 < ~/Developer/D13423.diff [downloaded the RAW file from the Dev site]

Then ran make again and that was it basically.

7 Likes

Wow, this is rather amazing. It means that the feature is pretty darn close.
Here’s crossing fingers that the AMD Macs do get a fully featured pass too (i.e. MetalRT and all the Metal crunchies)

Certainly does. I read the diffs yesterday and the code committed seemed total genius and I couldn’t but help think… this looks like it might be very close indeed.

3 Likes

Absolutely can’t wait to have Metal support!

3 Likes

Trying to compile it with the patch applied but I keep getting errors any ideas why ?


You need to set WITH_METAL compile flag

not sure I understand, I think I managed to add it to “make config” and it is on, but still does not work.

Yes i thought i found the easy fix … Sorry for giving you hope … it also not workng for me .

No worries, I guess we will just have to wait.

Yes Christmas is coming :wink:

1 Like

I just tested the refactored patch and it still works, after some fiddling. So for the impatient people, here is a small guide to build it.

  1. Download the latest revision off the .diff-file (in Safari by right-clicking, otherwise the patch can get defective).
  2. in the terminal apply the patch, like so (including a successful output message):
bash-3.2$ patch -p1 <  ~/Downloads/D13423 
patching file intern/cycles/blender/CMakeLists.txt
patching file intern/cycles/blender/addon/engine.py
patching file intern/cycles/blender/addon/properties.py
patching file intern/cycles/blender/addon/ui.py
patching file intern/cycles/blender/device.cpp
patching file intern/cycles/blender/python.cpp
patching file intern/cycles/bvh/CMakeLists.txt
patching file intern/cycles/bvh/bvh.cpp
patching file intern/cycles/bvh/metal.h
patching file intern/cycles/bvh/metal.mm
patching file intern/cycles/cmake/external_libs.cmake
patching file intern/cycles/device/CMakeLists.txt
patching file intern/cycles/device/device.h
patching file intern/cycles/device/device.cpp
patching file intern/cycles/device/memory.h
patching file intern/cycles/device/metal/bvh.h
patching file intern/cycles/device/metal/bvh.mm
patching file intern/cycles/device/metal/device.h
patching file intern/cycles/device/metal/device.mm
patching file intern/cycles/device/metal/device_impl.h
patching file intern/cycles/device/metal/device_impl.mm
patching file intern/cycles/device/metal/kernel.h
patching file intern/cycles/device/metal/kernel.mm
patching file intern/cycles/device/metal/queue.h
patching file intern/cycles/device/metal/queue.mm
patching file intern/cycles/device/metal/util.h
patching file intern/cycles/device/metal/util.mm
patching file intern/cycles/device/multi/device.cpp
patching file intern/cycles/kernel/device/gpu/kernel.h
patching file intern/cycles/util/math.h
patching file intern/cycles/util/path.h
patching file intern/cycles/util/path.cpp
  1. In blender/CMakeLists.txt add i.e. after the CUDA/OPTIX-section:
if(APPLE)
option(WITH_CYCLES_DEVICE_METAL       "Enable Cycles APPLE METAL compute support" ON)
endif()
  1. In blender/release/scripts/startup/bl_ui/space_userpref.py

Search and delete:
and sys.platform != "darwin"

  1. In blender/cycles/CMakeList.txt add somewhere:
if(WITH_CYCLES_DEVICE_METAL)
  add_definitions(-DWITH_METAL)
endif()

I hope, this post will get obsolete soon and we will see it in the main repo. It looks really good to me.

7 Likes

that mod works before it keeping crashing when trying to render thanks :blush:

Great guide Staars thank you for posting. That is exactly what I did except for No 5. I’m actually skeptical No 4 is necessary as I tried it both ways and it worked for both!

The guide certainly works on the X86 build for me and when run under Rosetta 2 on M1 Max GPU rendering works.

I had a really good attempt at getting the ARM native version to build and ultimately failed but I got close. All of those errors Steve-Hanff are from the ARM build as I saw them on that build.

I managed to get the ARM Darwin Libs to download and set the CMake arch to arm64 and it gets so far into the build but still fails. I only tried building using an i9 Intel chip which definitely can compile for ARM.

There is a bug in 3.1 (even the daily X86 and ARM builds) where you can’t select anything reliably in the viewport. If I spot the viewport object selection bug being fixed in the 3.1 master I’ll re-compile again but hopefully by then the Metal patches will have also landed in the daily anyway.

3 Likes

Just followed the entire thread on the blenderArtists forum! The work you guys have done is amazing! Thanks for getting some numbers out so I do some preliminary testing on my current system and benchmark against it :wink: (GTX 1660 Super, Ryzen 5 3600, 32GB RAM).
Will post my results here shortly :slight_smile:

I’m back.
GTX 1660 Super, BMW27.
Blender 3.0.
40s

For further feedback on Metal, let’s use this new topic:

3 Likes

According to Apple, the M1 has the fastest integrated graphics in a personal computer. Graphics performance tests have suggested the M1 chip offers performance that exceeds the GeForce GTX 1050 Ti and Radeon RX 560. It also earned an OpenCL score of 19305, similar to the Radeon RX 560X and Radeon Pro WX 4100.

Is anyone still using Open CL? Apple doesn’t even keep this API current. I mean Blender doesn’t even support Open CL anymore.

It’s better to use Metal benchmarks to compare against cards that also support Metal. Since most people are using Macs to run programs that are Metal compliant and slowly native ARM, like Blender.

Metal score for the M1 Max scores are around 69000 which put it in the same league as the desktop
RX 5700XT
Radeon VII
Pro Vegas 56

1 Like

Sorry for being completely off topic and restarting this thread but I have been flailing around in a foreign area for a while, hoping someone who understands OpenCL, GPU details can help.

@Staars Wondering if you could point me in the right direction to get OpenCL working for my M1 MacBook?

I am trying to do what you did above except for darktable, which will likely never get a Metal port from Apple. Thx for any help.

I can not really help here that much.
What I did was basically to revert all commits, that deactivated OpenCL for Cycles in MacOS. This was relatively easy, as all the needed code had been there before. I did not add anything new nor a single line of OpenCL specific code.

You may succeed by digging in the code and find the places, where OpenCL is selectively turned off for for MacOS in the functions you want to checkout.

But I do not recommend to spend much time with it. It is very well possible to not even beat the CPU-only variant and every MacOS update may break it.
(BTW to be off topic too: I see massive performance losses in the Ventura betas in Cycles on my Vega56. Let‘s hope there is still a lot of debug code in it.)