I’m working on porting an app to GPU, which has consisted of simply prepending __host__ __device__
for many functions which are not performance-critical. I have been lately stuck by what is either blindness on my behalf or a compiler bug.
To be brief, if I have a constructor for a class called “Cell” defined as follows:
class Cell {
public:
explicit Cell(pugi::xml_node cell_node);
__host__ Cell() {}
__host__ virtual ~Cell() {}
__host__ __device__ temperature(unsigned indx);
private:
double temperature_;
string name_;
};
Where string
is a class that can only be constructed on the host, but I copy to device after construction.
Amazingly, when I try to compile this part of my code, I see the following error:
error: calling a __host__ function("string::string") from a __device__ function("Cell::Cell") is not allowed
But I don’t want NVCC to compile __device__
code for the Cell constructor! Why is this happening? I have clearly marked my default constructor as host only. I am unable to produce this in a complete MWE at the moment.