Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ jobs:
ccache --show-stats && ccache --zero-stats

- name: Build and Install
env:
IPCTK_WITH_SIMD: ${{ runner.os == 'Linux' && '0' || '1' }}
run: |
pip install --verbose . && ccache --show-stats
Comment thread
zfergus marked this conversation as resolved.

Expand Down
17 changes: 17 additions & 0 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ You can test that the installation was successful by doing
python -c "import ipctk"
```

#### SIMD

SIMD optimizations are enabled by default. To disable them (e.g., for compatibility with older or cross-compiled targets), set `IPCTK_WITH_SIMD=0` before installing:

```sh
IPCTK_WITH_SIMD=0 pip install .
```

Accepted falsy values: `0`, `off`, `false`, `no` (case-insensitive). Any other value keeps SIMD enabled.

:::{note}
Pre-built binary wheels from PyPI have SIMD support baked in at wheel-build time. The `IPCTK_WITH_SIMD` variable only applies when building from source. To force a source build from PyPI, use:
```sh
IPCTK_WITH_SIMD=0 pip install --no-binary ipctk ipctk
```
:::

### CMake Build

Alternatively, you can use `cmake` directly. To do this, use the following commands from the root of the repository:
Expand Down
39 changes: 18 additions & 21 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,23 @@ def build_extension(self, ext):
out = subprocess.check_output(["cmake", "--version"])
except OSError:
raise RuntimeError(
"CMake must be installed to build the following extensions: " +
", ".join(e.name for e in self.extensions))
"CMake must be installed to build the following extensions: "
+ ", ".join(e.name for e in self.extensions)
)

extdir = os.path.abspath(os.path.dirname(
self.get_ext_fullpath(ext.name)))
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))

# required for auto-detection & inclusion of auxiliary "native" libs
if not extdir.endswith(os.path.sep):
extdir += os.path.sep

debug = (int(os.environ.get("DEBUG", 0)) if self.debug is None
else self.debug)
debug = int(os.environ.get("DEBUG", 0)) if self.debug is None else self.debug
cfg = "Debug" if debug else "Release"

# Allow users to disable SIMD via IPCTK_WITH_SIMD=0/off/false/no.
_simd_env = os.environ.get("IPCTK_WITH_SIMD", "1").strip().lower()
with_simd = "OFF" if _simd_env in {"0", "off", "false", "no"} else "ON"

# CMake lets you override the generator - we need to check this.
# Can be set with Conda-Build, for example.
cmake_generator = os.environ.get("CMAKE_GENERATOR", "")
Expand All @@ -55,13 +58,13 @@ def build_extension(self, ext):
f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm
"-DIPC_TOOLKIT_BUILD_TESTS=OFF",
"-DIPC_TOOLKIT_BUILD_PYTHON=ON",
f"-DIPC_TOOLKIT_WITH_SIMD={with_simd}",
]
build_args = []
# Adding CMake arguments set as environment variable
# (needed e.g. to build for ARM OSx on conda-forge)
if "CMAKE_ARGS" in os.environ:
cmake_args += [
item for item in os.environ["CMAKE_ARGS"].split(" ") if item]
cmake_args += [item for item in os.environ["CMAKE_ARGS"].split(" ") if item]

if self.compiler.compiler_type != "msvc":
# Using Ninja-build since it a) is available as a wheel and b)
Expand All @@ -73,8 +76,7 @@ def build_extension(self, ext):
try:
import ninja # noqa: F401

ninja_executable_path = os.path.join(
ninja.BIN_DIR, "ninja")
ninja_executable_path = os.path.join(ninja.BIN_DIR, "ninja")
cmake_args += [
"-GNinja",
f"-DCMAKE_MAKE_PROGRAM:FILEPATH={ninja_executable_path}",
Expand All @@ -83,10 +85,8 @@ def build_extension(self, ext):
pass

else:

# Single config generators are handled "normally"
single_config = any(
x in cmake_generator for x in {"NMake", "Ninja"})
single_config = any(x in cmake_generator for x in {"NMake", "Ninja"})

# CMake allows an arch-in-generator style for backward compatibility
contains_arch = any(x in cmake_generator for x in {"ARM", "Win64"})
Expand All @@ -108,8 +108,7 @@ def build_extension(self, ext):
# Cross-compile support for macOS - respect ARCHFLAGS if set
archs = re.findall(r"-arch (\S+)", os.environ.get("ARCHFLAGS", ""))
if archs:
cmake_args += [
"-DCMAKE_OSX_ARCHITECTURES={}".format(";".join(archs))]
cmake_args += ["-DCMAKE_OSX_ARCHITECTURES={}".format(";".join(archs))]

# Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level
# across all generators.
Expand All @@ -126,14 +125,12 @@ def build_extension(self, ext):
if not os.path.exists(build_temp):
os.makedirs(build_temp)

subprocess.check_call(["cmake", ext.sourcedir] +
cmake_args, cwd=build_temp)
subprocess.check_call(["cmake", "--build", "."] +
build_args, cwd=build_temp)
subprocess.check_call(["cmake", ext.sourcedir] + cmake_args, cwd=build_temp)
subprocess.check_call(["cmake", "--build", "."] + build_args, cwd=build_temp)


setup(
ext_modules=[CMakeExtension('ipctk')],
ext_modules=[CMakeExtension("ipctk")],
cmdclass={"build_ext": CMakeBuild},
zip_safe=False
zip_safe=False,
)
Loading