|
@@ -1,30 +1,29 @@
|
|
diff --git a/examples/server/server.cpp b/examples/server/server.cpp
|
|
diff --git a/examples/server/server.cpp b/examples/server/server.cpp
|
|
-index 3102762c..568ac1d0 100644
|
|
|
|
|
|
+index 7800c6e7..be30db23 100644
|
|
--- a/examples/server/server.cpp
|
|
--- a/examples/server/server.cpp
|
|
+++ b/examples/server/server.cpp
|
|
+++ b/examples/server/server.cpp
|
|
-@@ -307,6 +307,10 @@ struct llama_client_slot
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
|
|
+@@ -30,6 +30,10 @@
|
|
|
|
+ #include <atomic>
|
|
|
|
+ #include <signal.h>
|
|
|
|
|
|
+#ifdef GGML_USE_CUBLAS
|
|
+#ifdef GGML_USE_CUBLAS
|
|
+extern "C" GGML_CALL void ggml_free_cublas(void);
|
|
+extern "C" GGML_CALL void ggml_free_cublas(void);
|
|
+#endif
|
|
+#endif
|
|
+
|
|
+
|
|
- struct llama_server_context
|
|
|
|
- {
|
|
|
|
- llama_model *model = nullptr;
|
|
|
|
-@@ -353,6 +357,10 @@ struct llama_server_context
|
|
|
|
|
|
+ using json = nlohmann::json;
|
|
|
|
+
|
|
|
|
+ struct server_params
|
|
|
|
+@@ -353,6 +357,9 @@ struct llama_server_context
|
|
llama_free_model(model);
|
|
llama_free_model(model);
|
|
model = nullptr;
|
|
model = nullptr;
|
|
}
|
|
}
|
|
+#ifdef GGML_USE_CUBLAS
|
|
+#ifdef GGML_USE_CUBLAS
|
|
+ ggml_free_cublas();
|
|
+ ggml_free_cublas();
|
|
+#endif
|
|
+#endif
|
|
-+
|
|
|
|
}
|
|
}
|
|
|
|
|
|
bool load_model(const gpt_params ¶ms_)
|
|
bool load_model(const gpt_params ¶ms_)
|
|
-@@ -3093,6 +3101,7 @@ int main(int argc, char **argv)
|
|
|
|
|
|
+@@ -3143,6 +3150,7 @@ int main(int argc, char **argv)
|
|
sigemptyset (&sigint_action.sa_mask);
|
|
sigemptyset (&sigint_action.sa_mask);
|
|
sigint_action.sa_flags = 0;
|
|
sigint_action.sa_flags = 0;
|
|
sigaction(SIGINT, &sigint_action, NULL);
|
|
sigaction(SIGINT, &sigint_action, NULL);
|
|
@@ -32,13 +31,8 @@ index 3102762c..568ac1d0 100644
|
|
#elif defined (_WIN32)
|
|
#elif defined (_WIN32)
|
|
auto console_ctrl_handler = +[](DWORD ctrl_type) -> BOOL {
|
|
auto console_ctrl_handler = +[](DWORD ctrl_type) -> BOOL {
|
|
return (ctrl_type == CTRL_C_EVENT) ? (signal_handler(SIGINT), true) : false;
|
|
return (ctrl_type == CTRL_C_EVENT) ? (signal_handler(SIGINT), true) : false;
|
|
-@@ -3106,3 +3115,4 @@ int main(int argc, char **argv)
|
|
|
|
- llama_backend_free();
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
-+
|
|
|
|
diff --git a/ggml-cuda.cu b/ggml-cuda.cu
|
|
diff --git a/ggml-cuda.cu b/ggml-cuda.cu
|
|
-index 96976f24..3543920e 100644
|
|
|
|
|
|
+index 933ebbc4..88a4f664 100644
|
|
--- a/ggml-cuda.cu
|
|
--- a/ggml-cuda.cu
|
|
+++ b/ggml-cuda.cu
|
|
+++ b/ggml-cuda.cu
|
|
@@ -39,6 +39,7 @@
|
|
@@ -39,6 +39,7 @@
|
|
@@ -49,30 +43,30 @@ index 96976f24..3543920e 100644
|
|
#define cublasGemmEx hipblasGemmEx
|
|
#define cublasGemmEx hipblasGemmEx
|
|
#define cublasGemmBatchedEx hipblasGemmBatchedEx
|
|
#define cublasGemmBatchedEx hipblasGemmBatchedEx
|
|
#define cublasGemmStridedBatchedEx hipblasGemmStridedBatchedEx
|
|
#define cublasGemmStridedBatchedEx hipblasGemmStridedBatchedEx
|
|
-@@ -7928,10 +7929,11 @@ GGML_CALL bool ggml_cublas_loaded(void) {
|
|
|
|
|
|
+@@ -7991,10 +7992,10 @@ GGML_CALL bool ggml_cublas_loaded(void) {
|
|
return g_cublas_loaded;
|
|
return g_cublas_loaded;
|
|
}
|
|
}
|
|
|
|
|
|
-+static bool g_cublas_initialized = false;
|
|
|
|
-+
|
|
|
|
- GGML_CALL void ggml_init_cublas() {
|
|
|
|
|
|
+-GGML_CALL void ggml_init_cublas() {
|
|
- static bool initialized = false;
|
|
- static bool initialized = false;
|
|
|
|
++static bool g_cublas_initialized = false;
|
|
|
|
|
|
- if (!initialized) {
|
|
- if (!initialized) {
|
|
|
|
++GGML_CALL void ggml_init_cublas() {
|
|
+ if (!g_cublas_initialized) {
|
|
+ if (!g_cublas_initialized) {
|
|
|
|
|
|
#ifdef __HIP_PLATFORM_AMD__
|
|
#ifdef __HIP_PLATFORM_AMD__
|
|
// Workaround for a rocBLAS bug when using multiple graphics cards:
|
|
// Workaround for a rocBLAS bug when using multiple graphics cards:
|
|
-@@ -7941,7 +7943,7 @@ GGML_CALL void ggml_init_cublas() {
|
|
|
|
|
|
+@@ -8004,7 +8005,7 @@ GGML_CALL void ggml_init_cublas() {
|
|
#endif
|
|
#endif
|
|
|
|
|
|
if (cudaGetDeviceCount(&g_device_count) != cudaSuccess) {
|
|
if (cudaGetDeviceCount(&g_device_count) != cudaSuccess) {
|
|
- initialized = true;
|
|
- initialized = true;
|
|
+ g_cublas_initialized = true;
|
|
+ g_cublas_initialized = true;
|
|
g_cublas_loaded = false;
|
|
g_cublas_loaded = false;
|
|
|
|
+ fprintf(stderr, "%s: no " GGML_CUDA_NAME " devices found, " GGML_CUDA_NAME " will be disabled\n", __func__);
|
|
return;
|
|
return;
|
|
- }
|
|
|
|
-@@ -8011,7 +8013,7 @@ GGML_CALL void ggml_init_cublas() {
|
|
|
|
|
|
+@@ -8075,7 +8076,7 @@ GGML_CALL void ggml_init_cublas() {
|
|
// configure logging to stdout
|
|
// configure logging to stdout
|
|
// CUBLAS_CHECK(cublasLoggerConfigure(1, 1, 0, nullptr));
|
|
// CUBLAS_CHECK(cublasLoggerConfigure(1, 1, 0, nullptr));
|
|
|
|
|
|
@@ -81,25 +75,30 @@ index 96976f24..3543920e 100644
|
|
g_cublas_loaded = true;
|
|
g_cublas_loaded = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-@@ -11528,3 +11530,17 @@ GGML_CALL int ggml_backend_cuda_reg_devices() {
|
|
|
|
|
|
+@@ -11604,3 +11605,23 @@ GGML_CALL int ggml_backend_cuda_reg_devices() {
|
|
}
|
|
}
|
|
return device_count;
|
|
return device_count;
|
|
}
|
|
}
|
|
+
|
|
+
|
|
|
|
++
|
|
+extern "C" GGML_CALL void ggml_free_cublas(void);
|
|
+extern "C" GGML_CALL void ggml_free_cublas(void);
|
|
+GGML_CALL void ggml_free_cublas(void) {
|
|
+GGML_CALL void ggml_free_cublas(void) {
|
|
+ for (int id = 0; id < g_device_count; ++id) {
|
|
+ for (int id = 0; id < g_device_count; ++id) {
|
|
-+#if !defined(GGML_USE_HIPBLAS)
|
|
|
|
-+ CU_CHECK(cuMemUnmap(g_cuda_pool_addr[id], g_cuda_pool_size[id]));
|
|
|
|
-+ g_cuda_pool_size[id] = 0;
|
|
|
|
-+ g_cuda_pool_addr[id] = 0;
|
|
|
|
|
|
++#if !(defined(GGML_USE_HIPBLAS) && defined(__HIP_PLATFORM_AMD__))
|
|
|
|
++ if (g_device_caps[id].vmm) {
|
|
|
|
++ CU_CHECK(cuMemUnmap(g_cuda_pool_addr[id], g_cuda_pool_size[id]));
|
|
|
|
++ g_cuda_pool_size[id] = 0;
|
|
|
|
++ g_cuda_pool_addr[id] = 0;
|
|
|
|
++ }
|
|
+#endif
|
|
+#endif
|
|
|
|
++ // TODO: free legacy non-vmm memory
|
|
|
|
++ // destroy cublas handle
|
|
+ CUBLAS_CHECK(cublasDestroy(g_cublas_handles[id]));
|
|
+ CUBLAS_CHECK(cublasDestroy(g_cublas_handles[id]));
|
|
+ g_cublas_handles[id] = nullptr;
|
|
+ g_cublas_handles[id] = nullptr;
|
|
+ }
|
|
+ }
|
|
|
|
++
|
|
+ g_cublas_initialized = false;
|
|
+ g_cublas_initialized = false;
|
|
+}
|
|
+}
|
|
-\ No newline at end of file
|
|
|
|
diff --git a/ggml-cuda.h b/ggml-cuda.h
|
|
diff --git a/ggml-cuda.h b/ggml-cuda.h
|
|
index b1ebd61d..b4c80c2c 100644
|
|
index b1ebd61d..b4c80c2c 100644
|
|
--- a/ggml-cuda.h
|
|
--- a/ggml-cuda.h
|