1

I have been happily ignoring this for a while, but it has become quite a problem now - I hope you guys can help me out.

I am calling cudaMallocPitch, but whatever I try, It keeps giving me the red underlining and the 'invalid arguments' error. Even when I copy the source code from the Nvidia CUDA C Programming guide it still gives me the error. I am quite new to CUDA, so please do not hesitate to point out anything you might think would be obvious that could be causing the problem.

Here is the exact code I am referring to:

int width = 64, height = 64;
    float* devPtr;
    size_t pitch;
    cudaMallocPitch(&devPtr, pitch,
                    width * sizeof(float), height);

Any comment is greatly appreciated, cheers.

Boyentenbi
  • 417
  • 4
  • 14

1 Answers1

1

The second parameter is supposed to be a size_t*, but you're passing a size_t. Try this instead:

cudaMallocPitch(&devPtr, &pitch, width * sizeof(float), height);

Note also that the last parameter type is also size_t. Perhaps height would be better as a size_t.

Joseph Mansfield
  • 108,238
  • 20
  • 242
  • 324
  • Since [cudaMallocPitch](http://docs.nvidia.com/cuda/cuda-runtime-api/index.html#group__CUDART__MEMORY_1g80d689bc903792f906e49be4a0b6d8db) expects to report the pitch back to the calling process, we must pass it the address of the pitch variable (i.e. pass as a pointer, by reference) so it can modify `pitch` in the calling process. `height` as an `int` rather than `size_t` should not matter. – Robert Crovella Apr 07 '13 at 23:33
  • Still no luck! I tried your code, as well as using height as a size_t, but it's still got the red underline and the same error – Boyentenbi Apr 07 '13 at 23:37
  • 1
    The red underline may be a side effect of using CUDA in VS. You might want to search "CUDA red underline" to see more information about this. If the code compiles and runs correctly (use [error checking!!!](http://stackoverflow.com/questions/14038589/what-is-the-canonical-way-to-check-for-errors-using-the-cuda-runtime-api)) the red underline is, well, a red-herring. Otherwise, post the error returned by they *compiler* and/or the *runtime error* rather than using what is returned by intellisense/visual studio. – Robert Crovella Apr 07 '13 at 23:42