Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build cuspatial with scikit-build #524

Merged
merged 16 commits into from
May 20, 2022
Merged
Changes from 1 commit
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
Next Next commit
Build with scikit-build mostly working, except that cuspatial CPP lib…
…rary link is not being create correctly and needs to be manually added with LD_LIBRARY_PATH.
  • Loading branch information
vyasr committed May 17, 2022
commit 316f497022a509e4bff3c220bd14d59e827ecb89
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ DartConfiguration.tcl
dist/
cuspatial.egg-info/
python/build
_skbuild
python/*/build
python/cuspatial/*/_lib/**/*.cpp
python/cuspatial/*/_lib/**/*.h
52 changes: 52 additions & 0 deletions python/cuspatial/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# =============================================================================
# Copyright (c) 2022, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations under
# the License.
# =============================================================================

cmake_minimum_required(VERSION 3.20.1 FATAL_ERROR)

set(cuspatial_version 22.06.00)

file(DOWNLOAD https://raw.githubusercontent.com/rapidsai/rapids-cmake/branch-22.06/RAPIDS.cmake
${CMAKE_BINARY_DIR}/RAPIDS.cmake)
include(${CMAKE_BINARY_DIR}/RAPIDS.cmake)

project(
cuspatial-python
VERSION ${cuspatial_version}
LANGUAGES # TODO: Building Python extension modules via the python_extension_module requires the C
# language to be enabled here. The test project that is built in scikit-build to verify
# various linking options for the python library is hardcoded to build with C, so until
# that is fixed we need to keep C.
C CXX)

option(FIND_CUSPATIAL_CPP "Search for existing cuspatial C++ installations before defaulting to local files"
OFF)

# If the user requested it we attempt to find cuspatial.
if(FIND_CUSPATIAL_CPP)
find_package(cuspatial ${cuspatial_version})
else()
set(cuspatial_FOUND OFF)
endif()

if(NOT cuspatial_FOUND)
# TODO: This will not be necessary once we upgrade to CMake 3.22, which will pull in the required
# languages for the C++ project even if this project does not require those languges.
enable_language(CUDA)
add_subdirectory(../../cpp cuspatial-cpp)
endif()

include(rapids-cython)
rapids_cython_init()

add_subdirectory(cuspatial/_lib)
42 changes: 42 additions & 0 deletions python/cuspatial/cuspatial/_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# =============================================================================
# Copyright (c) 2022, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations under
# the License.
# =============================================================================

set(cython_sources
hausdorff.pyx
interpolate.pyx
point_in_polygon.pyx
polygon_bounding_boxes.pyx
polyline_bounding_boxes.pyx
quadtree.pyx
shapefile_reader.pyx
spatial.pyx
spatial_join.pyx
spatial_window.pyx
trajectory.pyx
)
set(linked_libraries cuspatial::cuspatial)

rapids_cython_create_modules(SOURCE_FILES "${cython_sources}" LINKED_LIBRARIES "${linked_libraries}"
CXX)
target_link_libraries(hausdorff cuspatial::cuspatial)
target_link_libraries(interpolate cuspatial::cuspatial)
target_link_libraries(point_in_polygon cuspatial::cuspatial)
target_link_libraries(polygon_bounding_boxes cuspatial::cuspatial)
target_link_libraries(polyline_bounding_boxes cuspatial::cuspatial)
target_link_libraries(quadtree cuspatial::cuspatial)
target_link_libraries(shapefile_reader cuspatial::cuspatial)
target_link_libraries(spatial cuspatial::cuspatial)
target_link_libraries(spatial_join cuspatial::cuspatial)
target_link_libraries(spatial_window cuspatial::cuspatial)
target_link_libraries(trajectory cuspatial::cuspatial)
24 changes: 24 additions & 0 deletions python/cuspatial/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) 2022, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

[build-system]

requires = [
"wheel",
"setuptools",
"cython>=0.29,<0.30",
"scikit-build>=0.13.1",
"cmake>=3.20.1,!=3.23.0",
"ninja",
]
74 changes: 4 additions & 70 deletions python/cuspatial/setup.py
Original file line number Diff line number Diff line change
@@ -1,66 +1,9 @@
# Copyright (c) 2018, NVIDIA CORPORATION.
import os
import shutil
import sysconfig
from distutils.sysconfig import get_python_lib

import numpy as np
from Cython.Build import cythonize
from setuptools import find_packages, setup
from setuptools.extension import Extension
# Copyright (c) 2018-2022, NVIDIA CORPORATION.
from setuptools import find_packages
from skbuild import setup

import versioneer

install_requires = ["numba", "cython"]
cython_files = ["cuspatial/_lib/**/*.pyx"]

CUDA_HOME = os.environ.get("CUDA_HOME", False)
if not CUDA_HOME:
path_to_cuda_gdb = shutil.which("cuda-gdb")
if path_to_cuda_gdb is None:
raise OSError(
"Could not locate CUDA. "
"Please set the environment variable "
"CUDA_HOME to the path to the CUDA installation "
"and try again."
)
CUDA_HOME = os.path.dirname(os.path.dirname(path_to_cuda_gdb))

if not os.path.isdir(CUDA_HOME):
raise OSError(f"Invalid CUDA_HOME: directory does not exist: {CUDA_HOME}")

cuda_include_dir = os.path.join(CUDA_HOME, "include")

CUSPATIAL_ROOT = os.environ.get("CUSPATIAL_ROOT", "../../cpp/build/")

try:
nthreads = int(os.environ.get("PARALLEL_LEVEL", "0") or "0")
except Exception:
nthreads = 0

extensions = [
Extension(
"*",
sources=cython_files,
include_dirs=[
"../../cpp/include",
os.path.join(CUSPATIAL_ROOT, "include"),
os.path.join(CUSPATIAL_ROOT, "_deps/libcudacxx-src/include"),
os.path.join(
os.path.dirname(sysconfig.get_path("include")),
"rapids/libcudacxx",
),
os.path.dirname(sysconfig.get_path("include")),
np.get_include(),
cuda_include_dir,
],
library_dirs=[get_python_lib()],
libraries=["cudf", "cuspatial"],
language="c++",
extra_compile_args=["-std=c++17"],
)
]

setup(
name="cuspatial",
version=versioneer.get_version(),
@@ -80,18 +23,9 @@
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
],
# Include the separately-compiled shared library
setup_requires=["cython"],
ext_modules=cythonize(
extensions,
nthreads=nthreads,
compiler_directives=dict(
profile=False, language_level=3, embedsignature=True
),
),
packages=find_packages(include=["cuspatial", "cuspatial.*"]),
package_data={"cuspatial._lib": ["*.pxd"]},
cmdclass=versioneer.get_cmdclass(),
install_requires=install_requires,
install_requires=["numba"],
zip_safe=False,
)