Virtual functions in the target region

A virtual function in the third target region fails on the device, am I doing something wrong in the
below code? Clang is built daily from the main.

#include <memory_resource>
#include
#include
#include <omp.h>
#include
#include <boost/core/demangle.hpp>
#include

extern “C” {
void* llvm_omp_target_alloc_shared(size_t, int);
}

class Base {
public:
virtual void send() = 0;
};

class Derived : public Base {
public:
void send() { printf(“executing send() on device\n”); };
};

int main() {

#pragma omp target
{
Base *p = new Derived();
p->send(); // ok as new is called in the target region
}

auto p1 = (uintptr_t)llvm_omp_target_alloc_shared(sizeof(Derived), 0);
#pragma omp target
new (reinterpret_cast<Derived*>(p1)) Derived();

#pragma omp target
{
reinterpret_cast<Derived*>(p1)->send(); // ok through p1 Derived::send() is called on device
}

auto p2 = (Derived*)llvm_omp_target_alloc_shared(sizeof(Derived), 0);
#pragma omp target
new (p2) Derived();

#pragma omp target is_device_ptr(p2)
{
p2->send(); // not working
}

return 0;
}

Why has one target region an is_device_ptr(p2) but the other one does not?
What is the behavior you see, e.g., where does it crash?

Shown in the 2nd target region I think you taught me the trick to avoid the is_device_ptr() clause in the target construct. It crashes in the last target region.

Why doesn’t the first target region have a is_device_ptr(p2)? It is not mapped after all, this way it is nulled, I’d assume.

1 Like

That was it.