CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
153 lines
3.9 KiB
C++
153 lines
3.9 KiB
C++
// RUN: %libomptarget-compilexx-run-and-check-generic
|
|
// REQUIRES: gpu
|
|
|
|
#include <assert.h>
|
|
#include <omp.h>
|
|
#include <stdio.h>
|
|
|
|
#define TEST_VAL 10
|
|
|
|
#pragma omp declare target
|
|
|
|
class Base {
|
|
public:
|
|
virtual int foo() { return 1; }
|
|
virtual int bar() { return 2; }
|
|
virtual int foo_with_arg(int x) { return x; }
|
|
};
|
|
|
|
class Derived : public Base {
|
|
public:
|
|
virtual int foo() { return 10; }
|
|
virtual int bar() { return 20; }
|
|
virtual int foo_with_arg(int x) { return -x; }
|
|
};
|
|
|
|
#pragma omp end declare target
|
|
|
|
int test_virtual_implicit_map() {
|
|
Base base;
|
|
Derived derived;
|
|
int result1, result2, result3, result4, result5, result6;
|
|
|
|
// map both base and derived objects up front, since the spec
|
|
// requires that when first mapping a C++ object that the static
|
|
// type must match the dynamic type
|
|
#pragma omp target data map(base, derived)
|
|
{
|
|
Base *p1 = &base;
|
|
Base *p2 = &derived;
|
|
|
|
#pragma omp target map(from : result1, result2, result3, result4, result5, \
|
|
result6)
|
|
{
|
|
// These calls will fail if Clang does not
|
|
// translate/attach the vtable pointer in each object
|
|
result1 = p1->foo();
|
|
result2 = p1->bar();
|
|
result3 = p2->foo();
|
|
result4 = p2->bar();
|
|
result5 = base.foo();
|
|
result6 = derived.foo();
|
|
}
|
|
}
|
|
|
|
assert(result1 == 1 && "p1->foo() implicit map Failed");
|
|
assert(result2 == 2 && "p1->bar() implicit map Failed");
|
|
assert(result3 == 10 && "p2->foo() implicit map Failed");
|
|
assert(result4 == 20 && "p2->bar() implicit map Failed");
|
|
assert(result5 == 1 && "base.foo() implicit map Failed");
|
|
assert(result6 == 10 && "derived.foo() implicit map Failed");
|
|
return 0;
|
|
}
|
|
|
|
int test_virtual_explicit_map() {
|
|
Base base;
|
|
Derived derived;
|
|
int result1, result2, result3, result4;
|
|
|
|
// map both base and derived objects up front, since the spec
|
|
// requires that when first mapping a C++ object that the static
|
|
// type must match the dynamic type
|
|
#pragma omp target data map(base, derived)
|
|
{
|
|
Base *p1 = &base;
|
|
Base *p2 = &derived;
|
|
|
|
#pragma omp target map(p1[0 : 0], p2[0 : 0]) \
|
|
map(from : result1, result2, result3, result4)
|
|
{
|
|
result1 = p1->foo();
|
|
result2 = p1->bar();
|
|
result3 = p2->foo();
|
|
result4 = p2->bar();
|
|
}
|
|
}
|
|
|
|
assert(result1 == 1 && "p1->foo() explicit map Failed");
|
|
assert(result2 == 2 && "p1->bar() explicit map Failed");
|
|
assert(result3 == 10 && "p2->foo() explicit map Failed");
|
|
assert(result4 == 20 && "p2->bar() explicit map Failed");
|
|
return 0;
|
|
}
|
|
|
|
int test_virtual_reference() {
|
|
Derived ddd;
|
|
Base cont;
|
|
Base &bbb = ddd;
|
|
|
|
int b_ret, d_ret, c_ret;
|
|
|
|
#pragma omp target data map(to : ddd, cont)
|
|
{
|
|
#pragma omp target map(bbb, ddd, cont) map(from : b_ret, d_ret, c_ret)
|
|
{
|
|
b_ret = bbb.foo_with_arg(TEST_VAL);
|
|
d_ret = ddd.foo_with_arg(TEST_VAL);
|
|
c_ret = cont.foo_with_arg(TEST_VAL);
|
|
}
|
|
}
|
|
|
|
assert(c_ret == TEST_VAL && "Control Base call failed on gpu");
|
|
assert(b_ret == -TEST_VAL && "Reference to derived call failed on gpu");
|
|
assert(d_ret == -TEST_VAL && "Derived call failed on gpu");
|
|
|
|
return 0;
|
|
}
|
|
|
|
int test_virtual_reference_implicit() {
|
|
Derived ddd;
|
|
Base cont;
|
|
Base &bbb = ddd;
|
|
|
|
int b_ret, d_ret, c_ret;
|
|
|
|
#pragma omp target data map(to : ddd, cont)
|
|
{
|
|
#pragma omp target map(from : b_ret, d_ret, c_ret)
|
|
{
|
|
b_ret = bbb.foo_with_arg(TEST_VAL);
|
|
d_ret = ddd.foo_with_arg(TEST_VAL);
|
|
c_ret = cont.foo_with_arg(TEST_VAL);
|
|
}
|
|
}
|
|
|
|
assert(c_ret == TEST_VAL && "Control Base call failed on gpu (implicit)");
|
|
assert(b_ret == -TEST_VAL &&
|
|
"Reference to derived call failed on gpu (implicit)");
|
|
assert(d_ret == -TEST_VAL && "Derived call failed on gpu (implicit)");
|
|
|
|
return 0;
|
|
}
|
|
|
|
int main() {
|
|
test_virtual_implicit_map();
|
|
test_virtual_explicit_map();
|
|
test_virtual_reference();
|
|
test_virtual_reference_implicit();
|
|
|
|
// CHECK: PASS
|
|
printf("PASS\n");
|
|
return 0;
|
|
}
|