parent
69f277f8ee
commit
7b4773b24d
5
cblas.h
5
cblas.h
|
@ -25,6 +25,11 @@ char* openblas_get_config(void);
|
||||||
/*Get the CPU corename on runtime.*/
|
/*Get the CPU corename on runtime.*/
|
||||||
char* openblas_get_corename(void);
|
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);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Get the parallelization type which is used by OpenBLAS */
|
/* Get the parallelization type which is used by OpenBLAS */
|
||||||
int openblas_get_parallel(void);
|
int openblas_get_parallel(void);
|
||||||
/* OpenBLAS is compiled for sequential use */
|
/* OpenBLAS is compiled for sequential use */
|
||||||
|
|
|
@ -72,6 +72,7 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#if defined(OS_LINUX) || defined(OS_NETBSD) || defined(OS_DARWIN) || defined(OS_ANDROID) || defined(OS_SUNOS) || defined(OS_FREEBSD) || defined(OS_OPENBSD) || defined(OS_DRAGONFLY) || defined(OS_HAIKU)
|
#if defined(OS_LINUX) || defined(OS_NETBSD) || defined(OS_DARWIN) || defined(OS_ANDROID) || defined(OS_SUNOS) || defined(OS_FREEBSD) || defined(OS_OPENBSD) || defined(OS_DRAGONFLY) || defined(OS_HAIKU)
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
@ -279,6 +280,23 @@ int get_node(void);
|
||||||
|
|
||||||
static int increased_threads = 0;
|
static int increased_threads = 0;
|
||||||
|
|
||||||
|
#ifdef OS_LINUX
|
||||||
|
int openblas_setaffinity(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_setaffinity_np(thread, cpusetsize, cpu_set);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void* blas_thread_server(void *arg){
|
static void* blas_thread_server(void *arg){
|
||||||
|
|
||||||
/* Thread identifier */
|
/* Thread identifier */
|
||||||
|
|
|
@ -91,3 +91,8 @@ typedef int blasint;
|
||||||
#define openblas_complex_xdouble_real(z) ((z).real)
|
#define openblas_complex_xdouble_real(z) ((z).real)
|
||||||
#define openblas_complex_xdouble_imag(z) ((z).imag)
|
#define openblas_complex_xdouble_imag(z) ((z).imag)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Inclusion of Linux-specific header is needed for definition of cpu_set_t. */
|
||||||
|
#ifdef OPENBLAS_OS_LINUX
|
||||||
|
#include <sched.h>
|
||||||
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue