From 8668571040bd72338593b4fe0a6c9d1509295da4 Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Wed, 27 Jul 2022 19:14:36 +0200 Subject: [PATCH 1/2] add openblas_getaffinity() --- cblas.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cblas.h b/cblas.h index a5ad25ad79..c2bdd27fa4 100644 --- a/cblas.h +++ b/cblas.h @@ -28,6 +28,8 @@ char* openblas_get_corename(void); #ifdef OPENBLAS_OS_LINUX /* Sets thread affinity for OpenBLAS threads. `thread_idx` is in [0, openblas_get_num_threads()-1]. */ int openblas_setaffinity(int thread_idx, size_t cpusetsize, cpu_set_t* cpu_set); +/* Queries thread affinity for OpenBLAS threads. `thread_idx` is in [0, openblas_get_num_threads()-1]. */ +int openblas_getaffinity(int thread_idx, size_t cpusetsize, cpu_set_t* cpu_set); #endif /* Get the parallelization type which is used by OpenBLAS */ From 30473b6a9d2179606ad4eff2861418b6b6e7e9f0 Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Wed, 27 Jul 2022 19:15:18 +0200 Subject: [PATCH 2/2] add openblas_getaffinity() --- driver/others/blas_server.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/driver/others/blas_server.c b/driver/others/blas_server.c index ec79075fe0..9cfd825ecb 100644 --- a/driver/others/blas_server.c +++ b/driver/others/blas_server.c @@ -352,6 +352,20 @@ int openblas_setaffinity(int thread_idx, size_t cpusetsize, cpu_set_t* cpu_set) return pthread_setaffinity_np(thread, cpusetsize, cpu_set); } +int openblas_getaffinity(int thread_idx, size_t cpusetsize, cpu_set_t* cpu_set) { + const int active_threads = openblas_get_num_threads(); + + if (thread_idx < 0 || thread_idx >= active_threads) { + errno = EINVAL; + return -1; + } + + pthread_t thread = (thread_idx == active_threads - 1) + ? pthread_self() + : blas_threads[thread_idx]; + + return pthread_getaffinity_np(thread, cpusetsize, cpu_set); +} #endif static void* blas_thread_server(void *arg){