@@ -22,24 +22,37 @@ if (BUILD_VECTOR_LIB AND BUILD_VECTOR_XLA_LIB)
2222 )
2323 message (STATUS "XLA include directory: '${XLA_DIR} '" )
2424
25- # Find CUDA toolkit for headers and linking (optional - XLA disabled if not found)
25+ # CUDA toolkit is optional: when found we additionally compile/link the GPU
26+ # handlers, otherwise XLA is built with CPU-only support (e.g. macOS).
2627 find_package (CUDAToolkit QUIET )
2728
29+ # Always build the CPU XLA handlers. The GPU handlers in
30+ # ale_vector_xla_interface.cpp are guarded by BUILD_VECTOR_XLA_GPU, which is
31+ # only defined below when the CUDA Toolkit is found, so they are naturally
32+ # skipped when CUDA is unavailable (e.g. macOS).
33+ target_sources (_ale_py PRIVATE ale_vector_python_interface.cpp ale_vector_xla_interface.cpp )
34+ target_include_directories (_ale_py PUBLIC ${XLA_DIR} )
35+ target_compile_definitions (_ale_py PRIVATE BUILD_VECTOR_LIB BUILD_VECTOR_XLA_LIB )
36+ set_target_properties (_ale_py PROPERTIES
37+ POSITION_INDEPENDENT_CODE ON
38+ )
39+
2840 if (CUDAToolkit_FOUND)
29- message (STATUS "CUDA Toolkit found: ${CUDAToolkit_VERSION} " )
30- target_sources ( _ale_py PRIVATE ale_vector_python_interface.cpp ale_vector_xla_interface.cpp )
31- target_include_directories ( _ale_py PUBLIC ${XLA_DIR} )
41+ message (STATUS "CUDA Toolkit found: ${CUDAToolkit_VERSION} - enabling GPU XLA support " )
42+ # The GPU handlers only use the CUDA runtime API (no device kernels), so
43+ # the host compiler can build them given the CUDA headers and cudart.
3244 target_include_directories (_ale_py PRIVATE ${CUDAToolkit_INCLUDE_DIRS} )
33- target_compile_definitions (_ale_py PRIVATE BUILD_VECTOR_LIB BUILD_VECTOR_XLA_LIB )
34- target_link_libraries (_ale_py PRIVATE CUDA::cudart )
35-
36- set_target_properties (_ale_py PROPERTIES
37- POSITION_INDEPENDENT_CODE ON
38- )
45+ target_compile_definitions (_ale_py PRIVATE BUILD_VECTOR_XLA_GPU )
46+ if (WIN32 )
47+ # Static linking bakes cudart into _ale_py.pyd so there is no runtime DLL to find.
48+ target_link_libraries (_ale_py PRIVATE CUDA::cudart_static )
49+ else ()
50+ # The loader resolves libcudart via the toolkit's lib path / the manylinux image, and
51+ # jax already loads the same runtime in-process, so there is no missing-library issue.
52+ target_link_libraries (_ale_py PRIVATE CUDA::cudart )
53+ endif ()
3954 else ()
40- message (WARNING "CUDA Toolkit not found - disabling XLA support. Install CUDA Toolkit to enable XLA." )
41- target_sources (_ale_py PRIVATE ale_vector_python_interface.cpp )
42- target_compile_definitions (_ale_py PRIVATE BUILD_VECTOR_LIB )
55+ message (STATUS "CUDA Toolkit not found - building CPU-only XLA support" )
4356 endif ()
4457elseif (BUILD_VECTOR_LIB)
4558 target_sources (_ale_py PRIVATE ale_vector_python_interface.cpp )
0 commit comments