Skip to content

Commit 6411255

Browse files
authored
Merge pull request numpy#24162 from bashtage/clang-cl-meson
ENH: Improve clang-cl compliance
2 parents c6a449c + c5948c4 commit 6411255

File tree

4 files changed

+126
-7
lines changed

4 files changed

+126
-7
lines changed

.github/workflows/windows_clangcl.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Test Clang-CL Build (Windows)
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
- maintenance/**
8+
9+
env:
10+
PYTHON_VERSION: 3.11
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
14+
cancel-in-progress: true
15+
16+
permissions:
17+
contents: read # to fetch code (actions/checkout)
18+
19+
jobs:
20+
meson:
21+
name: Meson windows build/test
22+
runs-on: windows-2019
23+
# if: "github.repository == 'numpy/numpy'"
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
27+
with:
28+
submodules: recursive
29+
fetch-depth: 0
30+
- name: Setup Python
31+
uses: actions/setup-python@bd6b4b6205c4dbad673328db7b31b7fab9e241c0 # v4.6.1
32+
with:
33+
python-version: ${{ env.PYTHON_VERSION }}
34+
35+
- name: Install dependencies
36+
run: |
37+
pip install -r build_requirements.txt
38+
- name: openblas-libs
39+
run: |
40+
# Download and install pre-built OpenBLAS library
41+
# with 32-bit interfaces
42+
# Unpack it in the pkg-config hardcoded path
43+
choco install unzip -y
44+
choco install wget -y
45+
# Install llvm, which contains clang-cl
46+
choco install llvm -y --version=16.0.6
47+
choco install -y --checksum 6004DF17818F5A6DBF19CB335CC92702 pkgconfiglite
48+
wget https://anaconda.org/multibuild-wheels-staging/openblas-libs/v0.3.21/download/openblas-v0.3.21-win_amd64-gcc_10_3_0.zip
49+
unzip -d c:\opt openblas-v0.3.21-win_amd64-gcc_10_3_0.zip
50+
echo "PKG_CONFIG_PATH=c:\opt\64\lib\pkgconfig;" >> $env:GITHUB_ENV
51+
- name: meson-configure
52+
run: |
53+
"[binaries]","c = 'clang-cl'","cpp = 'clang-cl'","ar = 'llvm-lib'","c_ld = 'lld-link'","cpp_ld = 'lld-link'" | Out-File $PWD/clang-cl-build.ini -Encoding ascii
54+
meson setup build --prefix=$PWD\build-install --native-file=$PWD/clang-cl-build.ini -Ddebug=false --optimization 2 --vsenv
55+
- name: meson-build
56+
run: |
57+
meson compile -C build -v
58+
59+
- name: meson-install
60+
run: |
61+
cd build
62+
meson install --no-rebuild
63+
- name: build-path
64+
run: |
65+
echo "installed_path=$PWD\build-install\Lib\site-packages" >> $env:GITHUB_ENV
66+
- name: post-install
67+
run: |
68+
$numpy_path = "${env:installed_path}\numpy"
69+
$libs_path = "${numpy_path}\.libs"
70+
mkdir ${libs_path}
71+
$ob_path = "C:/opt/64/bin/"
72+
cp $ob_path/*.dll $libs_path
73+
# Write _distributor_init.py to load .libs DLLs.
74+
python -c "from tools import openblas_support; openblas_support.make_init(r'${numpy_path}')"
75+
76+
- name: prep-test
77+
run: |
78+
echo "PYTHONPATH=${env:installed_path}" >> $env:GITHUB_ENV
79+
python -m pip install -r test_requirements.txt
80+
python -m pip install threadpoolctl
81+
82+
- name: test
83+
run: |
84+
mkdir tmp
85+
cd tmp
86+
echo "============================================"
87+
python -c "import numpy; print(numpy.show_runtime())"
88+
echo "============================================"
89+
echo "LASTEXITCODE is '$LASTEXITCODE'"
90+
python -c "import numpy, sys; sys.exit(numpy.test(verbose=3) is False)"
91+
echo "LASTEXITCODE is '$LASTEXITCODE'"

numpy/core/src/multiarray/_multiarray_tests.c.src

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,13 +1966,13 @@ get_fpu_mode(PyObject *NPY_UNUSED(self), PyObject *args)
19661966
return NULL;
19671967
}
19681968

1969-
#if defined(_MSC_VER)
1969+
#if defined(_MSC_VER) && !defined(__clang__)
19701970
{
19711971
unsigned int result = 0;
19721972
result = _controlfp(0, 0);
19731973
return PyLong_FromLongLong(result);
19741974
}
1975-
#elif defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__))
1975+
#elif (defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__))) || (defined(_MSC_VER) && defined(__clang__))
19761976
{
19771977
unsigned short cw = 0;
19781978
__asm__("fstcw %w0" : "=m" (cw));

numpy/core/tests/test_einsum.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
assert_raises, suppress_warnings, assert_raises_regex, assert_allclose
1111
)
1212

13+
try:
14+
COMPILERS = np.show_config(mode="dicts")["Compilers"]
15+
USING_CLANG_CL = COMPILERS["c"]["name"] == "clang-cl"
16+
except TypeError:
17+
USING_CLANG_CL = False
18+
1319
# Setup for optimize einsum
1420
chars = 'abcdefghij'
1521
sizes = np.array([2, 3, 4, 5, 4, 3, 2, 6, 5, 4, 3])
@@ -611,13 +617,23 @@ def check_einsum_sums(self, dtype, do_opt=False):
611617
[2.]) # contig_stride0_outstride0_two
612618

613619
def test_einsum_sums_int8(self):
614-
if sys.platform == 'darwin' and platform.machine() == 'x86_64':
615-
pytest.xfail('Fails on macOS x86-64 with Meson, see gh-23838')
620+
if (
621+
(sys.platform == 'darwin' and platform.machine() == 'x86_64')
622+
or
623+
USING_CLANG_CL
624+
):
625+
pytest.xfail('Fails on macOS x86-64 and when using clang-cl '
626+
'with Meson, see gh-23838')
616627
self.check_einsum_sums('i1')
617628

618629
def test_einsum_sums_uint8(self):
619-
if sys.platform == 'darwin' and platform.machine() == 'x86_64':
620-
pytest.xfail('Fails on macOS x86-64 with Meson, see gh-23838')
630+
if (
631+
(sys.platform == 'darwin' and platform.machine() == 'x86_64')
632+
or
633+
USING_CLANG_CL
634+
):
635+
pytest.xfail('Fails on macOS x86-64 and when using clang-cl '
636+
'with Meson, see gh-23838')
621637
self.check_einsum_sums('u1')
622638

623639
def test_einsum_sums_int16(self):

numpy/core/tests/test_scalarmath.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
assert_warns, _SUPPORTS_SVE,
1818
)
1919

20+
try:
21+
COMPILERS = np.show_config(mode="dicts")["Compilers"]
22+
USING_CLANG_CL = COMPILERS["c"]["name"] == "clang-cl"
23+
except TypeError:
24+
USING_CLANG_CL = False
25+
2026
types = [np.bool_, np.byte, np.ubyte, np.short, np.ushort, np.intc, np.uintc,
2127
np.int_, np.uint, np.longlong, np.ulonglong,
2228
np.single, np.double, np.longdouble, np.csingle,
@@ -798,7 +804,13 @@ class TestBitShifts:
798804
@pytest.mark.parametrize('op',
799805
[operator.rshift, operator.lshift], ids=['>>', '<<'])
800806
def test_shift_all_bits(self, type_code, op):
801-
""" Shifts where the shift amount is the width of the type or wider """
807+
"""Shifts where the shift amount is the width of the type or wider """
808+
if (
809+
USING_CLANG_CL and
810+
type_code in ("l", "L") and
811+
op is operator.lshift
812+
):
813+
pytest.xfail("Failing on clang-cl builds")
802814
# gh-2449
803815
dt = np.dtype(type_code)
804816
nbits = dt.itemsize * 8

0 commit comments

Comments
 (0)