Skip to content

Commit a31b064

Browse files
committed
fix compile def openblas, blis for compat libs, nvpl compile def, warn if no blas vendor set
1 parent cc0a043 commit a31b064

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

ggml/src/ggml-blas/CMakeLists.txt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,12 @@ if (BLAS_FOUND)
3232
pkg_check_modules(DepBLAS openblas)
3333
endif()
3434
elseif (${GGML_BLAS_VENDOR} MATCHES "FLAME")
35-
add_compile_definitions(GGML_BLAS_USE_BLIS)
3635
pkg_check_modules(DepBLAS blis)
3736
elseif (${GGML_BLAS_VENDOR} MATCHES "ATLAS")
3837
pkg_check_modules(DepBLAS blas-atlas)
3938
elseif (${GGML_BLAS_VENDOR} MATCHES "FlexiBLAS")
4039
pkg_check_modules(DepBLAS flexiblas_api)
4140
elseif (${GGML_BLAS_VENDOR} MATCHES "Intel")
42-
add_compile_definitions(GGML_BLAS_USE_MKL)
4341
# all Intel* libraries share the same include path
4442
pkg_check_modules(DepBLAS mkl-sdl)
4543
elseif (${GGML_BLAS_VENDOR} MATCHES "NVHPC")
@@ -74,10 +72,26 @@ if (BLAS_FOUND)
7472

7573
target_compile_options(ggml-blas PRIVATE ${BLAS_LINKER_FLAGS})
7674

77-
if ("${BLAS_INCLUDE_DIRS}" MATCHES "mkl" AND (${GGML_BLAS_VENDOR} MATCHES "Generic" OR ${GGML_BLAS_VENDOR} MATCHES "Intel"))
75+
if ("${GGML_BLAS_VENDOR}" STREQUAL "")
76+
message(WARNING "GGML_BLAS_VENDOR is not set; some methods may not link properly.")
77+
endif()
78+
79+
if ("${GGML_BLAS_VENDOR}" MATCHES "Intel" OR ("${BLAS_INCLUDE_DIRS}" MATCHES "mkl" AND "${GGML_BLAS_VENDOR}" MATCHES "Generic"))
7880
add_compile_definitions(GGML_BLAS_USE_MKL)
7981
endif()
8082

83+
if ("${GGML_BLAS_VENDOR}" MATCHES "OpenBLAS")
84+
add_compile_definitions(GGML_BLAS_USE_OPENBLAS)
85+
endif()
86+
87+
if ("${GGML_BLAS_VENDOR}" MATCHES "FLAME" OR "${GGML_BLAS_VENDOR}" MATCHES "AOCL" OR "${GGML_BLAS_VENDOR}" MATCHES "AOCL_mt")
88+
add_compile_definitions(GGML_BLAS_USE_BLIS)
89+
endif()
90+
91+
if ("${GGML_BLAS_VENDOR}" MATCHES "NVPL")
92+
add_compile_definitions(GGML_BLAS_USE_NVPL)
93+
endif()
94+
8195
target_link_libraries (ggml-blas PRIVATE ${BLAS_LIBRARIES})
8296
target_include_directories(ggml-blas PRIVATE ${BLAS_INCLUDE_DIRS})
8397
else()

ggml/src/ggml-blas/ggml-blas.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,11 @@ static void ggml_backend_blas_mul_mat(ggml_backend_blas_context * ctx, struct gg
115115
#endif
116116
}
117117

118-
#if defined(OPENBLAS_VERSION)
118+
#if defined(GGML_BLAS_USE_OPENBLAS)
119119
openblas_set_num_threads(ctx->n_threads);
120-
#endif
121-
122-
#if defined(GGML_BLAS_USE_BLIS)
120+
#elif defined(GGML_BLAS_USE_BLIS)
123121
bli_thread_set_num_threads(ctx->n_threads);
124-
#endif
125-
126-
#if defined(GGML_BLAS_USE_NVPL)
122+
#elif defined(GGML_BLAS_USE_NVPL)
127123
nvpl_blas_set_num_threads(ctx->n_threads);
128124
#endif
129125

@@ -288,7 +284,7 @@ ggml_backend_t ggml_backend_blas_init(void) {
288284
/* .context = */ ctx,
289285
};
290286

291-
#if defined(OPENBLAS_VERSION) && defined(GGML_USE_OPENMP)
287+
#if defined(GGML_BLAS_USE_OPENBLAS) && defined(GGML_USE_OPENMP)
292288
if (openblas_get_parallel() != OPENBLAS_OPENMP) {
293289
GGML_LOG_DEBUG("%s: warning: ggml is using OpenMP, but OpenBLAS was compiled without OpenMP support\n", __func__);
294290
}
@@ -329,7 +325,7 @@ static const char * ggml_backend_blas_device_get_description(ggml_backend_dev_t
329325
return "BLIS";
330326
#elif defined(GGML_BLAS_USE_NVPL)
331327
return "NVPL";
332-
#elif defined(OPENBLAS_VERSION)
328+
#elif defined(GGML_BLAS_USE_OPENBLAS)
333329
return "OpenBLAS";
334330
#else
335331
return "BLAS";

0 commit comments

Comments
 (0)