Michael Podvitskiy commited on
Commit
dd66fc9
·
1 Parent(s): 8a1bb27

cmake : try to fix sycl+intel build (llama/9487)

Browse files
Files changed (1) hide show
  1. ggml/src/CMakeLists.txt +39 -38
ggml/src/CMakeLists.txt CHANGED
@@ -26,7 +26,8 @@ if (NOT MSVC)
26
  endif()
27
  endif()
28
 
29
- unset(GGML_EXTRA_LIBS)
 
30
 
31
  if (APPLE AND GGML_ACCELERATE)
32
  find_library(ACCELERATE_FRAMEWORK Accelerate)
@@ -37,7 +38,7 @@ if (APPLE AND GGML_ACCELERATE)
37
  add_compile_definitions(ACCELERATE_NEW_LAPACK)
38
  add_compile_definitions(ACCELERATE_LAPACK_ILP64)
39
 
40
- list(APPEND GGML_EXTRA_LIBS ${ACCELERATE_FRAMEWORK})
41
  else()
42
  message(WARNING "Accelerate framework not found")
43
  endif()
@@ -89,7 +90,7 @@ if (GGML_METAL)
89
  COMMENT "Generate assembly for embedded Metal library"
90
  )
91
 
92
- list(APPEND GGML_SOURCES_METAL ${METALLIB_EMBED_ASM})
93
  else()
94
  if (GGML_METAL_SHADER_DEBUG)
95
  # custom command to do the following:
@@ -134,7 +135,7 @@ if (GGML_METAL)
134
  )
135
  endif() # GGML_METAL_EMBED_LIBRARY
136
 
