Add 'libgomp.c++/pr101544-1{,-O0}.C', 'libgomp.oacc-c++/pr101544-1.C' [PR101544]

PR target/101544
	libgomp/
	* testsuite/libgomp.c++/pr101544-1.C: New.
	* testsuite/libgomp.c++/pr101544-1-O0.C: Likewise.
	* testsuite/libgomp.oacc-c++/pr101544-1.C: Likewise.
This commit is contained in:
Thomas Schwinge 2022-07-12 09:59:10 +02:00 committed by Thomas Schwinge
parent 65b31b3fff
commit 62312c778a
3 changed files with 94 additions and 0 deletions

View file

@ -0,0 +1,4 @@
// { dg-additional-options -foffload-options=-lstdc++ }
// { dg-additional-options -O0 }
#include "pr101544-1.C"

View file

@ -0,0 +1,83 @@
// { dg-additional-options -foffload-options=-lstdc++ }
// See also '../libgomp.oacc-c++/pr101544-1.C'.
#ifndef ALWAYS_INLINE
# define ALWAYS_INLINE
#endif
//===--- declare_target_base_class.cpp --------------------------------------===//
//
// OpenMP API Version 4.5 Nov 2015
//
// This test was suggested by members of NERSC. This test defines a declare
// target region which includes only a base class and a 'concrete' device
// pointer.
//
// Test suggestion comes from Chris Daily and Rahulkumar Gayatri from NERSC
////===----------------------------------------------------------------------===//
#include <new>
#include <vector>
#include <iostream>
#pragma omp declare target
//#pragma acc routine //TODO error: '#pragma acc routine' not immediately followed by function declaration or definition
class S {
public:
//#pragma acc routine //TODO error: '#pragma acc routine' must be at file scope
ALWAYS_INLINE
S() : _devPtr(nullptr) {}
//#pragma acc routine //TODO error: '#pragma acc routine' must be at file scope
ALWAYS_INLINE
double sag(double x, double y) {
return x + y;
}
S* cloneToDevice() {
S* ptr;
#pragma omp target map(ptr)
#pragma acc serial copy(ptr)
{
ptr = new S();
}
_devPtr = ptr;
return ptr;
}
private:
S* _devPtr;
};
//#pragma acc routine (S) //TODO error: 'class S' does not refer to a function
//#pragma acc routine (S::S) //TODO error: '#pragma acc routine' names a set of overloads
//#pragma acc routine (S::sag) //TODO error: '#pragma acc routine' names a set of overloads
#pragma omp end declare target
int main() {
int errors = 0;
S s;
S* devPtr = s.cloneToDevice();
std::vector<double> in(10, 0.0);
for(int i = 0; i < 10; i++) {
in[i] = i;
}
std::vector<double> out(10, 0.0);
double* inptr = in.data();
double* outptr = out.data();
#pragma omp target teams distribute parallel for map(inptr[:10], outptr[:10]) is_device_ptr(devPtr)
#pragma acc parallel loop copy(inptr[:10], outptr[:10]) deviceptr(devPtr)
for(int i = 0; i < 10; i++) {
outptr[i] = devPtr->sag(inptr[i], inptr[i]);
}
for(int i = 0; i < 10; i++) {
if (out[i] != i * 2)
{
++errors;
std::cerr << "ERROR: " << "i = " << i << ": " << out[i] << " != " << (i * 2) << "\n";
}
}
return errors ? 1 : 0;
}

View file

@ -0,0 +1,7 @@
// { dg-additional-options -foffload-options=-lstdc++ }
// { dg-additional-options -fno-inline } for stable results regarding OpenACC 'routine'.
// But actually, as none of the '#pragma acc routine' syntax is accepted, force inlining:
#define ALWAYS_INLINE __attribute__((always_inline))
#include "../libgomp.c++/pr101544-1.C"
//TODO { dg-prune-output {using 'vector_length \(32\)', ignoring 1} }