Skip to content

Commit 2c5adec

Browse files
Xarbirusggerganov
authored andcommitted
cmake : try to fix sycl+intel build (llama/9487)
1 parent aacf70d commit 2c5adec

File tree

1 file changed

+39
-38
lines changed

1 file changed

+39
-38
lines changed

ggml/src/CMakeLists.txt

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ if (NOT MSVC)
2626
endif()
2727
endif()
2828

29-
unset(GGML_EXTRA_LIBS)
29+
unset(GGML_EXTRA_LIBS_PRIVATE)
30+
unset(GGML_EXTRA_LIBS_PUBLIC)
3031

3132
if (APPLE AND GGML_ACCELERATE)
3233
find_library(ACCELERATE_FRAMEWORK Accelerate)
@@ -37,7 +38,7 @@ if (APPLE AND GGML_ACCELERATE)
3738
add_compile_definitions(ACCELERATE_NEW_LAPACK)
3839
add_compile_definitions(ACCELERATE_LAPACK_ILP64)
3940

40-
list(APPEND GGML_EXTRA_LIBS ${ACCELERATE_FRAMEWORK})
41+
list(APPEND GGML_EXTRA_LIBS_PRIVATE ${ACCELERATE_FRAMEWORK})
4142
else()
4243
message(WARNING "Accelerate framework not found")
4344
endif()
@@ -89,7 +90,7 @@ if (GGML_METAL)
8990
COMMENT "Generate assembly for embedded Metal library"
9091
)
9192

92-
list(APPEND GGML_SOURCES_METAL ${METALLIB_EMBED_ASM})
93+
list(APPEND GGML_SOURCES_METAL ${METALLIB_EMBED_ASM})
9394
else()
9495
if (GGML_METAL_SHADER_DEBUG)
9596
# custom command to do the following:
@@ -134,7 +135,7 @@ if (GGML_METAL)
134135
)
135136
endif() # GGML_METAL_EMBED_LIBRARY
136137

