Skip to content

Commit aba3445

Browse files
authored
Use library_dirs for cython linking, link cudatoolkit libs, allow setting UCX install location (#1698)
This PR is a continuation of #1694. Similar to rapidsai/cuml#4015, this PR updates setup.py to: * Use `library_dirs` instead of `runtime_library_dirs` when linking Cython. * Allow overriding UCX lib and include dirs via a `UCX_HOME` envvar. * Link `cudart`, `cusparse`, and `cusolver`. These are necessary to compile the Cython via `pip` when not inside a conda environment and when UCX is installed to a location other than `/usr` or `/usr/local`. Authors: - Paul Taylor (https://github.com/trxcllnt) Approvers: - Rick Ratzel (https://github.com/rlratzel) URL: #1698
1 parent 6ad797f commit aba3445

File tree

2 files changed

+42
-18
lines changed

2 files changed

+42
-18
lines changed

cpp/cmake/thirdparty/get_faiss.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ function(find_and_configure_faiss)
4040

4141
if(FAISS_ADDED)
4242
set(FAISS_GPU_HEADERS ${FAISS_SOURCE_DIR} PARENT_SCOPE)
43-
add_library(FAISS::FAISS ALIAS faiss)
43+
endif()
44+
45+
if(TARGET faiss AND NOT TARGET FAISS::FAISS)
46+
add_library(FAISS::FAISS ALIAS faiss)
4447
endif()
4548

4649
endfunction()

python/setup.py

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import os
1515
import sys
16+
import sysconfig
1617
import shutil
1718

1819
from setuptools import setup, find_packages, Command
@@ -29,13 +30,25 @@
2930

3031

3132
INSTALL_REQUIRES = ['numba', 'cython']
33+
CYTHON_FILES = ['cugraph/**/*.pyx']
34+
35+
UCX_HOME = get_environment_option("UCX_HOME")
36+
CUDA_HOME = get_environment_option('CUDA_HOME')
37+
CONDA_PREFIX = get_environment_option('CONDA_PREFIX')
3238

3339
conda_lib_dir = os.path.normpath(sys.prefix) + '/lib'
3440
conda_include_dir = os.path.normpath(sys.prefix) + '/include'
3541

36-
CYTHON_FILES = ['cugraph/**/*.pyx']
42+
if CONDA_PREFIX:
43+
conda_include_dir = CONDA_PREFIX + '/include'
44+
conda_lib_dir = CONDA_PREFIX + '/lib'
45+
46+
if not UCX_HOME:
47+
UCX_HOME = CONDA_PREFIX if CONDA_PREFIX else os.sys.prefix
48+
49+
ucx_include_dir = os.path.join(UCX_HOME, "include")
50+
ucx_lib_dir = os.path.join(UCX_HOME, "lib")
3751

38-
CUDA_HOME = os.environ.get("CUDA_HOME", False)
3952
if not CUDA_HOME:
4053
path_to_cuda_gdb = shutil.which("cuda-gdb")
4154
if path_to_cuda_gdb is None:
@@ -53,11 +66,7 @@
5366
)
5467

5568
cuda_include_dir = os.path.join(CUDA_HOME, "include")
56-
57-
if (os.environ.get('CONDA_PREFIX', None)):
58-
conda_prefix = os.environ.get('CONDA_PREFIX')
59-
conda_include_dir = conda_prefix + '/include'
60-
conda_lib_dir = conda_prefix + '/lib'
69+
cuda_lib_dir = os.path.join(CUDA_HOME, "lib64")
6170

6271
# Optional location of C++ build folder that can be configured by the user
6372
libcugraph_path = get_environment_option('CUGRAPH_BUILD_PATH')
@@ -69,6 +78,9 @@
6978
# https://github.com/rapidsai/raft/issues/83
7079
raft_include_dir = use_raft_package(raft_path, libcugraph_path)
7180

81+
if not libcugraph_path:
82+
libcugraph_path = conda_lib_dir
83+
7284

7385
class CleanCommand(Command):
7486
"""Custom clean command to tidy up the project root."""
@@ -101,16 +113,25 @@ def run(self):
101113
EXTENSIONS = [
102114
Extension("*",
103115
sources=CYTHON_FILES,
104-
include_dirs=[conda_include_dir,
105-
'../cpp/include',
106-
"../thirdparty/cub",
107-
raft_include_dir,
108-
os.path.join(
109-
conda_include_dir, "libcudacxx"),
110-
cuda_include_dir],
111-
library_dirs=[get_python_lib()],
112-
runtime_library_dirs=[conda_lib_dir],
113-
libraries=['cugraph', 'nccl'],
116+
include_dirs=[
117+
conda_include_dir,
118+
ucx_include_dir,
119+
'../cpp/include',
120+
"../thirdparty/cub",
121+
raft_include_dir,
122+
os.path.join(conda_include_dir, "libcudacxx"),
123+
cuda_include_dir,
124+
os.path.dirname(sysconfig.get_path("include"))
125+
],
126+
library_dirs=[
127+
get_python_lib(),
128+
conda_lib_dir,
129+
libcugraph_path,
130+
ucx_lib_dir,
131+
cuda_lib_dir,
132+
os.path.join(os.sys.prefix, "lib")
133+
],
134+
libraries=['cudart', 'cusparse', 'cusolver', 'cugraph', 'nccl'],
114135
language='c++',
115136
extra_compile_args=['-std=c++17'])
116137
]

0 commit comments

Comments
 (0)