Skip to content

Commit 596ed7c

Browse files
authored
Merge pull request #284 from mattip/windows-threading
Windows threading fix
2 parents 5cfb9c1 + f21b340 commit 596ed7c

11 files changed

Lines changed: 171 additions & 34 deletions

‎.gitattributes‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Patches must reach the build byte-identical: their line endings have to match
2+
# the files they patch, and checkout conversion would break that.
3+
*.patch -text

‎.github/workflows/posix.yml‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,19 @@ jobs:
119119
name: wheels-${{ matrix.os }}-${{ matrix.PLAT }}-${{ matrix.INTERFACE64 }}-${{ matrix.MB_ML_LIBC }}-${{ matrix.MB_ML_VER }}
120120
path: dist/scipy_openblas*.whl
121121

122+
upload:
123+
name: Upload to anaconda.org
124+
needs: build
125+
if: ${{ inputs.publish == false && (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') }}
126+
runs-on: ubuntu-latest
127+
steps:
128+
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
129+
with:
130+
pattern: wheels-*
131+
merge-multiple: true
132+
path: dist
133+
122134
- name: Upload to ananconda.org
123-
if: ${{ inputs.publish == false && (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') }}
124135
uses: scientific-python/upload-nightly-action@0.6.4
125136
with:
126137
artifacts_path: dist

‎.github/workflows/windows-arm.yml‎

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,27 @@ jobs:
8181
name: wheels-${{ env.PLAT }}-${{ env.INTERFACE64 }}
8282
path: dist/scipy_openblas*.whl
8383

84-
- name: Install Anaconda client
85-
run: |
86-
# Rust installation needed for rpds-py.
87-
Invoke-WebRequest https://static.rust-lang.org/rustup/dist/aarch64-pc-windows-msvc/rustup-init.exe -UseBasicParsing -Outfile rustup-init.exe
88-
.\rustup-init.exe -y
89-
$env:PATH="$env:PATH;$env:USERPROFILE\.cargo\bin"
90-
# cryptography dropped win-arm64 for 46.0.4, make sure we don't try to compile from source
91-
pip install --only-binary :all: cryptography
92-
pip install anaconda-client
84+
upload:
85+
name: Upload to anaconda.org
86+
needs: build
87+
runs-on: ubuntu-latest
88+
steps:
89+
- uses: actions/checkout@v6.0.1
90+
91+
- uses: actions/setup-python@v6.2.0
92+
with:
93+
python-version: 3.11
94+
95+
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
96+
with:
97+
pattern: wheels-*
98+
merge-multiple: true
99+
path: dist
93100

94101
- name: Upload
95-
# see https://github.com/marketplace/actions/setup-miniconda for why
96-
# `-el {0}` is required.
97-
shell: bash -el {0}
98102
env:
99103
ANACONDA_SCIENTIFIC_PYTHON_UPLOAD: ${{ secrets.ANACONDA_SCIENTIFIC_PYTHON_UPLOAD }}
100104
run: |
105+
python -m pip install anaconda-client
101106
source tools/upload_to_anaconda_staging.sh
102107
upload_wheels

‎.github/workflows/windows.yml‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,20 +168,27 @@ jobs:
168168
python -m pip install pkgconf
169169
python -m pkgconf scipy-openblas --cflags
170170
171-
- uses: conda-incubator/setup-miniconda@v4.0.1
171+
upload:
172+
name: Upload to anaconda.org
173+
needs: build
174+
runs-on: ubuntu-latest
175+
steps:
176+
- uses: actions/checkout@v6.0.1
177+
178+
- uses: actions/setup-python@v6.2.0
179+
with:
180+
python-version: 3.11
181+
182+
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
172183
with:
173-
channels: conda-forge
174-
channel-priority: true
175-
activate-environment: upload
176-
miniforge-version: latest
184+
pattern: wheels-*
185+
merge-multiple: true
186+
path: dist
177187

178188
- name: Upload
179-
# see https://github.com/marketplace/actions/setup-miniconda for why
180-
# `-el {0}` is required.
181-
shell: bash -el {0}
182189
env:
183190
ANACONDA_SCIENTIFIC_PYTHON_UPLOAD: ${{ secrets.ANACONDA_SCIENTIFIC_PYTHON_UPLOAD }}
184191
run: |
185-
conda install -y anaconda-client
192+
python -m pip install anaconda-client
186193
source tools/upload_to_anaconda_staging.sh
187194
upload_wheels

‎CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## OpenBLAS v0.3.34 (v0.3.34)
22

3+
### 0.3.34.237.2 (2026-10-16)
4+
5+
- Patch windows to use a per-thread queue instead of mistakenly sharing the
6+
thread queue. Also simplify windows-arm64 upload to anaconda
7+
38
### 0.3.34.237.1 (2026-10-09)
49

510
- Build every manylinux, musllinux and macOS wheel without a runtime
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
diff --git a/exports/Makefile b/exports/Makefile
2-
index 668a4866e..956b51bf4 100644
32
--- a/exports/Makefile
43
+++ b/exports/Makefile
5-
@@ -126,8 +126,9 @@ dll : ../$(LIBDLLNAME)
4+
@@ -129,8 +129,9 @@ dll : ../$(LIBDLLNAME)
65
../$(LIBDLLNAME) : ../$(LIBNAME) $(LIBPREFIX).def dllinit.$(SUFFIX)
76
$(RANLIB) ../$(LIBNAME)
87
$(CC) $(CFLAGS) $(LDFLAGS) $(LIBPREFIX).def dllinit.$(SUFFIX) \
@@ -12,4 +11,4 @@ index 668a4866e..956b51bf4 100644
1211
+ dlltool -D $(LIBDLLNAME) -d $(LIBPREFIX).def -l ../$(LIBDLLNAME).a
1312

1413
$(LIBPREFIX).def : $(GENSYM)
15-
./$(GENSYM) win2k $(ARCH) dummy $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) "$(SYMBOLPREFIX)" "$(SYMBOLSUFFIX)" $(BUILD_LAPACK_DEPRECATED) $(BUILD_BFLOAT16) $(BUILD_SINGLE) $(BUILD_DOUBLE) $(BUILD_COMPLEX) $(BUILD_COMPLEX16) > $(@F)
14+
./$(GENSYM) win2k $(ARCH) dummy $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) "$(SYMBOLPREFIX)" "$(SYMBOLSUFFIX)" $(BUILD_LAPACK_DEPRECATED) $(BUILD_BFLOAT16) $(BUILD_HFLOAT16) $(BUILD_SINGLE) $(BUILD_DOUBLE) $(BUILD_COMPLEX) $(BUILD_COMPLEX16) > $(@F)
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
Give the Windows thread pool its own queue link, see MacPython/openblas-libs#283
2+
3+
diff --git a/common_thread.h b/common_thread.h
4+
--- a/common_thread.h
5+
+++ b/common_thread.h
6+
@@ -119,6 +119,14 @@ typedef struct blas_queue {
7+
struct blas_queue *next;
8+
9+
#if defined( __WIN32__) || defined(__CYGWIN32__) || defined(_WIN32) || defined(__CYGWIN__)
10+
+ /*
11+
+ * Link used exclusively by the Windows thread pool to chain the jobs that
12+
+ * are waiting to be picked up. It is deliberately kept separate from
13+
+ * "next" above, which is owned (and rebuilt on every call) by whoever
14+
+ * submitted the job: appending to the pool must never write into the
15+
+ * queue nodes of another caller.
16+
+ */
17+
+ struct blas_queue *pool_next;
18+
CRITICAL_SECTION lock;
19+
HANDLE finish;
20+
volatile int finished;
21+
diff --git a/driver/others/blas_server_win32.c b/driver/others/blas_server_win32.c
22+
--- a/driver/others/blas_server_win32.c
23+
+++ b/driver/others/blas_server_win32.c
24+
@@ -57,6 +57,7 @@ typedef struct{
25+
HANDLE killed;
26+
27+
blas_queue_t *queue; /* Parameter Pointer */
28+
+ blas_queue_t *tail; /* Last job waiting in "queue", for O(1) append */
29+
int shutdown; /* server shutdown flag */
30+
31+
} blas_pool_t;
32+
@@ -239,7 +240,10 @@ static DWORD WINAPI blas_thread_server(void *arg){
33+
EnterCriticalSection(&pool.lock);
34+
35+
queue = pool.queue;
36+
- if (queue) pool.queue = queue->next;
37+
+ if (queue) {
38+
+ pool.queue = queue->pool_next;
39+
+ if (pool.queue == NULL) pool.tail = NULL;
40+
+ }
41+
42+
LeaveCriticalSection(&pool.lock);
43+
44+
@@ -374,6 +378,7 @@ int blas_thread_init(void){
45+
46+
pool.shutdown = 0;
47+
pool.queue = NULL;
48+
+ pool.tail = NULL;
49+
50+
for(i = 0; i < blas_cpu_number - 1; i++){
51+
blas_threads[i] = CreateThread(NULL, 0,
52+
@@ -405,7 +410,7 @@ int exec_blas_async(BLASLONG pos, blas_queue_t *queue){
53+
if (unlikely(blas_server_avail == 0)) blas_thread_init();
54+
#endif
55+
56+
- blas_queue_t *current;
57+
+ blas_queue_t *current, *last = NULL;
58+
59+
current = queue;
60+
61+
@@ -419,19 +424,22 @@ int exec_blas_async(BLASLONG pos, blas_queue_t *queue){
62+
__asm__ __volatile__ ("stmxcsr %0" : "=m" (current -> sse_mode));
63+
#endif
64+
65+
+ /* Build the pool's own chain over this caller's jobs */
66+
+ current -> pool_next = current -> next;
67+
+ last = current;
68+
+
69+
current = current -> next;
70+
pos ++;
71+
}
72+
73+
EnterCriticalSection(&pool.lock);
74+
75+
- if (pool.queue) {
76+
- current = pool.queue;
77+
- while (current -> next) current = current -> next;
78+
- current -> next = queue;
79+
+ if (pool.tail) {
80+
+ pool.tail -> pool_next = queue;
81+
} else {
82+
pool.queue = queue;
83+
}
84+
+ pool.tail = last;
85+
86+
LeaveCriticalSection(&pool.lock);
87+
88+
@@ -568,6 +576,7 @@ void goto_set_num_threads(int num_threads)
89+
90+
pool.shutdown = 0;
91+
pool.queue = NULL;
92+
+ pool.tail = NULL;
93+
blas_server_avail = 1;
94+
}
95+

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ build-backend = "setuptools.build_meta"
99
[project]
1010
name = "scipy-openblas64"
1111
# v0.3.34-237-g1ad90fb1
12-
version = "0.3.34.237.1"
12+
version = "0.3.34.237.2"
1313
requires-python = ">=3.7"
1414
description = "Provides OpenBLAS for python packaging"
1515
readme = "README.md"

‎tools/build_steps_win_arm64.bat‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,12 @@ if errorlevel 1 (
7171
)
7272

7373
REM Patch
74-
for /r %%f in (..\patches\*) do git apply %%f
75-
if errorlevel 1 exit /b 1
74+
set patch_rc=0
75+
for %%f in (..\patches\*.patch ..\patches-windows\*.patch) do (
76+
git apply --ignore-whitespace %%f
77+
if errorlevel 1 set patch_rc=1
78+
)
79+
if not "%patch_rc%"=="0" exit /b 1
7680

7781
REM Patch VERSION
7882
REM version=$(grep "^version =" ../pyproject.toml | sed 's/version = "//;s/"//')

‎tools/build_steps_windows.sh‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,13 @@ interface_flags="$interface_flags SYMBOLPREFIX=scipy_ LIBNAMEPREFIX=scipy_ FIXED
9090
GCC_TAG="gcc_$(gcc -dumpversion | tr .- _)"
9191
OPENBLAS_VERSION=$(git describe --tags --abbrev=8)
9292

93-
# Patch OpenBLAS build to resolve all symbols and avoid linking
94-
# with libquadmath
95-
patch -p1 < ../patches-windows/openblas-make-libs.patch
93+
# --ignore-whitespace because the files patched here do not agree on line
94+
# endings (blas_server_win32.c is CRLF, common_thread.h is not) and neither
95+
# does checkout across platforms.
96+
for p in ../patches-windows/*.patch; do
97+
[ -e "$p" ] || continue
98+
git apply --ignore-whitespace "$p"
99+
done
96100

97101
# Patch VERSION
98102
version=$(grep "^version =" ../pyproject.toml | sed 's/version = "//;s/"//')

0 commit comments

Comments
 (0)