0

I'm new to CUDA and I was trying a sample program using cudaMemcpyToSymbol, but its giving me cudaErrorUnknown. Below is the sample program Im trying.

At the last line, its printing "The output of cudaMemcpyToSymbol() is: cudaErrorUnknown".

#include <iostream>
#include<cuda_runtime.h>
#include<string>

using namespace std;

int main()
{
void *ptr0,*ptr1;
string out;
char str[100]="Hi, I am Ellesemere. What is ur name?";
char output[100];
out=cudaGetErrorString(cudaSetDevice(0));
cout<<"The value of cudaSetDevice() is: "<<out<<endl;

out=cudaGetErrorString(cudaMalloc(&ptr0,100));
cout<<"The output of cudaMalloc() is: "<<out<<endl;

out=cudaGetErrorString(cudaMemcpyToSymbol(ptr0,str,100,0,cudaMemcpyHostToDevice));
cout<<"The output of cudaMemcpyToSymbol() is: "<<out<<endl;

}

I m expecting cudaSuccess as the output of cudaMemcpyToSymbol instead of cudaErrorUnknown. Can anyone please help me what might be going wrong.

Satyanvesh D
  • 323
  • 1
  • 4
  • 16
  • 1
    ptr0 is not a device symbol. You can't use cudaMemcpyToSymbol to copy to it. Use cudaMemcpy insteqd – talonmies Aug 26 '19 at 08:42
  • @talonmies Im confused here. Why is ptr0 not a device symbol. We have done a cudaMalloc on ptr0. If this is not correct, how can we use cudaMemcpyToSymbol properly in this scenario. – Satyanvesh D Aug 26 '19 at 08:49
  • 1
    Device symbols are statically declared variables explicitly marked as `__device__` or `__constant__` . You don't have that here. See the attached duplicate or read the programming guide – talonmies Aug 26 '19 at 08:57
  • @talonmies Thanks. Got clarity after going through the link which you had provided. – Satyanvesh D Aug 28 '19 at 06:04

0 Answers0