Skip to content

Commit 720ab81

Browse files
committed
GPU CMake: enable the Metal backend by default where the toolchain supports it
ENABLE_METAL defaults to AUTO like the other backends: it is used when the Metal toolchain compiles MSL 4.1 (macOS 27) and silently skipped otherwise. Notice that in any case by default we use the CPU, even when Metal is available.
1 parent 34e1c54 commit 720ab81

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

‎dependencies/FindO2GPU.cmake‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# or submit itself to any jurisdiction.
1111

1212
# NOTE!!!! - Whenever this file is changed, move it over to alidist/resources
13-
# FindO2GPU.cmake Version 23
13+
# FindO2GPU.cmake Version 25
1414

1515
set(CUDA_COMPUTETARGET_DEFAULT_FULL 80-real;86-real;89-real;120-real;75-virtual)
1616
set(HIP_AMDGPUTARGET_DEFAULT_FULL gfx906;gfx908)
@@ -21,8 +21,7 @@ if(NOT DEFINED ENABLE_CUDA)
2121
set(ENABLE_CUDA "AUTO")
2222
endif()
2323
if(NOT DEFINED ENABLE_METAL)
24-
# OFF rather than AUTO while the backend is unproven
25-
set(ENABLE_METAL "OFF")
24+
set(ENABLE_METAL "AUTO")
2625
endif()
2726
if(NOT DEFINED ENABLE_OPENCL)
2827
set(ENABLE_OPENCL "AUTO")
@@ -467,15 +466,14 @@ if(ENABLE_METAL)
467466
# The frameworks are there on every macOS, but the backend needs MSL 4.1, which
468467
# is macOS 27 and its toolchain, so ask the compiler instead of assuming. A
469468
# library built as MSL 4.1 also only loads on macOS 27 and later.
470-
if(NOT DEFINED GPUCA_METAL_MSL41)
469+
# Only a success is cached, so that installing the toolchain is picked up.
470+
if(NOT GPUCA_METAL_MSL41)
471471
set(GPUCA_METAL_PROBE "${CMAKE_CURRENT_BINARY_DIR}/metal_msl41_probe.metal")
472472
file(WRITE "${GPUCA_METAL_PROBE}" "#include <metal_stdlib>\nkernel void probe(device float* o [[buffer(0)]], uint i [[thread_position_in_grid]]) { o[i] = o[i] * 2.0f; }\n")
473473
execute_process(COMMAND xcrun -sdk macosx metal -std=metal4.1 -c "${GPUCA_METAL_PROBE}" -o "${GPUCA_METAL_PROBE}.air"
474-
RESULT_VARIABLE GPUCA_METAL_PROBE_RESULT OUTPUT_QUIET ERROR_QUIET)
474+
RESULT_VARIABLE GPUCA_METAL_PROBE_RESULT OUTPUT_QUIET ERROR_VARIABLE GPUCA_METAL_PROBE_ERROR)
475475
if(GPUCA_METAL_PROBE_RESULT EQUAL 0)
476476
set(GPUCA_METAL_MSL41 ON CACHE INTERNAL "Metal toolchain compiles MSL 4.1")
477-
else()
478-
set(GPUCA_METAL_MSL41 OFF CACHE INTERNAL "Metal toolchain compiles MSL 4.1")
479477
endif()
480478
endif()
481479
if(METAL_FRAMEWORK AND COREFOUNDATION_FRAMEWORK AND FOUNDATION_FRAMEWORK AND QUARTZCORE_FRAMEWORK AND GPUCA_METAL_MSL41)
@@ -487,8 +485,9 @@ if(ENABLE_METAL)
487485
if(NOT METAL_FRAMEWORK OR NOT COREFOUNDATION_FRAMEWORK OR NOT FOUNDATION_FRAMEWORK OR NOT QUARTZCORE_FRAMEWORK)
488486
message(FATAL_ERROR "Metal frameworks not available")
489487
endif()
490-
message(FATAL_ERROR "The Metal backend needs MSL 4.1: this toolchain rejects -std=metal4.1, and the result would need macOS 27 to run")
488+
message(FATAL_ERROR "The Metal backend needs MSL 4.1: this toolchain rejects -std=metal4.1, and the result would need macOS 27 to run\n${GPUCA_METAL_PROBE_ERROR}")
491489
else()
490+
message(STATUS "Metal backend disabled, the toolchain does not compile MSL 4.1: ${GPUCA_METAL_PROBE_ERROR}")
492491
set(METAL_ENABLED OFF)
493492
endif()
494493
endif()

0 commit comments

Comments
 (0)