Why every call to nppSetStream tries to open "/sys/kernel/debug/clock/emc/possible_rates" on Orin?

Hi,
I was looking for sources of inefficiencies in my image processing, such as unnecessary calls to malloc and kernel calls.
I found that when I call cv::cuda::warpAffine it calls nppSetStream, which tries to open non-existing file “/sys/kernel/debug/clock/emc/possible_rates”
and it allocates and frees several blocks of memory on each call. This unnecessarily slows down warpAffine by about 5%.
To reproduce just do:
cudaStream_t testStream;
cudaStreamCreateWithFlags(&testStream, cudaStreamNonBlocking);
for(int retry = 0; retry < 30; retry++)
{
cudaStream_t oldStream = nppGetStream();
int res = nppSetStream(testStream);
nppSetStream(oldStream);
}
Compile and run with strace and you will these lines repeated 30 times:
openat(AT_FDCWD, “/sys/kernel/debug/clock/emc/possible_rates”, O_RDONLY) = -1 EACCES (Permission denied)
ioctl(5, _IOC(_IOC_READ|_IOC_WRITE, 0x47, 0x1e, 0x10), 0xffffc843b5e0) = 0
The only work around I found is to avoid using NPP entirely.
Can NPP be fixed to avoid unnecessary calls to a file, which is not present and cannot be accessible?
Thank you

Hi,

Confirmed that we can reproduce the same issue in our environment.
Will check with our internal team and share more info with you later.

Thanks.

Hi,

Direct calls to nppSetStream are no longer supported.
Please try to use NPP stream contexts.

We did some experiments with NPP stream contexts.
The frequency of opening the EMC clock node is much fewer.

Here is the change we applied for your reference:

diff --git a/main.cpp b/main.cpp
index 6b19444..0a39148 100644
--- a/main.cpp
+++ b/main.cpp
@@ -7,11 +7,13 @@ int main(int argc, char *argv[])
     cudaStream_t testStream;
     cudaStreamCreateWithFlags(&testStream, cudaStreamNonBlocking);

+    NppStreamContext nppStreamContext{};
     for(int retry = 0; retry < 30; retry++)
     {
         cudaStream_t oldStream = nppGetStream();
-        int res = nppSetStream(testStream);
-        nppSetStream(oldStream);
+        nppGetStreamContext(&nppStreamContext);
+        nppStreamContext.hStream = testStream;
+        nppStreamContext.hStream = oldStream;
     }
     exit(EXIT_SUCCESS);
 }

Thanks.

Unfortunately, it is not my code, which calls nppSetStream - I simply use OpenCV cuda library functions, such as cv::cuda::warpAffine and it, like many other OpenCV calls use class NppStreamHandler, which calls nppSetStream . See
https://github.com/opencv/opencv/blob/4.x/modules/core/include/opencv2/core/private.cuda.hpp

Hi,

OpenCV is open sourced library.
Please rebuild a package with the modified NppStreamHandler.

You can find an OpenCV building script below:

Thanks.

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