Highly Efficient FFT for Exascale: HeFFTe v2.4
Loading...
Searching...
No Matches
heffte_backend_vector.h
1/*
2 -- heFFTe --
3 Univ. of Tennessee, Knoxville
4 @date
5*/
6
7#ifndef HEFFTE_BACKEND_VECTOR_H
8#define HEFFTE_BACKEND_VECTOR_H
9
10#ifdef Heffte_ENABLE_GPU
11
20namespace heffte{
21
26namespace gpu {
27
52 template<typename scalar_type, typename manipulator>
53 class device_vector{
54 public:
56 using value_type = scalar_type;
58 using backend_device = typename manipulator::backend_device;
60 using stream_type = typename backend_device::stream_type;
61
63 device_vector(size_t num_entries = 0) :
64 device(),
65 num(num_entries),
66 device_data(manipulator::template allocate<scalar_type>(device.stream(), num_entries))
67 {}
69 device_vector(backend_device const &new_device, size_t num_entries = 0) :
70 device(new_device),
71 num(num_entries),
72 device_data(manipulator::template allocate<scalar_type>(device.stream(), num_entries))
73 {}
75 device_vector(scalar_type const *begin, scalar_type const *end) :
76 device_vector(std::distance(begin, end)){
77 manipulator::copy_device_to_device(device.stream(), begin, num, device_data);
78 }
80 device_vector(backend_device const &new_device, scalar_type const *begin, scalar_type const *end) :
81 device_vector(new_device, std::distance(begin, end)){
82 manipulator::copy_device_to_device(device.stream(), begin, num, device_data);
83 }
84
86 device_vector(const device_vector<scalar_type, manipulator>& other) :
87 device_vector(other.device, other.num){
88 manipulator::copy_device_to_device(device.stream(), other.device_data, num, device_data);
89 }
91 device_vector(device_vector<scalar_type, manipulator> &&other) :
92 device(other.device),
93 num(c11_exchange(other.num, 0)),
94 device_data(c11_exchange(other.device_data, nullptr))
95 {}
96
98 device_vector(scalar_type* &&raw_pointer, size_t num_entries) :
99 device(),
100 num(num_entries),
101 device_data(c11_exchange(raw_pointer, nullptr))
102 {}
104 device_vector(backend_device const &new_device, scalar_type* &&raw_pointer, size_t num_entries) :
105 device(new_device),
106 num(num_entries),
107 device_data(c11_exchange(raw_pointer, nullptr))
108 {}
109
111 ~device_vector(){ manipulator::free(device.stream(), device_data); }
112
114 void operator =(device_vector<scalar_type, manipulator> const &other){
115 device_vector<scalar_type, manipulator> temp(other);
116 device = temp.device;
117 std::swap(num, temp.num);
118 std::swap(device_data, temp.device_data);
119 }
120
122 void operator =(device_vector<scalar_type, manipulator>&& other){
123 device_vector<scalar_type, manipulator> temp(std::move(other));
124 device = temp.device;
125 std::swap(num, temp.num);
126 std::swap(device_data, temp.device_data);
127 }
128
130 scalar_type* data(){ return device_data; }
132 const scalar_type* data() const{ return device_data; }
133
135 size_t size() const{ return num; }
137 bool empty() const{ return (num == 0); }
138
140 scalar_type* release(){
141 num = 0;
142 return c11_exchange(device_data, nullptr);
143 }
144
146 stream_type device_stream(){ return device.stream(); }
148 stream_type device_stream() const{ return device.stream(); }
149
150 private:
152 backend_device device;
154 size_t num;
156 scalar_type *device_data;
157 };
158
163 int device_count();
164
171 void device_set(int active_device);
172
177 void synchronize_default_stream();
178
179}
180
181}
182
183#endif
184
185#endif /* HEFFTE_BACKEND_VECTOR_H */
T c11_exchange(T &obj, U &&new_value)
Replace with the C++ 2014 std::exchange later.
Definition heffte_utils.h:37
Namespace containing all HeFFTe methods and classes.
Definition heffte_backend_cuda.h:38