alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
ViewStdVector.hpp
Go to the documentation of this file.
1/* Copyright 2022 Axel Huebl, Benjamin Worpitz, Jan Stephan, Bernhard Manfred Gruber
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5/* TODO: Once C++20 is available remove this file and replace with a generic ContiguousContainer solution based on
6 * concepts. It should be sufficient to check for the existence of Container.size() and Container.data() */
7
8#pragma once
9
11#include "alpaka/dev/DevCpu.hpp"
14
15#include <vector>
16
17namespace alpaka::trait
18{
19 //! The std::vector device type trait specialization.
20 template<typename TElem, typename TAllocator>
21 struct DevType<std::vector<TElem, TAllocator>>
22 {
23 using type = DevCpu;
24 };
25
26 //! The std::vector device get trait specialization.
27 template<typename TElem, typename TAllocator>
28 struct GetDev<std::vector<TElem, TAllocator>>
29 {
30 ALPAKA_FN_HOST static auto getDev(std::vector<TElem, TAllocator> const& /* view */) -> DevCpu
31 {
32 return getDevByIdx(PlatformCpu{}, 0u);
33 }
34 };
35
36 //! The std::vector dimension getter trait specialization.
37 template<typename TElem, typename TAllocator>
38 struct DimType<std::vector<TElem, TAllocator>>
39 {
41 };
42
43 //! The std::vector memory element type get trait specialization.
44 template<typename TElem, typename TAllocator>
45 struct ElemType<std::vector<TElem, TAllocator>>
46 {
47 using type = TElem;
48 };
49
50 template<typename TElem, typename TAllocator>
51 struct GetExtents<std::vector<TElem, TAllocator>>
52 {
53 ALPAKA_FN_HOST constexpr auto operator()(std::vector<TElem, TAllocator> const& a)
55 {
56 return {std::size(a)};
57 }
58 };
59
60 //! The std::vector native pointer get trait specialization.
61 template<typename TElem, typename TAllocator>
62 struct GetPtrNative<std::vector<TElem, TAllocator>>
63 {
64 ALPAKA_FN_HOST static auto getPtrNative(std::vector<TElem, TAllocator> const& view) -> TElem const*
65 {
66 return std::data(view);
67 }
68
69 ALPAKA_FN_HOST static auto getPtrNative(std::vector<TElem, TAllocator>& view) -> TElem*
70 {
71 return std::data(view);
72 }
73 };
74
75 //! The std::vector offset get trait specialization.
76 template<typename TElem, typename TAllocator>
77 struct GetOffsets<std::vector<TElem, TAllocator>>
78 {
79 ALPAKA_FN_HOST auto operator()(std::vector<TElem, TAllocator> const&) const
81 {
82 return {0};
83 }
84 };
85
86 //! The std::vector idx type trait specialization.
87 template<typename TElem, typename TAllocator>
88 struct IdxType<std::vector<TElem, TAllocator>>
89 {
90 using type = std::size_t;
91 };
92} // namespace alpaka::trait
The CPU device handle.
Definition DevCpu.hpp:56
A n-dimensional vector.
Definition Vec.hpp:38
#define ALPAKA_FN_HOST
Definition Common.hpp:40
The accelerator traits.
typename trait::IdxType< T >::type Idx
Definition Traits.hpp:29
ALPAKA_FN_HOST auto getDevByIdx(TPlatform const &platform, std::size_t const &devIdx) -> Dev< TPlatform >
Definition Traits.hpp:62
std::integral_constant< std::size_t, N > DimInt
STL namespace.
The CPU device platform.
The device type trait.
Definition Traits.hpp:23
The dimension getter type trait.
Definition Traits.hpp:14
The element type trait.
Definition Traits.hpp:16
static ALPAKA_FN_HOST auto getDev(std::vector< TElem, TAllocator > const &) -> DevCpu
The device get trait.
Definition Traits.hpp:27
ALPAKA_FN_HOST constexpr auto operator()(std::vector< TElem, TAllocator > const &a) -> Vec< DimInt< 1 >, Idx< std::vector< TElem, TAllocator > > >
The GetExtents trait for getting the extents of an object as an alpaka::Vec.
Definition Traits.hpp:37
ALPAKA_FN_HOST auto operator()(std::vector< TElem, TAllocator > const &) const -> Vec< DimInt< 1 >, Idx< std::vector< TElem, TAllocator > > >
The GetOffsets trait for getting the offsets of an object as an alpaka::Vec.
Definition Traits.hpp:33
static ALPAKA_FN_HOST auto getPtrNative(std::vector< TElem, TAllocator > &view) -> TElem *
static ALPAKA_FN_HOST auto getPtrNative(std::vector< TElem, TAllocator > const &view) -> TElem const *
The native pointer get trait.
Definition Traits.hpp:54
The idx type trait.
Definition Traits.hpp:25