aligned.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020-2025, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <rmm/detail/export.hpp>
20 
21 #include <cassert>
22 #include <cstddef>
23 #include <cstdint>
24 
25 namespace RMM_EXPORT rmm {
26 
37 static constexpr std::size_t RMM_DEFAULT_HOST_ALIGNMENT{alignof(std::max_align_t)};
38 
43 static constexpr std::size_t CUDA_ALLOCATION_ALIGNMENT{256};
44 
52 [[nodiscard]] bool is_pow2(std::size_t value) noexcept;
53 
61 [[nodiscard]] bool is_supported_alignment(std::size_t alignment) noexcept;
62 
71 [[nodiscard]] std::size_t align_up(std::size_t value, std::size_t alignment) noexcept;
72 
81 [[nodiscard]] std::size_t align_down(std::size_t value, std::size_t alignment) noexcept;
82 
91 [[nodiscard]] bool is_aligned(std::size_t value, std::size_t alignment) noexcept;
92 
101 [[nodiscard]] bool is_pointer_aligned(void* ptr,
102  std::size_t alignment = CUDA_ALLOCATION_ALIGNMENT) noexcept;
103  // end of group
105 
106 } // namespace RMM_EXPORT rmm
static constexpr std::size_t CUDA_ALLOCATION_ALIGNMENT
Default alignment used for CUDA memory allocation.
Definition: aligned.hpp:43
std::size_t align_down(std::size_t value, std::size_t alignment) noexcept
Align down to the nearest multiple of specified power of 2.
bool is_supported_alignment(std::size_t alignment) noexcept
Returns whether or not alignment is a valid memory alignment.
bool is_pointer_aligned(void *ptr, std::size_t alignment=CUDA_ALLOCATION_ALIGNMENT) noexcept
Checks whether the provided pointer is aligned to a specified alignment.
static constexpr std::size_t RMM_DEFAULT_HOST_ALIGNMENT
Default alignment used for host memory allocated by RMM.
Definition: aligned.hpp:37
bool is_pow2(std::size_t value) noexcept
Returns whether or not value is a power of 2.
bool is_aligned(std::size_t value, std::size_t alignment) noexcept
Checks whether a value is aligned to a multiple of a specified power of 2.
std::size_t align_up(std::size_t value, std::size_t alignment) noexcept
Align up to nearest multiple of specified power of 2.