@@ -72,71 +72,77 @@ if (GGML_SYCL_GRAPH)
7272 target_compile_definitions (ggml-sycl PRIVATE GGML_SYCL_GRAPH)
7373endif ()
7474
75- find_package (oneMath QUIET )
76- if (NOT oneMath_FOUND)
77- message ("-- oneMath not found: oneMath will be automatically downloaded" )
78- # Use FetchContent to automatically pull and build oneMath
79- include (FetchContent)
80- set (BUILD_FUNCTIONAL_TESTS False )
81- set (BUILD_EXAMPLES False )
82- set (TARGET_DOMAINS blas)
75+ # Link against Intel oneMKL or oneMath
76+ if (GGML_SYCL_TARGET STREQUAL "INTEL" )
77+ # Intel devices use Intel oneMKL directly instead of oneMath to avoid the limitation of linking Intel oneMKL statically
78+ # See https://github.com/uxlfoundation/oneMath/issues/654
79+ find_package (MKL REQUIRED)
80+ target_link_libraries (ggml-sycl PRIVATE MKL::MKL MKL::MKL_SYCL)
81+ target_compile_definitions (ggml-sycl PRIVATE GGML_SYCL_USE_INTEL_ONEMKL)
82+ else ()
83+ find_package (oneMath QUIET )
84+ if (NOT oneMath_FOUND)
85+ message ("-- oneMath not found: oneMath will be automatically downloaded" )
86+ # Use FetchContent to automatically pull and build oneMath
87+ include (FetchContent)
88+ set (BUILD_FUNCTIONAL_TESTS False )
89+ set (BUILD_EXAMPLES False )
90+ set (TARGET_DOMAINS blas)
91+ if (GGML_SYCL_TARGET STREQUAL "NVIDIA" )
92+ set (ENABLE_MKLCPU_BACKEND False )
93+ set (ENABLE_MKLGPU_BACKEND False )
94+ set (ENABLE_CUBLAS_BACKEND True )
95+ elseif (GGML_SYCL_TARGET STREQUAL "AMD" )
96+ set (ENABLE_MKLCPU_BACKEND False )
97+ set (ENABLE_MKLGPU_BACKEND False )
98+ set (ENABLE_ROCBLAS_BACKEND True )
99+ # Ensure setting a string variable here is not overriden by oneMath CACHE variables
100+ cmake_policy (SET CMP0126 NEW)
101+ # Setting the device architecture is only needed and useful for AMD devices in oneMath
102+ set (HIP_TARGETS ${GGML_SYCL_DEVICE_ARCH} CACHE STRING "oneMath HIP target" FORCE)
103+ endif ()
104+ FetchContent_Declare(
105+ ONEMATH
106+ GIT_REPOSITORY https://github.com/uxlfoundation/oneMath.git
107+ GIT_TAG c255b1b4c41e2ee3059455c1f96a965d6a62568a
108+ )
109+ FetchContent_MakeAvailable(ONEMATH)
110+ # Create alias to match with find_package targets name
111+ function (onemath_alias target )
112+ if (TARGET ${target} _obj)
113+ # Silence verbose warnings from external libraries
114+ target_compile_options (${target} _obj PRIVATE -w)
115+ endif ()
116+ if (TARGET ${target} )
117+ add_library (ONEMATH::${target} ALIAS ${target} )
118+ endif ()
119+ endfunction ()
120+ onemath_alias(onemath)
121+ onemath_alias(onemath_blas_mklcpu)
122+ onemath_alias(onemath_blas_mklgpu)
123+ onemath_alias(onemath_blas_cublas)
124+ onemath_alias(onemath_blas_rocblas)
125+ endif ()
126+
127+ # Below oneMath compile-time dispatching is used for better performance
83128 if (GGML_SYCL_TARGET STREQUAL "NVIDIA" )
84- set (ENABLE_MKLCPU_BACKEND False )
85- set (ENABLE_MKLGPU_BACKEND False )
86- set (ENABLE_CUBLAS_BACKEND True )
129+ target_link_libraries (ggml-sycl PRIVATE ONEMATH::onemath_blas_cublas)
130+ target_compile_options (ggml-sycl PRIVATE "-fsycl-targets=nvptx64-nvidia-cuda" )
131+ target_link_options (ggml-sycl PRIVATE "-fsycl-targets=nvptx64-nvidia-cuda" )
132+ target_compile_definitions (ggml-sycl PRIVATE GGML_SYCL_NVIDIA)
87133 elseif (GGML_SYCL_TARGET STREQUAL "AMD" )
88- set (ENABLE_MKLCPU_BACKEND False )
89- set (ENABLE_MKLGPU_BACKEND False )
90- set (ENABLE_ROCBLAS_BACKEND True )
91- # Ensure setting a string variable here is not overriden by oneMath CACHE variables
92- cmake_policy (SET CMP0126 NEW)
93- # Setting the device architecture is only needed and useful for AMD devices in oneMath
94- set (HIP_TARGETS ${GGML_SYCL_DEVICE_ARCH} CACHE STRING "oneMath HIP target" FORCE)
95- endif ()
96- FetchContent_Declare(
97- ONEMATH
98- GIT_REPOSITORY https://github.com/uxlfoundation/oneMath.git
99- GIT_TAG c255b1b4c41e2ee3059455c1f96a965d6a62568a
100- )
101- FetchContent_MakeAvailable(ONEMATH)
102- # Create alias to match with find_package targets name
103- function (onemath_alias target )
104- if (TARGET ${target} _obj)
105- # Silence verbose warnings from external libraries
106- target_compile_options (${target} _obj PRIVATE -w)
134+ if (NOT GGML_SYCL_DEVICE_ARCH)
135+ message (ERROR "Can't enable SYCL hip backend, GGML_SYCL_DEVICE_ARCH has not been set." )
107136 endif ()
108- if (TARGET ${target} )
109- add_library (ONEMATH::${target} ALIAS ${target} )
110- endif ()
111- endfunction ()
112- onemath_alias(onemath)
113- onemath_alias(onemath_blas_mklcpu)
114- onemath_alias(onemath_blas_mklgpu)
115- onemath_alias(onemath_blas_cublas)
116- onemath_alias(onemath_blas_rocblas)
117- endif ()
118-
119- # Below oneMath compile-time dispatching is used for better performance
120- if (GGML_SYCL_TARGET STREQUAL "INTEL" )
121- target_link_libraries (ggml-sycl PRIVATE ONEMATH::onemath_blas_mklgpu)
122- target_compile_definitions (ggml-sycl PRIVATE GGML_SYCL_INTEL)
123- elseif (GGML_SYCL_TARGET STREQUAL "NVIDIA" )
124- target_link_libraries (ggml-sycl PRIVATE ONEMATH::onemath_blas_cublas)
125- target_compile_options (ggml-sycl PRIVATE "-fsycl-targets=nvptx64-nvidia-cuda" )
126- target_link_options (ggml-sycl PRIVATE "-fsycl-targets=nvptx64-nvidia-cuda" )
127- target_compile_definitions (ggml-sycl PRIVATE GGML_SYCL_NVIDIA)
128- elseif (GGML_SYCL_TARGET STREQUAL "AMD" )
129- if (NOT GGML_SYCL_DEVICE_ARCH)
130- message (ERROR "Can't enable SYCL hip backend, GGML_SYCL_DEVICE_ARCH has not been set." )
137+ target_link_libraries (ggml-sycl PRIVATE ONEMATH::onemath_blas_rocblas)
138+ target_compile_options (ggml-sycl PRIVATE "-fsycl-targets=amdgcn-amd-amdhsa" )
139+ target_link_options (ggml-sycl PRIVATE "-fsycl-targets=amdgcn-amd-amdhsa" )
140+ target_compile_definitions (ggml-sycl PRIVATE GGML_SYCL_AMD)
141+ else ()
142+ # Fallback to oneMath runtime dispatcher
143+ target_link_libraries (ggml-sycl PRIVATE ONEMATH::onemath)
144+ target_compile_definitions (ggml-sycl PRIVATE GGML_SYCL_GENERIC)
131145 endif ()
132- target_link_libraries (ggml-sycl PRIVATE ONEMATH::onemath_blas_rocblas)
133- target_compile_options (ggml-sycl PRIVATE "-fsycl-targets=amdgcn-amd-amdhsa" )
134- target_link_options (ggml-sycl PRIVATE "-fsycl-targets=amdgcn-amd-amdhsa" )
135- target_compile_definitions (ggml-sycl PRIVATE GGML_SYCL_AMD)
136- else ()
137- # Fallback to oneMath runtime dispatcher
138- target_link_libraries (ggml-sycl PRIVATE ONEMATH::onemath)
139- target_compile_definitions (ggml-sycl PRIVATE GGML_SYCL_GENERIC)
140146endif ()
141147
142148if (GGML_SYCL_DEVICE_ARCH)
0 commit comments