An Nguyễn
An Nguyễn

Reputation: 25

CUDA: Can allocate matrix once use in multi kernel?

I have a question that is: If i allocate 1 matrix 2D and i memcpy it into GPU and i have 2 kernel using the same that matrix, is it possible using which i don't memcpy that matrix again for kernel 2? And if it auto memcpy that matrix again for kernel 2, Does it take the time to auto memcpy it again ?

Upvotes: 0

Views: 48

Answers (1)

Robert Crovella
Robert Crovella

Reputation: 152003

You don't need to transfer data from host to device twice, if you want to use it in 2 kernels. Once you transfer it, it is in GPU memory and will stay there until your program terminates (or you explicitly deallocate it using e.g. cudaFree).

Just pass the pointer to the region/matrix to both kernels. If the first kernel modifies the data and the second kernel runs later (after the first kernel finishes), the second kernel will see the modified data.

Upvotes: 2

Related Questions