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

Use scikit-build for the build process #976

Merged
merged 52 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
2f772dc
initial work on scikit-build
kkraus14 Oct 27, 2020
63bdfc7
Fix install paths in cmake
kkraus14 Nov 30, 2020
66d070b
Minimal changes to get rmm to compile.
vyasr Feb 4, 2022
fb32ec7
Some degree of further simplification.
vyasr Feb 5, 2022
3eb20fa
Remove unnecessary cmake symlinks.
vyasr Feb 5, 2022
ee69827
Move cython module adding logic to a function.
vyasr Feb 5, 2022
41d600f
Apply linters.
vyasr Feb 5, 2022
f5f9bb2
Add TODOs documenting various issues discovered.
vyasr Feb 5, 2022
6cc43bc
Fix install destination.
vyasr Feb 7, 2022
ecf3621
Add missing copyrights.
vyasr Feb 7, 2022
e5b1e43
Some basic cleanup.
vyasr Feb 10, 2022
b5cd9cf
Use cmake_path to compute install destination.
vyasr Feb 11, 2022
c9e0a17
Add an option to look for existing rmm installations rather than pull…
vyasr Feb 11, 2022
383e68a
Run formatters.
vyasr Feb 11, 2022
a576c2a
Remove unnecessary includes and add some comments.
vyasr Feb 11, 2022
9a6ccfb
Remove unnecessary CUDAToolkit.
vyasr Feb 11, 2022
3481d36
Fix formatting.
vyasr Feb 11, 2022
defcbf0
Prevent scikit-build from marking all symbols as local, which clobber…
vyasr Feb 16, 2022
b076457
Silence CMake warnings about an unused variable.
vyasr Feb 16, 2022
82366e5
Run cmake-format.
vyasr Feb 16, 2022
57cc78e
Address PR comments.
vyasr Feb 17, 2022
6993f2d
Stop on first test failure.
vyasr Feb 17, 2022
4f752b0
Actually stop on first test failure.
vyasr Feb 17, 2022
6d98e69
Add scikit-build to all conda environment and recipes as well as the …
vyasr Feb 17, 2022
f54978c
Disable cudaMallocAsync using CMake directly now that we have access …
vyasr Feb 17, 2022
9c39e04
Pass CMake variable correctly.
vyasr Feb 17, 2022
696430e
Remove unnecessary endifs.
vyasr Feb 17, 2022
6951f75
Move scikit-build override to separate helper file and add license.
vyasr Feb 17, 2022
81d7a7b
Run cmake-format.
vyasr Feb 17, 2022
e33e681
Revert "Run cmake-format."
vyasr Feb 17, 2022
62ed5f0
Revert "Move scikit-build override to separate helper file and add li…
vyasr Feb 17, 2022
70e3d9e
Update CMake requirement in pyproject.toml.
vyasr Feb 18, 2022
7b9679d
Add cmake to meta.yaml and make scikit-build version explicit in pypr…
vyasr Feb 18, 2022
fe444bb
Disable async support.
vyasr Feb 18, 2022
ead4f39
Use add_compile_definitions correctly.
vyasr Feb 18, 2022
260951c
Request verbose output from ninja and make sure to tell the install s…
vyasr Feb 18, 2022
9c044d1
Selectively disable async APIs and remove unnecessary verbosity.
vyasr Feb 18, 2022
75995bf
Clear _skbuild dir to avoid pulling builds from other executors.
vyasr Feb 19, 2022
84fe4ab
Stop failing on the first test and print some information about where…
vyasr Feb 19, 2022
f0ffdec
Go back to failing on first error to avoid segfault.
vyasr Feb 22, 2022
33f979f
Print info before failure.
vyasr Feb 22, 2022
b374e92
Ensure that every package has a different package_data list to avoid …
vyasr Mar 7, 2022
504325f
Remove debugging cruft.
vyasr Mar 7, 2022
fa27df8
Clean up TODOs.
vyasr Mar 7, 2022
1a4bedc
Merge remote-tracking branch 'origin/branch-22.04' into scikit_build
vyasr Mar 7, 2022
0488b8e
Make cmake-lint happy.
vyasr Mar 7, 2022
4867f97
Make cmake-format happy.
vyasr Mar 7, 2022
3bba733
Address PR comments.
vyasr Mar 10, 2022
c6b57bc
Address PR review.
vyasr Mar 10, 2022
c210bfb
Add contributing documentation.
vyasr Mar 10, 2022
cd796bd
Add the prefix path.
vyasr Mar 10, 2022
f0ac0df
Apply suggestions from code review
vyasr Mar 11, 2022
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ pip-delete-this-directory.txt
# Ignore dynamically generated .pxd files
python/rmm/_cuda/gpu.pxd

