From 65a847cd361d33b4a65c10d13eefb11eb02f04d7 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Tue, 3 Feb 2015 12:23:34 -0500 Subject: [PATCH] Introduce openblas_get_num_threads and openblas_get_num_procs --- cblas.h | 6 ++++ cblas_noconst.h | 6 ++++ driver/others/Makefile | 8 ++++- driver/others/memory.c | 8 +++++ driver/others/openblas_get_num_procs.c | 40 ++++++++++++++++++++++++ driver/others/openblas_get_num_threads.c | 40 ++++++++++++++++++++++++ exports/gensymbol | 5 ++- 7 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 driver/others/openblas_get_num_procs.c create mode 100644 driver/others/openblas_get_num_threads.c diff --git a/cblas.h b/cblas.h index d1c029afa..a21863d88 100644 --- a/cblas.h +++ b/cblas.h @@ -13,6 +13,12 @@ extern "C" { void openblas_set_num_threads(int num_threads); void goto_set_num_threads(int num_threads); +/*Get the number of threads on runtime.*/ +int openblas_get_num_threads(void); + +/*Get the number of physical processors (cores).*/ +int openblas_get_num_procs(void); + /*Get the build configure on runtime.*/ char* openblas_get_config(void); diff --git a/cblas_noconst.h b/cblas_noconst.h index bc6382513..f6a6baf62 100644 --- a/cblas_noconst.h +++ b/cblas_noconst.h @@ -13,6 +13,12 @@ extern "C" { void openblas_set_num_threads(int num_threads); void goto_set_num_threads(int num_threads); +/*Get the number of threads on runtime.*/ +int openblas_get_num_threads(void); + +/*Get the number of physical processors (cores).*/ +int openblas_get_num_procs(void); + /*Get the build configure on runtime.*/ char* openblas_get_config(void); diff --git a/driver/others/Makefile b/driver/others/Makefile index fc73871cc..ed145cee8 100644 --- a/driver/others/Makefile +++ b/driver/others/Makefile @@ -1,7 +1,7 @@ TOPDIR = ../.. include ../../Makefile.system -COMMONOBJS = memory.$(SUFFIX) xerbla.$(SUFFIX) c_abs.$(SUFFIX) z_abs.$(SUFFIX) openblas_set_num_threads.$(SUFFIX) openblas_get_config.$(SUFFIX) openblas_get_parallel.$(SUFFIX) openblas_error_handle.$(SUFFIX) +COMMONOBJS = memory.$(SUFFIX) xerbla.$(SUFFIX) c_abs.$(SUFFIX) z_abs.$(SUFFIX) openblas_set_num_threads.$(SUFFIX) openblas_get_num_threads.$(SUFFIX) openblas_get_num_procs.$(SUFFIX) openblas_get_config.$(SUFFIX) openblas_get_parallel.$(SUFFIX) openblas_error_handle.$(SUFFIX) #COMMONOBJS += slamch.$(SUFFIX) slamc3.$(SUFFIX) dlamch.$(SUFFIX) dlamc3.$(SUFFIX) @@ -103,6 +103,12 @@ blas_server.$(SUFFIX) : $(BLAS_SERVER) ../../common.h ../../common_thread.h ../. openblas_set_num_threads.$(SUFFIX) : openblas_set_num_threads.c $(CC) $(CFLAGS) -c $< -o $(@F) +openblas_get_num_threads.$(SUFFIX) : openblas_get_num_threads.c + $(CC) $(CFLAGS) -c $< -o $(@F) + +openblas_get_num_procs.$(SUFFIX) : openblas_get_num_procs.c + $(CC) $(CFLAGS) -c $< -o $(@F) + openblas_get_config.$(SUFFIX) : openblas_get_config.c $(CC) $(CFLAGS) -c $< -o $(@F) diff --git a/driver/others/memory.c b/driver/others/memory.c index 16d68cced..e245d9e53 100644 --- a/driver/others/memory.c +++ b/driver/others/memory.c @@ -241,6 +241,10 @@ void set_stack_limit(int limitMB){ */ #endif +int openblas_get_num_procs(void) { + return get_num_procs(); +} + /* OpenBLAS uses the numbers of CPU cores in multithreading. It can be set by openblas_set_num_threads(int num_threads); @@ -323,6 +327,10 @@ int blas_get_cpu_number(void){ } #endif +int openblas_get_num_threads(void) { + return blas_get_cpu_number(); +} + struct release_t { void *address; void (*func)(struct release_t *); diff --git a/driver/others/openblas_get_num_procs.c b/driver/others/openblas_get_num_procs.c new file mode 100644 index 000000000..6b0c1ec5c --- /dev/null +++ b/driver/others/openblas_get_num_procs.c @@ -0,0 +1,40 @@ +/***************************************************************************** +Copyright (c) 2011-2014, The OpenBLAS Project +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. Neither the name of the OpenBLAS project nor the names of + its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**********************************************************************************/ + +#include "common.h" + +extern int openblas_get_num_procs(void); + +int openblas_get_num_procs_(void) { + return openblas_get_num_procs(); +} diff --git a/driver/others/openblas_get_num_threads.c b/driver/others/openblas_get_num_threads.c new file mode 100644 index 000000000..e31aa4b4a --- /dev/null +++ b/driver/others/openblas_get_num_threads.c @@ -0,0 +1,40 @@ +/***************************************************************************** +Copyright (c) 2011-2014, The OpenBLAS Project +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. Neither the name of the OpenBLAS project nor the names of + its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**********************************************************************************/ + +#include "common.h" + +extern int openblas_get_num_threads(void); + +int openblas_get_num_threads_(void) { + return openblas_get_num_threads(); +} diff --git a/exports/gensymbol b/exports/gensymbol index 8bd2f17af..2155f801f 100644 --- a/exports/gensymbol +++ b/exports/gensymbol @@ -81,7 +81,10 @@ #both underscore and no underscore @misc_common_objs = ( - openblas_set_num_threads, openblas_get_parallel, + openblas_get_parallel, + openblas_get_num_procs, + openblas_set_num_threads, + openblas_get_num_threads, ); @misc_no_underscore_objs = (