137
- list(APPEND GGML_EXTRA_LIBS
138
  ${FOUNDATION_LIBRARY}
139
  ${METAL_FRAMEWORK}
140
  ${METALKIT_FRAMEWORK}
@@ -159,11 +160,11 @@ if (GGML_OPENMP)
159
 
160
  add_compile_definitions(GGML_USE_OPENMP)
161
 
162
- list(APPEND GGML_EXTRA_LIBS OpenMP::OpenMP_C OpenMP::OpenMP_CXX)
163
 
164
  if (GGML_MUSA)
165
- list(APPEND GGML_EXTRA_INCLUDES "/usr/lib/llvm-10/include/openmp")
166
- list(APPEND GGML_EXTRA_LIBS "/usr/lib/llvm-10/lib/libomp.so")
167
  endif()
168
  else()
169
  message(WARNING "OpenMP not found")
@@ -246,8 +247,8 @@ if (GGML_BLAS)
246
  set(GGML_HEADERS_BLAS ../include/ggml-blas.h)
247
  set(GGML_SOURCES_BLAS ggml-blas.cpp)
248
 
249
- list(APPEND GGML_EXTRA_LIBS ${BLAS_LIBRARIES})
250
- list(APPEND GGML_EXTRA_INCLUDES ${BLAS_INCLUDE_DIRS})
251
  else()
252
  message(WARNING "BLAS not found, please refer to "
253
  "https://cmake.org/cmake/help/latest/module/FindBLAS.html#blas-lapack-vendors"
@@ -370,19 +371,19 @@ if (GGML_CUDA)
370
  if (GGML_STATIC)
371
  if (WIN32)
372
  # As of 12.3.1 CUDA Toolkit for Windows does not offer a static cublas library
373
- list(APPEND GGML_EXTRA_LIBS CUDA::cudart_static CUDA::cublas CUDA::cublasLt)
374
  else ()
375
  if (GGML_MUSA)
376
- list(APPEND GGML_EXTRA_LIBS MUSA::musart_static MUSA::mublas_static)
377
  else()
378
- list(APPEND GGML_EXTRA_LIBS CUDA::cudart_static CUDA::cublas_static CUDA::cublasLt_static)
379
  endif()
380
  endif()
381
  else()
382
  if (GGML_MUSA)
383
- list(APPEND GGML_EXTRA_LIBS MUSA::musart MUSA::mublas)
384
  else()
385
- list(APPEND GGML_EXTRA_LIBS CUDA::cudart CUDA::cublas CUDA::cublasLt)
386
  endif()
387
  endif()
388
 
@@ -390,9 +391,9 @@ if (GGML_CUDA)
390
  # No VMM requested, no need to link directly with the cuda driver lib (libcuda.so)
391
  else()
392
  if (GGML_MUSA)
393
- list(APPEND GGML_EXTRA_LIBS MUSA::musa_driver) # required by muDeviceGetAttribute(), muMemGetAllocationGranularity(...), ...
394
  else()
395
- list(APPEND GGML_EXTRA_LIBS CUDA::cuda_driver) # required by cuDeviceGetAttribute(), cuMemGetAllocationGranularity(...), ...
396
  endif()
397
  endif()
398
  else()
@@ -497,7 +498,7 @@ if (GGML_HIPBLAS)
497
 
498
  if (CXX_IS_HIPCC)
499
  set_source_files_properties(${GGML_SOURCES_ROCM} PROPERTIES LANGUAGE CXX)
500
- list(APPEND GGML_EXTRA_LIBS hip::device)
501
  else()
502
  set_source_files_properties(${GGML_SOURCES_ROCM} PROPERTIES LANGUAGE HIP)
503
  endif()
@@ -506,8 +507,7 @@ if (GGML_HIPBLAS)
506
  message(FATAL_ERROR "Static linking not supported for HIP/ROCm")
507
  endif()
508
 
509
- # TODO: this "PUBLIC" here seems wrong
510
- list(APPEND GGML_EXTRA_LIBS PUBLIC hip::host roc::rocblas roc::hipblas)
511
  endif()
512
 
513
  if (GGML_SYCL)
@@ -563,24 +563,23 @@ if (GGML_SYCL)
563
  endif()
564
 
565
  if (${DNNL_FOUND} AND GGML_SYCL_TARGET STREQUAL "INTEL")
566
- list(APPEND GGML_EXTRA_LIBS DNNL::dnnl)
567
  endif()
568
 
569
  if (WIN32)
570
  find_package(IntelSYCL REQUIRED)
571
  find_package(MKL REQUIRED)
572
- list(APPEND GGML_EXTRA_LIBS IntelSYCL::SYCL_CXX MKL::MKL MKL::MKL_SYCL)
573
  else()
574
  if (GGML_SYCL_TARGET STREQUAL "INTEL")
575
- list(APPEND GGML_EXTRA_LIBS OpenCL mkl_core pthread m dl mkl_sycl_blas mkl_intel_ilp64 mkl_tbb_thread)
 
576
  elseif (GGML_SYCL_TARGET STREQUAL "NVIDIA")
577
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsycl-targets=nvptx64-nvidia-cuda")
578
- list(APPEND GGML_EXTRA_LIBS pthread m dl onemkl)
 
579
  endif()
580
  endif()
581
- if (${DNNL_FOUND} AND GGML_SYCL_TARGET STREQUAL "INTEL")
582
- list(APPEND GGML_EXTRA_LIBS DNNL::dnnl)
583
- endif()
584
  endif()
585
 
586
  if (GGML_RPC)
@@ -589,7 +588,7 @@ if (GGML_RPC)
589
  list(APPEND GGML_CDEF_PUBLIC GGML_USE_RPC)
590
 
591
  if (WIN32)
592
- list(APPEND GGML_EXTRA_LIBS ws2_32)
593
  endif()
594
 
595
  set(GGML_HEADERS_RPC ../include/ggml-rpc.h)
@@ -667,8 +666,8 @@ if (GGML_VULKAN)
667
  set(GGML_HEADERS_VULKAN ${CMAKE_CURRENT_SOURCE_DIR}/../include/ggml-vulkan.h ${_ggml_vk_header})
668
  set(GGML_SOURCES_VULKAN ggml-vulkan.cpp ${_ggml_vk_source})
669
 
670
- list(APPEND GGML_EXTRA_LIBS Vulkan::Vulkan)
671
- list(APPEND GGML_EXTRA_INCLUDES ${CMAKE_CURRENT_BINARY_DIR})
672
  else()
673
  message(WARNING "Vulkan not found")
674
  endif()
@@ -827,8 +826,8 @@ if (GGML_KOMPUTE)
827
 
828
  list(APPEND GGML_CDEF_PUBLIC GGML_USE_KOMPUTE)
829
 
830
- list(APPEND GGML_EXTRA_LIBS kompute)
831
- list(APPEND GGML_EXTRA_INCLUDES ${CMAKE_CURRENT_BINARY_DIR})
832
  else()
833
  message(WARNING "Kompute not found")
834
  endif()
@@ -893,9 +892,9 @@ if (GGML_CANN)
893
  message(STATUS "CANN: CANN_INCLUDE_DIRS = ${CANN_INCLUDE_DIRS}")
894
  message(STATUS "CANN: CANN_LIBRARIES = ${CANN_LIBRARIES}")
895
 
896
- list(APPEND GGML_EXTRA_LIBS ${CANN_LIBRARIES} )
897
- list(APPEND GGML_EXTRA_INCLUDES ${CANN_INCLUDE_DIRS})
898
- list(APPEND GGML_EXTRA_LIBDIRS ${CANN_INSTALL_DIR}/lib64)
899
 
900
  list(APPEND GGML_CDEF_PUBLIC GGML_USE_CANN)
901
  endif()
@@ -1339,9 +1338,7 @@ target_include_directories(ggml PRIVATE . ${GGML_EXTRA_INCLUDES})
1339
  target_link_directories (ggml PRIVATE ${GGML_EXTRA_LIBDIRS})
1340
  target_compile_features (ggml PRIVATE c_std_11) # don't bump
1341
 
1342
- list(REMOVE_DUPLICATES GGML_EXTRA_LIBS)
1343
-
1344
- target_link_libraries(ggml PRIVATE Threads::Threads ${GGML_EXTRA_LIBS})
1345
 
1346
  find_library(MATH_LIBRARY m)
1347
  if (MATH_LIBRARY)
@@ -1350,6 +1347,10 @@ if (MATH_LIBRARY)
1350
  endif()
1351
  endif()
1352
 
 
 
 
 
1353
  if (BUILD_SHARED_LIBS)
1354
  set_target_properties(ggml PROPERTIES POSITION_INDEPENDENT_CODE ON)
1355
  target_compile_definitions(ggml PRIVATE GGML_SHARED GGML_BUILD)
 
26
  endif()
27
  endif()
28
 
29
+ unset(GGML_EXTRA_LIBS_PRIVATE)
30
+ unset(GGML_EXTRA_LIBS_PUBLIC)
31
 
32
  if (APPLE AND GGML_ACCELERATE)
33
  find_library(ACCELERATE_FRAMEWORK Accelerate)
 
38
  add_compile_definitions(ACCELERATE_NEW_LAPACK)
39
  add_compile_definitions(ACCELERATE_LAPACK_ILP64)
40
 
41
+ list(APPEND GGML_EXTRA_LIBS_PRIVATE ${ACCELERATE_FRAMEWORK})
42
  else()
43
  message(WARNING "Accelerate framework not found")
44
  endif()
 
90
  COMMENT "Generate assembly for embedded Metal library"
91
  )
92
 
93
+ list(APPEND GGML_SOURCES_METAL ${METALLIB_EMBED_ASM})
94
  else()
95
  if (GGML_METAL_SHADER_DEBUG)
96
  # custom command to do the following:
 
135
  )
