Skip to content

Commit 0d45b71

Browse files
committed
[GR-45220] Add flang support for scipy
PullRequest: graalpython/2731
2 parents f890648 + 2a9409a commit 0d45b71

File tree

6 files changed

+434
-433
lines changed

6 files changed

+434
-433
lines changed

graalpython/lib-graalpython/modules/ginstall.py

Lines changed: 3 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -330,111 +330,15 @@ def hypothesis(**kwargs):
330330
sortedcontainers(**kwargs)
331331
install_from_pypi("hypothesis==5.41.1", **kwargs)
332332

333-
# Does not yet work
334-
# def h5py(**kwargs):
335-
# try:
336-
# import pkgconfig
337-
# except ImportError:
338-
# print("Installing required dependency: pkgconfig")
339-
# pkgconfig(**kwargs)
340-
# install_from_pypi("h5py==2.9.0", **kwargs)
341-
# try:
342-
# import six
343-
# except ImportError:
344-
# print("Installing required dependency: six")
345-
# pkgconfig(**kwargs)
346-
# install_from_pypi("six==1.12.0", **kwargs)
347-
#
348-
# def keras_applications(**kwargs):
349-
# try:
350-
# import h5py
351-
# except ImportError:
352-
# print("Installing required dependency: h5py")
353-
# h5py(**kwargs)
354-
# install_from_pypi("Keras-Applications==1.0.6", **kwargs)
355-
356333
@pip_package()
357334
def setuptools_scm(**kwargs):
358335
setuptools(**kwargs)
359336
install_with_pip("setuptools_scm==7.1.0", **kwargs)
360337

361338
@pip_package()
362339
def numpy(**kwargs):
363-
setuptools(**kwargs)
364-
Cython(**kwargs)
365-
366-
blas_env = get_path_env_var("BLAS")
367-
blas_lib = os.path.split(blas_env)[0] if blas_env else None
368-
blas_include = get_path_env_var("BLAS_INCLUDE")
369-
openblas_lib = None
370-
openblas_include = None
371-
if blas_env and 'openblas' in blas_env:
372-
openblas_lib = blas_lib
373-
openblas_include = blas_include
374-
lapack_env = get_path_env_var('LAPACK')
375-
lapack_lib = os.path.split(lapack_env)[0] if lapack_env else None
376-
lapack_include = get_path_env_var('LAPACK_INCLUDE')
377-
378-
def make_site_cfg(root):
379-
with open(os.path.join(root, "site.cfg"), "w+") as SITE_CFG:
380-
if openblas_lib:
381-
info("detected OPENBLAS / [LAPACK]")
382-
cfg = f"""
383-
[openblas]
384-
openblas_libs = openblas
385-
include_dirs = {openblas_include}
386-
library_dirs = {openblas_lib}
387-
runtime_library_dirs = {openblas_lib}"""
388-
if lapack_lib:
389-
cfg += f"""
390-
[lapack]
391-
lapack_libs = lapack
392-
include_dirs = {lapack_include}
393-
library_dirs = {lapack_lib}"""
394-
else:
395-
cfg += f"""
396-
[lapack]
397-
lapack_libs = openblas
398-
library_dirs = {openblas_lib}"""
399-
400-
info(cfg)
401-
SITE_CFG.write(cfg)
402-
403-
elif blas_lib:
404-
info("detected BLAS / [LAPACK]")
405-
cfg = f"""
406-
[blas]
407-
include_dirs = {blas_include}
408-
library_dirs = {blas_lib}"""
409-
if lapack_lib:
410-
cfg += f"""
411-
[lapack]
412-
lapack_libs = lapack
413-
include_dirs = {lapack_include}
414-
library_dirs = {lapack_lib}"""
415-
416-
info(cfg)
417-
SITE_CFG.write(cfg)
418-
419-
# honor following selected env variables: BLAS, LAPACK, ATLAS
420-
numpy_build_env = {}
421-
for key in ("BLAS", "LAPACK", "ATLAS"):
422-
if key in os.environ:
423-
numpy_build_env[key] = os.environ[key]
424-
425-
if have_lapack() or have_openblas():
426-
append_env_var(numpy_build_env, 'CFLAGS', '-Wno-error=implicit-function-declaration')
427-
info(f"have lapack or blas ... CLFAGS={numpy_build_env['CFLAGS']}")
428-
429-
with_flang = have_flang_new()
430-
build_cmd = ["build_ext", "--disable-optimization"]
431-
if with_flang:
432-
numpy_build_env["FC"] = "flang-new"
433-
numpy_build_env["CC"] = "clang"
434-
numpy_build_env["CXX"] = "clang++"
435-
build_cmd += ["config", "--fcompiler=flang-new"]
436-
install_from_pypi("numpy==1.23.5", build_cmd=build_cmd, env=numpy_build_env, pre_install_hook=make_site_cfg,
437-
**kwargs)
340+
install_with_pip("Cython", **kwargs)
341+
install_with_pip("numpy", **kwargs)
438342

