Failure to detect GPU on macOS 10.12.4

This was originally posted on http://stackoverflow.com/questions/43790846/cuda-does-not-detect-gpu-on-macos-10-12-4. I’ll try to update both places if I find a solution.

I am running macOS Sierra 10.12.4 and trying to use Tensorflow with an NVIDIA GeForce GTX 980 GPU via CUDA.

I installed the latest version of everything:

macOS:             10.12.4
NVIDIA Web Driver: 10.17.34 (378.05.05.05f02)
CUDA Driver:       8.0.81
CUDA Toolkit:      8.0.61
Clang:             Apple LLVM version 8.0.0 (clang-800.0.42.1)

The GPU shows up in System Profiler just fine. The CUDA prefpane also shows the GPU as connected. (I know because when the GPU is disconnected, it tells me this.)

I set my environment variables:

export PATH="/Developer/NVIDIA/CUDA-8.0/bin${PATH:+:${PATH}}"
export DYLD_LIBRARY_PATH="/Developer/NVIDIA/CUDA-8.0/lib${DYLD_LIBRARY_PATH:+:${DYLD_LIBRARY_PATH}}"

Then I built the deviceQuery tool and ran it,

bin/x86_64/darwin/release/deviceQuery Starting...

CUDA Device Query (Runtime API) version (CUDART static linking)

cudaGetDeviceCount returned 35
-> CUDA driver version is insufficient for CUDA runtime version

As far as I know there is no CUDA Toolkit 8.0.81 release yet, so then I downgraded to version 8.0.61 of the driver, rebooted, and tried again:

bin/x86_64/darwin/release/deviceQuery Starting...

CUDA Device Query (Runtime API) version (CUDART static linking)

cudaGetDeviceCount returned 38
-> no CUDA-capable device is detected
Result = FAIL

I do not have the CUDA_VISIBLE_DEVICES environment variable set, as I’ve seen in some other answers, but setting it to 0, 1, or 2 doesn’t have any effect.

All of the CUDA libraries that deviceQuery loads seem to be the latest versions.

dyld: loaded: /usr/local/cuda/lib/libcuda.dylib
dyld: loaded: /Library/Frameworks/CUDA.framework/Versions/A/CUDA
dyld: loaded: /Library/Frameworks/CUDA.framework/Versions/A/Libraries/libcuda_378.05.05.05_mercury.dylib
dyld: loaded: /Library/Frameworks/CUDA.framework/Versions/A/Libraries/libfatbinaryLoader.dylib
dyld: loaded: /Library/Frameworks/CUDA.framework/Versions/A/Libraries/libptxJitCompiler.dylib