# How to pass cv::cuda::GpuMat to a kernel as cv::cuda::PtrStepSz?

**URL:** <https://forum.opencv.org/t/how-to-pass-cv-gpumat-to-a-kernel-as-cv-ptrstepsz/17588>\
**Category:** C++\
**Tags:** cuda\
**Created:** [May 9, 2024, 12:57pm UTC](https://forum.opencv.org/t/how-to-pass-cv-gpumat-to-a-kernel-as-cv-ptrstepsz/17588 "2024-05-09T12:57:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abinas\_Chopdar](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/abinas_chopdar/32/10019_2.png) [@Abinas\_Chopdar](https://forum.opencv.org/u/Abinas_Chopdar)\
**Post date:** [May 9, 2024, 12:57pm UTC](https://forum.opencv.org/t/how-to-pass-cv-gpumat-to-a-kernel-as-cv-ptrstepsz/17588/1 "2024-05-09T12:57:38Z")

</div>

I need to pass cv::cuda::GpuMat as argument to a CUDA kernel function. I came across, that a cv::cuda::GpuMat can be passed to kernel as cv::cuda::PtrStepSz. I am not able to find documentation or any implementation example for the same. What is the proper syntax to pass cv::cuda::GpuMat? How to access the cv::cuda::PtrStepSz inside kernel?  
If available kindly share resources to better understand utilisation of cv::cuda::PtrStepSz.

---

<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:** [May 10, 2024, 5:30am UTC](https://forum.opencv.org/t/how-to-pass-cv-gpumat-to-a-kernel-as-cv-ptrstepsz/17588/2 "2024-05-10T05:30:26Z")

</div>

Nearly all of the internal CUDA code is passed a `GpuMat` which is [implicitly](https://en.cppreference.com/w/cpp/language/cast_operator) converted to a `PtrStep` or `PtrStepSz` because of

```auto
template <typename _Tp> operator PtrStepSz<_Tp>() const;

```

> <https://github.com/opencv/opencv/blob/1d9a4120fa7dbeab6316c255d283c16cd006a35e/modules/core/include/opencv2/core/cuda.hpp#L277>

See resize for an example. The kernel is passed a `PtrStepSz` for `dst`

```auto
template <class Ptr2D, typename T> __global__ void resize(Ptr2D src, PtrStepSz<T> dst, const float fy, const float fx)

```

> <https://github.com/opencv/opencv_contrib/blob/3c2bcbfe8374edaf3eb756b560374244538d57b6/modules/cudawarping/src/cuda/resize.cu#L109>

but is orginally called with a `GpuMat`

> <https://github.com/opencv/opencv_contrib/blob/3c2bcbfe8374edaf3eb756b560374244538d57b6/modules/cudawarping/src/resize.cpp#L87>
