Debian Codegraph @

libgomp/testsuite/libgomp.c++/pr101544-1.C

raw
1 // See also '../libgomp.oacc-c++/pr101544-1.C'.
2 #ifndef ALWAYS_INLINE
3 # define ALWAYS_INLINE
4 #endif
5
6 //===--- declare_target_base_class.cpp --------------------------------------===//
7 //
8 // OpenMP API Version 4.5 Nov 2015
9 //
10 // This test was suggested by members of NERSC. This test defines a declare
11 // target region which includes only a base class and a 'concrete' device
12 // pointer.
13 //
14 // Test suggestion comes from Chris Daily and Rahulkumar Gayatri from NERSC
15 ////===----------------------------------------------------------------------===//
16
17 #include <new>
18 #include <vector>
19 #include <iostream>
20
21 #pragma omp declare target
22 //#pragma acc routine //TODO error: '#pragma acc routine' not immediately followed by function declaration or definition
23 class S {
24 public:
25 //#pragma acc routine //TODO error: '#pragma acc routine' must be at file scope
26 ALWAYS_INLINE
27 S() : _devPtr(nullptr) {}
28 //#pragma acc routine //TODO error: '#pragma acc routine' must be at file scope
29 ALWAYS_INLINE
30 double sag(double x, double y) {
31 return x + y;
32 }
33 S* cloneToDevice() {
34 S* ptr;
35 #pragma omp target map(ptr)
36 #pragma acc serial copy(ptr)
37 {
38 ptr = new S();
39 }
40 _devPtr = ptr;
41 return ptr;
42 }
43 private:
44 S* _devPtr;
45 };
46 //#pragma acc routine (S) //TODO error: 'class S' does not refer to a function
47 //#pragma acc routine (S::S) //TODO error: '#pragma acc routine' names a set of overloads
48 //#pragma acc routine (S::sag) //TODO error: '#pragma acc routine' names a set of overloads
49 #pragma omp end declare target
50
51 int main() {
52 int errors = 0;
53
54 S s;
55 S* devPtr = s.cloneToDevice();
56
57 std::vector<double> in(10, 0.0);
58 for(int i = 0; i < 10; i++) {
59 in[i] = i;
60 }
61
62 std::vector<double> out(10, 0.0);
63
64 double* inptr = in.data();
65 double* outptr = out.data();
66
67 #pragma omp target teams distribute parallel for map(inptr[:10], outptr[:10]) is_device_ptr(devPtr)
68 #pragma acc parallel loop copy(inptr[:10], outptr[:10]) deviceptr(devPtr)
69 for(int i = 0; i < 10; i++) {
70 outptr[i] = devPtr->sag(inptr[i], inptr[i]);
71 }
72
73 for(int i = 0; i < 10; i++) {
74 if (out[i] != i * 2)
75 {
76 ++errors;
77 std::cerr << "ERROR: " << "i = " << i << ": " << out[i] << " != " << (i * 2) << "\n";
78 }
79 }
80
81 return errors ? 1 : 0;
82 }