Hi, i have some problem with passing **char to cuda kernel.
i want to print string and always empty string.
int main () {
cudaError_t err = cudaSuccess;
string line,y, line2, x;
int i = 0, n,j;
int *len;
int *score;
int *dscore;
int *dlen;
vector<string> sequence_id;
vector<string>::iterator it;
ifstream myfile ("prot_list.csv");
if (myfile.is_open())
{
while ( getline (myfile,line) )
{
sequence_id.push_back(line);
//cout << line << "\n";
}
myfile.close();
}
//else cout << "Unable to open file";
cin >> n;
//cout << n << "\n";
if(n == 0)
n = sequence_id.size();
int size = sequence_id.size();
cout << size << "\n";
const char **sequence = new const char*;
const char **dsequence = new const char*;
//sequence = (const char**)malloc(size * sizeof(const char));
score = (int*)malloc(((n) *(n)) * sizeof(int));
len = (int*)malloc(size * sizeof(int));
//score = 10;
cudaMalloc((void**)&dsequence, size * sizeof(const char*));
cudaMalloc((void**)&dscore, ((n) *(n)) * sizeof(int));
cudaMalloc((void**)&dlen,size * sizeof(int));
for(it = sequence_id.begin(); it < sequence_id.end(); it++){
ifstream myfile2 ("Fasta/" + *it + ".fasta");
if (myfile2.is_open())
{
const char *tem;
x = "";
while ( getline (myfile2,line2) )
{
if(line2[0] != '>')
x += line2;
}
tem = x.c_str();
sequence[i] = tem;
len[i] = x.length();
//cout << *it << " : " << sequence[i] << "\n";
myfile2.close();
}
//else cout << *it << " Unable to open file \n";
i++;
}
err = cudaMemcpy(dsequence, sequence, size * sizeof(const char*), cudaMemcpyHostToDevice);
if (err != cudaSuccess)
{
fprintf(stderr, "Failed to copy vector B from host to device (error code %s)!\n", cudaGetErrorString(err));
exit(EXIT_FAILURE);
}
err = cudaMemcpy(dscore, score, ((n) * (n)) * sizeof(int), cudaMemcpyHostToDevice);
if (err != cudaSuccess)
{
fprintf(stderr, "Failed to copy vector B from host to device (error code %s)!\n", cudaGetErrorString(err));
exit(EXIT_FAILURE);
}
err = cudaMemcpy(dlen, len,size * sizeof(int), cudaMemcpyHostToDevice);
if (err != cudaSuccess)
{
fprintf(stderr, "Failed to copy vector B from host to device (error code %s)!\n", cudaGetErrorString(err));
exit(EXIT_FAILURE);
}
int threadsPerBlock = n;
int blocksPerGrid = 1;
for(j= 0; j < threadsPerBlock; j++){
FillMatrix <<<blocksPerGrid, threadsPerBlock>>>(dsequence,dlen,n,j,dscore);
}
err = cudaMemcpy(score, dscore, ((n) *(n)) * sizeof(int), cudaMemcpyDeviceToHost);
if (err != cudaSuccess)
{
fprintf(stderr, "Failed to copy score from device to host (error code %s)!\n", cudaGetErrorString(err));
exit(EXIT_FAILURE);
}
for(int i = 0; i< n ; i++){
for(int j = 0; j < n; j++){
cout << sequence_id.at(i) << "," << sequence_id.at(j) << "," << score[(i*(n)) + j] << "\n";
}
}
cudaFree(dsequence); cudaFree(dscore); cudaFree(dlen);
return 0;
}
this for kernel code
__global__ void FillMatrix(const char **sequence,int *s_length, int n, int a, int *score)
{
int b = threadIdx.x + blockIdx.x*blockDim.x;
const int rows = s_length[a],cols = s_length[b];
score[(a*(n)) + b] = rows;
printf("string %d = %s %d\n",s_length[b], sequence[a],b);
}