11message (STATUS "GGML_SYCL_TARGET=${GGML_SYCL_TARGET} " )
22
3- if (NOT GGML_SYCL_TARGET MATCHES "^(INTEL|NVIDIA|AMD)$" )
3+ if (NOT GGML_SYCL_TARGET MATCHES "^(INTEL.* |NVIDIA|AMD)$" )
44 message (FATAL_ERROR "Invalid backend chosen, supported options are INTEL, NVIDIA, or AMD" )
55endif ()
66
@@ -30,8 +30,6 @@ if (GGML_SYCL_F16)
3030 add_compile_definitions (GGML_SYCL_F16)
3131endif ()
3232
33- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-narrowing -fsycl" )
34-
3533if (GGML_SYCL_TARGET STREQUAL "NVIDIA" )
3634 add_compile_definitions (GGML_SYCL_WARP_SIZE=32)
3735elseif (GGML_SYCL_TARGET STREQUAL "AMD" )
@@ -51,44 +49,90 @@ target_sources(ggml-sycl PRIVATE ${GGML_HEADERS_SYCL} ${GGML_SOURCES_SYCL})
5149find_package (DNNL)
5250message ("-- DNNL found:" ${DNNL_FOUND} )
5351
54- if (GGML_SYCL_TARGET STREQUAL "INTEL" )
52+ if (GGML_SYCL_TARGET MATCHES "INTEL.* " )
5553 add_compile_definitions (GGML_SYCL_DNNL=${DNNL_FOUND} )
5654else ()
5755 add_compile_definitions (GGML_SYCL_DNNL=0)
5856endif ()
5957
60- if (${DNNL_FOUND} AND GGML_SYCL_TARGET STREQUAL "INTEL" )
58+ if (${DNNL_FOUND} AND GGML_SYCL_TARGET MATCHES "INTEL.* " )
6159 target_link_libraries (ggml-sycl PRIVATE DNNL::dnnl)
6260endif ()
6361
64- if ( WIN32 )
65- find_package (IntelSYCL REQUIRED )
66- find_package (MKL REQUIRED)
67- target_link_libraries (ggml-sycl PRIVATE IntelSYCL::SYCL_CXX MKL::MKL MKL::MKL_SYCL )
62+ find_package (IntelSYCL )
63+ if (IntelSYCL_FOUND )
64+ # Use oneAPI CMake when possible
65+ target_link_libraries (ggml-sycl PRIVATE IntelSYCL::SYCL_CXX)
6866else ()
69- if (GGML_SYCL_TARGET STREQUAL "INTEL" )
70- target_link_libraries (ggml-sycl PRIVATE sycl OpenCL mkl_core pthread m dl mkl_sycl_blas mkl_intel_ilp64 mkl_tbb_thread)
71- elseif (GGML_SYCL_TARGET STREQUAL "NVIDIA" )
72- add_compile_definitions (GGML_SYCL_NVIDIA)
73- find_package (oneMath REQUIRED)
74- target_link_libraries (ggml-sycl PRIVATE sycl pthread m dl ONEMATH::onemath_blas_cublas)
75- target_compile_options (ggml-sycl PRIVATE "-fsycl-targets=nvptx64-nvidia-cuda" )
76- # Disable warnings for using deprecated oneapi::mkl namespace in oneMath
77- # Using the deprecated API in oneMath is useful to have a similar API than Intel oneMKL
78- target_compile_options (ggml-sycl PRIVATE "-Wno-deprecated-declarations" )
67+ # Fallback to the simplest way of enabling SYCL when using intel/llvm nightly for instance
68+ target_compile_options (ggml-sycl PRIVATE "-fsycl" )
69+ target_link_options (ggml-sycl PRIVATE "-fsycl" )
70+ endif ()
71+
72+ target_compile_options (ggml-sycl PRIVATE "-Wno-narrowing" )
73+
74+ find_package (oneMath QUIET )
75+ if (NOT oneMath_FOUND)
76+ message ("-- oneMath not found: oneMath will be automatically downloaded" )
77+ # Use FetchContent to automatically pull and build oneMath
78+ include (FetchContent)
79+ set (BUILD_FUNCTIONAL_TESTS False )
80+ set (BUILD_EXAMPLES False )
81+ set (TARGET_DOMAINS blas)
82+ if (GGML_SYCL_TARGET STREQUAL "NVIDIA" )
83+ set (ENABLE_MKLCPU_BACKEND False )
84+ set (ENABLE_MKLGPU_BACKEND False )
85+ set (ENABLE_CUBLAS_BACKEND True )
7986 elseif (GGML_SYCL_TARGET STREQUAL "AMD" )
80- if (NOT GGML_SYCL_DEVICE_ARCH)
81- message (ERROR "Can't enable SYCL hip backend, GGML_SYCL_DEVICE_ARCH has not been set." )
82- endif ()
83- find_package (oneMath REQUIRED)
84- target_link_libraries (ggml-sycl PRIVATE sycl pthread m dl onemath)
85- target_compile_options (ggml-sycl PRIVATE "-fsycl-targets=amdgcn-amd-amdhsa" )
86- # Disable warnings for using deprecated oneapi::mkl namespace in oneMath
87- # Using the deprecated API in oneMath is useful to have a similar API than Intel oneMKL
88- target_compile_options (ggml-sycl PRIVATE "-Wno-deprecated-declarations" )
87+ set (ENABLE_MKLCPU_BACKEND False )
88+ set (ENABLE_MKLGPU_BACKEND False )
89+ set (ENABLE_ROCBLAS_BACKEND True )
8990 endif ()
91+ FetchContent_Declare(
92+ ONEMATH
93+ GIT_REPOSITORY https://github.com/uxlfoundation/oneMath.git
94+ GIT_TAG develop
95+ )
96+ FetchContent_MakeAvailable(ONEMATH)
97+ # Create alias to match with find_package targets name
98+ function (onemath_alias target )
99+ if (TARGET ${target} )
100+ add_library (ONEMATH::${target} ALIAS ${target} )
101+ endif ()
102+ endfunction ()
103+ onemath_alias(onemath_blas_mklcpu)
104+ onemath_alias(onemath_blas_mklgpu)
105+ onemath_alias(onemath_blas_cublas)
106+ onemath_alias(onemath_blas_rocblas)
107+ endif ()
90108
91- if (GGML_SYCL_DEVICE_ARCH)
92- target_compile_options (ggml-sycl PRIVATE "-Xsycl-target-backend --offload-arch=${GGML_SYCL_DEVICE_ARCH} " )
109+ # Below oneMath compile-time dispatching is used for better performance
110+ if (GGML_SYCL_TARGET STREQUAL "INTEL_CPU" )
111+ target_link_libraries (ggml-sycl PRIVATE ONEMATH::onemath_blas_mklcpu)
112+ target_compile_definitions (ggml-sycl PRIVATE GGML_SYCL_INTEL GGML_SYCL_INTEL_CPU)
113+ elseif (GGML_SYCL_TARGET STREQUAL "INTEL_GPU" )
114+ target_link_libraries (ggml-sycl PRIVATE ONEMATH::onemath_blas_mklgpu)
115+ target_compile_definitions (ggml-sycl PRIVATE GGML_SYCL_INTEL GGML_SYCL_INTEL_GPU)
116+ elseif (GGML_SYCL_TARGET STREQUAL "NVIDIA" )
117+ target_link_libraries (ggml-sycl PRIVATE ONEMATH::onemath_blas_cublas)
118+ target_compile_options (ggml-sycl PRIVATE "-fsycl-targets=nvptx64-nvidia-cuda" )
119+ target_link_options (ggml-sycl PRIVATE "-fsycl-targets=nvptx64-nvidia-cuda" )
120+ target_compile_definitions (ggml-sycl PRIVATE GGML_SYCL_NVIDIA)
121+ elseif (GGML_SYCL_TARGET STREQUAL "AMD" )
122+ if (NOT GGML_SYCL_DEVICE_ARCH)
123+ message (ERROR "Can't enable SYCL hip backend, GGML_SYCL_DEVICE_ARCH has not been set." )
93124 endif ()
125+ target_link_libraries (ggml-sycl PRIVATE ONEMATH::onemath_blas_rocblas)
126+ target_compile_options (ggml-sycl PRIVATE "-fsycl-targets=amdgcn-amd-amdhsa" )
127+ target_link_options (ggml-sycl PRIVATE "-fsycl-targets=amdgcn-amd-amdhsa" )
128+ target_compile_definitions (ggml-sycl PRIVATE GGML_SYCL_AMD)
129+ else ()
130+ # Fallback to oneMath runtime dispatcher
131+ target_link_libraries (ggml-sycl PRIVATE ONEMATH::onemath)
132+ target_compile_definitions (ggml-sycl PRIVATE GGML_SYCL_GENERIC)
133+ endif ()
134+
135+ if (GGML_SYCL_DEVICE_ARCH)
136+ target_compile_options (ggml-sycl PRIVATE -Xsycl-target -backend --offload-arch=${GGML_SYCL_DEVICE_ARCH} )
137+ target_link_options (ggml-sycl PRIVATE -Xsycl-target -backend --offload-arch=${GGML_SYCL_DEVICE_ARCH} )
94138endif ()
0 commit comments