Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8882013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:28:17+00:00 2026-06-14T20:28:17+00:00

Device GeForce GTX 680 In my program,value is copied from host to device variable

  • 0

Device GeForce GTX 680
In my program,value is copied from host to device variable using CUDA Memcpy. I could see that previous values are retained in global memory on different executions of program.(Running the executable multiple times)
Code test.cu:

First run:

const test[]="overflowhappen";
cudaMalloc((void **) &test_d, sizeof(char)*strlen(test));

cudaMemcpy(test_d,test,sizeof(char)*strlen(test),cudaMemcpyHostToDevice);
function<<<1,1>>>(testfn);


nvcc test.cu
cuda-gdb a.out

<gdb> b testfn
<gdb>p test_d  ->>overflowhappen

Second run(I changed test string to var)

const test[]="var"
cudaMalloc((void **) &test_d, sizeof(char)*strlen(test));
cudaMemcpy(test_d,test,sizeof(char)*strlen(test),cudaMemcpyHostToDevice);
function<<<1,1>>>(testfn);

nvcc test.cu
cuda-gdb a.out

<gdb> b testfn
<gdb>p test_d  ->> varrflowhappen

“rflowhappen” is copied from previous run.I tried cudaMemset to the variable but, still it shows values from previous runs as the variable value. Is it a problem with code? .How can I prevent it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:28:18+00:00Added an answer on June 14, 2026 at 8:28 pm

    I think the bug may be trivial: you didn’t copy the end-string character 0.
    When copying C strings, you should always take strlen+1.
    As a result, in your second run, you allocate memory and copy {'v','a','r'}, instead of {'v','a','r','\0'}.

    When you then try to print it, you get var##### where #### is whatever garbage was there in memory. My guess is that in the first run, that garbage was 0 so the string ended seemingly correct, while in the second run it was the garbage left by the first program.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Device GeForce GTX 680 In the program, i have very long array to be
I'm using a GeForce GTX 580 (compute capability 2.0). In my program i'm suspecting
I am using Compute Prof 3.2 and a Geforce GTX 280. I have compute
I want to collect device attributes and send them to the mdm server using
I'm designing a device which will be connected to a computer using ethernet. It
Querying device information with clGetDeviceInfo() using CL_DEVICE_GLOBAL_MEM_SIZE returns 1GB even though RAM is 2GB.
When I am running the devicequey from CUDA SDK I'm getting segmentation fault error:
My device used to have no problem returning the correct date from NSDate, but
I've written a small CUDA program on my macbook pro and now tried it
On Virtual device all works fine. Where could be trouble? Device - Nexus. Maybe

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.