# Cuda Runtime API error for cuda Graph and OpenCV

**URL:** <https://forums.developer.nvidia.com/t/cuda-runtime-api-error-for-cuda-graph-and-opencv/215408>\
**Category:** Jetson Xavier NX\
**Tags:** opencv, nvbugs, cuda\
**Created:** [May 24, 2022, 9:18am UTC](https://forums.developer.nvidia.com/t/cuda-runtime-api-error-for-cuda-graph-and-opencv/215408 "2022-05-24T09:18:32Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![fd1](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@fd1](https://forums.developer.nvidia.com/u/fd1)\
**Post date:** [May 24, 2022, 9:18am UTC](https://forums.developer.nvidia.com/t/cuda-runtime-api-error-for-cuda-graph-and-opencv/215408/1 "2022-05-24T09:18:32Z")

</div>

Hello there,

I created a Cuda Graph, using the runtime api and recording the operations; for now it’s a just a simple loop of [resize operations from opencv](https://docs.opencv.org/4.5.5/db/d29/group__cudawarping.html#ga4f5fa0770d1c9efbadb9be1b92a6452a);

I then try to inspect the graph using a simple operation as calling:

```auto
auto getKernelParams(cudaGraphNode_t &n) -> cudaKernelNodeParams
{
    cudaKernelNodeParams par;
    cudaGraphKernelNodeGetParams(n, &par);
};

```

but the call to cudaGraphKernelNodeGetParams return error “cudaErrorInvalidDeviceFunction”;

What are the reasons of this kind of error?  
Cuda is installed using the sdk manager. Ubuntu 18, Jetpack 4.6 and Cuda 10.2;

---

<div class="post-metadata">

**Author:** ![AastaLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/aastalll/32/14043_2.png) [@AastaLLL](https://forums.developer.nvidia.com/u/AastaLLL)\
**Post date:** [May 25, 2022, 3:07am UTC](https://forums.developer.nvidia.com/t/cuda-runtime-api-error-for-cuda-graph-and-opencv/215408/3 "2022-05-25T03:07:57Z")

</div>

Hi,

You can find the detailed error information in our document below:

[_https://docs.nvidia.com/cuda/cuda-runtime-api/group\_\_CUDART\_\_TYPES.html_](https://docs.nvidia.com/cuda/cuda-runtime-api/group __CUDART__ TYPES.html)  
_cudaErrorInvalidDeviceFunction = 98_  
_The requested device function does not exist or is not compiled for the proper device architecture._

The error indicates your CUDA app has not complied with NX architecture.  
Please make sure you have added this to the `nvcc` configuration.

For example:

```auto
$ nvcc -gencode arch=compute_72,code=sm_72 test.cu

```

Thanks.

---

<div class="post-metadata">

**Author:** ![fd1](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@fd1](https://forums.developer.nvidia.com/u/fd1)\
**Post date:** [May 25, 2022, 8:46am UTC](https://forums.developer.nvidia.com/t/cuda-runtime-api-error-for-cuda-graph-and-opencv/215408/4 "2022-05-25T08:46:30Z")

</div>

Thanks @AastaLLL for the answer;

The problem is that I don’t compile anything with nvcc; moreover OpenCV is installed using your JEP script (correct architteture). The error is just coming from the call to the API.

I’m using CMakeLists to find Cuda and the linkage is correct, also according to the documentation, the [set-get function for kernel parameters](https://docs.nvidia.com/cuda/archive/10.2/cuda-runtime-api/group __CUDART__ GRAPH.html#group __CUDART__ GRAPH_1g931a1af826d30fdad0b556da917f6705) are the **only** 2 function that actually can return that specific error.

So I’m curious about other reason for the error apart from the wrong device architecture.

---

<div class="post-metadata">

**Author:** ![AastaLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/aastalll/32/14043_2.png) [@AastaLLL](https://forums.developer.nvidia.com/u/AastaLLL)\
**Post date:** [May 27, 2022, 3:31am UTC](https://forums.developer.nvidia.com/t/cuda-runtime-api-error-for-cuda-graph-and-opencv/215408/5 "2022-05-27T03:31:52Z")

</div>

Hi,

You can set GPU architecture in CMakeLists as well.  
Here is an example for your reference:

> <https://github.com/dusty-nv/jetson-inference/blob/master/CMakeLists.txt#L74>

Please noted that the GPU architecture of Xavier NX is `sm_72`.  
Thanks.

---

<div class="post-metadata">

**Author:** ![fd1](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@fd1](https://forums.developer.nvidia.com/u/fd1)\
**Post date:** [May 27, 2022, 12:52pm UTC](https://forums.developer.nvidia.com/t/cuda-runtime-api-error-for-cuda-graph-and-opencv/215408/6 "2022-05-27T12:52:07Z")

</div>

Hi @AastaLLL,  
I implemented your suggestion but it didn’t change anything; I made a small sample to reproduce the “error”, it might be helpful to understand better what is going on; I tried to stay close to the structure of the main project but there are some differences in the code since we are using cpp20 and GCC11.x;

The sample compiles with GCC7.5; and the build commands are in the bash script.  
[sample.zip](https://forums.developer.nvidia.com/uploads/short-url/xeWHR3Qt1LwTvnDRyavUMBdGzPc.zip) (6.3 KB)

Thanks.

---

<div class="post-metadata">

**Author:** ![AastaLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/aastalll/32/14043_2.png) [@AastaLLL](https://forums.developer.nvidia.com/u/AastaLLL)\
**Post date:** [May 30, 2022, 6:35am UTC](https://forums.developer.nvidia.com/t/cuda-runtime-api-error-for-cuda-graph-and-opencv/215408/7 "2022-05-30T06:35:30Z")

</div>

Thanks for sharing the source with us.

We are going to check it internally.  
Will get back to you later.

---

<div class="post-metadata">

**Author:** ![AastaLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/aastalll/32/14043_2.png) [@AastaLLL](https://forums.developer.nvidia.com/u/AastaLLL)\
**Post date:** [June 16, 2022, 4:38am UTC](https://forums.developer.nvidia.com/t/cuda-runtime-api-error-for-cuda-graph-and-opencv/215408/8 "2022-06-16T04:38:47Z")

</div>

Hi,

Thanks for your patience.

We try to reproduce this issue on a JetPack 4.6.1 environment.  
But the compiling fails due to a missing OpenCV header as below:

```auto
In file included from /home/nvidia/topic_215408/sample/SampleLib/processor.hpp:4:0,
                 from /home/nvidia/topic_215408/sample/exec/sample.cpp:1:
/home/nvidia/topic_215408/sample/SampleLib/image_processing.hpp:4:10: fatal error: opencv2/cudawarping.hpp: No such file or directory
 #include <opencv2/cudawarping.hpp>
          ^ ~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

```

Is this reproducible with the default OpenCV package?  
If not, could you share which OpenCV version you use?

Thanks.

---

<div class="post-metadata">

**Author:** ![fd1](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@fd1](https://forums.developer.nvidia.com/u/fd1)\
**Post date:** [June 17, 2022, 6:32am UTC](https://forums.developer.nvidia.com/t/cuda-runtime-api-error-for-cuda-graph-and-opencv/215408/9 "2022-06-17T06:32:07Z")

</div>

Hi,

The OpenCV package is built from sorce using your(I guess) script [JEP](https://github.com/AastaNV/JEP/blob/master/script/install_opencv4.5.0_Jetson.sh). Version is 4.5.4 and it is built with cuda support.

IIRC there might be some differences like not building for python and/or using ccache; I’ll attach the generated makefile for a comparison if needed.  
[makefile\_text.txt](https://forums.developer.nvidia.com/uploads/short-url/9Jp3Y7FUPdPl5g9zAvv62zetNmQ.txt) (332.0 KB)

---

<div class="post-metadata">

**Author:** ![AastaLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/aastalll/32/14043_2.png) [@AastaLLL](https://forums.developer.nvidia.com/u/AastaLLL)\
**Post date:** [June 28, 2022, 6:23am UTC](https://forums.developer.nvidia.com/t/cuda-runtime-api-error-for-cuda-graph-and-opencv/215408/10 "2022-06-28T06:23:04Z")

</div>

Hi,

Here are some updates for you:

We can reproduce this issue internally.  
It looks like there are issues related to the CUDA Graph but we need more time to investigate.  
Will give you an update once we got further information.

Thanks.

---

<div class="post-metadata">

**Author:** ![fd1](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@fd1](https://forums.developer.nvidia.com/u/fd1)\
**Post date:** [June 28, 2022, 8:37am UTC](https://forums.developer.nvidia.com/t/cuda-runtime-api-error-for-cuda-graph-and-opencv/215408/12 "2022-06-28T08:37:23Z")

</div>

Thanks @AastaLLL

I’ll wait for the update.

---

<div class="post-metadata">

**Author:** ![AastaLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/aastalll/32/14043_2.png) [@AastaLLL](https://forums.developer.nvidia.com/u/AastaLLL)\
**Post date:** [July 13, 2022, 8:38am UTC](https://forums.developer.nvidia.com/t/cuda-runtime-api-error-for-cuda-graph-and-opencv/215408/13 "2022-07-13T08:38:40Z")

</div>

Hi,

Thanks for your patience.  
This issue is related to CUDA runtime API.

If you create the CUDA graph from a dynamic library and tries to introspect it outside the library.  
The query functions may fail because the nodes reference CUDA C++ symbols that belong to a different runtime and are not in the local runtime’s map.

The workaround currently is to use driver APIs instead.  
We can run your sample without issue after switching to the driver APIs.

Here is our change for your reference: [driverAPIs.patch](https://forums.developer.nvidia.com/uploads/short-url/rY7v2ASmWccGH9aWh7iMxWg5N3a.patch) (3.4 KB)

Thanks.

---

<div class="post-metadata">

**Author:** ![fd1](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@fd1](https://forums.developer.nvidia.com/u/fd1)\
**Post date:** [July 13, 2022, 10:13am UTC](https://forums.developer.nvidia.com/t/cuda-runtime-api-error-for-cuda-graph-and-opencv/215408/14 "2022-07-13T10:13:05Z")

</div>

Thanks to you.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/system/32/68080_2.png) [@system](https://forums.developer.nvidia.com/u/system)\
**Post date:** [August 3, 2022, 3:04am UTC](https://forums.developer.nvidia.com/t/cuda-runtime-api-error-for-cuda-graph-and-opencv/215408/16 "2022-08-03T03:04:41Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
