# Is it possible to access CuPy array directly within cuda\_GpuMat

**URL:** <https://forum.opencv.org/t/is-it-possible-to-access-cupy-array-directly-within-cuda-gpumat/12404>\
**Category:** Python\
**Tags:** cuda, cupy\
**Created:** [March 17, 2023, 6:22am UTC](https://forum.opencv.org/t/is-it-possible-to-access-cupy-array-directly-within-cuda-gpumat/12404 "2023-03-17T06:22:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![amanda-peng](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@amanda-peng](https://forum.opencv.org/u/amanda-peng)\
**Post date:** [March 17, 2023, 6:22am UTC](https://forum.opencv.org/t/is-it-possible-to-access-cupy-array-directly-within-cuda-gpumat/12404/1 "2023-03-17T06:22:07Z")

</div>

Is it possible to access CuPy array/memory directly within cuda\_GpuMat to support CudaArrayInterface?

Implemented a wrapper of CudaArrayInterface works fine to move GpuMat memory directly to CuPy. However, it failed with moving from CuPy array to GpuMat.

Reference below link  
[rapidsai/cucim#329 (comment)](https://github.com/rapidsai/cucim/issues/329#issuecomment-1397507158)

if initiated cuda\_GpuMat with CuPy array pointer, the result is not as expected, it seems cv2.cuda\_GpuMat calls some default allocator and does not use the passed pointer memory.

img\_cv2\_cu = cv2.cuda\_GpuMat(img\_cp. **cuda\_array\_interface** [‘shape’],  
cv2.CV\_8U, # or cv2.CV\_8UC1  
img\_cp.cuda\_array\_interface[‘data’][0])

Is there anyone can help to check this ? any guidance on how to do this?

---

<div class="post-metadata">

**Author:** ![cudawarped](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@cudawarped](https://forum.opencv.org/u/cudawarped)\
**Post date:** [March 17, 2023, 3:14pm UTC](https://forum.opencv.org/t/is-it-possible-to-access-cupy-array-directly-within-cuda-gpumat/12404/2 "2023-03-17T15:14:12Z")

</div>

See my reply to the thread you linked to.
