Skip to content

Commit

Permalink
added support for older glibc versions
Browse files Browse the repository at this point in the history
  • Loading branch information
passscoed committed Aug 15, 2024
1 parent b1303bf commit 65bbabe
Show file tree
Hide file tree
Showing 27 changed files with 36 additions and 44 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ dist/
*.egg
*.py[cod]
__pycache__/
venv/
venv/
bin/
/lib64/
pyvenv.cfg
/lib/
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "pyNFFT3"
version = "0.2.1"
version = "0.2.2"
authors = [
{ name="Michael Nolander", email="nolander.michael@gmail.com" },
]
Expand All @@ -13,7 +13,8 @@ readme = "README.md"
requires-python = ">=3.8"
dependencies = [
"numpy>=2.0.0",
"cpufeature>=0.2.1",
"py-cpuinfo>=9.0.0",
"packaging>=24.1",
]

[project.urls]
Expand Down
69 changes: 28 additions & 41 deletions src/pyNFFT3/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os, sys, io
import ctypes
import cpufeature
from cpuinfo import get_cpu_info
from packaging.version import Version


# Create dummy classes for plans
Expand All @@ -22,56 +23,42 @@ class fastsum_plan(ctypes.Structure):
pass


# Redirect output from stdout to buffer
buffer = io.StringIO()
old_stdout = sys.stdout
sys.stdout = buffer
cpufeature.print_features()
features_output = buffer.getvalue()
sys.stdout = old_stdout
cpu_features = {}
# Create dict from buffer
for line in features_output.strip().split("\n"):
if ":" in line:
key, value = line.split(":", 1)
key = key.strip()
value = value.strip()
cpu_features[key] = value == "True" or value == "False"

glibcver = ""
# Determine the file extension for shared libraries based on the operating system
if os.name == "nt": # Windows
ending = ".dll"
elif os.uname().sysname == "Darwin": # macOS
ending = ".dylib"
else: # Linux
ending = ".so"
glibcver = "glibc2.40"
if Version(os.confstr("CS_GNU_LIBC_VERSION").split(" ")[1]) < Version("2.35"):
glibcver = "glibc2.22"

if "avx2" in get_cpu_info()["flags"]:
flag = "AVX2"
elif "avx" in get_cpu_info()["flags"]:
flag = "AVX"
elif "sse2" in get_cpu_info()["flags"]:
flag = "SSE2"
else:
raise RuntimeError("CPU type not supported")


# Check for CPU features and adjust library paths
package_dir = os.path.dirname(__file__)
if cpu_features.get("AVX2", False):
lib_path_nfft = os.path.join(package_dir, "lib", "AVX2", "libnfftjulia" + ending)
lib_path_nfct = os.path.join(package_dir, "lib", "AVX2", "libnfctjulia" + ending)
lib_path_nfst = os.path.join(package_dir, "lib", "AVX2", "libnfstjulia" + ending)
lib_path_fastsum = os.path.join(
package_dir, "lib", "AVX2", "libfastsumjulia" + ending
)
elif cpu_features.get("AVX", False):
print("USing AVX2")
lib_path_nfft = os.path.join(package_dir, "lib", "AVX", "libnfftjulia" + ending)
lib_path_nfct = os.path.join(package_dir, "lib", "AVX", "libnfctjulia" + ending)
lib_path_nfst = os.path.join(package_dir, "lib", "AVX", "libnfstjulia" + ending)
lib_path_fastsum = os.path.join(
package_dir, "lib", "AVX", "libfastsumjulia" + ending
)
elif cpu_features.get("SSE2", False):
lib_path_nfft = os.path.join(package_dir, "lib", "SSE2", "libnfftjulia" + ending)
lib_path_nfct = os.path.join(package_dir, "lib", "SSE2", "libnfctjulia" + ending)
lib_path_nfst = os.path.join(package_dir, "lib", "SSE2", "libnfstjulia" + ending)
lib_path_fastsum = os.path.join(
package_dir, "lib", "SSE2", "libfastsumjulia" + ending
)
else:
raise RuntimeError("CPU type not supported")
lib_path_nfft = os.path.join(
package_dir, "lib", flag, glibcver, "libnfftjulia" + ending
)
lib_path_nfct = os.path.join(
package_dir, "lib", flag, glibcver, "libnfctjulia" + ending
)
lib_path_nfst = os.path.join(
package_dir, "lib", flag, glibcver, "libnfstjulia" + ending
)
lib_path_fastsum = os.path.join(
package_dir, "lib", flag, glibcver, "libfastsumjulia" + ending
)

# Load the libraries
_nfftlib = ctypes.CDLL(lib_path_nfft)
Expand Down
Binary file added src/pyNFFT3/lib/AVX/glibc2.22/libfastsumjulia.so
Binary file not shown.
Binary file added src/pyNFFT3/lib/AVX/glibc2.22/libnfctjulia.so
Binary file not shown.
Binary file added src/pyNFFT3/lib/AVX/glibc2.22/libnfftjulia.so
Binary file not shown.
Binary file added src/pyNFFT3/lib/AVX/glibc2.22/libnfstjulia.so
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
Binary file added src/pyNFFT3/lib/AVX2/glibc2.22/libnfctjulia.so
Binary file not shown.
Binary file added src/pyNFFT3/lib/AVX2/glibc2.22/libnfftjulia.so
Binary file not shown.
Binary file added src/pyNFFT3/lib/AVX2/glibc2.22/libnfstjulia.so
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
Binary file added src/pyNFFT3/lib/SSE2/glibc2.22/libnfctjulia.so
Binary file not shown.
Binary file added src/pyNFFT3/lib/SSE2/glibc2.22/libnfftjulia.so
Binary file not shown.
Binary file added src/pyNFFT3/lib/SSE2/glibc2.22/libnfstjulia.so
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 65bbabe

Please sign in to comment.