<div dir="ltr">Johannes,<div>Tested with Trunk on POWER8:</div><div><br></div><div>test5.cpp:20:40: error: expected expression containing only member accesses and/or array sections based on named variables<br>                #pragma omp target enter data map(to:*this, this->arr[0:100])<br>                                                     ^~~~~<br>test5.cpp:23:40: error: expected expression containing only member accesses and/or array sections based on named variables<br>                #pragma omp target enter data map(to:*this, this->arr[0:100])<br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Jan 18, 2020 at 4:50 AM Doerfert, Johannes <<a href="mailto:jdoerfert@anl.gov">jdoerfert@anl.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Check the attached email from Tom for a way to make this work. Let me know what you think<br>
<br>
<br>
<br>
---------------------------------------<br>
Johannes Doerfert<br>
Researcher<br>
<br>
Argonne National Laboratory<br>
Lemont, IL 60439, USA<br>
<br>
<a href="mailto:jdoerfert@anl.gov" target="_blank">jdoerfert@anl.gov</a><br>
<br>
________________________________________<br>
From: Alexey Bataev <<a href="mailto:a.bataev@hotmail.com" target="_blank">a.bataev@hotmail.com</a>><br>
Sent: Friday, January 17, 2020 03:33<br>
To: Itaru Kitayama<br>
Cc: Doerfert, Johannes; openmp-dev<br>
Subject: Re: [Openmp-dev] Target CUDA RTL --> CUDA error is: an illegal memory access was encountered<br>
<br>
The compiler does not work the way you want. It is not an issue of OpenMP but of C++ itself.<br>
<br>
Best regards,<br>
Alexey Bataev<br>
<br>
16 янв. 2020 г., в 23:20, Itaru Kitayama <<a href="mailto:itaru.kitayama@gmail.com" target="_blank">itaru.kitayama@gmail.com</a>> написал(а):<br>
<br>
<br>
#include <stdio.h><br>
<br>
class AbsBase {<br>
public:<br>
        virtual int f() = 0;<br>
};<br>
<br>
class Derived : public AbsBase {<br>
private:<br>
        //int *arr = new int[100];<br>
        int arr[100];<br>
public:<br>
        int f() { return arr[0]; }<br>
        void fillarray() {<br>
                arr[0] = 1234;<br>
        }<br>
};<br>
<br>
int main() {<br>
        AbsBase *absBase = new Derived();<br>
Derived *p = static_cast<Derived*>(absBase);<br>
        p->fillarray();<br>
#pragma omp target parallel for map(to: p[0:1])<br>
        for (int i=0;i<10;i++) {<br>
                //Derived d1(*static_cast<Derived*>(absBase));<br>
                Derived d1(*p);<br>
                printf("arr[0] is %d\n", d1.f());<br>
        }<br>
}<br>
<br>
Above gives me what I wanted to see, but I would like to avoid doing a cast on a pointer<br>
to an abstract base class, but the instantiation is done by the derived class.<br>
<br>
<br>
On Fri, Jan 17, 2020 at 6:07 PM Alexey Bataev <<a href="mailto:a.bataev@hotmail.com" target="_blank">a.bataev@hotmail.com</a><mailto:<a href="mailto:a.bataev@hotmail.com" target="_blank">a.bataev@hotmail.com</a>>> wrote:<br>
AbsBase is a pointer to a base class? Then not, compiler is not aware that it is a pointer to the derived class and copies the array as an array of base class, nit derived one.<br>
<br>
Best regards,<br>
Alexey Bataev<br>
<br>
16 янв. 2020 г., в 22:58, Itaru Kitayama <<a href="mailto:itaru.kitayama@gmail.com" target="_blank">itaru.kitayama@gmail.com</a><mailto:<a href="mailto:itaru.kitayama@gmail.com" target="_blank">itaru.kitayama@gmail.com</a>>> написал(а):<br>
<br>
<br>
If I change class Derived's private data to an array of 100 integers, it executes, but<br>
the first element of the array is reported as 0, instead of 1234. Shouldn't bitwise copy<br>
work when mapping the pointer to AbsBase class like an array of one?<br>
<br>
On Wed, Jan 15, 2020 at 2:32 PM Alexey Bataev <<a href="mailto:a.bataev@hotmail.com" target="_blank">a.bataev@hotmail.com</a><mailto:<a href="mailto:a.bataev@hotmail.com" target="_blank">a.bataev@hotmail.com</a>>> wrote:<br>
And it should fail since you're mapping non trivially copyable type.<br>
<br>
Best regards,<br>
Alexey Bataev<br>
<br>
14 янв. 2020 г., в 19:14, Itaru Kitayama <<a href="mailto:itaru.kitayama@gmail.com" target="_blank">itaru.kitayama@gmail.com</a><mailto:<a href="mailto:itaru.kitayama@gmail.com" target="_blank">itaru.kitayama@gmail.com</a>>> написал(а):<br>
<br>
<br>
This piece of C++ program execution fails at run time.<br>
<br>
#include <stdio.h><br>
<br>
class AbsBase {<br>
public:<br>
        virtual int f() = 0;<br>
};<br>
<br>
class Derived : public AbsBase {<br>
private:<br>
        int *arr = new int[100];<br>
public:<br>
        int f() { return arr[0]; }<br>
        void fillarray() {<br>
                arr[0] = 1234;<br>
        }<br>
};<br>
<br>
int main() {<br>
        AbsBase *absBase = new Derived();<br>
        static_cast<Derived*>(absBase)->fillarray();<br>
#pragma omp target parallel for map(to: absBase[0:1])<br>
        for (int i=0;i<10;i++) {<br>
                Derived d1(*static_cast<Derived*>(absBase));<br>
                printf("arr[0] is %d\n", d1.f());<br>
        }<br>
}<br>
<br>
On Sun, Jan 12, 2020 at 1:45 PM Doerfert, Johannes <<a href="mailto:jdoerfert@anl.gov" target="_blank">jdoerfert@anl.gov</a><mailto:<a href="mailto:jdoerfert@anl.gov" target="_blank">jdoerfert@anl.gov</a>>> wrote:<br>
On 01/12, Itaru Kitayama wrote:<br>
> Do you guys have a timeframe for that feature<br>
> Implemented?<br>
<br>
I do not and I don't know anyone who will drive this right now.<br>
<br>
As mentioned before, you should be able to "move/copy-create" the<br>
elements on the device in order to use virtual functions.<br>
<br>
<br>
> On Sun, Jan 12, 2020 at 12:51 Doerfert, Johannes <<a href="mailto:jdoerfert@anl.gov" target="_blank">jdoerfert@anl.gov</a><mailto:<a href="mailto:jdoerfert@anl.gov" target="_blank">jdoerfert@anl.gov</a>>> wrote:<br>
><br>
> > On 01/11, Alexey Bataev via Openmp-dev wrote:<br>
> > > Virtual functions are not supported.<br>
> ><br>
> > Not yet ;).<br>
> ><br>
> > We'll get it with 5.1 so we might actually implement it soon. Till then,<br>
> > you have to create the object on the device you call the virtual<br>
> > function.<br>
> ><br>
<br>
--<br>
<br>
Johannes Doerfert<br>
Researcher<br>
<br>
Argonne National Laboratory<br>
Lemont, IL 60439, USA<br>
<br>
<a href="mailto:jdoerfert@anl.gov" target="_blank">jdoerfert@anl.gov</a><mailto:<a href="mailto:jdoerfert@anl.gov" target="_blank">jdoerfert@anl.gov</a>><br>
</blockquote></div>