Skip to content

Commit f9a1ece

Browse files
committed
Restore CLBlast back-end
Partially revert "ggml: remove OpenCL (ggml-org#7735)" Restore functionality, skip documentation
1 parent 7a16ce7 commit f9a1ece

13 files changed

+2473
-16
lines changed

CMakeLists.txt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ option(LLAMA_CUDA_FA_ALL_QUANTS "llama: compile all quants for Flas
111111
option(LLAMA_CURL "llama: use libcurl to download model from an URL" OFF)
112112
option(LLAMA_HIPBLAS "llama: use hipBLAS" OFF)
113113
option(LLAMA_HIP_UMA "llama: use HIP unified memory architecture" OFF)
114+
option(LLAMA_CLBLAST "llama: use CLBlast" OFF)
114115
option(LLAMA_VULKAN "llama: use Vulkan" OFF)
115116
option(LLAMA_VULKAN_CHECK_RESULTS "llama: run Vulkan op checks" OFF)
116117
option(LLAMA_VULKAN_DEBUG "llama: enable Vulkan debug output" OFF)
@@ -503,6 +504,22 @@ if (LLAMA_RPC)
503504
set(GGML_SOURCES_RPC ggml-rpc.cpp)
504505
endif()
505506

507+
if (LLAMA_CLBLAST)
508+
find_package(CLBlast)
509+
if (CLBlast_FOUND)
510+
message(STATUS "CLBlast found")
511+
512+
set(GGML_HEADERS_OPENCL ggml-opencl.h)
513+
set(GGML_SOURCES_OPENCL ggml-opencl.cpp)
514+
515+
add_compile_definitions(GGML_USE_CLBLAST)
516+
517+
set(LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS} clblast)
518+
else()
519+
message(WARNING "CLBlast not found")
520+
endif()
521+
endif()
522+
506523
if (LLAMA_VULKAN)
507524
find_package(Vulkan)
508525
if (Vulkan_FOUND)
@@ -1252,6 +1269,7 @@ add_library(ggml OBJECT
12521269
ggml-quants.c
12531270
ggml-quants.h
12541271
${GGML_SOURCES_CUDA} ${GGML_HEADERS_CUDA}
1272+
${GGML_SOURCES_OPENCL} ${GGML_HEADERS_OPENCL}
12551273
${GGML_SOURCES_METAL} ${GGML_HEADERS_METAL}
12561274
${GGML_SOURCES_RPC} ${GGML_HEADERS_RPC}
12571275
${GGML_SOURCES_EXTRA} ${GGML_HEADERS_EXTRA}
@@ -1339,9 +1357,8 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/LlamaConfig.cmake
13391357
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Llama)
13401358

13411359
set(GGML_PUBLIC_HEADERS "ggml.h" "ggml-alloc.h" "ggml-backend.h"
1342-
"${GGML_HEADERS_CUDA}"
1343-
"${GGML_HEADERS_METAL}"
1344-
"${GGML_HEADERS_EXTRA}")
1360+
"${GGML_HEADERS_CUDA}" "${GGML_HEADERS_OPENCL}"
1361+
"${GGML_HEADERS_METAL}" "${GGML_HEADERS_EXTRA}")
13451362

13461363
set_target_properties(ggml PROPERTIES PUBLIC_HEADER "${GGML_PUBLIC_HEADERS}")
13471364
install(TARGETS ggml PUBLIC_HEADER)

Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,23 @@ ggml-cuda.o: ggml-cuda.cu ggml-cuda.h ggml.h ggml-backend.h ggml-backend-impl.h
548548
$(NVCC_COMPILE)
549549
endif # LLAMA_CUDA
550550

551+
ifdef LLAMA_CLBLAST
552+
MK_CPPFLAGS += -DGGML_USE_CLBLAST $(shell pkg-config --cflags-only-I clblast OpenCL)
553+
MK_CFLAGS += $(shell pkg-config --cflags-only-other clblast OpenCL)
554+
MK_CXXFLAGS += $(shell pkg-config --cflags-only-other clblast OpenCL)
555+
556+
# Mac provides OpenCL as a framework
557+
ifeq ($(UNAME_S),Darwin)
558+
MK_LDFLAGS += -lclblast -framework OpenCL
559+
else
560+
MK_LDFLAGS += $(shell pkg-config --libs clblast OpenCL)
561+
endif
562+
OBJS += ggml-opencl.o
563+
564+
ggml-opencl.o: ggml-opencl.cpp ggml-opencl.h
565+
$(CXX) $(CXXFLAGS) -c $< -o $@
566+
endif # LLAMA_CLBLAST
567+
551568
ifdef LLAMA_VULKAN
552569
MK_CPPFLAGS += -DGGML_USE_VULKAN
553570
MK_LDFLAGS += -lvulkan

