Invalid argument cudaMemcpy

My program starts 2 threads - Thread A (for input) and B (for processing). I also have a pair of pointers to 2 buffers, so when Thread A has finished copying data to Buffer 1, Thread B starts processing Buffer 1, and Thread A starts copying data to Buffer 2. Then, when Buffer 2 is full, copies of Thread A data to buffer 1 and stream B process buffer 2, etc.

My problem arises when I try to execute cudaMemcpy Buffer [] in d_Buffer (which was previously cudaMalloc'd on the main thread, i.e. before creating the stream. Buffer [] was also malloc'd on the main thread). I get the error "wrong argument", but I have no idea what is an invalid argument.

I have reduced my program to a single-threaded program, but still use 2 buffers. That is, copying and processing occur one after another, and not simultaneously. The cudaMemcpy line is exactly the same as the dual-line one. A single-threaded program works great.

I am not sure where the error is.

Thanks.

Regards, Rayne

+6
source share
1 answer

If you do this with CUDA 3.2 or earlier, the reason is that the GPU contexts are tied to a specific thread. If a multi-threaded program allocates memory on the same GPU from different host threads, allocations end with setting different contexts, and pointers from one context are not transferred to another context. Each context has its own โ€œvirtualizedโ€ memory space for work.

The solution is to either use the context migration API to transfer one context from the stream to the stream, how it works, or try the new CUDA 4.0rc2 publication, which should support what you are trying to do without using contextual migration. The downside is that 4.0rc2 is a test release and it requires a specific beta driver. This driver will not work with all hardware (e.g. laptops).

+5
source

Source: https://habr.com/ru/post/885628/


All Articles