Runtime error: cudaMemcpy2D (...) FAILED: 1(invalid argument)

Hi, I have two simple programs. The former builds and runs without any issue. The latter that is similar raises the following error at runtime.

0: cudaMemcpy2D (dst=0x7f0dafe02000, dpitch=4, src=0x7f0dafdff000, spitch=4, width=4, height=1024) FAILED: 1(invalid argument)

Without errors:

program tests
implicit none

integer, dimension(32,32) :: B
integer, device :: B_d(32,32), B_d2(32,32)

B=1
B_d=B

B_d2(1:3,:)=B_d(2:4,:)

end program

With runtime error:

program tests
implicit none

integer, dimension(32,32,2) :: B
integer, device :: B_d(32,32,2), B_d2(32,32)

B=1
B_d=B

B_d2(:,:)=B_d(:,:,0)

end program

If it wasn’t a compiler issue, could you please help me understand why the second program doesn’t work? I think both are valid. I did the test with nvidia-hpc-sdk 24.3 and CUDA 12.2

Hi - so if I compile your runtime error code as written, I indeed get your error. However - something stands out to me as an issue there. In Fortran, the index starts at 1, not 0 - however, it appears that you’re treating it as 0 in your example. I’m pretty sure that’s your issue.

For example, if I make this change:

!B_d2(:,:)=B_d(:,:,0)
B_d2(:,:)=B_d(:,:,1)

Then the code appears to run correctly. Alternatively, if you need the 3d index to start at 0 for whatever reason, then in the declaration of B_d, I can instead declare it this way:

B_d(32,32,0:1) ![i.e. start at 0, and have 2 elements in the 3rd dimension]

Then the code also appears to run correctly.

Please let me know if this helps resolve your issue!

My mistake!, you’re absolutely right @scamp1, thank you very much.

Perfect! Glad to have been of help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.