# Ignore _skbuild directory
_skbuild/

# Unit test / coverage reports
htmlcov/
.tox/
Expand Down
8 changes: 7 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ into three categories:
8. Once reviewed and approved, a RAPIDS developer will merge your pull request. Note that for C++ code, two reviewers
are required.

To set up a development environment, follow the steps in the [README](https://github.com/rapidsai/rmm/blob/main/README.md) for cloning the repository and creating the conda environment.
Once the environment is created, you can build and install RMM using
```bash
$ python setup.py develop
```
This command will build the RMM Python library inside the clone and automatically make it importable when running Python anywhere on your machine.
Remember, if you are unsure about anything, don't hesitate to comment on issues
and ask for clarifications!

Expand All @@ -52,7 +58,7 @@ implementation of the issue, ask them in the issue instead of the PR.

### Building and Testing on a gpuCI image locally

Before submitting a pull request, you can do a local build and test on your machine that mimics our gpuCI environment using the `ci/local/build.sh` script.
Before submitting a pull request, you can do a local build and test on your machine that mimics our gpuCI environment using the `ci/local/build.sh` script.
For detailed information on usage of this script, see [here](ci/local/README.md).

## Attribution
Expand Down
13 changes: 7 additions & 6 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ HELP="$0 [clean] [librmm] [rmm] [-v] [-g] [-n] [-s] [--ptds] [--no-cudamallocasy
default action (no args) is to build and install 'librmm' and 'rmm' targets
"
LIBRMM_BUILD_DIR=${LIBRMM_BUILD_DIR:=${REPODIR}/build}
RMM_BUILD_DIR=${REPODIR}/python/build
BUILD_DIRS="${LIBRMM_BUILD_DIR} ${RMM_BUILD_DIR}"
RMM_BUILD_DIR="${REPODIR}/python/build ${REPODIR}/python/_skbuild"
vyasr marked this conversation as resolved.
Show resolved Hide resolved
BUILD_DIR="${LIBRMM_BUILD_DIR} ${RMM_BUILD_DIR}"

# Set defaults for vars modified by flags to this script
VERBOSE_FLAG=""
Expand Down Expand Up @@ -157,7 +157,7 @@ if hasArg clean; then
if [ -d "${bd}" ]; then
find "${bd}" -mindepth 1 -delete
rmdir "${bd}" || true
fi
fi
done
fi

Expand All @@ -178,15 +178,16 @@ if (( NUMARGS == 0 )) || hasArg rmm; then
cd "${REPODIR}/python"
export INSTALL_PREFIX
echo "building rmm..."

if [[ ${CUDA_MALLOC_ASYNC_SUPPORT} == OFF ]]; then
python setup.py build_ext_no_async --inplace
python setup.py build_ext --inplace -- -DCUDA_MALLOC_ASYNC_SUPPORT=OFF -DCMAKE_PREFIX_PATH=${INSTALL_PREFIX}
else
python setup.py build_ext --inplace
python setup.py build_ext --inplace -- -DCMAKE_PREFIX_PATH=${INSTALL_PREFIX}
fi

if [[ ${INSTALL_TARGET} != "" ]]; then
echo "installing rmm..."
python setup.py install --single-version-externally-managed --record=record.txt
python setup.py install --single-version-externally-managed --record=record.txt -- -DCMAKE_PREFIX_PATH=${INSTALL_PREFIX}
fi

fi
1 change: 1 addition & 0 deletions ci/release/update-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function sed_runner() {
}

sed_runner 's/'" VERSION .*"'/'" VERSION ${NEXT_FULL_TAG}"'/g' CMakeLists.txt
sed_runner 's/'"rmm_version .*)"'/'"rmm_version ${NEXT_FULL_TAG})"'/g' python/CMakeLists.txt
sed_runner 's/'"branch-.*\/RAPIDS.cmake"'/'"branch-${NEXT_SHORT_TAG}\/RAPIDS.cmake"'/g' CMakeLists.txt

sed_runner 's/'"PROJECT_NUMBER = .*"'/'"PROJECT_NUMBER = ${NEXT_SHORT_TAG}"'/g' doxygen/Doxyfile
Expand Down
2 changes: 1 addition & 1 deletion cmake/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"max_pargs_hwrap": 999
},
"lint": {
"disabled_codes": ["C0301"],
"disabled_codes": ["C0301", "C0112"],
"function_pattern": "[0-9A-z_]+",
"macro_pattern": "[0-9A-z_]+",
"global_var_pattern": "[A-z][0-9A-z_]+",
Expand Down
1 change: 1 addition & 0 deletions conda/environments/rmm_dev_cuda11.5.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies:
- cffi>=1.10.0
- pytest
- cudatoolkit=11.5
- scikit-build>=0.13.1
- spdlog>=1.8.5,<1.9
- cython>=0.29,<0.30
- gcovr>=5.0
Expand Down
1 change: 1 addition & 0 deletions conda/environments/rmm_dev_cuda11.6.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies:
- cffi>=1.10.0
- pytest
- cudatoolkit=11.6
- scikit-build>=0.13.1
- spdlog>=1.8.5,<1.9
- cython>=0.29,<0.30
- gcovr>=5.0
Expand Down
6 changes: 4 additions & 2 deletions conda/recipes/rmm/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019-2021, NVIDIA CORPORATION.
# Copyright (c) 2019-2022, NVIDIA CORPORATION.

{% set version = environ.get('GIT_DESCRIBE_TAG', '0.0.0.dev').lstrip('v') + environ.get('VERSION_SUFFIX', '') %}
{% set py_version=environ.get('CONDA_PY', 35) %}
Expand Down Expand Up @@ -27,7 +27,9 @@ requirements:
- python
- librmm {{ version }}
- setuptools
- cython >=0.29,<0.30
- cython>=0.29,<0.30
- cmake>=3.20.1
- scikit-build>=0.13.1
- spdlog>=1.8.5,<2.0.0a0
- cudatoolkit {{ cuda_version }}.*
- cuda-python >=11.5,<12.0
Expand Down
65 changes: 65 additions & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# =============================================================================
# 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)

# TODO: Pull this directly from the file written by rapids_cmake_write_version_file.
set(rmm_version 22.04.00)
robertmaynard marked this conversation as resolved.
Show resolved Hide resolved

project(
rmm-python
VERSION ${rmm_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
# TODO: The C++ RMM CMake configuration targets cuda_std_17 features, which prior to
# CMake 3.22 will also pull in the corresponding required languages even if this project
# does not actually require those languages. As a result, we need to include CUDA here.
# We can remove CUDA once we upgrade the minimum required CMake version to 3.22.
CUDA)

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

find_package(PythonExtensions REQUIRED)
find_package(Cython REQUIRED)

# Ignore unused variable warning.
set(ignored_variable "${SKBUILD}")

# If the user requested it we attempt to find RMM. TODO: Should we allow the user to specify a path
# instead of just searching? This version assumes that the installation has been appropriately
# configured for CMake discovery.
if(FIND_RMM_CPP)
find_package(RMM ${rmm_version})
vyasr marked this conversation as resolved.
Show resolved Hide resolved
else()
set(RMM_FOUND OFF)
endif()

if(DEFINED CUDA_MALLOC_ASYNC_SUPPORT AND NOT CUDA_MALLOC_ASYNC_SUPPORT)
add_compile_definitions("RMM_DISABLE_CUDA_MALLOC_ASYNC")
endif()

if(NOT RMM_FOUND)
set(BUILD_TESTS OFF)
set(BUILD_BENCHMARKS OFF)
add_subdirectory(../ rmm-cpp)
endif()

add_subdirectory(cmake)
add_subdirectory(rmm/_cuda)
add_subdirectory(rmm/_lib)
16 changes: 16 additions & 0 deletions python/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# =============================================================================
# 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.
# =============================================================================

include(rmm_python_helpers.cmake)
include(skbuild_patches.cmake)
48 changes: 48 additions & 0 deletions python/cmake/rmm_python_helpers.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# =============================================================================
# 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.
# =============================================================================

#[=======================================================================[.rst:
add_cython_modules
------------------

Generate C(++) from Cython and create Python modules.

.. code-block:: cmake

add_cython_modules(<ModuleName...>)

Creates a Cython target for a module, then adds a corresponding Python
extension module.

``ModuleName``
The list of modules to build.

#]=======================================================================]
function(add_cython_modules cython_modules)
foreach(cython_module ${cython_modules})
add_cython_target(${cython_module} CXX PY3)
add_library(${cython_module} MODULE ${cython_module})
python_extension_module(${cython_module})

# To avoid libraries being prefixed with "lib".
set_target_properties(${cython_module} PROPERTIES PREFIX "")
target_link_libraries(${cython_module} rmm::rmm)

# Compute the install directory relative to the source and rely on installs being relative to
# the CMAKE_PREFIX_PATH for e.g. editable installs.
cmake_path(RELATIVE_PATH CMAKE_CURRENT_SOURCE_DIR BASE_DIRECTORY ${rmm-python_SOURCE_DIR}
OUTPUT_VARIABLE install_dst)
install(TARGETS ${cython_module} DESTINATION ${install_dst})
endforeach(cython_module ${cython_sources})
endfunction()
48 changes: 48 additions & 0 deletions python/cmake/skbuild_patches.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# =============================================================================
# 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.
# =============================================================================

#[=======================================================================[.rst:
_set_python_extension_symbol_visibility
---------------------------------------

The original version of this function in scikit-build runs a linker script to
modify the visibility of symbols. This version is a patch to avoid overwriting
the visibility of symbols because RMM specifically overrides some symbol
visibility in order to share certain functional-local static variables.

#]=======================================================================]
# TODO: Should we guard this based on a scikit-build version? Override this function to avoid
# scikit-build clobbering symbol visibility.
function(_set_python_extension_symbol_visibility _target)
if(PYTHON_VERSION_MAJOR VERSION_GREATER 2)
set(_modinit_prefix "PyInit_")
else()
set(_modinit_prefix "init")
endif()
message("_modinit_prefix:${_modinit_prefix}")
if("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
set_target_properties(${_target} PROPERTIES LINK_FLAGS "/EXPORT:${_modinit_prefix}${_target}")
elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(_script_path ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_target}-version-script.map)
file(
WRITE ${_script_path}
# Note: The change is to this script, which does not indiscriminately mark all non PyInit
# symbols as local.
"{global: ${_modinit_prefix}${_target}; };")
set_property(
TARGET ${_target}
APPEND_STRING
PROPERTY LINK_FLAGS " -Wl,--version-script=\"${_script_path}\"")
endif()
endfunction()
3 changes: 2 additions & 1 deletion python/dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2021, NVIDIA CORPORATION.
# Copyright (c) 2021-2022, NVIDIA CORPORATION.

clang==8.0.1
flake8==3.8.3
Expand All @@ -12,3 +12,4 @@ pytest-xdist
cython>=0.29,<0.30
wheel
setuptools
scikit-build>=0.13.1
19 changes: 17 additions & 2 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
# Copyright (c) 2021, NVIDIA CORPORATION.
# Copyright (c) 2021-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",
"cython>=0.29,<0.30",
"scikit-build>=0.13.1",
"cmake>=3.20.1",
"ninja",
]

[tool.black]
Expand Down
19 changes: 19 additions & 0 deletions python/rmm/_cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# =============================================================================
# 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 the list of Cython files to build
set(cython_modules stream)

# Build all of the Cython targets
add_cython_modules("${cython_modules}")
19 changes: 19 additions & 0 deletions python/rmm/_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# =============================================================================
# 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 the list of Cython files to build
set(cython_modules device_buffer lib memory_resource cuda_stream)

# Build all of the Cython targets
add_cython_modules("${cython_modules}")
Loading