Add openblas_getaffinity() extension (Linux-only)tags/v0.3.21
| @@ -28,6 +28,8 @@ char* openblas_get_corename(void); | |||||
| #ifdef OPENBLAS_OS_LINUX | #ifdef OPENBLAS_OS_LINUX | ||||
| /* Sets thread affinity for OpenBLAS threads. `thread_idx` is in [0, openblas_get_num_threads()-1]. */ | /* 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); | 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 | #endif | ||||
| /* Get the parallelization type which is used by OpenBLAS */ | /* Get the parallelization type which is used by OpenBLAS */ | ||||
| @@ -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); | 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 | #endif | ||||
| static void* blas_thread_server(void *arg){ | static void* blas_thread_server(void *arg){ | ||||