From 1597316b97cbf45ac0a313f9292efca4199c7905 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 5 Feb 2024 03:10:16 +0100 Subject: [PATCH] client: debug Apple Silicon GPU detection --- client/gpu_detect.cpp | 38 +++++++++++++++++++++++++------------- client/gpu_opencl.cpp | 11 ++++------- lib/coproc.h | 4 ++-- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/client/gpu_detect.cpp b/client/gpu_detect.cpp index 56a3077e0c..b6fb79c180 100644 --- a/client/gpu_detect.cpp +++ b/client/gpu_detect.cpp @@ -212,7 +212,8 @@ void COPROCS::detect_gpus(vector &warnings) { catch (...) { gpu_warning(warnings, "Caught SIGSEGV in OpenCL detection"); } -#else +#else // non-Windows + void (*old_sig)(int) = signal(SIGSEGV, segv_handler); if (setjmp(resume)) { gpu_warning(warnings, "Caught SIGSEGV in NVIDIA GPU detection"); @@ -227,6 +228,8 @@ void COPROCS::detect_gpus(vector &warnings) { } else { ati.get(warnings); } +#else + apple_gpu.get(warnings); #endif if (setjmp(resume)) { gpu_warning(warnings, "Caught SIGSEGV in INTEL GPU detection"); @@ -848,24 +851,33 @@ void COPROC_APPLE::get(vector&) { if (retval) return; FILE* f = fopen("temp", "r"); if (!f) return; - char buf[256], model[256]; - int n, metal; - bool have_model=false, have_ncores=false, have_metal=false; + char buf[256], chipset_model[256]; + int n, metalv; + bool have_model=false, have_ncores=false, have_metalv=false; while (fgets(buf, sizeof(buf), f)) { - if (sscanf(buf, "%*[ ]Chipset Model: %[^\n]", model) == 1) { + if (sscanf(buf, "%*[ ]Chipset Model: %[^\n]", chipset_model) == 1) { have_model = true; - } else if (sscanf(buf, "%*[ ]Total Number of Cores: %d", n) == 1) { + } else if (sscanf(buf, "%*[ ]Total Number of Cores: %d", &n) == 1) { have_ncores = true; - } else if (sscanf(buf, "%*[ ]Metal Support: %[^\n]", metal) == 1) { - have_metal = true; + } else if (sscanf(buf, "%*[ ]Metal Support: Metal %d", &metalv) == 1) { + have_metalv = true; } } fclose(f); - if (have_model && have_ncores && have_metal) { - count = 1; - safe_strcpy(chipset_model, model); - ncores = n; - metal_support = metal; + if (have_model && have_ncores && have_metalv) { + COPROC_APPLE ca; + ca.count = 1; + safe_strcpy(ca.model, chipset_model); + ca.ncores = n; + ca.metal_support = metalv; + ca.have_metal = true; + apple_gpus.push_back(ca); } } + +void COPROC_APPLE::correlate(bool, vector &ignore_devs) { + if (!ignore_devs.empty() && ignore_devs[0]==0) return; + if (apple_gpus.empty()) return; + *this = apple_gpus[0]; +} #endif diff --git a/client/gpu_opencl.cpp b/client/gpu_opencl.cpp index f774fe110b..010c2e524e 100644 --- a/client/gpu_opencl.cpp +++ b/client/gpu_opencl.cpp @@ -717,12 +717,6 @@ void COPROCS::get_opencl( prop.opencl_available_ram = prop.global_mem_size; apple_gpu_opencls.push_back(prop); - - // At present Apple GPUs only support OpenCL - // and do not have a native GPGPU framework, - // so treat each detected GPU as a native device. - // - apple_gpus.push_back(c); } else { //////////// OTHER GPU OR ACCELERATOR ////////////// // Put each coprocessor instance into a separate other_opencls element @@ -857,9 +851,12 @@ void COPROCS::correlate_opencl( use_all, apple_gpu_opencls, ignore_gpu_instance[PROC_TYPE_APPLE_GPU] ); - apple_gpu.available_ram = apple_gpu.opencl_prop.global_mem_size; safe_strcpy(apple_gpu.model, apple_gpu.opencl_prop.name); } + apple_gpu.set_peak_flops(); + if (!apple_gpu.available_ram) { + apple_gpu.available_ram = apple_gpu.opencl_prop.global_mem_size; + } } } diff --git a/lib/coproc.h b/lib/coproc.h index e0c5538ad7..37622f7581 100644 --- a/lib/coproc.h +++ b/lib/coproc.h @@ -382,8 +382,8 @@ struct COPROC_APPLE : public COPROC { #endif COPROC_APPLE(int): COPROC() {} COPROC_APPLE(): COPROC() {clear();} - void get(std::vector& ) {}; - void correlate(bool , std::vector& ) {}; + void get(std::vector&); + void correlate(bool , std::vector&); void clear(); int parse(XML_PARSER&); void set_peak_flops();