Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some questions about unified-memory,dataElem.cu file #42

Open
GeneralJing opened this issue Apr 12, 2022 · 1 comment
Open

some questions about unified-memory,dataElem.cu file #42

GeneralJing opened this issue Apr 12, 2022 · 1 comment
Labels

Comments

@GeneralJing
Copy link

In the unified-memory example, the dataElem.cu file, the codes below:

// Copy up each piece separately, including new “text” pointer value
①cudaMemcpy(d_elem, elem, sizeof(DataElement), cudaMemcpyHostToDevice);
②cudaMemcpy(d_name, elem->name, namelen, cudaMemcpyHostToDevice);
③cudaMemcpy(&(d_elem->name), &d_name, sizeof(char*), cudaMemcpyHostToDevice);

// Finally we can launch our kernel, but CPU & GPU use different copies of “elem”
④Kernel<<< 1, 1 >>>(d_elem);

⑤cudaMemcpy(&(elem->value), &(d_elem->value), sizeof(int), cudaMemcpyDeviceToHost);
⑥cudaMemcpy(elem->name, d_name, namelen, cudaMemcpyDeviceToHost);

step② and ③,why didn't copy data from elem->name to d_elem->name? if i firstly copy data from elem->name to d_name, when step ③, why is the parameter cudaMemcpyHostToDevice, not cudaMemcpyDeviceToDevice?
and after the kernel executed. step ⑥, why did you copy data from d_name to elem->name, not d_elem->name to elem->name?

@harrism
Copy link
Member

harrism commented Apr 26, 2022

@nsakharnykh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants