-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require explicit pool size in
pool_memory_resource
and move some th…
…ings out of detail namespace (#1417) Fixes #1416. - ~Deprecates existing ctors of `pool_memory_resource` that provide optional parameter for the initial pool size.~ - Adds new ctors that require an explicit initial pool size. - We don't yet deprecate anything in this PR because that would break builds of some RAPIDS libraries. We will follow up with PRs to cuDF, cuGraph and anything else needed to remove deprecated usages after this PR is merged. - Adds a new utility `fraction_of_available_device_memory` that calculates the specified fraction of free memory on the current CUDA device. This is now used in tests to provide an explicit pool size and can be used to produce the previous behavior of `pool_memory_resource` for consumers of the library. - Moves `available_device_memory` from a detail header to `cuda_device.hpp` so it is now publicly usable, along with the above utility. - Temporarily adds `detail::available_device_memory` as an alias of the above in order to keep cudf and cugraph building until we can update them. - Duplicates commonly externally used alignment functions that are currently in `rmm::detail` to the public `rmm` namespace. The detail versions will be removed after cuDF and cuGraph are updated to not use them. Authors: - Mark Harris (https://github.com/harrism) - Lawrence Mitchell (https://github.com/wence-) Approvers: - Michael Schellenberger Costa (https://github.com/miscco) - Lawrence Mitchell (https://github.com/wence-) - Jake Hemstad (https://github.com/jrhemstad) URL: #1417
- Loading branch information
Showing
41 changed files
with
420 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* Copyright (c) 2020-2024, 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <cassert> | ||
#include <cstddef> | ||
#include <cstdint> | ||
|
||
namespace rmm { | ||
|
||
/** | ||
* @addtogroup utilities | ||
* @{ | ||
* @file | ||
*/ | ||
|
||
/** | ||
* @brief Default alignment used for host memory allocated by RMM. | ||
* | ||
*/ | ||
static constexpr std::size_t RMM_DEFAULT_HOST_ALIGNMENT{alignof(std::max_align_t)}; | ||
|
||
/** | ||
* @brief Default alignment used for CUDA memory allocation. | ||
* | ||
*/ | ||
static constexpr std::size_t CUDA_ALLOCATION_ALIGNMENT{256}; | ||
|
||
/** | ||
* @brief Returns whether or not `value` is a power of 2. | ||
* | ||
* @param[in] value to check. | ||
* | ||
* @return Whether the input a power of two with non-negative exponent | ||
*/ | ||
constexpr bool is_pow2(std::size_t value) { return (value != 0U) && ((value & (value - 1)) == 0U); } | ||
|
||
/** | ||
* @brief Returns whether or not `alignment` is a valid memory alignment. | ||
* | ||
* @param[in] alignment to check | ||
* | ||
* @return Whether the alignment is valid | ||
*/ | ||
constexpr bool is_supported_alignment(std::size_t alignment) { return is_pow2(alignment); } | ||
|
||
/** | ||
* @brief Align up to nearest multiple of specified power of 2 | ||
* | ||
* @param[in] value value to align | ||
* @param[in] alignment amount, in bytes, must be a power of 2 | ||
* | ||
* @return Return the aligned value, as one would expect | ||
*/ | ||
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); | ||
} | ||
|
||
/** | ||
* @brief Align down to the nearest multiple of specified power of 2 | ||
* | ||
* @param[in] value value to align | ||
* @param[in] alignment amount, in bytes, must be a power of 2 | ||
* | ||
* @return Return the aligned value, as one would expect | ||
*/ | ||
constexpr std::size_t align_down(std::size_t value, std::size_t alignment) noexcept | ||
{ | ||
assert(is_supported_alignment(alignment)); | ||
return value & ~(alignment - 1); | ||
} | ||
|
||
/** | ||
* @brief Checks whether a value is aligned to a multiple of a specified power of 2 | ||
* | ||
* @param[in] value value to check for alignment | ||
* @param[in] alignment amount, in bytes, must be a power of 2 | ||
* | ||
* @return true if aligned | ||
*/ | ||
constexpr bool is_aligned(std::size_t value, std::size_t alignment) noexcept | ||
{ | ||
assert(is_supported_alignment(alignment)); | ||
return value == align_down(value, alignment); | ||
} | ||
|
||
/** | ||
* @brief Checks whether the provided pointer is aligned to a specified @p alignment | ||
* | ||
* @param[in] ptr pointer to check for alignment | ||
* @param[in] alignment required alignment in bytes, must be a power of 2 | ||
* | ||
* @return true if the pointer is aligned | ||
*/ | ||
inline bool is_pointer_aligned(void* ptr, std::size_t alignment = CUDA_ALLOCATION_ALIGNMENT) | ||
{ | ||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) | ||
return is_aligned(reinterpret_cast<std::uintptr_t>(ptr), alignment); | ||
} | ||
|
||
/** @} */ // end of group | ||
|
||
} // namespace rmm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.