Skip to content

Commit 5135d5c

Browse files
authored
Merge pull request #5844 from kumaraditya303/develop
fix data races in blas_server and level3_thread
2 parents f986fd3 + ea2a52d commit 5135d5c

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

.github/workflows/dynamic_arch.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ jobs:
200200
- msystem: MINGW32
201201
idx: int32
202202
target-prefix: mingw-w64-i686
203-
fc-pkg:
203+
fc-pkg:
204204
- msystem: CLANG64
205205
idx: int32
206206
target-prefix: mingw-w64-clang-x86_64
@@ -460,13 +460,12 @@ jobs:
460460
run: |
461461
cd build
462462
if [ "${{ matrix.backend }}" = "tsan" ]; then
463-
export OPENBLAS_NUM_THREADS=2
464463
export LLVM_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer
465464
export TSAN_OPTIONS=halt_on_error=1:exitcode=66:second_deadlock_stack=1
466465
else
467-
export OPENBLAS_NUM_THREADS=8
468466
export OMP_NUM_THREADS=16
469467
fi
468+
export OPENBLAS_NUM_THREADS=8
470469
ctest -R 'dgemm_thread_safety|dgemm_thread_safety_mixed|dgemv_thread_safety' --output-on-failure
471470
472471
@@ -687,7 +686,7 @@ jobs:
687686
- name: Build OpenBLAS
688687
run: |
689688
make -j${nproc} TARGET=NEOVERSEN1 USE_OPENMP=1
690-
689+
691690
neoverse_n1_ilp64_build:
692691
if: "github.repository == 'OpenMathLib/OpenBLAS'"
693692
runs-on: ubuntu-24.04-arm

driver/level3/level3_thread.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@
9898
#endif
9999

100100
typedef struct {
101+
#ifdef HAVE_C11
102+
_Atomic
103+
#else
101104
volatile
105+
#endif
102106
BLASLONG working[MAX_CPU_NUMBER][CACHE_LINE_SIZE * DIVIDE_RATE_MAX];
103107
} job_t;
104108

driver/others/blas_server.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,13 @@ int blas_thread_init(void){
631631
exec_blas ... returns after jobs are finished.
632632
*/
633633

634+
#if defined(USE_PTHREAD_LOCK)
635+
static pthread_mutex_t exec_queue_lock = PTHREAD_MUTEX_INITIALIZER;
636+
#elif defined(USE_PTHREAD_SPINLOCK)
637+
static pthread_spinlock_t exec_queue_lock = 0;
638+
#else
634639
static BLASULONG exec_queue_lock = 0;
640+
#endif
635641

636642
int exec_blas_async(BLASLONG pos, blas_queue_t *queue){
637643

@@ -652,7 +658,7 @@ int exec_blas_async(BLASLONG pos, blas_queue_t *queue){
652658
fprintf(STDERR, "Exec_blas_async is called. Position = %d\n", pos);
653659
#endif
654660

655-
blas_lock(&exec_queue_lock);
661+
LOCK_COMMAND(&exec_queue_lock);
656662

657663
while (queue) {
658664
queue -> position = pos;
@@ -717,7 +723,7 @@ int exec_blas_async(BLASLONG pos, blas_queue_t *queue){
717723

718724
}
719725

720-
blas_unlock(&exec_queue_lock);
726+
UNLOCK_COMMAND(&exec_queue_lock);
721727

722728
#ifdef SMP_DEBUG
723729
fprintf(STDERR, "Done(Number of threads = %2ld).\n", exec_count);

0 commit comments

Comments
 (0)