Skip to content

Morphology operation is slower on GPU than same operation on CPU #3798

@cg3dland

Description

@cg3dland
System information
  • OpenCV => 4.8.0
  • Operating System / Platform => Nvidia JetPack 6.0 (Ubuntu 22.04) / Nvidia Jetson Orin NX
  • Compiler => gcc 11.4.0
Detailed description

I am trying to test the morphology operation on GPU, the test platform is Nvidia Jetson Orin NX, the JetPack 6.0 (R36.3.0, Ubuntu 22.04) + cuda 12.2 is installed on the test platform.
I download, build and installed the OpenCV 4.8.0 and opencv_contrib 4.8 on the test platform, and then, I code a test program to call morphology interfaces on GPU (cuda::MorphologyFilter->apply) and CPU (morphologyEx) to compare its performance, in my opinion, the same operation on GPU should be faster than on CPU, but in my test, the morphology operation is slower on GPU than it on CPU.
The source of test program and relative image file are attached in a zip file for your reference.
Could you please help me to check if any problem or bug happens in my test program?

Steps to reproduce
  1. compiler the program with command "g++ -D PROFILE_SAMPLE -o morph morph.cpp pkg-config --cflags --libs opencv4 -I /usr/local/cuda/include -L /usr/local/cuda/lib64 -l cudart", an executable file "morph" is generated if no error happens;
  2. run the program morph which built by the step 1 without any arguments, it will read the image file "./baboon.jpg", and do morphology operations on GPU and CPU, and calculate the time cost by the operations on GPU and CPU, print out the time cost on the terminal.
  3. on my test platform - Jetson Orin NX, the printed out is listed below:

(base) nvidia@ubuntu:~/opencv/rep$ ./morph
264 times morphology operations are done with OpenCV on GPU!
Time for morphology : 4396.36 ms
in system time : 4397 ms
264 times morphology operations are done with OpenCV on CPU!
Time for morphology : 1867.39 ms
in system time : 1868 ms

We can find that it costs 4396.36ms to do 264 times morphology operations on GPU, and it costs 1867.39ms to do 264 times morphology operations on CPU.

source code and relative image file

morph.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions