Skip to content

Commit 800e0ee

Browse files
committed
Merge remote-tracking branch 'origin/static-linking-mex' into static-linking-mex
2 parents 4dfaff5 + 2efd5f0 commit 800e0ee

21 files changed

+503
-80
lines changed

.github/workflows/customized-win-shells.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
shell: bash -el {0}
2525
working-directory: ${{ github.workspace }}/source/MagTenseFortranCuda/cuda
2626
run: |
27-
nvcc -c MagTenseCudaBlas.cu -ccbin "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.42.34433\bin\Hostx64\x64" -o MagTenseCudaBlas.o
27+
nvcc -c MagTenseCudaBlas.cu -ccbin "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.42.34438\bin\Hostx64\x64" -o MagTenseCudaBlas.o
2828
2929
- name: Run Developer PowerShell for VS 2022
3030
shell: pwsh -NoExit -ExecutionPolicy ByPass -File {0}

.github/workflows/linux-python-package-conda.yml

+55-58
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ on: [push]
44

55
jobs:
66
build-linux:
7+
strategy:
8+
matrix:
9+
py-version: [312, 313]
710
runs-on: ubuntu-latest
811
defaults:
912
run:
1013
shell: bash -el {0}
14+
env:
15+
build_file: python/.build/env-${{ matrix.py-version }}-linux.yml
1116

1217
steps:
1318
- name: Checkout repository
@@ -24,14 +29,14 @@ jobs:
2429
uses: actions/cache@v4
2530
env:
2631
# Increase this value to reset cache manually
27-
CACHE_NUMBER: 0
32+
cache_number: 0
2833
with:
2934
path: ${{ env.CONDA }}/envs
30-
key: conda-${{ runner.os }}-${{hashFiles('python/build_env_linux.yml') }}-${{ env.CACHE_NUMBER }}
35+
key: conda-${{ runner.os }}-${{ hashFiles(env.build_file) }}-${{ env.cache_number }}
3136
id: cache
3237

3338
- name: Update environment
34-
run: conda env update -n magtense-env -f python/build_env_linux.yml
39+
run: conda env update -n magtense-env -f ${{ env.build_file }}
3540
if: steps.cache.outputs.cache-hit != 'true'
3641

3742
- name: Create directory for wrappers of compiled Fortran source code
@@ -51,91 +56,83 @@ jobs:
5156
5257
- name: Build pip-wheels
5358
working-directory: ${{ github.workspace }}/python/
54-
run: python scripts/dist_pypi.py
59+
run: python .build/dist_pypi.py --py_versions ${{ matrix.py-version }}
5560

5661
- name: cpu - Archive pip-wheel
5762
uses: actions/upload-artifact@v4
5863
with:
59-
name: pip-wheel-cpu
60-
path: ${{ github.workspace }}/python/dist/magtense-*-0-*.whl
64+
name: pip-wheel-${{ matrix.py-version }}-cpu
65+
path: ${{ github.workspace }}/python/dist/magtense-*-0-py${{ matrix.py-version }}-none-manylinux1_x86_64.whl
6166

6267
- name: cu12 - Archive pip-wheel
6368
uses: actions/upload-artifact@v4
6469
with:
65-
name: pip-wheel-cu12
66-
path: ${{ github.workspace }}/python/dist/magtense-*-1-*.whl
70+
name: pip-wheel-${{ matrix.py-version }}-cu12
71+
path: ${{ github.workspace }}/python/dist/magtense-*-1-py${{ matrix.py-version }}-none-manylinux1_x86_64.whl
6772

6873

69-
test-linux-cpu:
70-
runs-on: ubuntu-24.04
74+
test-linux:
75+
strategy:
76+
matrix:
77+
mt-punit: [cpu, cu12]
78+
py-version: [312, 313]
79+
runs-on: ubuntu-latest
7180
needs: build-linux
7281
defaults:
7382
run:
7483
shell: bash -el {0}
7584