136
  endif() # GGML_METAL_EMBED_LIBRARY
137
 
138
+ list(APPEND GGML_EXTRA_LIBS_PRIVATE
139
  ${FOUNDATION_LIBRARY}
140
  ${METAL_FRAMEWORK}
141
  ${METALKIT_FRAMEWORK}
 
160
 
161
  add_compile_definitions(GGML_USE_OPENMP)
162
 
163
+ list(APPEND GGML_EXTRA_LIBS_PRIVATE OpenMP::OpenMP_C OpenMP::OpenMP_CXX)
164
 
165
  if (GGML_MUSA)
166
+ list(APPEND GGML_EXTRA_INCLUDES "/usr/lib/llvm-10/include/openmp")
167
+ list(APPEND GGML_EXTRA_LIBS_PRIVATE "/usr/lib/llvm-10/lib/libomp.so")
168
  endif()
169
  else()
170
  message(WARNING "OpenMP not found")
 
247
  set(GGML_HEADERS_BLAS ../include/ggml-blas.h)
248
  set(GGML_SOURCES_BLAS ggml-blas.cpp)
249
 
250
+ list(APPEND GGML_EXTRA_LIBS_PRIVATE ${BLAS_LIBRARIES})
251
+ list(APPEND GGML_EXTRA_INCLUDES ${BLAS_INCLUDE_DIRS})
252
  else()
253
  message(WARNING "BLAS not found, please refer to "
254
  "https://cmake.org/cmake/help/latest/module/FindBLAS.html#blas-lapack-vendors"
 
371
  if (GGML_STATIC)
372
  if (WIN32)
373
  # As of 12.3.1 CUDA Toolkit for Windows does not offer a static cublas library
374
+ list(APPEND GGML_EXTRA_LIBS_PRIVATE CUDA::cudart_static CUDA::cublas CUDA::cublasLt)
375
  else ()
376
  if (GGML_MUSA)
377
+ list(APPEND GGML_EXTRA_LIBS_PRIVATE MUSA::musart_static MUSA::mublas_static)
378
  else()
379
+ list(APPEND GGML_EXTRA_LIBS_PRIVATE CUDA::cudart_static CUDA::cublas_static CUDA::cublasLt_static)
380
  endif()
381
  endif()
382
  else()
383
  if (GGML_MUSA)
384
+ list(APPEND GGML_EXTRA_LIBS_PRIVATE MUSA::musart MUSA::mublas)
385
  else()
386
+ list(APPEND GGML_EXTRA_LIBS_PRIVATE CUDA::cudart CUDA::cublas CUDA::cublasLt)
387
  endif()
388
  endif()
389
 
 
391
  # No VMM requested, no need to link directly with the cuda driver lib (libcuda.so)
392
  else()
393
  if (GGML_MUSA)
394
+ list(APPEND GGML_EXTRA_LIBS_PRIVATE MUSA::musa_driver) # required by muDeviceGetAttribute(), muMemGetAllocationGranularity(...), ...
395
  else()
396
+ list(APPEND GGML_EXTRA_LIBS_PRIVATE CUDA::cuda_driver) # required by cuDeviceGetAttribute(), cuMemGetAllocationGranularity(...), ...
397
  endif()
398
  endif()
399
  else()
 
498
 
499
  if (CXX_IS_HIPCC)
500
  set_source_files_properties(${GGML_SOURCES_ROCM} PROPERTIES LANGUAGE CXX)
501
+ list(APPEND GGML_EXTRA_LIBS_PRIVATE hip::device)
502
  else()
503
  set_source_files_properties(${GGML_SOURCES_ROCM} PROPERTIES LANGUAGE HIP)
504
  endif()
 
507
  message(FATAL_ERROR "Static linking not supported for HIP/ROCm")
508
  endif()
509
 
510
+ list(APPEND GGML_EXTRA_LIBS_PUBLIC hip::host roc::rocblas roc::hipblas)
 
511
  endif()
512
 
513
  if (GGML_SYCL)
 
563
  endif()
564
 
565
  if (${DNNL_FOUND} AND GGML_SYCL_TARGET STREQUAL "INTEL")
566
+ list(APPEND GGML_EXTRA_LIBS_PRIVATE DNNL::dnnl)
567
  endif()
568
 
569
  if (WIN32)
570
  find_package(IntelSYCL REQUIRED)
571
  find_package(MKL REQUIRED)
572
+ list(APPEND GGML_EXTRA_LIBS_PRIVATE IntelSYCL::SYCL_CXX MKL::MKL MKL::MKL_SYCL)
573
  else()
574
  if (GGML_SYCL_TARGET STREQUAL "INTEL")
575
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsycl")
576
+ list(APPEND GGML_EXTRA_LIBS_PRIVATE OpenCL mkl_core pthread m dl mkl_sycl_blas mkl_intel_ilp64 mkl_tbb_thread)
577
  elseif (GGML_SYCL_TARGET STREQUAL "NVIDIA")
578
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsycl")
579
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsycl-targets=nvptx64-nvidia-cuda")
580
+ list(APPEND GGML_EXTRA_LIBS_PRIVATE pthread m dl onemkl)
581
  endif()
582
  endif()
 
 
 
583
  endif()
584
 
585
  if (GGML_RPC)
 
588
  list(APPEND GGML_CDEF_PUBLIC GGML_USE_RPC)
589
 
590
  if (WIN32)
591
+ list(APPEND GGML_EXTRA_LIBS_PRIVATE ws2_32)
592
  endif()
593
 
594
  set(GGML_HEADERS_RPC ../include/ggml-rpc.h)
 
666
  set(GGML_HEADERS_VULKAN ${CMAKE_CURRENT_SOURCE_DIR}/../include/ggml-vulkan.h ${_ggml_vk_header})
667
  set(GGML_SOURCES_VULKAN ggml-vulkan.cpp ${_ggml_vk_source})
668
 
669
+ list(APPEND GGML_EXTRA_LIBS_PRIVATE Vulkan::Vulkan)
670
+ list(APPEND GGML_EXTRA_INCLUDES ${CMAKE_CURRENT_BINARY_DIR})
671
  else()
672
  message(WARNING "Vulkan not found")
673
  endif()
 
826
 
827
  list(APPEND GGML_CDEF_PUBLIC GGML_USE_KOMPUTE)
828
 
829
+ list(APPEND GGML_EXTRA_LIBS_PRIVATE kompute)
830
+ list(APPEND GGML_EXTRA_INCLUDES ${CMAKE_CURRENT_BINARY_DIR})
831
  else()
832
  message(WARNING "Kompute not found")
833
  endif()
 
892
  message(STATUS "CANN: CANN_INCLUDE_DIRS = ${CANN_INCLUDE_DIRS}")
893
  message(STATUS "CANN: CANN_LIBRARIES = ${CANN_LIBRARIES}")
894
 
895
+ list(APPEND GGML_EXTRA_LIBS_PRIVATE ${CANN_LIBRARIES} )
896
+ list(APPEND GGML_EXTRA_INCLUDES ${CANN_INCLUDE_DIRS})
897
+ list(APPEND GGML_EXTRA_LIBDIRS ${CANN_INSTALL_DIR}/lib64)
898
 
899
  list(APPEND GGML_CDEF_PUBLIC GGML_USE_CANN)
900
  endif()
 
1338
  target_link_directories (ggml PRIVATE ${GGML_EXTRA_LIBDIRS})
1339
  target_compile_features (ggml PRIVATE c_std_11) # don't bump
1340
 
1341
+ list(APPEND GGML_EXTRA_LIBS_PRIVATE Threads::Threads)
 
 
1342
 
1343
  find_library(MATH_LIBRARY m)
1344
  if (MATH_LIBRARY)
 
1347
  endif()
1348
  endif()
1349
 
1350
+ list(REMOVE_DUPLICATES GGML_EXTRA_LIBS_PRIVATE)
1351
+ list(REMOVE_DUPLICATES GGML_EXTRA_LIBS_PUBLIC)
1352
+ target_link_libraries(ggml PRIVATE ${GGML_EXTRA_LIBS_PRIVATE} PUBLIC ${GGML_EXTRA_LIBS_PUBLIC})
1353
+
1354
  if (BUILD_SHARED_LIBS)
1355
  set_target_properties(ggml PROPERTIES POSITION_INDEPENDENT_CODE ON)
1356
  target_compile_definitions(ggml PRIVATE GGML_SHARED GGML_BUILD)