439343
# print numpy configuration
440344
if sys.implementation.name != 'graalpy' or __graalpython__.platform_id != 'managed':
@@ -507,55 +411,7 @@ def pandas(**kwargs):
507411

508412
@pip_package()
509413
def scipy(**kwargs):
510-
# honor following selected env variables: BLAS, LAPACK, ATLAS
511-
scipy_build_env = {}
512-
for key in ("BLAS", "LAPACK", "ATLAS"):
513-
if key in os.environ:
514-
scipy_build_env[key] = os.environ[key]
515-
516-
if sys.implementation.name == "graalpy":
517-
if not os.environ.get("VIRTUAL_ENV", None):
518-
xit("SciPy can only be installed within a venv.")
519-
from distutils.sysconfig import get_config_var
520-
scipy_build_env["LDFLAGS"] = get_config_var("LDFLAGS")
521-
522-
if have_lapack() or have_openblas():
523-
append_env_var(scipy_build_env, 'CFLAGS', '-Wno-error=implicit-function-declaration')
524-
info(f"have lapack or blas ... CFLAGS={scipy_build_env['CFLAGS']}")
525-
526-
# install dependencies
527-
numpy(**kwargs)
528-
pybind11(**kwargs)
529-
pythran(**kwargs)
530-
531-
# scipy_version = "1.8.1"
532-
scipy_version = "1.9.3"
533-
with_meson = False
534-
if scipy_version >= "1.9.1":
535-
meson(**kwargs)
536-
ninja(**kwargs)
537-
with_flang = have_flang_new()
538-
with_meson = True
539-
if with_flang:
540-
# until flang-new can compile propack we disable it (during runtime)
541-
scipy_build_env["USE_PROPACK"] = "0"
542-
scipy_build_env['CC'] = 'clang'
543-
scipy_build_env['CXX'] = 'clang++'
544-
scipy_build_env['FC'] = 'flang-new'
545-
if sys.implementation.name == "graalpy":
546-
cflags = "-flto=full"
547-
else:
548-
ld = 'lld'
549-
cflags = "-flto=full -fuse-ld=lld -Wl,--mllvm=-lto-embed-bitcode=optimized,--lto-O0"
550-
scipy_build_env['CC_LD'] = ld
551-
scipy_build_env['CXX_LD'] = ld
552-
scipy_build_env['FC_LD'] = ld
553-
scipy_build_env['CFLAGS'] = cflags
554-
scipy_build_env['CXXFLAGS'] = cflags
555-
scipy_build_env['FFLAGS'] = cflags
556-
scipy_build_env['FFLAGS'] = cflags
557-
append_env_var(scipy_build_env, 'LDFLAGS', f'-L{get_flang_new_lib_dir()}')
558-
install_from_pypi(f"scipy=={scipy_version}", env=scipy_build_env, with_meson=with_meson, **kwargs)
414+
install_with_pip("scipy", **kwargs)
559415

560416
@pip_package()
561417
def scikit_learn(**kwargs):

graalpython/lib-graalpython/patches/scipy/metadata.toml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@ version = '== 1.8.1'
1111
patch = 'scipy-1.8.1.patch'
1212

1313
[[rules]]
14-
version = '== 1.9.1'
15-
patch = 'scipy-1.9.1.patch'
16-
17-
[[rules]]
18-
# pin 1.9.3
19-
install-priority = 10
2014
version = '== 1.9.3'
2115
patch = 'scipy-1.9.3.patch'
2216

2317
[[rules]]
24-
version = '== 1.10.0'
25-
patch = 'scipy-1.10.0.patch'
18+
# pin to 1.10.1
19+
install-priority = 10
20+
version = '== 1.10.1'
21+
patch = 'scipy-1.10.1.patch'

graalpython/lib-graalpython/patches/scipy/scipy-1.10.0.patch

Lines changed: 0 additions & 135 deletions
This file was deleted.

0 commit comments

Comments
 (0)