Fallback from CL to cpu when buffer sizes too large #115
dsignarius
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
CLblast actually does use very small buffers - should not exceed a couple hundred MB at most. If your GPU cannot handle this , it is probably better to just start with OpenBLAS. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Thank you for developing this, enjoying greatly exploring it.
While playing, have found some instances require a buffer larger than my opencl setup will allow.. mainly due to it only allowing 1/4 size as max buffer, also small vram.
This patch will allow the CL version to fallback to openblas if any of the buffer sizes will be over the size that your machine will allow you to allocate.
This would just fail on the call otherwise, so allows things to carry on. Also allows users with smaller vrams and opencl cards to play around with larger models. It will fit the bits that fit on the card on it, otherwise use the cpu variant.
diff --git a/ggml_blas_adapter.c b/ggml_blas_adapter.c
index 27ddcdb..a73e95f 100644
--- a/ggml_blas_adapter.c
+++ b/ggml_blas_adapter.c
@@ -32,6 +32,13 @@ cl_program program;
cl_kernel kernel_q4_0, kernel_q4_1, kernel_q4_2, kernel_q4_3;
bool cl_initialized = false;
+#define CLFALLBACKTOBLAS
+
+#ifdef CLFALLBACKTOBLAS
+cl_ulong cl_max_mem_size = 0;
+cl_ulong cl_max_buffer_size = 0;
+#endif
+
size_t cl_size_a = 0, cl_size_b = 0, cl_size_qb = 0, cl_size_c = 0;
cl_mem cl_buffer_a, cl_buffer_b, cl_buffer_qb, cl_buffer_c;
@@ -152,6 +159,25 @@ static void ggml_cl_sgemm_wrapper(const enum CBLAS_ORDER order, const enum CBLAS
queue = clCreateCommandQueue(context, device, 0, &err);
CL_CHECK(err, "clCreateCommandQueue");
+#ifdef CLFALLBACKTOBLAS
+#endif
+
+
free(platforms);
free(devices);
@@ -185,6 +211,47 @@ static void ggml_cl_sgemm_wrapper(const enum CBLAS_ORDER order, const enum CBLAS
cl_initialized = true;
}
+#ifdef CLFALLBACKTOBLAS
+#if 1
+#endif
+#endif
cl_kernel kernel;
@@ -291,7 +358,9 @@ static void ggml_cl_sgemm_wrapper(const enum CBLAS_ORDER order, const enum CBLAS
clReleaseEvent(events[0]);
clReleaseEvent(events[1]);
}
+#ifdef CLFALLBACKTOBLAS
+#endif
}
#endif
#endif
Beta Was this translation helpful? Give feedback.
All reactions