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

Add rapids_cpm_nvcomp with prebuilt binary support #190

Merged
merged 23 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c518023
Add rapids_cpm_nvcomp with prebuilt binary support
robertmaynard May 10, 2022
c2fb8cc
Update rapids_cpm_nvcomp with install rules
robertmaynard May 13, 2022
d33f602
fix style issues found by ci
robertmaynard May 13, 2022
a78e8ef
Update testing/cpm/cpm_nvcomp-override-clears-proprietary_binary.cmake
robertmaynard May 13, 2022
853ead1
Update testing/cpm/cpm_nvcomp-invalid-arch.cmake
robertmaynard May 13, 2022
20d9cb3
Update testing/cpm/cpm_nvcomp-export.cmake
robertmaynard May 13, 2022
71a30dd
Update docs/packages/rapids_cpm_versions.rst
robertmaynard May 13, 2022
c4d4450
Update docs/packages/rapids_cpm_versions.rst
robertmaynard May 13, 2022
2dc013a
Update docs/packages/rapids_cpm_versions.rst
robertmaynard May 13, 2022
6e37baa
Update docs/packages/rapids_cpm_versions.rst
robertmaynard May 13, 2022
632bbf9
Update rapids-cmake/cpm/detail/get_proprietary_binary.cmake
robertmaynard May 13, 2022
d40c14d
simplify rapids_cpm_get_proprietary_binary as found in code review
robertmaynard May 13, 2022
b8ffa15
Update rapids-cmake/cpm/nvcomp.cmake
robertmaynard May 13, 2022
b638b29
Update rapids-cmake/cpm/nvcomp.cmake
robertmaynard May 13, 2022
cdc697d
Update rapids-cmake/cpm/nvcomp.cmake
robertmaynard May 13, 2022
9b94e88
Update comment to be correct
robertmaynard May 13, 2022
93d3e04
Update rapids-cmake/cpm/nvcomp.cmake
robertmaynard May 13, 2022
0819a38
reorder so exclude variable exists
robertmaynard May 13, 2022
ae4fab0
Remove unneeded build export set logic
robertmaynard May 13, 2022
453f1f9
Encode json loading from global properties in a function
robertmaynard May 13, 2022
94b241e
change license file location
robertmaynard May 13, 2022
4073c7f
Improve USE_PROPRIETARY_BINARY docs
robertmaynard May 16, 2022
8429f0a
Correct style issues found by CI
robertmaynard May 16, 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
10 changes: 10 additions & 0 deletions cmake-format-rapids-cmake.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@
"BUILD_EXPORT_SET": 1
}
},
"rapids_cpm_nvcomp": {
"pargs": {
"nargs": 0
},
"kwargs": {
"BUILD_EXPORT_SET": 1,
"INSTALL_EXPORT_SET": 1,
"USE_PROPRIETARY_BINARY": 1
}
},
"rapids_cpm_rmm": {
"pargs": {
"nargs": 0
Expand Down
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ package uses :ref:`can be found here. <cpm_versions>`
/packages/rapids_cpm_gtest
/packages/rapids_cpm_libcudacxx
/packages/rapids_cpm_nvbench
/packages/rapids_cpm_nvcomp
/packages/rapids_cpm_rmm
/packages/rapids_cpm_spdlog
/packages/rapids_cpm_thrust
Expand Down
7 changes: 7 additions & 0 deletions docs/packages/proprietary_binary.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

{
"proprietary_binary" : {
"aarch64-linux" : "<url>",
"x86_64-linux" : "<url>"
}
}
1 change: 1 addition & 0 deletions docs/packages/rapids_cpm_nvcomp.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. cmake-module:: ../../rapids-cmake/cpm/nvcomp.cmake
25 changes: 25 additions & 0 deletions docs/packages/rapids_cpm_versions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,31 @@ as needed.

If no such field exists the default is `false` for default packages, and `true` for any package that has an override.

``proprietary_binary``

An optional dictonary of cpu architecture and operating system keys to url values that represents a download for a pre-built proprietary version of the library.
robertmaynard marked this conversation as resolved.
Show resolved Hide resolved
If a matching key exists the binary will be used instead of the specified git url and tag.
To determine the correct key, CMake will query for a key that matches the lower case value of `<arch>-<os>` where `arch` maps to :cmake:variable:`CMAKE_SYSTEM_PROCESSOR` and `os` maps to :cmake:variable:`CMAKE_SYSTEM_NAME`.

If no such key exists the request to use a `proprietary_binary` will be ignored.

.. literalinclude:: /packages/proprietary_binary.json
:language: json

As this represents a proprietary binary only the following packages support this command:
- nvcomp

Due to requirements of proprietary binarues, explicit opt-in by the user on usage is required.
robertmaynard marked this conversation as resolved.
Show resolved Hide resolved
Therefore for this binary to be used the caller must call the associated `rapids_cpm` command
with the `USE_PROPRIETARY_BLOB` set to `ON`.

Supports the following placeholders:
- ``${rapids-cmake-version}`` will be evulated to 'major.minor' of the current rapids-cmake cal-ver value.
robertmaynard marked this conversation as resolved.
Show resolved Hide resolved
- ``${version}`` will be evulated to the contents of the ``version`` field.
robertmaynard marked this conversation as resolved.
Show resolved Hide resolved

If this field exists in the default package, the value will be ignored when an override file
entry exists for the package. This ensures that the git url or `proprietary_binary` entry in the override will be used.

rapids-cmake package versions
#############################

Expand Down
78 changes: 78 additions & 0 deletions rapids-cmake/cpm/detail/get_proprietary_binary.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#=============================================================================
# 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_guard(GLOBAL)

#[=======================================================================[.rst:
get_proprietary_binary
-------------------

.. versionadded:: v22.06.00

Download the associated proprietary binary for the given project based on
the current CPU target architecture ( x86_64, aarch64, etc )

.. note::
if override => the proprietary entry only in the override will be evaluated
if no override => the proprietary entry only in the default will be evaluated


#]=======================================================================]
function(rapids_cpm_get_proprietary_binary package_name version)

get_property(override_json_data GLOBAL PROPERTY rapids_cpm_${package_name}_override_json)
robertmaynard marked this conversation as resolved.
Show resolved Hide resolved
# need to search the `proprietary_binary` dictonary for a key with the same name as
robertmaynard marked this conversation as resolved.
Show resolved Hide resolved
# lower_case(`CMAKE_SYSTEM_PROCESSOR-CMAKE_SYSTEM_NAME`).
set(key "${CMAKE_SYSTEM_PROCESSOR}-${CMAKE_SYSTEM_NAME}")
string(TOLOWER ${key} key)

if(override_json_data)
string(JSON value ERROR_VARIABLE have_error GET "${override_json_data}" "proprietary_binary"
"${key}")
else()
get_property(json_data GLOBAL PROPERTY rapids_cpm_${package_name}_json)
string(JSON value ERROR_VARIABLE have_error GET "${json_data}" "proprietary_binary" "${key}")
endif()

if(have_error)
message(VERBOSE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we fail harder here? Or at least, propagate sufficient information for the parent scope to fail harder? As it stands now, if a user passes USE_PROPERIETARY_BINARY to rapids_cpm_nvcomp and no binary is found, there will just be a small message. Shouldn't rapids_cpm_nvcomp fail in that scenario (even if rapids_cpm_get_proprietary_binary shouldn't)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could implement it that way.

My concern is that since nvcomp doesn't have arm binaries, projects like cudf would need to somehow query rapids-cmake to see if the platform they are running on has binary support and if so request USE_PROPERIETARY_BINARY.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After talking with vysar offline we agreed more documentation is needed in USE_PROPRIETARY_BINARY to explain the behavior of the command when an override exists, or if no binary exists for platform ( arm / windows / etc ).

"${package_name} requested usage of a proprietary_binary but none exist for ${CMAKE_SYSTEM_PROCESSOR}"
)
return()
endif()

# proprietary_binary now is the url that we need to download
set(proprietary_binary ${value})
robertmaynard marked this conversation as resolved.
Show resolved Hide resolved

if(NOT DEFINED rapids-cmake-version)
include("${rapids-cmake-dir}/rapids-version.cmake")
endif()

# Evaluate any magic placeholders in the proprietary_binary value including the
# `rapids-cmake-version` value
cmake_language(EVAL CODE "set(proprietary_binary ${proprietary_binary})")
robertmaynard marked this conversation as resolved.
Show resolved Hide resolved

if(proprietary_binary)
# download and extract the binaries since they don't exist on the machine
include(FetchContent)
set(pkg_name "${package_name}_proprietary_binary")
FetchContent_Declare(${pkg_name} URL ${proprietary_binary})
FetchContent_MakeAvailable(${pkg_name})

# Tell the subsequent rapids_cpm_find where to search so that it uses this binary
set(${package_name}_ROOT "${${pkg_name}_SOURCE_DIR}" PARENT_SCOPE)
set(${package_name}_proprietary_binary ON PARENT_SCOPE)
endif()
endfunction()
141 changes: 141 additions & 0 deletions rapids-cmake/cpm/nvcomp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#=============================================================================
# Copyright (c) 2021, 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_guard(GLOBAL)

#[=======================================================================[.rst:
rapids_cpm_nvcomp
-----------------

.. versionadded:: v22.06.00

Allow projects to find or build `nvComp` via `CPM` with built-in
tracking of these dependencies for correct export support.

Uses the version of nvComp :ref:`specified in the version file <cpm_versions>` for consistency
across all RAPIDS projects.

.. code-block:: cmake

rapids_cpm_nvcomp( [BUILD_EXPORT_SET <export-name>]
robertmaynard marked this conversation as resolved.
Show resolved Hide resolved
[INSTALL_EXPORT_SET <export-name>]
[USE_PROPRIETARY_BINARY <ON|OFF>]
)

``BUILD_EXPORT_SET``
Record that a :cmake:command:`CPMFindPackage(<PackageName> ...)` call needs to occur as part of
our build directory export set.

``INSTALL_EXPORT_SET``
Record a :cmake:command:`find_dependency(<PackageName> ...) <cmake:module:CMakeFindDependencyMacro>` call needs to occur as part of
our build directory export set.

.. note::
Installation of nvcomp will occur if an INSTALL_EXPORT_SET is provided, and nvcomp
is added to the project via :cmake:command:`add_subdirectory <cmake:command:add_subdirectory>` by CPM.

``USE_PROPRIETARY_BINARY``
By enabling this flag you and using the software, you agree to fully comply with the terms and conditions of
robertmaynard marked this conversation as resolved.
Show resolved Hide resolved
nvcomp's NVIDIA Software License Agreement. Found at https://developer.download.nvidia.com/compute/nvcomp/2.3/LICENSE.txt

Result Targets
^^^^^^^^^^^^^^
nvcomp::nvcomp target will be created

Result Variables
^^^^^^^^^^^^^^^^
:cmake:variable:`nvcomp_SOURCE_DIR` is set to the path to the source directory of nvcomp.
:cmake:variable:`nvcomp_BINARY_DIR` is set to the path to the build directory of nvcomp.
:cmake:variable:`nvcomp_ADDED` is set to a true value if nvcomp has not been added before.
:cmake:variable:`nvcomp_VERSION` is set to the version of nvcomp specified by the versions.json.
:cmake:variable:`nvcomp_proprietary_binary` is set to ON if the proprietary binary is being used

#]=======================================================================]
function(rapids_cpm_nvcomp)
list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.cpm.nvcomp")

set(options)
set(one_value USE_PROPRIETARY_BINARY BUILD_EXPORT_SET INSTALL_EXPORT_SET)
set(multi_value)
cmake_parse_arguments(RAPIDS "${options}" "${one_value}" "${multi_value}" ${ARGN})

# Fix up RAPIDS_UNPARSED_ARGUMENTS to have EXPORT_SETS As this is need for rapids_cpm_find
robertmaynard marked this conversation as resolved.
Show resolved Hide resolved
if(RAPIDS_INSTALL_EXPORT_SET)
list(APPEND RAPIDS_UNPARSED_ARGUMENTS INSTALL_EXPORT_SET ${RAPIDS_INSTALL_EXPORT_SET})
endif()
if(RAPIDS_BUILD_EXPORT_SET)
list(APPEND RAPIDS_UNPARSED_ARGUMENTS BUILD_EXPORT_SET ${RAPIDS_BUILD_EXPORT_SET})
endif()

set(to_exclude OFF)
if(NOT RAPIDS_INSTALL_EXPORT_SET OR exclude)
robertmaynard marked this conversation as resolved.
Show resolved Hide resolved
set(to_exclude ON)
endif()

include("${rapids-cmake-dir}/cpm/detail/package_details.cmake")
rapids_cpm_package_details(nvcomp version repository tag shallow exclude)

# first see if we have a proprietary pre-built binary listed in versions.json and it if requested.
#
robertmaynard marked this conversation as resolved.
Show resolved Hide resolved
set(nvcomp_proprietary_binary OFF) # will be set to true by rapids_cpm_get_proprietary_binary
if(RAPIDS_USE_PROPRIETARY_BINARY)
include("${rapids-cmake-dir}/cpm/detail/get_proprietary_binary.cmake")
rapids_cpm_get_proprietary_binary(nvcomp ${version})
endif()

include("${rapids-cmake-dir}/cpm/find.cmake")
rapids_cpm_find(nvcomp ${version} ${RAPIDS_UNPARSED_ARGUMENTS}
GLOBAL_TARGETS nvcomp::nvcomp
CPM_ARGS
GIT_REPOSITORY ${repository}
GIT_TAG ${tag}
GIT_SHALLOW ${shallow}
EXCLUDE_FROM_ALL ${to_exclude}
OPTIONS "BUILD_STATIC ON" "BUILD_TESTS OFF" "BUILD_BENCHMARKS OFF"
"BUILD_EXAMPLES OFF")

# nvcomp creates the correct namespace aliases
robertmaynard marked this conversation as resolved.
Show resolved Hide resolved
if(NOT TARGET nvcomp::nvcomp AND TARGET nvcomp)
add_library(nvcomp::nvcomp ALIAS nvcomp)
endif()

# Propagate up variables that CPMFindPackage provide
set(nvcomp_SOURCE_DIR "${nvcomp_SOURCE_DIR}" PARENT_SCOPE)
set(nvcomp_BINARY_DIR "${nvcomp_BINARY_DIR}" PARENT_SCOPE)
set(nvcomp_ADDED "${nvcomp_ADDED}" PARENT_SCOPE)
set(nvcomp_VERSION ${version} PARENT_SCOPE)
set(nvcomp_proprietary_binary ${nvcomp_proprietary_binary} PARENT_SCOPE)

# Setup up install rules when using the proprietary_binary When building from source, nvcomp will
robertmaynard marked this conversation as resolved.
Show resolved Hide resolved
# set the correct install rules
include("${rapids-cmake-dir}/export/find_package_root.cmake")
if(RAPIDS_INSTALL_EXPORT_SET AND nvcomp_proprietary_binary)
include(GNUInstallDirs)
install(DIRECTORY "${nvcomp_ROOT}/lib/" DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(DIRECTORY "${nvcomp_ROOT}/include/" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# place the license information in the location that conda uses
install(FILES "${nvcomp_ROOT}/NOTICE" DESTINATION info/licenses/ RENAME NVCOMP_NOTICE)
install(FILES "${nvcomp_ROOT}/LICENSE" DESTINATION info/licenses/ RENAME NVCOMP_LICENSE)
endif()

if(RAPIDS_BUILD_EXPORT_SET AND nvcomp_proprietary_binary)
# point our consumers to where they can find the pre-built version
rapids_export_find_package_root(BUILD nvcomp "${nvcomp_ROOT}" ${RAPIDS_BUILD_EXPORT_SET})
elseif(RAPIDS_BUILD_EXPORT_SET)
# point our consumers to where they can find the source version
rapids_export_find_package_root(BUILD nvcomp "${nvcomp_BINARY_DIR}" ${RAPIDS_BUILD_EXPORT_SET})
robertmaynard marked this conversation as resolved.
Show resolved Hide resolved
endif()

endfunction()
8 changes: 8 additions & 0 deletions rapids-cmake/cpm/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
"git_url" : "https://github.com/NVIDIA/nvbench.git",
"git_tag" : "a72f248af6323915419e03c0d7d56a35c9b4819a"
},
"nvcomp" : {
"version" : "2.3",
"git_url" : "https://github.com/NVIDIA/nvcomp.git",
"git_tag" : "v2.2.0",
"proprietary_binary" : {
"x86_64-linux" : "http://developer.download.nvidia.com/compute/nvcomp/${version}/local_installers/nvcomp_${version}_Linux_CUDA_11.x.tgz"
}
},
"rmm" : {
"version" : "${rapids-cmake-version}",
"git_url" : "https://github.com/rapidsai/rmm.git",
Expand Down
7 changes: 7 additions & 0 deletions testing/cpm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ add_cmake_config_test( cpm_libcudacxx-simple.cmake )
add_cmake_config_test( cpm_nvbench-export.cmake )
add_cmake_config_test( cpm_nvbench-simple.cmake )

add_cmake_config_test( cpm_nvcomp-export.cmake )
add_cmake_config_test( cpm_nvcomp-proprietary-off.cmake )
add_cmake_config_test( cpm_nvcomp-proprietary-on.cmake )
add_cmake_config_test( cpm_nvcomp-simple.cmake )
add_cmake_config_test( cpm_nvcomp-invalid-arch.cmake )
add_cmake_config_test( cpm_nvcomp-override-clears-proprietary_binary.cmake )

add_cmake_config_test( cpm_rmm-export.cmake )
add_cmake_config_test( cpm_rmm-simple.cmake )

Expand Down
31 changes: 31 additions & 0 deletions testing/cpm/cpm_nvcomp-export.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#=============================================================================
# Copyright (c) 2021, NVIDIA CORPORATION.
robertmaynard marked this conversation as resolved.
Show resolved Hide resolved
#
# 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(${rapids-cmake-dir}/cpm/init.cmake)
include(${rapids-cmake-dir}/cpm/nvcomp.cmake)

rapids_cpm_init()
rapids_cpm_nvcomp(BUILD_EXPORT_SET test)
rapids_cpm_nvcomp(BUILD_EXPORT_SET test2)

get_target_property(packages rapids_export_build_test PACKAGE_NAMES)
if(NOT nvcomp IN_LIST packages)
message(FATAL_ERROR "rapids_cpm_nvcomp failed to record nvcomp needs to be exported")
endif()

get_target_property(packages rapids_export_build_test2 PACKAGE_NAMES)
if(NOT nvcomp IN_LIST packages)
message(FATAL_ERROR "rapids_cpm_nvcomp failed to record nvcomp needs to be exported")
endif()
30 changes: 30 additions & 0 deletions testing/cpm/cpm_nvcomp-invalid-arch.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#=============================================================================
# Copyright (c) 2021, NVIDIA CORPORATION.
robertmaynard marked this conversation as resolved.
Show resolved Hide resolved
#
# 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(${rapids-cmake-dir}/cpm/init.cmake)
include(${rapids-cmake-dir}/cpm/nvcomp.cmake)

rapids_cpm_init()

if(TARGET nvcomp::nvcomp)
message(FATAL_ERROR "Expected nvcomp::nvcomp expected to not exist")
endif()

set(CMAKE_SYSTEM_PROCESSOR "i686") # Don't do this outside of tests
rapids_cpm_nvcomp(USE_PROPRIETARY_BINARY ON)

if(nvcomp_proprietary_binary)
message(FATAL_ERROR "Shouldn't have found a pre-built version of nvcomp for a non-existent CMAKE_SYSTEM_PROCESSOR key")
endif()
Loading