137-
list(APPEND GGML_EXTRA_LIBS
138+
list(APPEND GGML_EXTRA_LIBS_PRIVATE
138139
${FOUNDATION_LIBRARY}
139140
${METAL_FRAMEWORK}
140141
${METALKIT_FRAMEWORK}
@@ -159,11 +160,11 @@ if (GGML_OPENMP)
159160

160161
add_compile_definitions(GGML_USE_OPENMP)
161162

162-
list(APPEND GGML_EXTRA_LIBS OpenMP::OpenMP_C OpenMP::OpenMP_CXX)
163+
list(APPEND GGML_EXTRA_LIBS_PRIVATE OpenMP::OpenMP_C OpenMP::OpenMP_CXX)
163164

164165
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")
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")
167168
endif()
168169
else()
169170
message(WARNING "OpenMP not found")
@@ -246,8 +247,8 @@ if (GGML_BLAS)
246247
set(GGML_HEADERS_BLAS ../include/ggml-blas.h)
247248
set(GGML_SOURCES_BLAS ggml-blas.cpp)
248249

249-
list(APPEND GGML_EXTRA_LIBS ${BLAS_LIBRARIES})
250-
list(APPEND GGML_EXTRA_INCLUDES ${BLAS_INCLUDE_DIRS})
250+
list(APPEND GGML_EXTRA_LIBS_PRIVATE ${BLAS_LIBRARIES})
251+
list(APPEND GGML_EXTRA_INCLUDES ${BLAS_INCLUDE_DIRS})
251252
else()
252253
message(WARNING "BLAS not found, please refer to "
253254
"https://cmake.org/cmake/help/latest/module/FindBLAS.html#blas-lapack-vendors"
@@ -370,29 +371,29 @@ if (GGML_CUDA)
370371
if (GGML_STATIC)
371372
if (WIN32)
372373
# 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+
list(APPEND GGML_EXTRA_LIBS_PRIVATE CUDA::cudart_static CUDA::cublas CUDA::cublasLt)
374375
else ()
375376
if (GGML_MUSA)
376-
list(APPEND GGML_EXTRA_LIBS MUSA::musart_static MUSA::mublas_static)
377+
list(APPEND GGML_EXTRA_LIBS_PRIVATE MUSA::musart_static MUSA::mublas_static)
377378
else()
378-
list(APPEND GGML_EXTRA_LIBS CUDA::cudart_static CUDA::cublas_static CUDA::cublasLt_static)
379+
list(APPEND GGML_EXTRA_LIBS_PRIVATE CUDA::cudart_static CUDA::cublas_static CUDA::cublasLt_static)
379380
endif()
380381
endif()
381382
else()
382383
if (GGML_MUSA)
383-
list(APPEND GGML_EXTRA_LIBS MUSA::musart MUSA::mublas)
384+
list(APPEND GGML_EXTRA_LIBS_PRIVATE MUSA::musart MUSA::mublas)
384385
else()
385-
list(APPEND GGML_EXTRA_LIBS CUDA::cudart CUDA::cublas CUDA::cublasLt)
386+
list(APPEND GGML_EXTRA_LIBS_PRIVATE CUDA::cudart CUDA::cublas CUDA::cublasLt)
386387
endif()
387388
endif()
388389

389390
if (GGML_CUDA_NO_VMM)
390391
# No VMM requested, no need to link directly with the cuda driver lib (libcuda.so)
391392
else()
392393
if (GGML_MUSA)
393-
list(APPEND GGML_EXTRA_LIBS MUSA::musa_driver) # required by muDeviceGetAttribute(), muMemGetAllocationGranularity(...), ...
394+
list(APPEND GGML_EXTRA_LIBS_PRIVATE MUSA::musa_driver) # required by muDeviceGetAttribute(), muMemGetAllocationGranularity(...), ...
394395
else()
395-
list(APPEND GGML_EXTRA_LIBS CUDA::cuda_driver) # required by cuDeviceGetAttribute(), cuMemGetAllocationGranularity(...), ...
396+
list(APPEND GGML_EXTRA_LIBS_PRIVATE CUDA::cuda_driver) # required by cuDeviceGetAttribute(), cuMemGetAllocationGranularity(...), ...
396397
endif()
397398
endif()
398399
else()
@@ -497,7 +498,7 @@ if (GGML_HIPBLAS)
497498

498499
if (CXX_IS_HIPCC)
499500
set_source_files_properties(${GGML_SOURCES_ROCM} PROPERTIES LANGUAGE CXX)
500-
list(APPEND GGML_EXTRA_LIBS hip::device)
501+
list(APPEND GGML_EXTRA_LIBS_PRIVATE hip::device)
501502
else()
502503
set_source_files_properties(${GGML_SOURCES_ROCM} PROPERTIES LANGUAGE HIP)
503504
endif()
@@ -506,8 +507,7 @@ if (GGML_HIPBLAS)
506507
message(FATAL_ERROR "Static linking not supported for HIP/ROCm")
507508
endif()
508509

509-
# TODO: this "PUBLIC" here seems wrong
510-
list(APPEND GGML_EXTRA_LIBS PUBLIC hip::host roc::rocblas roc::hipblas)
510+
list(APPEND GGML_EXTRA_LIBS_PUBLIC hip::host roc::rocblas roc::hipblas)
511511
endif()
512512

513513
if (GGML_SYCL)
@@ -563,24 +563,23 @@ if (GGML_SYCL)
563563
endif()
564564

565565
if (${DNNL_FOUND} AND GGML_SYCL_TARGET STREQUAL "INTEL")
566-
list(APPEND GGML_EXTRA_LIBS DNNL::dnnl)
566+
list(APPEND GGML_EXTRA_LIBS_PRIVATE DNNL::dnnl)
567567
endif()
568568

569569
if (WIN32)
570570
find_package(IntelSYCL REQUIRED)
571571
find_package(MKL REQUIRED)
572-
list(APPEND GGML_EXTRA_LIBS IntelSYCL::SYCL_CXX MKL::MKL MKL::MKL_SYCL)
572+
list(APPEND GGML_EXTRA_LIBS_PRIVATE IntelSYCL::SYCL_CXX MKL::MKL MKL::MKL_SYCL)
573573
else()
574574
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)
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)
576577
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)
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)
579581
endif()
580582
endif()
581-
if (${DNNL_FOUND} AND GGML_SYCL_TARGET STREQUAL "INTEL")
582-
list(APPEND GGML_EXTRA_LIBS DNNL::dnnl)
583-
endif()
584583
endif()
585584