7685
steps:
77-
- name: Download a single artifact
78-
uses: actions/download-artifact@v4
79-
with:
80-
name: pip-wheel-cpu
81-
82-
- name: Create a new virtual environment
83-
run: |
84-
python3 -m venv ${{ github.workspace }}/.venv
85-
86-
- name: Install pip-wheel
87-
run: |
88-
source ${{ github.workspace }}/.venv/bin/activate
89-
files=(*)
90-
python3 -m pip install ${{ github.workspace }}/${files[0]}
91-
9286
- name: Checkout test scripts
9387
uses: actions/checkout@v4
9488
with:
9589
sparse-checkout: |
9690
python/tests/
97-
98-
- name: Test with pytest
99-
run: |
100-
source ${{ github.workspace }}/.venv/bin/activate
101-
export LD_LIBRARY_PATH=${{ github.workspace }}/.venv/lib:$LD_LIBRARY_PATH
102-
python3 -m pip install pytest
103-
pytest
104-
105-
106-
test-linux-cu12:
107-
runs-on: ubuntu-24.04
108-
needs: build-linux
109-
defaults:
110-
run:
111-
shell: bash -el {0}
91+
documentation/examples_FEM_validation/
11292
113-
steps:
11493
- name: Download a single artifact
11594
uses: actions/download-artifact@v4
11695
with:
117-
name: pip-wheel-cu12
96+
name: pip-wheel-${{ matrix.py-version }}-${{ matrix.mt-punit }}
97+
98+
# TODO Setup version selection with JavaScript
99+
# - id: get-id
100+
# uses: actions/github-script@0.9.0
101+
# with:
102+
# script: |
103+
# const id = context.payload.client_payload.value.split('-')[1]
104+
# core.setOutput('id', id)
105+
# - run: echo "${{steps.get-id.outputs.id}}"
106+
107+
- name: Setup Miniforge for python 3.12
108+
if: ${{ matrix.py-version }} == 312
109+
uses: conda-incubator/setup-miniconda@v3
110+
with:
111+
miniforge-version: latest
112+
python-version: 3.12
113+
auto-activate-base: true
114+
activate-environment: true
115+
116+
- name: Setup Miniforge for python 3.13
117+
if: ${{ matrix.py-version }} == 313
118+
uses: conda-incubator/setup-miniconda@v3
119+
with:
120+
miniforge-version: latest
121+
python-version: 3.13
122+
auto-activate-base: true
123+
activate-environment: true
118124

