Function pointers on MIC

Function pointers on MIC

I've recently been involved in porting an application to Nvidia's CUDA platform, and now we are looking to also support the Intel Phi platform. It looks like a lot of things are relatively easy to do if you have the parallelism set up with OpenMP on the host, but I had some specific questions about how function pointers are set up to figure out what is the same/different between the CUDA setup and the Intel setup.

I saw in the documentation that one version of the memory model for copying between host RAM and card RAM was the idea of shared memory using Cilk, where you do a "shared malloc" and apparently the compiler does some magic to make the virtual addresses the same on both host and device, thus you can assemble complex classes that actually have the same pointers (such as a linked list). I was wondering if this virtual address space trick was also extended to function locations? Aka if I set a pointer to a function on the host, is the pointer valid on the device (assuming the function is marked as target(mic))? Also along a similar line, if I have classes such as the following:

class A { virtual void foo() = 0; };

class B : public class A { virtual void foo() {} };

can I bitwise-copy an instance of class B to the device and expect to be able to call foo() on that object? Or is the v-table going to be invalid on the device because it is not in the same place as it is on the host?

Essentially, putting these two points together, the overall question would be: Can you use the Cilk shared malloc strategy on classes containing a v-table? Or would the fact that the class is effectively instantiated on the host and implicitly bitwise-copied to the device cause the v-table pointers to be broken on the device?

Thanks for your help answering these questions.

3 帖子 / 0 全新
最新文章
如需更全面地了解编译器优化,请参阅优化注意事项

I believe you can use the _Cilk_shared strategy on the classes A/B shown. I will double check w/Developers as this is not an area of expertise for me.

Also, there are three MIC samples shrd_ofld_vt01.cpp, shrd_ofld_vt02.cpp, and shrd_ofld_vt03.cpp (under: /opt/intel/composer_xe_2013/Samples/en_US/C++/mic_samples ) that demonstrate virtual functions with single/multiple inheritance that I believe tie to your interests.

Yes, you can use the _Cilk_shared feature for classes that use vtables.

In this model you will not be explicitly copying objects between CPU and MIC, the synchronization will be done automatically for you around offloads. So you don't need to be concerned with the vtable pointer. As an implementation detail, the vtable pointer in each object on CPU and MIC have the same value, but the CPU and MIC vtable contents are different. That way, virtual calls are resolved correctly on CPU and MIC even with different member function addresses.

登陆并发表评论。