Quantcast
Channel: Intel® Many Integrated Core Architecture
Viewing all articles
Browse latest Browse all 1347

Offloading virtual functions?

$
0
0

Hi,

Can we offload virtual functions. I am trying to do that using the following code and I am getting seg fault.

#include
using namespace std;

class Polygon {
public:

#pragma offload_attribute(push, target(mic))
virtual int area (int width, int height)
{ return 0; }
#pragma offload_attribute(pop)
int area_wrapper (int width, int height)
{
int c;
#pragma offload target(mic:0) \
in(width, height) \
out(c)
{
c = this->area(width, height);
}
return c;
}
};

class Rectangle: public Polygon {
public:
#pragma offload_attribute(push, target(mic))
int area (int width, int height)
{ return width * height; }
#pragma offload_attribute(pop)
};

class Triangle: public Polygon {
public:
#pragma offload_attribute(push, target(mic))
int area (int width, int height)
{ return (width * height / 2); }
#pragma offload_attribute(pop)
};

int main () {
Rectangle * ppoly1 = new Rectangle();
Triangle * ppoly2 = new Triangle();
Polygon * ppoly3 = new Polygon();
cout << ppoly1->area_wrapper(4, 5) << '\n';
cout << ppoly2->area_wrapper(4, 5) << '\n';
cout << ppoly3->area_wrapper(4, 5) << '\n';
return 0;
}

When I compile and run it, it results in:
$ icpc polygon.cpp
$./a.out
offload error: process on the device 0 was terminated by signal 11 (SIGSEGV)

Thanks in advance,
Sanchit


Viewing all articles
Browse latest Browse all 1347

Trending Articles