Skip to content

dlpack Python support for cuda_GpuMat and cuda_GpuMatND #27581

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

Open
wants to merge 10 commits into
base: 4.x
Choose a base branch
from

Conversation

dkurt
Copy link
Member

@dkurt dkurt commented Jul 26, 2025

Pull Request Readiness Checklist

resolves #16295

force_builders=Custom
buildworker:Custom=linux-4
build_image:Custom=ubuntu-cuda11:18.04
Xbuild_image:Custom=ubuntu-cuda11:18.04
docker run --gpus 0 -v ~/opencv:/opencv -v ~/opencv_contrib:/opencv_contrib -it nvidia/cuda:12.8.1-cudnn-devel-ubuntu22.04
apt-get update && apt-get install -y cmake python3-dev python3-pip python3-venv &&
python3 -m venv .venv &&
source .venv/bin/activate &&
pip install -U pip &&
pip install -U numpy &&
pip install torch --index-url https://download.pytorch.org/whl/cu128 &&
cmake \
    -DWITH_OPENCL=OFF \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_DOCS=OFF \
    -DWITH_CUDA=ON \
    -DOPENCV_DNN_CUDA=ON \
    -DOPENCV_EXTRA_MODULES_PATH=/opencv_contrib/modules \
    -DBUILD_LIST=ts,cudev,python3 \
    -S /opencv -B /opencv_build &&
cmake --build /opencv_build -j16
export PYTHONPATH=/opencv_build/lib/python3/:$PYTHONPATH

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

@asmorkalov asmorkalov self-requested a review July 28, 2025 05:50
@asmorkalov asmorkalov added this to the 4.13.0 milestone Jul 28, 2025
@asmorkalov asmorkalov added the category: gpu/cuda (contrib) OpenCV 4.0+: moved to opencv_contrib label Jul 28, 2025
@asmorkalov asmorkalov self-assigned this Jul 28, 2025
@asmorkalov
Copy link
Contributor

DLpack available as deb package on Ubuntu. It'll be great to support external instances via find_package too just i case of compatibility issues.

@asmorkalov
Copy link
Contributor

cc @cudawarped

@asmorkalov
Copy link
Contributor

Windows build warnings:

C:/GHA-OCV-2/_work/opencv/opencv/opencv/modules/core/misc/python/pyopencv_cuda.hpp(44): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data

C:/GHA-OCV-2/_work/opencv/opencv/opencv/modules/core/misc/python/pyopencv_cuda.hpp(60): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data

C:/GHA-OCV-2/_work/opencv/opencv/opencv/modules/core/misc/python/pyopencv_cuda.hpp(92): warning C4244: 'argument': conversion from 'int64_t' to 'int', possible loss of data

C:/GHA-OCV-2/_work/opencv/opencv/opencv/modules/core/misc/python/pyopencv_cuda.hpp(98): warning C4244: 'argument': conversion from 'int64_t' to 'int', possible loss of data

C:/GHA-OCV-2/_work/opencv/opencv/opencv/modules/core/misc/python/pyopencv_cuda.hpp(97): warning C4244: 'argument': conversion from 'int64_t' to 'int', possible loss of data

C:/GHA-OCV-2/_work/opencv/opencv/opencv/modules/core/misc/python/pyopencv_cuda.hpp(119): warning C4244: 'argument': conversion from 'int64_t' to 'int', possible loss of data

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xmemory(681): warning C4244: 'initializing': conversion from 'value_t' to '_Objty', possible loss of data

@dkurt dkurt force-pushed the d.kuryaev/dlpack branch from cb28a92 to 52af6a5 Compare August 5, 2025 09:52
@dkurt dkurt changed the title dlpack Python support for cuda_GpuMat dlpack Python support for cuda_GpuMat and cuda_GpuMatND Aug 7, 2025
@dkurt dkurt marked this pull request as ready for review August 7, 2025 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Any intention to add interoperability with DLPACK or mpi4py?
2 participants