Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for cudaMemcpy2DToArrayAsync #49

Closed
dennisai opened this issue Jul 28, 2017 · 1 comment
Closed

Support for cudaMemcpy2DToArrayAsync #49

dennisai opened this issue Jul 28, 2017 · 1 comment

Comments

@dennisai
Copy link

Hi,

I am using multiple streams w/ 2D textures in my application, and would like to asynchronously copy from a CudaPitchedDeviceVariable to a CudaTextureArray2D/CudaArray2D. Now, I see from the NVIDIA documentation here that there is a method called cudaMemcpy2DToArrayAsync, which might suit my purposes. However, when I looked through the API for CudaArray2D, I was only able to find synchronous copy methods (I checked the source). Is there any way to asynchronously copy to a CudaArray2D using a stream, using the current ManagedCuda API?

If not, is that a feature we can add? I'd be happy to help and make a pull request if someone would be able to help point me in the right direction!

Thanks,
Dennis

@dennisai
Copy link
Author

dennisai commented Jul 28, 2017

I tried writing the following code, and it seems to work!

private void CopyToArray2D(
    CudaPitchedDeviceVariable<float> src,
    CudaArray2D dst,
    CudaStream stream)
{
    CUDAMemCpy2D copyParams = new CUDAMemCpy2D();
    CUResult copyResult;

    copyParams.srcDevice = src.DevicePointer;
    copyParams.srcMemoryType = CUMemoryType.Device;
    copyParams.srcPitch = src.Pitch;
    copyParams.dstArray = dst.CUArray;
    copyParams.dstMemoryType = CUMemoryType.Array;
    copyParams.Height = src.Height;
    copyParams.WidthInBytes = src.WidthInBytes;

    if (stream != null)
    {
        copyResult = DriverAPINativeMethods.AsynchronousMemcpy_v2
            .cuMemcpy2DAsync_v2(ref copyParams, stream.Stream);
    }
    else
    {
        copyResult = DriverAPINativeMethods.SynchronousMemcpy_v2
            .cuMemcpy2D_v2(ref copyParams);
    }
        
    if (copyResult != CUResult.Success)
    {
        throw new CudaException(copyResult);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant