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 1005773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:21:03+00:00 2026-05-16T08:21:03+00:00

I am calling cudaMemcpy and the copy returns successfully however the source values are

  • 0

I am calling cudaMemcpy and the copy returns successfully however the source values are not being copied to the destination. I wrote a similar piece using memcpy() and that works fine. What am I missing here?

// host externs
extern unsigned char landmask[DIMX * DIMY];

// use device constant memory for landmask
unsigned char *tempmask;
__device__ unsigned char *landmask_d;

..

void checkCUDAError(const char* msg) {
cudaError_t err = cudaGetLastError();
  if (cudaSuccess != err) {
    fprintf(stderr, "Cuda error: %s: %s.\n", msg, cudaGetErrorString(err));
    exit(EXIT_FAILURE);
  }
}

..

// try a memcpy
size_t landMemSize_t landMemSize = DIMX * DIMY * sizeof(char);
tempmask = (unsigned char*)malloc(landMemSize);
memcpy(tempmask, landmask, DIMX * DIMY);
if (landmask[0] != *tempmask) printf("FAILURE!\n");

// allocate device memory for landmask
cudaMalloc((void **)&landmask_d, landMemSize);
printf("allocating %ld Kbytes for landmask\n", landMemSize/1024);
checkCUDAError("memory allocation");

// copy landmask from host to device
cudaMemcpy(landmask_d, landmask, landMemSize, cudaMemcpyHostToDevice);
checkCUDAError("memory copy");
if (landmask[0] != *landmask_d) printf("FAILURE!\n");

None of the CUDAErrors report any problem yet the second FAILURE is called..?

  • 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-05-16T08:21:03+00:00Added an answer on May 16, 2026 at 8:21 am
     if (landmask[0] != *landmask_d) printf("FAILURE!\n");
    

    you are comparing values in different memory domains.
    You should first copy memory from device to cpu and then compare

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

Sidebar

Related Questions

Calling concat on vectors returns a list. Being a total noob I would expect
Calling Thread.join blocks the current (main) thread. However not calling join results in all
Calling channel.position on an ENTER_FRAME event, I notice that it's not being updated every
I'd like to know if, when i'm calling cudaMemcpy(...) to get memory on the
Calling getActionBar returns null . This has been frequently reported so I've made sure
Calling setFocus(null) on the ItemizedOverlay does not 'unfocus' current marker. According to the documentation:
When calling CoInitializeEx , you can specify the following values for dwCoInit : typedef
Calling IEnumSTATURL::Next within my application returns E_UNEXPECTED(0x8000FFFF) instead of S_OK . Sadly, that particular
Calling the function MakeTree(4, gameboard) does not work properly, it only prints out the
Calling an asp.net mvc3 controller method which returns the results fine (list of an

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.