-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaxerr.thrust.inl
More file actions
63 lines (51 loc) · 1.43 KB
/
maxerr.thrust.inl
File metadata and controls
63 lines (51 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* @file maxerr.thrust.inl
* @author Jiannan Tian
* @brief
* @version 0.3
* @date 2022-10-08
*
* (C) 2022 by Indiana University, Argonne National Laboratory
*
*/
#ifndef C6875E14_650F_49ED_9DD5_E7F916EE31FF
#define C6875E14_650F_49ED_9DD5_E7F916EE31FF
#include "stat/compare/compare.thrust.hh"
// #include <thrust/count.h>
// #include <thrust/iterator/constant_iterator.h>
#include <thrust/device_ptr.h>
#include <thrust/execution_policy.h>
#include <thrust/device_vector.h>
#include "cusz/type.h"
#include <thrust/extrema.h>
#include <thrust/execution_policy.h>
namespace psz {
template <typename T>
void thrustgpu_get_maxerr(
T* reconstructed, // in
T* original, // in
size_t len, // in
T& maximum_val, // out
size_t& maximum_loc, // out
bool destructive)
{
T* diff;
if (destructive) {
diff = original; // aliasing
}
else {
GpuMalloc(&diff, sizeof(T) * len);
}
auto expr = [=] __device__(T rel, T oel) { return rel - oel; };
// typesafe (also with exec-policy binding)
thrust::device_ptr<T> r(reconstructed);
thrust::device_ptr<T> o(original);
thrust::device_ptr<T> d(diff);
thrust::transform(r, r + len, o, d, expr);
auto maximum_ptr = thrust::max_element(d, d + len);
maximum_val = *maximum_ptr;
maximum_loc = maximum_ptr - d;
if (not destructive) { GpuFree(diff); }
}
} // namespace psz
#endif /* C6875E14_650F_49ED_9DD5_E7F916EE31FF */