Custom opencv filter can't use GPU, please help!

126 views
Skip to first unread message

dongw...@gmail.com

unread,
Aug 30, 2016, 6:29:58 AM8/30/16
to kurento
Hi all:
I wrote a custom opencv filter, it will call libcaffe to do some object detection with GPU mode (with Caffe::set_mode(Caffe::GPU);), after I change kurento service from user kurento  to root, the filter can be loaded by kurento and init net ok, but when I run detection function, I found the func can't use GPU, looks like it only use CPU to calculate and take very long time to return result. I check GPU use rate with cmd line: nvidia-smi -a|grep Gpu   , it shoue gpu use rate is 0%.
But if I wrote another app which load the so with the totally same code, the GPU use rate can reach 96%, so could anyone help to tell me how to make kurento's filter use GPU? any configuration need be changed? 

dongw...@gmail.com

unread,
Aug 31, 2016, 2:30:28 AM8/31/16
to kurento, dongw...@gmail.com
To make things easy to reproduce, I wrote a so which use cuda print a message via GPU, then load the so in customer opencv plugin(do nothing except call entry() in process()), I found when the filter is running, no gpu involved, if I call entry() in a simple c program, then gpu use rate will be 74%. Below is my so code file hello.cu:

#include <stdio.h>

__global__ void myk(void)

{

    printf("Hello from thread %d block %d\n", threadIdx.x, blockIdx.x);

}

extern "C" 

void entry(void)

{

    myk<<<1,10>>>();

    printf("CUDA status: %d\n", cudaDeviceSynchronize());

}


The test file test.c:

#include <stdio.h>

void entry(void);

int main(void)

{

    while(1) {

        entry();

    }   

}


I call this in opencv filter as below:

...

extern "C" {

void entry(void);

}

....

void myopencvfilterOpenCVImpl::process (cv::Mat &mat) {

   entry();

}


Please help to answer how can I make GPU involve when I call it in kurento filter, thanks a lot!


在 2016年8月30日星期二 UTC+8下午6:29:58,dongw...@gmail.com写道:

dongw...@gmail.com

unread,
Aug 31, 2016, 2:49:56 AM8/31/16
to kurento, dongw...@gmail.com

nvidia-smi -a


Attached output of nvidia-smi -a as below, I found the process /usr/bin/kurento-media-server has been logged in it, but it only the utilization is 0%.

==============NVSMI LOG==============


Timestamp                           : Wed Aug 31 14:36:57 2016

Driver Version                      : 352.79


Attached GPUs                       : 4

