I have a C++ source code that uses String within the Class functions. I am having trouble with the Strings. I searched but could not find whether strings are allowed on GPU or not. For the illustration, I have created a small dummy program that re-generates the error. The program is given as follows.
#include <iostream>
class Dummy
{
public:
char* names;
int row;
int col;
std::string mat_name;
Dummy(int rows, int cols)
{
int i,j;
row = rows;
col = cols;
names = new char[row*col];
mat_name = "Sparse";
#pragma acc enter data copyin(this)
#pragma acc enter data create(names[0:row*col], mat_name)
for(i=0; i<row; i++)
{
for(j=0; j<col;j++)
names[i*row + j] = 'A'+i+j;
}
}
~Dummy()
{
#pragma acc exit data delete(names[0:row*col], mat_name)
#pragma acc exit data delete(this)
delete [] names;
names = nullptr;
}
#pragma acc routine seq
char get_mat_name()
{
int res = mat_name.compare("Sparse");
if(res == 1)
return 'd';
else
return 'K';
}
void Print()
{
int i,j;
for(i=0; i<row; i++)
{
for(j=0; j<col;j++)
{
std::cout << names[i*row + j];
}
std::cout << std::endl;
}
}
};
int main()
{
int row = 11;
int col = 11;
Dummy S1(row,col);
S1.Print();
#pragma acc update device(S1.names[0:row*col], S1.mat_name)
#pragma acc parallel loop
for(int i=0;i<row;i++)
for(int j=0;j<col;j++)
//Dummy operation to call a function that uses String
S1.names[i*row+j] = S1.get_mat_name();
std::cout << "Back from the device\n\n"<<std::endl;
#pragma acc update self(S1.names[0:row*col])
S1.Print();
std::cout<<"Exiting main()\n";
}
The error it generates is shown below.
67, Generating update device(S1.mat_name,S1.names[:row*col])
Generating NVIDIA GPU code
71, #pragma acc loop gang /* blockIdx.x */
72, #pragma acc loop seq
67, Generating implicit copy(S1) [if not already present]
71, Accelerator restriction: size of the GPU copy of S1.names is unknown
72, Loop is parallelizable
78, Generating update self(S1.names[:row*col])
Dummy::Dummy(int, int):
20, Generating enter data copyin(this[:1])
Generating enter data create(names[:col*row],mat_name)
Dummy::~Dummy():
32, Generating exit data delete(mat_name,this[:1],names[:col*row])
NVC++-S-1061-Procedures called in a compute region must have acc routine information - std::basic_string<char, std::char_traits<char>, std::allocator<char>>::compare(const char *) const (main.cpp: 39)
Dummy::get_mat_name():
39, Accelerator restriction: call to 'std::basic_string<char, std::char_traits<char>, std::allocator<char>>::compare(const char *) const' with no acc routine information
NVC++/x86-64 Linux 23.1-0: compilation completed with severe errors
I am compiling the program using
nvc++ -acc -gpu=cc86,deepcopy -cpp -Mlarge_arrays -Minfo -o=main main.cpp
Any help will be appreciated.