common/common.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3242,6 +3242,7 @@ void yaml_dump_non_result_info(FILE * stream, const gpt_params & params, const l
32423242
fprintf(stream, "cpu_has_avx512_vnni: %s\n", ggml_cpu_has_avx512_vnni() ? "true" : "false");
32433243
fprintf(stream, "cpu_has_cuda: %s\n", ggml_cpu_has_cuda() ? "true" : "false");
32443244
fprintf(stream, "cpu_has_vulkan: %s\n", ggml_cpu_has_vulkan() ? "true" : "false");
3245+
fprintf(stream, "cpu_has_clblast: %s\n", ggml_cpu_has_clblast() ? "true" : "false");
32453246
fprintf(stream, "cpu_has_kompute: %s\n", ggml_cpu_has_kompute() ? "true" : "false");
32463247
fprintf(stream, "cpu_has_fma: %s\n", ggml_cpu_has_fma() ? "true" : "false");
32473248
fprintf(stream, "cpu_has_gpublas: %s\n", ggml_cpu_has_gpublas() ? "true" : "false");

examples/llama-bench/llama-bench.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ struct test {
709709
static const std::string build_commit;
710710
static const int build_number;
711711
static const bool cuda;
712+
static const bool opencl;
712713
static const bool vulkan;
713714
static const bool kompute;
714715
static const bool metal;
@@ -797,6 +798,9 @@ struct test {
797798
if (cuda) {
798799
return GGML_CUDA_NAME;
799800
}
801+
if (opencl) {
802+
return "OpenCL";
803+
}
800804
if (vulkan) {
801805
return "Vulkan";
802806
}
@@ -825,7 +829,7 @@ struct test {
825829
static const std::vector<std::string> & get_fields() {
826830
static const std::vector<std::string> fields = {
827831
"build_commit", "build_number",
828-
"cuda", "vulkan", "kompute", "metal", "sycl", "rpc", "gpu_blas", "blas",
832+
"cuda", "opencl", "vulkan", "kompute", "metal", "sycl", "rpc", "gpu_blas", "blas",
829833
"cpu_info", "gpu_info",
830834
"model_filename", "model_type", "model_size", "model_n_params",
831835
"n_batch", "n_ubatch",
@@ -851,7 +855,7 @@ struct test {
851855
field == "avg_ns" || field == "stddev_ns") {
852856
return INT;
853857
}
854-
if (field == "cuda" || field == "vulkan" || field == "kompute" || field == "metal" ||
858+
if (field == "cuda" || field == "opencl" || field == "vulkan" || field == "kompute" || field == "metal" ||
855859
field == "gpu_blas" || field == "blas" || field == "sycl" ||field == "f16_kv" || field == "no_kv_offload" ||
856860
field == "flash_attn" || field == "use_mmap" || field == "embeddings") {
857861
return BOOL;
@@ -880,7 +884,7 @@ struct test {
880884
}
881885
std::vector<std::string> values = {
882886
build_commit, std::to_string(build_number),
883-
std::to_string(cuda), std::to_string(vulkan), std::to_string(vulkan),
887+
std::to_string(cuda), std::to_string(opencl), std::to_string(vulkan), std::to_string(vulkan),
884888
std::to_string(metal), std::to_string(sycl), std::to_string(rpc), std::to_string(gpu_blas), std::to_string(blas),
885889
cpu_info, gpu_info,
886890
model_filename, model_type, std::to_string(model_size), std::to_string(model_n_params),
@@ -909,6 +913,7 @@ struct test {
909913
const std::string test::build_commit = LLAMA_COMMIT;
910914
const int test::build_number = LLAMA_BUILD_NUMBER;
911915
const bool test::cuda = !!ggml_cpu_has_cuda();
916+
const bool test::opencl = !!ggml_cpu_has_clblast();
912917
const bool test::vulkan = !!ggml_cpu_has_vulkan();
913918
const bool test::kompute = !!ggml_cpu_has_kompute();
914919
const bool test::metal = !!ggml_cpu_has_metal();

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
windows = config.legacyPackages.llamaPackagesWindows.llama-cpp;
160160
}
161161
// lib.optionalAttrs pkgs.stdenv.isLinux {
162+
opencl = config.packages.default.override { useOpenCL = true; };
162163
cuda = config.legacyPackages.llamaPackagesCuda.llama-cpp;
163164

164165
mpi-cpu = config.packages.default.override { useMpi = true; };

0 commit comments

Comments
 (0)