@@ -1603,9 +1603,11 @@ void gotoblas_dummy_for_PGI(void) {
1603
1603
#endif
1604
1604
1605
1605
#else
1606
+ /* USE_TLS / COMPILE_TLS not set */
1607
+
1606
1608
#include <errno.h>
1607
1609
1608
- #ifdef OS_WINDOWS
1610
+ #if defined( OS_WINDOWS ) && !defined( OS_CYGWIN_NT )
1609
1611
#define ALLOC_WINDOWS
1610
1612
#ifndef MEM_LARGE_PAGES
1611
1613
#define MEM_LARGE_PAGES 0x20000000
@@ -1619,7 +1621,7 @@ void gotoblas_dummy_for_PGI(void) {
1619
1621
#include <stdio.h>
1620
1622
#include <fcntl.h>
1621
1623
1622
- #ifndef OS_WINDOWS
1624
+ #if !defined( OS_WINDOWS ) || defined( OS_CYGWIN_NT )
1623
1625
#include <sys/mman.h>
1624
1626
#ifndef NO_SYSV_IPC
1625
1627
#include <sys/shm.h>
@@ -1639,7 +1641,7 @@ void gotoblas_dummy_for_PGI(void) {
1639
1641
#include <sys/resource.h>
1640
1642
#endif
1641
1643
1642
- #if defined(OS_FREEBSD ) || defined(OS_DARWIN )
1644
+ #if defined(OS_FREEBSD ) || defined(OS_OPENBSD ) || defined( OS_DRAGONFLY ) || defined( OS_DARWIN )
1643
1645
#include <sys/sysctl.h>
1644
1646
#include <sys/resource.h>
1645
1647
#endif
@@ -1678,9 +1680,12 @@ void gotoblas_dummy_for_PGI(void) {
1678
1680
#elif (defined(OS_DARWIN ) || defined(OS_SUNOS )) && defined(C_GCC )
1679
1681
#define CONSTRUCTOR __attribute__ ((constructor))
1680
1682
#define DESTRUCTOR __attribute__ ((destructor))
1681
- #else
1683
+ #elif __GNUC__ && INIT_PRIORITY && (( GCC_VERSION >= 40300 ) || ( CLANG_VERSION >= 20900 ))
1682
1684
#define CONSTRUCTOR __attribute__ ((constructor(101)))
1683
1685
#define DESTRUCTOR __attribute__ ((destructor(101)))
1686
+ #else
1687
+ #define CONSTRUCTOR __attribute__ ((constructor))
1688
+ #define DESTRUCTOR __attribute__ ((destructor))
1684
1689
#endif
1685
1690
1686
1691
#ifdef DYNAMIC_ARCH
@@ -1740,7 +1745,8 @@ int i,n;
1740
1745
size = CPU_ALLOC_SIZE (nums );
1741
1746
ret = sched_getaffinity (0 ,size ,cpusetp );
1742
1747
if (ret != 0 ) return nums ;
1743
- nums = CPU_COUNT_S (size ,cpusetp );
1748
+ ret = CPU_COUNT_S (size ,cpusetp );
1749
+ if (ret > 0 && ret < nums ) nums = ret ;
1744
1750
CPU_FREE (cpusetp );
1745
1751
return nums ;
1746
1752
#endif
@@ -1756,7 +1762,7 @@ int get_num_procs(void) {
1756
1762
return nums ;
1757
1763
}
1758
1764
#endif
1759
-
1765
+
1760
1766
#ifdef OS_HAIKU
1761
1767
int get_num_procs (void ) {
1762
1768
static int nums = 0 ;
@@ -1793,7 +1799,7 @@ int get_num_procs(void) {
1793
1799
1794
1800
#endif
1795
1801
1796
- #if defined(OS_FREEBSD )
1802
+ #if defined(OS_FREEBSD ) || defined( OS_OPENBSD ) || defined( OS_DRAGONFLY )
1797
1803
1798
1804
int get_num_procs (void ) {
1799
1805
@@ -1870,7 +1876,7 @@ void openblas_fork_handler()
1870
1876
// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60035
1871
1877
// In the mean time build with USE_OPENMP=0 or link against another
1872
1878
// implementation of OpenMP.
1873
- #if !(defined(OS_WINDOWS ) || defined(OS_ANDROID )) && defined(SMP_SERVER )
1879
+ #if !(( defined(OS_WINDOWS ) && !defined( OS_CYGWIN_NT ) ) || defined(OS_ANDROID )) && defined(SMP_SERVER )
1874
1880
int err ;
1875
1881
err = pthread_atfork ((void (* )(void )) BLASFUNC (blas_thread_shutdown ), NULL , NULL );
1876
1882
if (err != 0 )
@@ -1883,19 +1889,19 @@ extern int openblas_goto_num_threads_env();
1883
1889
extern int openblas_omp_num_threads_env ();
1884
1890
1885
1891
int blas_get_cpu_number (void ){
1886
- #if defined(OS_LINUX ) || defined(OS_WINDOWS ) || defined(OS_FREEBSD ) || defined(OS_DARWIN ) || defined(OS_ANDROID )
1892
+ #if defined(OS_LINUX ) || defined(OS_WINDOWS ) || defined(OS_FREEBSD ) || defined(OS_OPENBSD ) || defined( OS_DRAGONFLY ) || defined( OS_DARWIN ) || defined(OS_ANDROID )
1887
1893
int max_num ;
1888
1894
#endif
1889
1895
int blas_goto_num = 0 ;
1890
1896
int blas_omp_num = 0 ;
1891
1897
1892
1898
if (blas_num_threads ) return blas_num_threads ;
1893
1899
1894
- #if defined(OS_LINUX ) || defined(OS_WINDOWS ) || defined(OS_FREEBSD ) || defined(OS_DARWIN ) || defined(OS_ANDROID )
1900
+ #if defined(OS_LINUX ) || defined(OS_WINDOWS ) || defined(OS_FREEBSD ) || defined(OS_OPENBSD ) || defined( OS_DRAGONFLY ) || defined( OS_DARWIN ) || defined(OS_ANDROID )
1895
1901
max_num = get_num_procs ();
1896
1902
#endif
1897
1903
1898
- blas_goto_num = 0 ;
1904
+ // blas_goto_num = 0;
1899
1905
#ifndef USE_OPENMP
1900
1906
blas_goto_num = openblas_num_threads_env ();
1901
1907
if (blas_goto_num < 0 ) blas_goto_num = 0 ;
@@ -1907,15 +1913,15 @@ int blas_get_cpu_number(void){
1907
1913
1908
1914
#endif
1909
1915
1910
- blas_omp_num = 0 ;
1916
+ // blas_omp_num = 0;
1911
1917
blas_omp_num = openblas_omp_num_threads_env ();
1912
1918
if (blas_omp_num < 0 ) blas_omp_num = 0 ;
1913
1919
1914
1920
if (blas_goto_num > 0 ) blas_num_threads = blas_goto_num ;
1915
1921
else if (blas_omp_num > 0 ) blas_num_threads = blas_omp_num ;
1916
1922
else blas_num_threads = MAX_CPU_NUMBER ;
1917
1923
1918
- #if defined(OS_LINUX ) || defined(OS_WINDOWS ) || defined(OS_FREEBSD ) || defined(OS_DARWIN ) || defined(OS_ANDROID )
1924
+ #if defined(OS_LINUX ) || defined(OS_WINDOWS ) || defined(OS_FREEBSD ) || defined(OS_OPENBSD ) || defined( OS_DRAGONFLY ) || defined( OS_DARWIN ) || defined(OS_ANDROID )
1919
1925
if (blas_num_threads > max_num ) blas_num_threads = max_num ;
1920
1926
#endif
1921
1927
@@ -2002,11 +2008,15 @@ static void *alloc_mmap(void *address){
2002
2008
}
2003
2009
2004
2010
if (map_address != (void * )-1 ) {
2011
+ #if defined(SMP ) && !defined(USE_OPENMP )
2005
2012
LOCK_COMMAND (& alloc_lock );
2013
+ #endif
2006
2014
release_info [release_pos ].address = map_address ;
2007
2015
release_info [release_pos ].func = alloc_mmap_free ;
2008
2016
release_pos ++ ;
2017
+ #if defined(SMP ) && !defined(USE_OPENMP )
2009
2018
UNLOCK_COMMAND (& alloc_lock );
2019
+ #endif
2010
2020
}
2011
2021
2012
2022
#ifdef OS_LINUX
@@ -2148,14 +2158,18 @@ static void *alloc_mmap(void *address){
2148
2158
#if defined(OS_LINUX ) && !defined(NO_WARMUP )
2149
2159
}
2150
2160
#endif
2151
- LOCK_COMMAND (& alloc_lock );
2152
2161
2153
2162
if (map_address != (void * )-1 ) {
2163
+ #if defined(SMP ) && !defined(USE_OPENMP )
2164
+ LOCK_COMMAND (& alloc_lock );
2165
+ #endif
2154
2166
release_info [release_pos ].address = map_address ;
2155
2167
release_info [release_pos ].func = alloc_mmap_free ;
2156
2168
release_pos ++ ;
2169
+ #if defined(SMP ) && !defined(USE_OPENMP )
2170
+ UNLOCK_COMMAND (& alloc_lock );
2171
+ #endif
2157
2172
}
2158
- UNLOCK_COMMAND (& alloc_lock );
2159
2173
2160
2174
return map_address ;
2161
2175
}
@@ -2554,6 +2568,11 @@ void *blas_memory_alloc(int procpos){
2554
2568
NULL ,
2555
2569
};
2556
2570
void * (* * func )(void * address );
2571
+
2572
+ #if defined(USE_OPENMP )
2573
+ if (!memory_initialized ) {
2574
+ #endif
2575
+
2557
2576
LOCK_COMMAND (& alloc_lock );
2558
2577
2559
2578
if (!memory_initialized ) {
@@ -2589,6 +2608,9 @@ void *blas_memory_alloc(int procpos){
2589
2608
2590
2609
}
2591
2610
UNLOCK_COMMAND (& alloc_lock );
2611
+ #if defined(USE_OPENMP )
2612
+ }
2613
+ #endif
2592
2614
2593
2615
#ifdef DEBUG
2594
2616
printf ("Alloc Start ...\n" );
@@ -2603,13 +2625,17 @@ void *blas_memory_alloc(int procpos){
2603
2625
2604
2626
do {
2605
2627
if (!memory[position].used && (memory[position].pos == mypos)) {
2628
+ #if defined(SMP) && !defined(USE_OPENMP)
2606
2629
LOCK_COMMAND(&alloc_lock);
2607
- // blas_lock(&memory[position].lock);
2608
-
2630
+ #else
2631
+ blas_lock(&memory[position].lock);
2632
+ #endif
2609
2633
if (!memory[position].used) goto allocation;
2610
-
2634
+ #if defined(SMP) && !defined(USE_OPENMP)
2611
2635
UNLOCK_COMMAND(&alloc_lock);
2612
- // blas_unlock(&memory[position].lock);
2636
+ #else
2637
+ blas_unlock(&memory[position].lock);
2638
+ #endif
2613
2639
}
2614
2640
2615
2641
position ++;
@@ -2647,7 +2673,6 @@ void *blas_memory_alloc(int procpos){
2647
2673
memory [position ].used = 1 ;
2648
2674
2649
2675
UNLOCK_COMMAND (& alloc_lock );
2650
- /* blas_unlock(&memory[position].lock);*/
2651
2676
2652
2677
if (!memory [position ].addr ) {
2653
2678
do {
@@ -2693,9 +2718,13 @@ void *blas_memory_alloc(int procpos){
2693
2718
2694
2719
} while ((BLASLONG )map_address == -1 );
2695
2720
2721
+ #if defined(SMP ) && !defined(USE_OPENMP )
2696
2722
LOCK_COMMAND (& alloc_lock );
2723
+ #endif
2697
2724
memory [position ].addr = map_address ;
2725
+ #if defined(SMP ) && !defined(USE_OPENMP )
2698
2726
UNLOCK_COMMAND (& alloc_lock );
2727
+ #endif
2699
2728
2700
2729
#ifdef DEBUG
2701
2730
printf (" Mapping Succeeded. %p(%d)\n" , (void * )memory [position ].addr , position );
@@ -2749,8 +2778,9 @@ void blas_memory_free(void *free_area){
2749
2778
#endif
2750
2779
2751
2780
position = 0 ;
2781
+ #if defined(SMP ) && !defined(USE_OPENMP )
2752
2782
LOCK_COMMAND (& alloc_lock );
2753
-
2783
+ #endif
2754
2784
while ((position < NUM_BUFFERS ) && (memory [position ].addr != free_area ))
2755
2785
position ++ ;
2756
2786
@@ -2764,7 +2794,9 @@ void blas_memory_free(void *free_area){
2764
2794
WMB ;
2765
2795
2766
2796
memory [position ].used = 0 ;
2797
+ #if defined(SMP ) && !defined(USE_OPENMP )
2767
2798
UNLOCK_COMMAND (& alloc_lock );
2799
+ #endif
2768
2800
2769
2801
#ifdef DEBUG
2770
2802
printf ("Unmap Succeeded.\n\n" );
@@ -2779,8 +2811,9 @@ void blas_memory_free(void *free_area){
2779
2811
for (position = 0 ; position < NUM_BUFFERS ; position ++ )
2780
2812
printf ("%4ld %p : %d\n" , position , memory [position ].addr , memory [position ].used );
2781
2813
#endif
2814
+ #if defined(SMP ) && !defined(USE_OPENMP )
2782
2815
UNLOCK_COMMAND (& alloc_lock );
2783
-
2816
+ #endif
2784
2817
return ;
2785
2818
}
2786
2819
0 commit comments