586585
if (GGML_RPC)
@@ -589,7 +588,7 @@ if (GGML_RPC)
589588
list(APPEND GGML_CDEF_PUBLIC GGML_USE_RPC)
590589

591590
if (WIN32)
592-
list(APPEND GGML_EXTRA_LIBS ws2_32)
591+
list(APPEND GGML_EXTRA_LIBS_PRIVATE ws2_32)
593592
endif()
594593

595594
set(GGML_HEADERS_RPC ../include/ggml-rpc.h)
@@ -667,8 +666,8 @@ if (GGML_VULKAN)
667666
set(GGML_HEADERS_VULKAN ${CMAKE_CURRENT_SOURCE_DIR}/../include/ggml-vulkan.h ${_ggml_vk_header})
668667
set(GGML_SOURCES_VULKAN ggml-vulkan.cpp ${_ggml_vk_source})
669668

670-
list(APPEND GGML_EXTRA_LIBS Vulkan::Vulkan)
671-
list(APPEND GGML_EXTRA_INCLUDES ${CMAKE_CURRENT_BINARY_DIR})
669+
list(APPEND GGML_EXTRA_LIBS_PRIVATE Vulkan::Vulkan)
670+
list(APPEND GGML_EXTRA_INCLUDES ${CMAKE_CURRENT_BINARY_DIR})
672671
else()
673672
message(WARNING "Vulkan not found")
674673
endif()
@@ -827,8 +826,8 @@ if (GGML_KOMPUTE)
827826
828827
list(APPEND GGML_CDEF_PUBLIC GGML_USE_KOMPUTE)
829828
830-
list(APPEND GGML_EXTRA_LIBS kompute)
831-
list(APPEND GGML_EXTRA_INCLUDES ${CMAKE_CURRENT_BINARY_DIR})
829+
list(APPEND GGML_EXTRA_LIBS_PRIVATE kompute)
830+
list(APPEND GGML_EXTRA_INCLUDES ${CMAKE_CURRENT_BINARY_DIR})
832831
else()
833832
message(WARNING "Kompute not found")
834833
endif()
@@ -893,9 +892,9 @@ if (GGML_CANN)
893892
message(STATUS "CANN: CANN_INCLUDE_DIRS = ${CANN_INCLUDE_DIRS}")
894893
message(STATUS "CANN: CANN_LIBRARIES = ${CANN_LIBRARIES}")
895894
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)
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)
899898
900899
list(APPEND GGML_CDEF_PUBLIC GGML_USE_CANN)
901900
endif()
@@ -1339,9 +1338,7 @@ target_include_directories(ggml PRIVATE . ${GGML_EXTRA_INCLUDES})
13391338
target_link_directories (ggml PRIVATE ${GGML_EXTRA_LIBDIRS})
13401339
target_compile_features (ggml PRIVATE c_std_11) # don't bump
13411340

1342-
list(REMOVE_DUPLICATES GGML_EXTRA_LIBS)
1343-
1344-
target_link_libraries(ggml PRIVATE Threads::Threads ${GGML_EXTRA_LIBS})
1341+
list(APPEND GGML_EXTRA_LIBS_PRIVATE Threads::Threads)
13451342

13461343
find_library(MATH_LIBRARY m)
13471344
if (MATH_LIBRARY)
@@ -1350,6 +1347,10 @@ if (MATH_LIBRARY)
13501347
endif()
13511348
endif()
13521349

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+
13531354
if (BUILD_SHARED_LIBS)
13541355
set_target_properties(ggml PROPERTIES POSITION_INDEPENDENT_CODE ON)
13551356
target_compile_definitions(ggml PRIVATE GGML_SHARED GGML_BUILD)

0 commit comments

Comments
 (0)