alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
alignment.hpp
Go to the documentation of this file.
1/* Copyright 2025 René Widera
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5/** @file This file provides a basic implementation of a SIMD vector.
6 *
7 * The implementation is based on the class Vec:
8 * - the storge policy should become the native SIMD implementation e.g. std::simd
9 * - load/ store and simd specifis should be implemented in the storage policy
10 * - the name of storage policy should be changed
11 *
12 * The current operator operations relay on compilers auto vectorization.
13 */
14
15#pragma once
16
18
19#include <bit>
20#include <cstdint>
21#include <functional>
22
23namespace alpaka::internal
24{
25 /** Calculates the best alignment based
26 *
27 * Takes care that the alignment never exceeds T_Alignment.
28 * In the worst case the alignment falls back to the alignment of the component type.
29 */
30 template<typename T_ValueType, uint32_t T_numElements, alpaka::concepts::Alignment T_Alignment>
31 consteval uint32_t optimalAlignment()
32 {
33 constexpr uint32_t currentTypeAlignment = static_cast<uint32_t>(alignof(T_ValueType));
34 if constexpr(T_numElements % 2 != 0u)
35 return currentTypeAlignment;
36
37 constexpr uint32_t dataSizeInBytes = static_cast<uint32_t>(sizeof(T_ValueType) * T_numElements);
38 constexpr uint32_t alignment = std::min(T_Alignment::template get<T_ValueType>(), dataSizeInBytes);
39 if constexpr(std::has_single_bit(alignment))
40 return alignment;
41
42 return static_cast<uint32_t>(alignof(T_ValueType));
43 }
44} // namespace alpaka::internal
constexpr decltype(auto) get(concepts::SpecializationOf< Dict > auto &t) noexcept
Definition Dict.hpp:151