@@ -389,6 +389,7 @@ struct ggml_backend_opencl_context {
389389 ADRENO_GPU_GEN adreno_gen;
390390
391391 cl_int alignment;
392+ size_t global_mem_size;
392393 size_t max_alloc_size;
393394 size_t max_workgroup_size;
394395 bool fp16_support;
@@ -3385,6 +3386,9 @@ static ggml_backend_opencl_context * ggml_cl2_init(ggml_backend_dev_t dev) {
33853386 backend_ctx->alignment = base_align_in_bits / 8u;
33863387 GGML_LOG_INFO("ggml_opencl: mem base addr align: %u\n", backend_ctx->alignment);
33873388
3389+ clGetDeviceInfo(device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof(size_t), &backend_ctx->global_mem_size, NULL);
3390+ GGML_LOG_INFO("ggml_opencl: global mem size: %zu MB\n", backend_ctx->global_mem_size/1024/1024);
3391+
33883392 clGetDeviceInfo(device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof(size_t), &backend_ctx->max_alloc_size, NULL);
33893393 GGML_LOG_INFO("ggml_opencl: max mem alloc size: %zu MB\n", backend_ctx->max_alloc_size/1024/1024);
33903394
@@ -6547,11 +6551,10 @@ static const char * ggml_backend_opencl_device_get_description(ggml_backend_dev_
65476551}
65486552
65496553static void ggml_backend_opencl_device_get_memory(ggml_backend_dev_t dev, size_t * free, size_t * total) {
6550- // no memory to report
6551- *free = 0;
6552- *total = 0;
6553-
6554- GGML_UNUSED(dev);
6554+ ggml_backend_opencl_device_context *dev_ctx = (ggml_backend_opencl_device_context *) dev->context;
6555+ ggml_backend_opencl_context * backend_ctx = (ggml_backend_opencl_context *) dev_ctx->backend_ctx;
6556+ *free = backend_ctx->global_mem_size - 1.5*1024*1024*1024; // leave 1.5 GB
6557+ *total = backend_ctx->global_mem_size;
65556558}
65566559
65576560static enum ggml_backend_dev_type ggml_backend_opencl_device_get_type(ggml_backend_dev_t dev) {
0 commit comments