When we use the device, e.g., with an API that interacts with it, we need to ensure the image is loaded and the constructors are executed. Two tests are included to verify we 1) load images and run constructors when needed, and 2) we do so lazily only if the device is actually used. --------- Co-authored-by: Joseph Huber <huberjn@outlook.com>
34 lines
657 B
C++
34 lines
657 B
C++
// RUN: %libomptarget-compilexx-generic
|
|
// RUN: %libomptarget-run-generic
|
|
// RUN: %libomptarget-compilexx-generic -DCTOR_KERNEL
|
|
// RUN: %not --crash %libomptarget-run-generic
|
|
// RUN: %libomptarget-compilexx-generic -DCTOR_API
|
|
// RUN: %not --crash %libomptarget-run-generic
|
|
|
|
#include <cstdio>
|
|
#include <omp.h>
|
|
|
|
void foo_dev() { __builtin_trap(); }
|
|
|
|
#pragma omp declare variant(foo_dev) match(device = {kind(nohost)})
|
|
void foo() {}
|
|
|
|
struct S {
|
|
S() { foo(); }
|
|
};
|
|
|
|
S s;
|
|
#pragma omp declare target(s)
|
|
|
|
int main() {
|
|
int Dev = omp_get_default_device();
|
|
|
|
#ifdef CTOR_KERNEL
|
|
#pragma omp target
|
|
{}
|
|
#endif
|
|
#ifdef CTOR_API
|
|
omp_get_mapped_ptr(&s, Dev);
|
|
#endif
|
|
}
|