From 4afd11dae5c254b3c78cd0fa241fe14305e599dd Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Sat, 18 Jul 2020 16:57:41 +0000 Subject: [PATCH 01/10] Add a check for C11 atomics and stdatomic.h --- c_check | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/c_check b/c_check index dd700b8b4..314c2b157 100644 --- a/c_check +++ b/c_check @@ -249,6 +249,28 @@ if (($architecture eq "x86") || ($architecture eq "x86_64")) { } } +$c11_atomics = 0; +if ($data =~ /HAVE_C11/) { + eval "use File::Temp qw(tempfile)"; + if ($@){ + warn "could not load PERL module File::Temp, so could not check compiler compatibility with C11"; + $c11_atomics = 0; + } else { + ($fh,$tmpf) = tempfile( SUFFIX => '.c' , UNLINK => 1 ); + print $tmpf "#include \nint main(void){}\n"; + $args = " -c -o $tmpf.o $tmpf"; + my @cmd = ("$compiler_name $flags $args >/dev/null 2>/dev/null"); + system(@cmd) == 0; + if ($? != 0) { + $c11_atomics = 0; + } else { + $c11_atomics = 1; + } + unlink("$tmpf.o"); + } +} + + $data = `$compiler_name $flags -S ctest1.c && grep globl ctest1.s | head -n 1 && rm -f ctest1.s`; $data =~ /globl\s([_\.]*)(.*)/; @@ -352,6 +374,8 @@ print CONFFILE "#define __32BIT__\t1\n" if $binformat eq bin32; print CONFFILE "#define __64BIT__\t1\n" if $binformat eq bin64; print CONFFILE "#define FUNDERSCORE\t$need_fu\n" if $need_fu ne ""; print CONFFILE "#define HAVE_MSA\t1\n" if $have_msa eq 1; +print CONFFILE "#define HAVE_C11\t1\n" if $c11_atomics eq 1; + if ($os eq "LINUX") { From 97d6eb97b15d2ece319da9c741ca13b2976013cc Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Sat, 18 Jul 2020 16:59:33 +0000 Subject: [PATCH 02/10] Report availability of C11 support --- ctest.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ctest.c b/ctest.c index 5e869b901..cd84ab1bb 100644 --- a/ctest.c +++ b/ctest.c @@ -153,3 +153,6 @@ ARCH_ARM ARCH_ARM64 #endif +#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) +HAVE_C11 +#endif From 94bab9d1f92325aec79aecc9daacfaef8903d359 Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Sat, 18 Jul 2020 17:03:31 +0000 Subject: [PATCH 03/10] Update conditional for atomics to use HAVE_C11 --- driver/others/blas_server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver/others/blas_server.c b/driver/others/blas_server.c index 04b614a6e..756e51b5d 100644 --- a/driver/others/blas_server.c +++ b/driver/others/blas_server.c @@ -141,7 +141,7 @@ typedef struct { } thread_status_t; -#if (__STDC_VERSION__ >= 201112L) +#ifdef HAVE_C11 #define atomic_load_queue(p) __atomic_load_n(p, __ATOMIC_RELAXED) #define atomic_store_queue(p, v) __atomic_store_n(p, v, __ATOMIC_RELAXED) #else From 791e046744116bbf06649ae43adf0febdcebb6a9 Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Sat, 18 Jul 2020 17:05:59 +0000 Subject: [PATCH 04/10] Update conditional for atomics to use HAVE_C11 --- driver/others/blas_server_omp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/driver/others/blas_server_omp.c b/driver/others/blas_server_omp.c index 4255852c8..b4eb27c25 100644 --- a/driver/others/blas_server_omp.c +++ b/driver/others/blas_server_omp.c @@ -55,7 +55,7 @@ int blas_server_avail = 0; static void * blas_thread_buffer[MAX_PARALLEL_NUMBER][MAX_CPU_NUMBER]; -#if __STDC_VERSION__ >= 201112L +#ifdef HAVE_C11 static atomic_bool blas_buffer_inuse[MAX_PARALLEL_NUMBER]; #else static _Bool blas_buffer_inuse[MAX_PARALLEL_NUMBER]; @@ -320,7 +320,7 @@ int exec_blas(BLASLONG num, blas_queue_t *queue){ while(true) { for(i=0; i < MAX_PARALLEL_NUMBER; i++) { -#if __STDC_VERSION__ >= 201112L +#ifdef HAVE_C11 _Bool inuse = false; if(atomic_compare_exchange_weak(&blas_buffer_inuse[i], &inuse, true)) { #else @@ -345,7 +345,7 @@ int exec_blas(BLASLONG num, blas_queue_t *queue){ exec_threads(&queue[i], buf_index); } -#if __STDC_VERSION__ >= 201112L +#ifdef HAVE_C11 atomic_store(&blas_buffer_inuse[buf_index], false); #else blas_buffer_inuse[buf_index] = false; From 09eb9d2584bd978815571b2860f06dedc9f606d2 Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Sat, 18 Jul 2020 17:07:38 +0000 Subject: [PATCH 05/10] Update conditional for atomics to HAVE_C11 --- driver/others/memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver/others/memory.c b/driver/others/memory.c index a5595aed4..9b6c226a1 100644 --- a/driver/others/memory.c +++ b/driver/others/memory.c @@ -1095,7 +1095,7 @@ static BLASULONG base_address = 0UL; static BLASULONG base_address = BASE_ADDRESS; #endif -#if __STDC_VERSION__ >= 201112L +#ifdef HAVE_C11 static _Atomic int memory_initialized = 0; #else static volatile int memory_initialized = 0; From 6f38de06d2a0ce372c631b01380be58932ec159a Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Sat, 18 Jul 2020 17:09:01 +0000 Subject: [PATCH 06/10] Update conditional for atomics to use HAVE_C11 --- driver/level3/level3_gemm3m_thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver/level3/level3_gemm3m_thread.c b/driver/level3/level3_gemm3m_thread.c index 9216daaed..39824fc5a 100644 --- a/driver/level3/level3_gemm3m_thread.c +++ b/driver/level3/level3_gemm3m_thread.c @@ -91,7 +91,7 @@ #endif typedef struct { -#if __STDC_VERSION__ >= 201112L +#ifdef HAVE_C11 _Atomic #else volatile From ce45af8151c96fcb1c75d3985d96c5b64a68f823 Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Sat, 18 Jul 2020 17:09:56 +0000 Subject: [PATCH 07/10] Update conditional for atomics to use HAVE_C11 --- driver/level3/level3_syrk_threaded.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver/level3/level3_syrk_threaded.c b/driver/level3/level3_syrk_threaded.c index 574f825b0..a041abac3 100644 --- a/driver/level3/level3_syrk_threaded.c +++ b/driver/level3/level3_syrk_threaded.c @@ -67,7 +67,7 @@ #endif typedef struct { -#if __STDC_VERSION__ >= 201112L +#ifdef HAVE_C11 _Atomic #else volatile From a36eb19ae0dfab6714f82abf90b1394012888ff3 Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Sat, 18 Jul 2020 17:13:24 +0000 Subject: [PATCH 08/10] Update conditional for C11 atomics to use HAVE_C11 --- common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common.h b/common.h index 00b34a3f7..d6637abe4 100644 --- a/common.h +++ b/common.h @@ -681,7 +681,7 @@ __declspec(dllimport) int __cdecl omp_in_parallel(void); __declspec(dllimport) int __cdecl omp_get_num_procs(void); #endif -#if (__STDC_VERSION__ >= 201112L) +#ifdef HAVE_C11 #if defined(C_GCC) && ( __GNUC__ < 7) // workaround for GCC bug 65467 #ifndef _Atomic From f4f74941bd5fadfe3fd662f4da8355f2c6250949 Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Sat, 18 Jul 2020 17:14:50 +0000 Subject: [PATCH 09/10] Update conditional for atomics to use HAVE_C11 --- lapack/getrf/getrf_parallel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lapack/getrf/getrf_parallel.c b/lapack/getrf/getrf_parallel.c index c602822a8..fc410b0e7 100644 --- a/lapack/getrf/getrf_parallel.c +++ b/lapack/getrf/getrf_parallel.c @@ -68,7 +68,7 @@ double sqrt(double); #define GETRF_FACTOR 1.00 -#if (__STDC_VERSION__ >= 201112L) +#ifdef HAVE_C11 #define atomic_load_long(p) __atomic_load_n(p, __ATOMIC_RELAXED) #define atomic_store_long(p, v) __atomic_store_n(p, v, __ATOMIC_RELAXED) #else From bbe119ee3bc0393dbc1d3422690c5f628576a3b4 Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Sat, 18 Jul 2020 17:19:59 +0000 Subject: [PATCH 10/10] Update conditional for atomics to use HAVE_C11 --- lapack/getrf/potrf_parallel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lapack/getrf/potrf_parallel.c b/lapack/getrf/potrf_parallel.c index 312509685..008fcb8cc 100644 --- a/lapack/getrf/potrf_parallel.c +++ b/lapack/getrf/potrf_parallel.c @@ -101,7 +101,7 @@ static FLOAT dm1 = -1.; #endif typedef struct { -#if __STDC_VERSION__ >= 201112L +#ifdef HAVE_C11 _Atomic #else volatile