Repository navigation
Convert part of RMM to a precompiled library #1896
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
Changes from 1 commit
0bbb038
008a99b
0637f84
bfd63a5
4113e98
ee37f7c
dd26598
d22cd09
d8173db
a29a2f9
dbd6b85
dd18602
9278dbb
c2b1911
219e068
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,31 +83,43 @@ include(cmake/thirdparty/get_nvtx.cmake) | |
| # ################################################################################################## | ||
| # * library targets -------------------------------------------------------------------------------- | ||
|
|
||
| add_library(rmm INTERFACE) | ||
| add_library(rmm SHARED src/aligned.cpp) | ||
| add_library(rmm::rmm ALIAS rmm) | ||
|
|
||
| target_include_directories( | ||
| rmm | ||
| INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>" | ||
| "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>" "$<INSTALL_INTERFACE:include>") | ||
| PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>" | ||
| "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>" | ||
| INTERFACE "$<INSTALL_INTERFACE:include>") | ||
|
|
||
| if(CUDA_STATIC_RUNTIME) | ||
| message(STATUS "RMM: Enabling static linking of cudart") | ||
| target_link_libraries(rmm INTERFACE CUDA::cudart_static) | ||
| target_link_libraries(rmm PUBLIC CUDA::cudart_static) | ||
| else() | ||
| target_link_libraries(rmm INTERFACE CUDA::cudart) | ||
| target_link_libraries(rmm PUBLIC CUDA::cudart) | ||
| endif() | ||
|
|
||
| target_link_libraries(rmm INTERFACE CCCL::CCCL) | ||
| target_link_libraries(rmm INTERFACE dl) | ||
| target_link_libraries(rmm INTERFACE nvtx3::nvtx3-cpp) | ||
| target_link_libraries(rmm INTERFACE rapids_logger::rapids_logger) | ||
| target_compile_features(rmm INTERFACE cxx_std_17 $<BUILD_INTERFACE:cuda_std_17>) | ||
| target_compile_definitions(rmm INTERFACE LIBCUDACXX_ENABLE_EXPERIMENTAL_MEMORY_RESOURCE) | ||
| target_link_libraries(rmm PUBLIC CCCL::CCCL ${CMAKE_DL_LIBS} nvtx3::nvtx3-cpp | ||
| rapids_logger::rapids_logger) | ||
|
|
||
| set_target_properties( | ||
| rmm | ||
| PROPERTIES BUILD_RPATH "\$ORIGIN" | ||
| INSTALL_RPATH "\$ORIGIN" | ||
| # set target compile options | ||
|
bdice marked this conversation as resolved.
Resolved
|
||
| CXX_STANDARD 17 | ||
| CXX_STANDARD_REQUIRED ON | ||
| CXX_VISIBILITY_PRESET hidden | ||
| CUDA_STANDARD 17 | ||
|
bdice marked this conversation as resolved.
Resolved
|
||
| CUDA_STANDARD_REQUIRED ON | ||
| CUDA_VISIBILITY_PRESET hidden | ||
| POSITION_INDEPENDENT_CODE ON | ||
| INTERFACE_POSITION_INDEPENDENT_CODE ON) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may be able to drop this eventually depending on how much of rmm stops being header-only. Ideally we wouldn't be proscribing this for consumers I think, @robertmaynard any thoughts?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally once RMM is a proper library we can drop |
||
| target_compile_definitions(rmm PUBLIC LIBCUDACXX_ENABLE_EXPERIMENTAL_MEMORY_RESOURCE) | ||
|
|
||
| # Enable NVTX if necessary | ||
| if(RMM_NVTX) | ||
| target_compile_definitions(rmm INTERFACE RMM_NVTX) | ||
| target_compile_definitions(rmm PUBLIC RMM_NVTX) | ||
| endif() | ||
|
|
||
| # ################################################################################################## | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /* | ||
| * Copyright (c) 2020-2024, NVIDIA CORPORATION. | ||
| * Copyright (c) 2020-2025, NVIDIA CORPORATION. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
|
|
@@ -49,10 +49,7 @@ static constexpr std::size_t CUDA_ALLOCATION_ALIGNMENT{256}; | |
| * | ||
| * @return True if the input is a power of two with non-negative integer exponent, false otherwise. | ||
| */ | ||
| [[nodiscard]] constexpr bool is_pow2(std::size_t value) noexcept | ||
| { | ||
| return (value != 0U) && ((value & (value - 1)) == 0U); | ||
| } | ||
| [[nodiscard]] RMM_EXPORT bool is_pow2(std::size_t value) noexcept; | ||
|
|
||
| /** | ||
| * @brief Returns whether or not `alignment` is a valid memory alignment. | ||
|
|
@@ -61,10 +58,7 @@ static constexpr std::size_t CUDA_ALLOCATION_ALIGNMENT{256}; | |
| * | ||
| * @return True if the alignment is valid, false otherwise. | ||
| */ | ||
| [[nodiscard]] constexpr bool is_supported_alignment(std::size_t alignment) noexcept | ||
| { | ||
| return is_pow2(alignment); | ||
| } | ||
| [[nodiscard]] RMM_EXPORT bool is_supported_alignment(std::size_t alignment) noexcept; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW, I believe We should, however, probably add
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the explanation! I was unsure about this. I will think some more about what solution seems the most natural. Related to the other comment below, I would like it if we could use either What do you think of this proposal:
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the topic of namespacing, I think there will also be a lot of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wrt the proposal, that sounds reasonable. Ideally we move to a situation where everything in the
I suppose your anonymous namespace suggestion would have the same effect.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, for sure. That will likely be for a later pass. I haven't touched any "detail" headers yet. |
||
|
|
||
| /** | ||
| * @brief Align up to nearest multiple of specified power of 2 | ||
|
|
@@ -74,11 +68,7 @@ static constexpr std::size_t CUDA_ALLOCATION_ALIGNMENT{256}; | |
| * | ||
| * @return the aligned value | ||
| */ | ||
| [[nodiscard]] constexpr std::size_t align_up(std::size_t value, std::size_t alignment) noexcept | ||
| { | ||
| assert(is_supported_alignment(alignment)); | ||
| return (value + (alignment - 1)) & ~(alignment - 1); | ||
| } | ||
| [[nodiscard]] RMM_EXPORT std::size_t align_up(std::size_t value, std::size_t alignment) noexcept; | ||
|
|
||
| /** | ||
| * @brief Align down to the nearest multiple of specified power of 2 | ||
|
|
@@ -88,11 +78,7 @@ static constexpr std::size_t CUDA_ALLOCATION_ALIGNMENT{256}; | |
| * | ||
| * @return the aligned value | ||
| */ | ||
| [[nodiscard]] constexpr std::size_t align_down(std::size_t value, std::size_t alignment) noexcept | ||
| { | ||
| assert(is_supported_alignment(alignment)); | ||
| return value & ~(alignment - 1); | ||
| } | ||
| [[nodiscard]] RMM_EXPORT std::size_t align_down(std::size_t value, std::size_t alignment) noexcept; | ||
|
|
||
| /** | ||
| * @brief Checks whether a value is aligned to a multiple of a specified power of 2 | ||
|
|
@@ -102,11 +88,7 @@ static constexpr std::size_t CUDA_ALLOCATION_ALIGNMENT{256}; | |
| * | ||
| * @return true if aligned | ||
| */ | ||
| [[nodiscard]] constexpr bool is_aligned(std::size_t value, std::size_t alignment) noexcept | ||
| { | ||
| assert(is_supported_alignment(alignment)); | ||
| return value == align_down(value, alignment); | ||
| } | ||
| [[nodiscard]] RMM_EXPORT bool is_aligned(std::size_t value, std::size_t alignment) noexcept; | ||
|
|
||
| /** | ||
| * @brief Checks whether the provided pointer is aligned to a specified @p alignment | ||
|
|
@@ -116,12 +98,8 @@ static constexpr std::size_t CUDA_ALLOCATION_ALIGNMENT{256}; | |
| * | ||
| * @return true if the pointer is aligned | ||
| */ | ||
| [[nodiscard]] inline bool is_pointer_aligned( | ||
| void* ptr, std::size_t alignment = CUDA_ALLOCATION_ALIGNMENT) noexcept | ||
| { | ||
| // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) | ||
| return is_aligned(reinterpret_cast<std::uintptr_t>(ptr), alignment); | ||
| } | ||
| [[nodiscard]] RMM_EXPORT bool is_pointer_aligned( | ||
| void* ptr, std::size_t alignment = CUDA_ALLOCATION_ALIGNMENT) noexcept; | ||
|
|
||
| /** @} */ // end of group | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * Copyright (c) 2020-2025, 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/aligned.hpp> | ||
|
|
||
| #include <cassert> | ||
| #include <cstddef> | ||
| #include <cstdint> | ||
|
|
||
| namespace RMM_NAMESPACE { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe here we should be using |
||
|
|
||
| bool is_pow2(std::size_t value) noexcept { return (value != 0U) && ((value & (value - 1)) == 0U); } | ||
|
|
||
| bool is_supported_alignment(std::size_t alignment) noexcept { return is_pow2(alignment); } | ||
|
|
||
| std::size_t align_up(std::size_t value, std::size_t alignment) noexcept | ||
| { | ||
| assert(is_supported_alignment(alignment)); | ||
| return (value + (alignment - 1)) & ~(alignment - 1); | ||
| } | ||
|
|
||
| std::size_t align_down(std::size_t value, std::size_t alignment) noexcept | ||
| { | ||
| assert(is_supported_alignment(alignment)); | ||
| return value & ~(alignment - 1); | ||
| } | ||
|
|
||
| bool is_aligned(std::size_t value, std::size_t alignment) noexcept | ||
| { | ||
| assert(is_supported_alignment(alignment)); | ||
| return value == align_down(value, alignment); | ||
| } | ||
|
|
||
| bool is_pointer_aligned(void* ptr, std::size_t alignment) noexcept | ||
| { | ||
| // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) | ||
| return is_aligned(reinterpret_cast<std::uintptr_t>(ptr), alignment); | ||
| } | ||
|
|
||
| } // namespace RMM_NAMESPACE | ||
Uh oh!
There was an error while loading. Please reload this page.