padding.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2023-2025, NVIDIA CORPORATION.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 #pragma once
7 
8 namespace raft_proto {
9 
10 /* Return the value that must be added to val to equal the next multiple of
11  * alignment greater than or equal to val */
12 template <typename T, typename U>
13 HOST DEVICE auto padding_size(T val, U alignment)
14 {
15  auto result = val;
16  if (alignment != 0) {
17  auto remainder = val % alignment;
18  result = alignment - remainder;
19  result *= (remainder != 0);
20  }
21  return result;
22 }
23 
24 /* Return the next multiple of alignment >= val */
25 template <typename T, typename U>
26 HOST DEVICE auto padded_size(T val, U alignment)
27 {
28  return val + padding_size(val, alignment);
29 }
30 
31 /* Return the value that must be added to val to equal the next multiple of
32  * alignment less than or equal to val */
33 template <typename T, typename U>
34 HOST DEVICE auto downpadding_size(T val, U alignment)
35 {
36  auto result = val;
37  if (alignment != 0) { result = val % alignment; }
38  return result;
39 }
40 
41 /* Return the next multiple of alignment <= val */
42 template <typename T, typename U>
43 HOST DEVICE auto downpadded_size(T val, U alignment)
44 {
45  return val - downpadding_size(val, alignment);
46 }
47 
48 } // namespace raft_proto
#define DEVICE
Definition: gpu_support.hpp:24
#define HOST
Definition: gpu_support.hpp:23
Definition: buffer.hpp:24
HOST DEVICE auto padded_size(T val, U alignment)
Definition: padding.hpp:26
HOST DEVICE auto downpadded_size(T val, U alignment)
Definition: padding.hpp:43
HOST DEVICE auto downpadding_size(T val, U alignment)
Definition: padding.hpp:34
HOST DEVICE auto padding_size(T val, U alignment)
Definition: padding.hpp:13