GPU 0000:02:00.0

    Product Name                    : Tesla K40c

    Product Brand                   : Tesla

    Display Mode                    : Disabled

    Display Active                  : Disabled

    Persistence Mode                : Disabled

    Accounting Mode                 : Disabled

    Accounting Mode Buffer Size     : 1920

    Driver Model

        Current                     : N/A

        Pending                     : N/A

    Serial Number                   : 0324915019018

    GPU UUID                        : GPU-dde35a3f-9e48-2f03-13f0-4625ebc4f0c4

    Minor Number                    : 0

    VBIOS Version                   : 80.80.3E.00.02

    MultiGPU Board                  : No

    Board ID                        : 0x200

    Inforom Version

        Image Version               : 2081.0206.01.04

        OEM Object                  : 1.1

        ECC Object                  : 3.0

        Power Management Object     : N/A

    GPU Operation Mode

        Current                     : N/A

        Pending                     : N/A

    PCI

        Bus                         : 0x02

        Device                      : 0x00

        Domain                      : 0x0000

        Device Id                   : 0x102410DE

        Bus Id                      : 0000:02:00.0

        Sub System Id               : 0x098310DE

        GPU Link Info

            PCIe Generation

                Max                 : 3

                Current             : 3

            Link Width

                Max                 : 16x

                Current             : 16x

        Bridge Chip

            Type                    : N/A

            Firmware                : N/A

        Replays since reset         : 0

        Tx Throughput               : N/A

        Rx Throughput               : N/A

    Fan Speed                       : 27 %

    Performance State               : P0

    Clocks Throttle Reasons

        Idle                        : Not Active

        Applications Clocks Setting : Active

        SW Power Cap                : Not Active

        HW Slowdown                 : Not Active

        Unknown                     : Not Active

    FB Memory Usage

        Total                       : 11519 MiB

        Used                        : 100 MiB

        Free                        : 11419 MiB

    BAR1 Memory Usage

        Total                       : 256 MiB

        Used                        : 4 MiB

        Free                        : 252 MiB

    Compute Mode                    : Default

    Utilization

        Gpu                         : 0 %

        Memory                      : 0 %

        Encoder                     : 0 %

        Decoder                     : 0 %

    Ecc Mode

        Current                     : Enabled

        Pending                     : Enabled

    ECC Errors

        Volatile

            Single Bit            

                Device Memory       : 0

                Register File       : 0

                L1 Cache            : 0

                L2 Cache            : 0

                Texture Memory      : 0

                Total               : 0

            Double Bit            

                Device Memory       : 0

                Register File       : 0

                L1 Cache            : 0

                L2 Cache            : 0

                Texture Memory      : 0

                Total               : 0

        Aggregate

            Single Bit            

                Device Memory       : 0

                Register File       : 0

                L1 Cache            : 0

                L2 Cache            : 0

                Texture Memory      : 0

                Total               : 0

            Double Bit            

                Device Memory       : 0

                Register File       : 0

                L1 Cache            : 0

                L2 Cache            : 0

                Texture Memory      : 0

                Total               : 0

    Retired Pages

        Single Bit ECC              : 0

        Double Bit ECC              : 0

        Pending                     : No

    Temperature

        GPU Current Temp            : 55 C

        GPU Shutdown Temp           : 95 C

        GPU Slowdown Temp           : 90 C

    Power Readings

        Power Management            : Supported

        Power Draw                  : 68.28 W

        Power Limit                 : 235.00 W

        Default Power Limit         : 235.00 W

        Enforced Power Limit        : 235.00 W

        Min Power Limit             : 180.00 W

        Max Power Limit             : 235.00 W

    Clocks

        Graphics                    : 745 MHz

        SM                          : 745 MHz

        Memory                      : 3004 MHz

    Applications Clocks

        Graphics                    : 745 MHz

        Memory                      : 3004 MHz

    Default Applications Clocks

        Graphics                    : 745 MHz

        Memory                      : 3004 MHz

    Max Clocks

        Graphics                    : 875 MHz

        SM                          : 875 MHz

        Memory                      : 3004 MHz

    Clock Policy

        Auto Boost                  : N/A

        Auto Boost Default          : N/A

    Processes

        Process ID                  : 121410

            Type                    : C

            Name                    : /usr/bin/kurento-media-server

            Used GPU Memory         : 75 MiB


If I run with another c program, the output is below:

    Utilization

        Gpu                         : 74 %

        Memory                      : 0 %

        Encoder                     : 0 %

        Decoder                     : 0 %

    Ecc Mode

        Current                     : Enabled

        Pending                     : Enabled

    ECC Errors

        Volatile

            Single Bit            

                Device Memory       : 0

                Register File       : 0

                L1 Cache            : 0

                L2 Cache            : 0

                Texture Memory      : 0

                Total               : 0

            Double Bit            

                Device Memory       : 0

                Register File       : 0

                L1 Cache            : 0

                L2 Cache            : 0

                Texture Memory      : 0

                Total               : 0

        Aggregate

            Single Bit            

                Device Memory       : 0

                Register File       : 0

                L1 Cache            : 0

                L2 Cache            : 0

                Texture Memory      : 0

                Total               : 0

            Double Bit            

                Device Memory       : 0

                Register File       : 0

                L1 Cache            : 0

                L2 Cache            : 0

                Texture Memory      : 0

                Total               : 0

    Retired Pages

        Single Bit ECC              : 0

        Double Bit ECC              : 0

        Pending                     : No

    Temperature

        GPU Current Temp            : 56 C

        GPU Shutdown Temp           : 95 C

        GPU Slowdown Temp           : 90 C

    Power Readings

        Power Management            : Supported

        Power Draw                  : 72.14 W

        Power Limit                 : 235.00 W

        Default Power Limit         : 235.00 W

        Enforced Power Limit        : 235.00 W

        Min Power Limit             : 180.00 W

        Max Power Limit             : 235.00 W

    Clocks

        Graphics                    : 745 MHz

        SM                          : 745 MHz

        Memory                      : 3004 MHz

    Applications Clocks

        Graphics                    : 745 MHz

        Memory                      : 3004 MHz

    Default Applications Clocks

        Graphics                    : 745 MHz

        Memory                      : 3004 MHz

    Max Clocks

        Graphics                    : 875 MHz

        SM                          : 875 MHz

        Memory                      : 3004 MHz

    Clock Policy

        Auto Boost                  : N/A

        Auto Boost Default          : N/A

    Processes

        Process ID                  : 121761

            Type                    : C

            Name                    : ./a.out

            Used GPU Memory         : 75 MiB



