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/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
build-docs:
name: Build Sphinx documentation
runs-on: ubuntu-latest
env:
SKIP_CUPY_INSTALL: 1

steps:
- name: Checkout repository
Expand Down
81 changes: 49 additions & 32 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,53 +1,70 @@
from setuptools import setup
import os
import re
import subprocess

dependencies = [
"numpy",
"pytest",
"cupy",
"numpy>=2.0,<2.5", # capped at <2.5 until we update numba-cuda to numba-cuda-mlir
"numba>=0.52",
# "larpix-control",
"pytest",
"larpix-control @ git+https://github.com/larpix/larpix-control.git@release",
"larpix-geometry",
"tqdm",
"fire",
"nvidia-ml-py",
]

# Extra development tools or CI/CD dependencies
optional_dep = {
"linting" : ["MonkeyType", "mypy", "ruff"],
"runner" : ["pandas", "rich"]
}

try:
import cupy
msg = '''
############ INFORMATION ############
Detected and using the installed cupy
Version: %s
Source : %s
#####################################\n
'''
print(msg % (str(cupy.__version__),str(cupy.__file__)))
except ImportError:
dependencies.append('cupy')

try:
cuda_dir = os.path.basename(os.environ['CUDA_HOME'])
cuda_ver = float(cuda_dir)
cuda_major_ver = int(cuda_ver)
print(f"larnd-sim -- Found CUDA version: {cuda_ver}")
except:
cuda_ver = cuda_major_ver = -1

if 'cupy' in dependencies:
if 'SKIP_CUPY_INSTALL' in os.environ:
dependencies.remove('cupy')
def get_cuda_version():
# Try nvcc --version (the CUDA compiler)
try:
res = subprocess.check_output(["nvcc", "--version"], stderr=subprocess.STDOUT).decode()
match = re.search(r"release (\d+)", res)
if match:
return int(match.group(1))
except (subprocess.CalledProcessError, FileNotFoundError):
pass

# Try $CUDA_HOME and extract version from directory name
cuda_home = os.environ.get("CUDA_HOME")
if cuda_home:
# Match digits in the basename, e.g. "12.2" -> 12
match = re.search(r"(\d+)", os.path.basename(cuda_home))
if match:
return int(match.group(1))

return None

cuda_major_ver = get_cuda_version()

# We only support CUDA 11 and higher
if cuda_major_ver is None or cuda_major_ver < 11:
if "SKIP_CUPY_INSTALL" not in os.environ:
raise RuntimeError(
f"CUDA version {cuda_major_ver} not detected or unsupported (<11). "
"Please set CUDA_HOME or ensure nvcc is in PATH, or use SKIP_CUPY_INSTALL=1 to skip CuPy."
)
else:
print(f"larnd-sim -- Found CUDA version: {cuda_major_ver}")

# Confirmed to have supported CUDA, check how to (or if) install CuPy
if "cupy" in dependencies:
if "SKIP_CUPY_INSTALL" in os.environ:
print("larnd-sim -- Skipping CuPy installation.")
dependencies.remove("cupy")
elif "ALWAYS_COMPILE_CUPY" not in os.environ:
print("larnd-sim -- Using pre-built wheel for CuPy and numba-cuda.")
dependencies.remove("cupy")
dependencies.append(f"cupy-cuda{cuda_major_ver}x")
dependencies.append(f"numba-cuda[cu{cuda_major_ver}]") # TODO: Update numba-cuda to numba-cuda-mlir
else:
if 'ALWAYS_COMPILE_CUPY' not in os.environ:
if cuda_major_ver in [11, 12, 13]:
dependencies.remove('cupy')
dependencies.append(f'cupy-cuda{cuda_major_ver}x')
dependencies.append(f'numba-cuda[cu{cuda_major_ver}]')
print("larnd-sim -- Attempting to build CuPy from source.")

setup(
install_requires=dependencies,
Expand Down
Loading