OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BufferCompaction.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
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 
23 #ifndef BUFFER_COMPACTION_H
24 #define BUFFER_COMPACTION_H
25 
26 #include <cstdint>
27 #include "../Shared/funcannotations.h"
28 
29 #ifndef __CUDACC__
30 #include <algorithm>
31 #endif
32 
33 constexpr int8_t MAX_BYTE_WIDTH_SUPPORTED = 8;
34 
35 #ifndef __CUDACC__
36 inline unsigned compact_byte_width(unsigned qw, unsigned low_bound) {
37  return std::max(qw, low_bound);
38 }
39 #endif
40 
41 template <typename T>
43  addr += sizeof(int64_t) - 1;
44  return (T)(((uint64_t)addr >> 3) << 3);
45 }
46 
47 // Return nearest multiple of N for val rounding up.
48 // Example: align_to<8>(10) = 16.
49 template <size_t N, typename T>
51  constexpr T mask = static_cast<T>(N - 1);
52  static_assert(N && (N & mask) == 0, "N must be a power of 2.");
53  return (val + mask) & ~mask;
54 }
55 
56 #endif /* BUFFER_COMPACTION_H */
unsigned compact_byte_width(unsigned qw, unsigned low_bound)
FORCE_INLINE HOST DEVICE T align_to(T const val)
#define DEVICE
#define HOST
#define FORCE_INLINE
constexpr unsigned N
Definition: Utm.h:110
constexpr int8_t MAX_BYTE_WIDTH_SUPPORTED
FORCE_INLINE HOST DEVICE T align_to_int64(T addr)