在 2016年8月30日星期二 UTC+8下午6:29:58,dongw...@gmail.com写道:
Hi all:

Zorro Zombi

unread,
Feb 8, 2017, 2:48:48 AM2/8/17
to kurento
Do you have any news? Could you fix it? Is https://groups.google.com/forum/#!topic/kurento/syz-5Wo0MKQ not the same?

dongw...@gmail.com

unread,
Feb 9, 2017, 2:58:43 AM2/9/17
to kurento
Hi Zorro:
I still can't find the root cause, but the issue only happened when filter load libcaffe, if run printf with cuda(like my example), I can see GPU has worked. It is not duplicate with my early issue, that issue is happened at init period, this issue is happened when filter is running, but GPU didn't work, only CPU is used for object detection.


在 2016年8月30日星期二 UTC+8下午6:29:58,dongw...@gmail.com写道:
Hi all:

Zorro Zombi

unread,
Feb 9, 2017, 4:04:22 AM2/9/17
to kurento
Thanks, today I understood problem it is the GStreamer problem. I could call gpu method with right functionality but I should now get around the gstreamer.

Micael Gallego

unread,
Feb 9, 2017, 4:36:26 AM2/9/17
to kur...@googlegroups.com
Hi Zorro, 

If you get GPU working in Kurento, can you share with all of us your findings? A sample project in GitHub would be awesome

Thanks in advance.

Best

Micael Gallego
Profesor de la Escuela Técnica Superior de Ingeniería Informática URJC

On Thu, Feb 9, 2017 at 10:04 AM, Zorro Zombi <zz3...@gmail.com> wrote:
Thanks, today I understood problem it is the GStreamer problem. I could call gpu method with right functionality but I should now get around the gstreamer.

--
You received this message because you are subscribed to the Google Groups "kurento" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kurento+unsubscribe@googlegroups.com.
To post to this group, send email to kur...@googlegroups.com.
Visit this group at https://groups.google.com/group/kurento.
To view this discussion on the web visit https://groups.google.com/d/msgid/kurento/e0b62673-bc8b-4c9e-9839-3e900cf4da3d%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Zorro Zombi

unread,
Feb 9, 2017, 5:27:12 AM2/9/17
to kurento
Now it seems not nice I only localised problem. I broke GStreamer and got right result from method getCudaEnableDeviceCount() it is 1. And it is almost all source. I don't know good the GStreamer. I should now read more about it.

Zorro Zombi

unread,
Feb 9, 2017, 9:00:19 AM2/9/17
to kurento
Seems I fixed the main problem I rebuilt OpenCV with flag -D BUILD_SHARED_LIBS=ON and copied builded libraries to folder /usr/lib/x86_64-linux-gnu. It seems not nice but it is work. You can try it simple add to kms OpenCV plugin sample:

#include "opencv2/gpu/gpu.hpp"

....

cout << "count cuda devices:" << gpu::getCudaEnabledDeviceCount() << endl;

Now I have 1.
Reply all
Reply to author
Forward
0 new messages