google-coral / libedgetpu

Source code for the userspace level runtime driver for Coral.ai devices.
Apache License 2.0
181 stars 62 forks source link

Conflict with Intel IPP #10

Closed YijinLiu closed 3 years ago

YijinLiu commented 3 years ago

I am testing a m2 edgetpu under ubuntu 18.04. To make it accessible to a non root user. I did this:

echo 'DRIVER=="apex", OWNER="$USER", GROUP="$USER"' > /etc/udev/rules.d/99-apex-perm.rules

Everything works great until I link the binary to OpenCV with Intel IPP. It fails at kernel_registers.cc:101 strace shows

openat(AT_FDCWD, "/dev/apex_0", O_RDWR) = 3
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, 3, 0x40000) = -1 EPERM (Operation not permitted)

dmesg shows

apex 0000:05:00.0: Permission checking failed.

The same binary (linked with IPP) works if run with root. It looks like IPP does sth. that changes the behavior of this mmap system call. Is it possible that the apex driver tries to use memory claimed by IPP?

YijinLiu commented 3 years ago

This seems to be a OpenCV issue. Here is a mini program to repro it:

#include <iostream>

#include <edgetpu.h>
#include <iw++/iw.hpp>

int main() {
    try {
        ipp::IwiSize size(1920, 1080);
        ipp::IwiImage image(size, ipp8u, 3); 
        auto status = ipp::iwiSet(128, image);
        if (status != ippStsNoErr) {
            std::cout << "Failed to set image!\n";
            return 2;
        }   
    } catch (...) {
    }   

    auto* edgetpu_mgr = edgetpu::EdgeTpuManager::GetSingleton();
    auto edgetpu_ctx = edgetpu_mgr->OpenDevice(edgetpu::DeviceType::kApexPci);
    if (!edgetpu_ctx) {
        std::cout << "Failed to open edgetpu!\n";
        return 4;
    }   
    return 0;
}

The binary compiled using this command (link with standalone IPP) is fine:

g++ -o verify_edgetpu_with_ipp verify_edgetpu_with_ipp.cc -ledgetpu 
       -I/opt/intel/oneapi/ipp/2021.1.1/include \
       -L/opt/intel/oneapi/ipp/2021.1.1/lib/intel64 \
       -Wl,-Bstatic -lipp_iw -lippcv -lippi -lipps -lippvm -lippcore -Wl,-Bdynamic

The binary compiled with this command (linked with OpenCV 3.4.3 IPP) is problematic:

g++ -o verify_edgetpu_with_ipp verify_edgetpu_with_ipp.cc -ledgetpu \
        -I/opt/intel/oneapi/ipp/2021.1.1/include \
        -Wl,-Bstatic -lippiw -lippicv -Wl,-Bdynamic

Anyway, I am still interested in seeing whether edgetpu team has any thoughts on this? This might help OpenCV guys to figure out what's wrong..

YijinLiu commented 3 years ago

In case it might be useful for others: after upgraded the kernel to 5.11.10, it's working well now.