2024-02-18 23:50:38 +00:00
|
|
|
diff --git a/examples/server/server.cpp b/examples/server/server.cpp
|
2024-03-11 19:57:48 +00:00
|
|
|
index 8fe5e0b1..53bf39c1 100644
|
2024-02-18 23:50:38 +00:00
|
|
|
--- a/examples/server/server.cpp
|
|
|
|
+++ b/examples/server/server.cpp
|
2024-03-11 19:57:48 +00:00
|
|
|
@@ -31,6 +31,10 @@
|
|
|
|
#include <atomic>
|
2024-02-20 22:42:31 +00:00
|
|
|
#include <signal.h>
|
2024-02-18 23:50:38 +00:00
|
|
|
|
|
|
|
+#ifdef GGML_USE_CUBLAS
|
|
|
|
+extern "C" GGML_CALL void ggml_free_cublas(void);
|
|
|
|
+#endif
|
|
|
|
+
|
2024-02-20 22:42:31 +00:00
|
|
|
using json = nlohmann::json;
|
|
|
|
|
2024-03-11 19:57:48 +00:00
|
|
|
struct server_params {
|
|
|
|
@@ -363,6 +367,10 @@ struct llama_server_context
|
2024-02-18 23:50:38 +00:00
|
|
|
llama_free_model(model);
|
|
|
|
model = nullptr;
|
|
|
|
}
|
2024-03-08 08:26:20 +00:00
|
|
|
+
|
2024-02-18 23:50:38 +00:00
|
|
|
+#ifdef GGML_USE_CUBLAS
|
|
|
|
+ ggml_free_cublas();
|
|
|
|
+#endif
|
|
|
|
}
|
|
|
|
|
2024-03-11 19:57:48 +00:00
|
|
|
bool load_model(const gpt_params ¶ms_)
|
|
|
|
@@ -3543,6 +3551,7 @@ int main(int argc, char **argv)
|
2024-02-18 23:50:38 +00:00
|
|
|
sigemptyset (&sigint_action.sa_mask);
|
|
|
|
sigint_action.sa_flags = 0;
|
|
|
|
sigaction(SIGINT, &sigint_action, NULL);
|
|
|
|
+ sigaction(SIGUSR1, &sigint_action, NULL);
|
|
|
|
#elif defined (_WIN32)
|
|
|
|
auto console_ctrl_handler = +[](DWORD ctrl_type) -> BOOL {
|
|
|
|
return (ctrl_type == CTRL_C_EVENT) ? (signal_handler(SIGINT), true) : false;
|
|
|
|
diff --git a/ggml-cuda.cu b/ggml-cuda.cu
|
2024-03-11 19:57:48 +00:00
|
|
|
index 72bcec8c..6c934e8c 100644
|
2024-02-18 23:50:38 +00:00
|
|
|
--- a/ggml-cuda.cu
|
|
|
|
+++ b/ggml-cuda.cu
|
2024-03-11 19:57:48 +00:00
|
|
|
@@ -43,6 +43,7 @@
|
2024-02-18 23:50:38 +00:00
|
|
|
#define __shfl_xor_sync(mask, var, laneMask, width) __shfl_xor(var, laneMask, width)
|
|
|
|
#define cublasComputeType_t hipblasDatatype_t //deprecated, new hipblasComputeType_t not in 5.6
|
|
|
|
#define cublasCreate hipblasCreate
|
|
|
|
+#define cublasDestroy hipblasDestroy
|
|
|
|
#define cublasGemmEx hipblasGemmEx
|
|
|
|
#define cublasGemmBatchedEx hipblasGemmBatchedEx
|
|
|
|
#define cublasGemmStridedBatchedEx hipblasGemmStridedBatchedEx
|
2024-03-11 19:57:48 +00:00
|
|
|
@@ -8751,10 +8752,10 @@ GGML_CALL bool ggml_cublas_loaded(void) {
|
2024-02-18 23:50:38 +00:00
|
|
|
return g_cublas_loaded;
|
|
|
|
}
|
|
|
|
|
2024-02-20 22:42:31 +00:00
|
|
|
-GGML_CALL void ggml_init_cublas() {
|
2024-02-18 23:50:38 +00:00
|
|
|
- static bool initialized = false;
|
2024-02-20 22:42:31 +00:00
|
|
|
+static bool g_cublas_initialized = false;
|
2024-02-18 23:50:38 +00:00
|
|
|
|
|
|
|
- if (!initialized) {
|
2024-02-20 22:42:31 +00:00
|
|
|
+GGML_CALL void ggml_init_cublas() {
|
2024-02-18 23:50:38 +00:00
|
|
|
+ if (!g_cublas_initialized) {
|
|
|
|
|
|
|
|
#ifdef __HIP_PLATFORM_AMD__
|
|
|
|
// Workaround for a rocBLAS bug when using multiple graphics cards:
|
2024-03-11 19:57:48 +00:00
|
|
|
@@ -8764,7 +8765,7 @@ GGML_CALL void ggml_init_cublas() {
|
2024-02-18 23:50:38 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (cudaGetDeviceCount(&g_device_count) != cudaSuccess) {
|
|
|
|
- initialized = true;
|
|
|
|
+ g_cublas_initialized = true;
|
|
|
|
g_cublas_loaded = false;
|
2024-02-20 22:42:31 +00:00
|
|
|
fprintf(stderr, "%s: no " GGML_CUDA_NAME " devices found, " GGML_CUDA_NAME " will be disabled\n", __func__);
|
2024-02-18 23:50:38 +00:00
|
|
|
return;
|
2024-03-11 19:57:48 +00:00
|
|
|
@@ -8835,7 +8836,7 @@ GGML_CALL void ggml_init_cublas() {
|
2024-02-18 23:50:38 +00:00
|
|
|
// configure logging to stdout
|
|
|
|
// CUBLAS_CHECK(cublasLoggerConfigure(1, 1, 0, nullptr));
|
|
|
|
|
|
|
|
- initialized = true;
|
|
|
|
+ g_cublas_initialized = true;
|
|
|
|
g_cublas_loaded = true;
|
|
|
|
}
|
|
|
|
}
|
2024-03-11 19:57:48 +00:00
|
|
|
@@ -12490,3 +12491,23 @@ GGML_CALL int ggml_backend_cuda_reg_devices() {
|
2024-02-18 23:50:38 +00:00
|
|
|
}
|
|
|
|
return device_count;
|
|
|
|
}
|
|
|
|
+
|
2024-03-09 23:55:34 +00:00
|
|
|
+
|
2024-02-18 23:50:38 +00:00
|
|
|
+extern "C" GGML_CALL void ggml_free_cublas(void);
|
|
|
|
+GGML_CALL void ggml_free_cublas(void) {
|
|
|
|
+ for (int id = 0; id < g_device_count; ++id) {
|
2024-02-20 22:42:31 +00:00
|
|
|
+#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;
|
|
|
|
+ }
|
2024-02-18 23:50:38 +00:00
|
|
|
+#endif
|
2024-02-20 22:42:31 +00:00
|
|
|
+ // TODO: free legacy non-vmm memory
|
|
|
|
+ // destroy cublas handle
|
2024-02-18 23:50:38 +00:00
|
|
|
+ CUBLAS_CHECK(cublasDestroy(g_cublas_handles[id]));
|
|
|
|
+ g_cublas_handles[id] = nullptr;
|
|
|
|
+ }
|
2024-02-20 22:42:31 +00:00
|
|
|
+
|
2024-02-18 23:50:38 +00:00
|
|
|
+ g_cublas_initialized = false;
|
|
|
|
+}
|
2024-03-11 19:57:48 +00:00
|
|
|
\ No newline at end of file
|
2024-02-18 23:50:38 +00:00
|
|
|
diff --git a/ggml-cuda.h b/ggml-cuda.h
|
2024-03-01 23:26:04 +00:00
|
|
|
index b1ebd61d..6dd58ddf 100644
|
2024-02-18 23:50:38 +00:00
|
|
|
--- a/ggml-cuda.h
|
|
|
|
+++ b/ggml-cuda.h
|
2024-03-01 23:26:04 +00:00
|
|
|
@@ -23,6 +23,9 @@ GGML_API GGML_CALL void ggml_init_cublas(void);
|
|
|
|
// Returns `true` if there are available CUDA devices and cublas loads successfully; otherwise, it returns `false`.
|
|
|
|
GGML_API GGML_CALL bool ggml_cublas_loaded(void);
|
2024-02-18 23:50:38 +00:00
|
|
|
|
|
|
|
+// Release CUDA resources
|
|
|
|
+GGML_API GGML_CALL void ggml_free_cublas(void);
|
|
|
|
+
|
2024-03-01 23:26:04 +00:00
|
|
|
GGML_API GGML_CALL void * ggml_cuda_host_malloc(size_t size);
|
|
|
|
GGML_API GGML_CALL void ggml_cuda_host_free(void * ptr);
|
2024-02-18 23:50:38 +00:00
|
|
|
|