gcc/libgomp/testsuite/libgomp.c++/target-has-device-addr-8.C
Marcel Vollweiler b4fb9f4f9a OpenMP, C++: Add template support for the has_device_addr clause.
This patch adds support for list items in the has_device_addr clause which type
is given by C++ template parameters.

gcc/cp/ChangeLog:

	* pt.cc (tsubst_omp_clauses): Added OMP_CLAUSE_HAS_DEVICE_ADDR.
	* semantics.cc (finish_omp_clauses): Added template decl processing.

libgomp/ChangeLog:

	* testsuite/libgomp.c++/target-has-device-addr-7.C: New test.
	* testsuite/libgomp.c++/target-has-device-addr-8.C: New test.
	* testsuite/libgomp.c++/target-has-device-addr-9.C: New test.
2022-05-16 01:02:50 -07:00

48 lines
983 B
C

/* Testing 'has_device_addr' clause on the target construct with template. */
#include <omp.h>
template <typename T>
void
foo (T (&x)[])
{
#pragma omp target has_device_addr(x)
for (int i = 0; i < 15; i++)
x[i] = 2 * i;
#pragma omp target has_device_addr(x[15:15])
for (int i = 15; i < 30; i++)
x[i] = 3 * i;
}
int
main ()
{
int *dp = (int*)omp_target_alloc (30*sizeof(int), 0);
#pragma omp target is_device_ptr(dp)
for (int i = 0; i < 30; i++)
dp[i] = i;
int (&x)[30] = *static_cast<int(*)[30]>(static_cast<void*>(dp));
foo <int> (x);
int y[30];
for (int i = 0; i < 30; ++i)
y[i] = 0;
int h = omp_get_initial_device ();
int t = omp_get_default_device ();
omp_target_memcpy (&y, dp, 30 * sizeof(int), 0, 0, h, t);
for (int i = 0; i < 15; ++i)
if (y[i] != 2 * i)
__builtin_abort ();
for (int i = 15; i < 30; ++i)
if (y[i] != 3 * i)
__builtin_abort ();
omp_target_free (dp, 0);
return 0;
}