Look, this is a forum for discussing CUDA issues. What you’re struggling with at the moment and throughout this thread are not CUDA issues at all, those are generic software engineering issues. Specifically, in the above code you’re copying a 1d array into memory that hasn’t been previously allocated (e.g. being uninitialized c_d[0] points to a random location in device memory prior to invocation of cudaMemcpy(c_d[i],…))
I suggest you temporarily forget about CUDA and write a piece of code, that allocates a 2d array in memory, then initializes all the values of the array with incremental integers starting from your credit card number, then copies it to another 2d array, then re-initializes all the values of the second 2d array with the incremental integers starting from the expiration date on the card (as an integer) and then copies the second array back into the first array. Then make sure (using, e.g. valgrind) that you don’t leak memory and don’t step on unallocated memory. And yes, you should initialize the arrays with some weird different numbers, NOT zeros/ones/minus-ones, so that you can clearly see from your printouts that these weird numbers are being copied. I would write the above code as a function, invoke it from main(…) and thus have what we call “a unit test”.
Once you’ve done that host-only code (which means DEBUGGED it and confirmed that your printouts display expected values), then it won’t be too hard to modify the code to allocate the second array on the device and copy host-to-device, device-to-host instead of memcpy, as well as replace the initialization of the second array with a kernel, which you probably had right in your first version.
Look, this is a forum for discussing CUDA issues. What you’re struggling with at the moment and throughout this thread are not CUDA issues at all, those are generic software engineering issues. Specifically, in the above code you’re copying a 1d array into memory that hasn’t been previously allocated (e.g. being uninitialized c_d[0] points to a random location in device memory prior to invocation of cudaMemcpy(c_d[i],…))
I suggest you temporarily forget about CUDA and write a piece of code, that allocates a 2d array in memory, then initializes all the values of the array with incremental integers starting from your credit card number, then copies it to another 2d array, then re-initializes all the values of the second 2d array with the incremental integers starting from the expiration date on the card (as an integer) and then copies the second array back into the first array. Then make sure (using, e.g. valgrind) that you don’t leak memory and don’t step on unallocated memory. And yes, you should initialize the arrays with some weird different numbers, NOT zeros/ones/minus-ones, so that you can clearly see from your printouts that these weird numbers are being copied. I would write the above code as a function, invoke it from main(…) and thus have what we call “a unit test”.
Once you’ve done that host-only code (which means DEBUGGED it and confirmed that your printouts display expected values), then it won’t be too hard to modify the code to allocate the second array on the device and copy host-to-device, device-to-host instead of memcpy, as well as replace the initialization of the second array with a kernel, which you probably had right in your first version.