- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, Can we offload virtual functions. I am trying to do that using the following code and I am getting seg fault. #include
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I believe this may require using _Cilk_shared/_Cilk_offload. Let me inquire with others more knowledgeable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Our C++ Developer confirmed offloading virtual functions requires using _Cilk_shared/_Cilk_for and provided the modified version of your program shown below. The output of the modified program is:
$ icpc t_new.cpp
$ ./a.out
20
10
0
t_new.cpp
==========
#include <iostream>
#include <offload.h>
using namespace std;
#pragma offload_attribute(push, _Cilk_shared)
class Polygon {
public:
virtual int area (int width, int height)
{
return 0;
}
int area_wrapper (int width, int height)
{
int c;
{
c = _Cilk_offload this->area(width, height);
}
return c;
}
};
#pragma offload_attribute(pop)
#pragma offload_attribute(push, _Cilk_shared)
class Rectangle: public Polygon
{
public:
int area (int width, int height)
{
return width * height;
}
};
#pragma offload_attribute(pop)
#pragma offload_attribute(push, _Cilk_shared)
class Triangle: public Polygon
{
public:
int area (int width, int height)
{
return (width * height / 2);
}
};
#pragma offload_attribute(pop)
int main ()
{
Rectangle * ppoly1 = new (_Offload_shared_malloc(sizeof(Rectangle))) Rectangle();
Triangle * ppoly2 = new (_Offload_shared_malloc(sizeof(Triangle))) Triangle();
Polygon * ppoly3 = new (_Offload_shared_malloc(sizeof(Polygon))) Polygon();
cout << ppoly1->area_wrapper(4, 5) << '\n';
cout << ppoly2->area_wrapper(4, 5) << '\n';
cout << ppoly3->area_wrapper(4, 5) << '\n';
return 0;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Kevin!
Will it hurt the performance to have a class instance in virtual shared memory between CPU and MIC using _Offload_shared_malloc(); especially if that class instance is accessed in critical section?
--Sanchit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Sanchit - Sorry, we are not clear about your question.
Does "critical section" mean a section of code critical to the code's performance? Or a code section guarded in some fashion for critical or exclusive access?
Or are you asking whether shared memory access is dramatically slower than non-shared memory and will having class objects in shared memory whose access is critical to the code's performance hurt overall performance?
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page