119125
- name: Create a new virtual environment
120-
run: |
121-
python3 -m venv ${{ github.workspace }}/.venv
122-
123-
- name: Install pip-wheel
126+
run: python3 -m venv ${{ github.workspace }}/.venv
127+
128+
# TODO Cache pip
129+
- name: Install pip-wheel and pytest
124130
run: |
125131
source ${{ github.workspace }}/.venv/bin/activate
126-
files=(*)
127-
python3 -m pip install ${{ github.workspace }}/${files[0]}
128-
129-
- name: Checkout test scripts
130-
uses: actions/checkout@v4
131-
with:
132-
sparse-checkout: |
133-
python/tests/
132+
python3 -m pip install ${{ github.workspace }}/*.whl
133+
python3 -m pip install pytest
134134
135-
- name: Test with pytest
135+
- name: Run tests
136136
run: |
137137
source ${{ github.workspace }}/.venv/bin/activate
138-
export LD_LIBRARY_PATH=${{ github.workspace }}/.venv/lib:$LD_LIBRARY_PATH
139-
python3 -m pip install pytest
140138
pytest
141-

.github/workflows/matlab_package.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
uses: conda-incubator/setup-miniconda@v3
3535
with:
3636
activate-environment: magtense-env
37-
environment-file: python/environment_linux.yml
37+
environment-file: python/.build/environment_linux.yml
3838
python-version: 3.12
3939
auto-activate-base: false
4040

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Win - Python package using conda / pip
2+
3+
on: [push]
4+
5+
jobs:
6+
build-win:
7+
runs-on: windows-latest
8+
env:
9+
build_file: python/.build/environment_win.yml
10+
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v4
14+
15+
- name: Setup Miniforge
16+
uses: conda-incubator/setup-miniconda@v3
17+
with:
18+
miniforge-version: latest
19+
activate-environment: magtense-env
20+
use-mamba: true
21+
22+
- name: Cache conda
23+
uses: actions/cache@v4
24+
env:
25+
# Increase this value to reset cache manually
26+
cache_number: 0
27+
with:
28+
path: ${{ env.CONDA }}/envs
29+
key: conda-${{ runner.os }}-${{ hashFiles(env.build_file) }}-${{ env.cache_number }}
30+
id: cache
31+
32+
- name: Update environment
33+
run: conda env update -n magtense-env -f ${{ env.build_file }}
34+
if: steps.cache.outputs.cache-hit != 'true'
35+
36+
- name: Compile Fortran files in Developer PowerShell for VS 2022
37+
shell: pwsh -NoExit -ExecutionPolicy ByPass -File {0}
38+
run: |
39+
cd "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\"
40+
.\Launch-VsDevShell.ps1
41+
cd ${{ github.workspace }}/python/src/magtense/lib/
42+
make ps
43+
44+
- name: Compile with nvcc in x64 Native Tools Command Prompt for VS 2022
45+
shell: cmd /k "{0}" -arch=amd64 -host_arch=x64
46+
working-directory: ${{ github.workspace }}/source/MagTenseFortranCuda/cuda
47+
run: |
48+
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat"
49+
nvcc -c MagTenseCudaBlas.cu -ccbin "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.42.34438\bin\Hostx64\x64" -o MagTenseCudaBlas.o
50+
51+
- name: Link Cuda wrapper in Developer PowerShell for VS 2022
52+
shell: pwsh -NoExit -ExecutionPolicy ByPass -File {0}
53+
run: |
54+
cd "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\"
55+
.\Launch-VsDevShell.ps1
56+
cd ${{ github.workspace }}/source/MagTenseFortranCuda/cuda
57+
make wrap
58+
59+
- name: Build Python wrapper in Command Prompt
60+
shell: cmd /C CALL {0}
61+
working-directory: ${{ github.workspace }}/python/src/magtense/lib/
62+
run: >-
63+
make cmdx64
64+
65+
- name: Install local magtense package with pip
66+
run: python -m pip install -e ${{ github.workspace }}/python
67+
68+
- name: Test with pytest
69+
run: |
70+
conda install pytest
71+
pytest

.gitignore

+6-7
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ ipch/
5959
*.sdf
6060
*.cachefile
6161

62+
# Visual Studio
63+
.vs/MagTense/v17/
64+
.vs/MagTense/CopilotIndices/
65+
*.vsidx
66+
6267
# Visual Studio profiler
6368
*.psess
6469
*.vsp
@@ -187,17 +192,11 @@ docs/source/_build
187192
*.vtuneproj
188193
*.prj
189194

190-
*.vsidx
195+
*.msg
191196
*.lock
192197

193198
# Notebooks
194199
nbs/
195200

196201
# Virtual environment
197202
.venv*/
198-
199-
.vs/MagTense/v17/
200-
201-
.vs/MagTense/CopilotIndices/
202-
203-
*.msg
File renamed without changes.

python/scripts/dist_pypi.py renamed to python/.build/dist_pypi.py

+24-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,30 @@ def main(py_versions):
5757
if lib_path is not None:
5858
subprocess.run(["rm", lib_path])
5959
lib_path = f"src/magtense/lib/magtensesource.{py_lib}-{arch}.{suffix}"
60-
subprocess.run(["cp", f"requirements-{cuda}.txt", "requirements.txt"])
60+
if platform == "linux":
61+
if cuda == "cpu":
62+
subprocess.run(
63+
[
64+
"patchelf",
65+
"--force-rpath",
66+
"--set-rpath",
67+
"$ORIGIN/../../../../../lib",
68+
lib_path,
69+
]
70+
)
71+
elif cuda == "cu12":
72+
subprocess.run(
73+
[
74+
"patchelf",
75+
"--force-rpath",
76+
"--set-rpath",
77+
"$ORIGIN/../../../../../lib:$ORIGIN/../../nvidia/cublas/lib/:$ORIGIN/../../nvidia/cuda_runtime/lib/:$ORIGIN/../../nvidia/cusparse/lib/",
78+
lib_path,
79+
]
80+
)
81+
subprocess.run(
82+
["cp", f".build/requirements-{py}-{cuda}.txt", "requirements.txt"]
83+
)
6184
subprocess.run(["python3", "-m", "build", "--wheel"])
6285
subprocess.run(
6386
[

python/build_env_linux.yml renamed to python/.build/env-312-linux.yml

+1
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,5 @@ dependencies:
102102
- ninja==1.11.1.3
103103
- numpy==2.2.3
104104
- packaging==24.2
105+
- patchelf==0.17.2.1
105106
- pyproject-hooks==1.2.0

0 commit comments

Comments
 (0)