(3) Joint compilation of MNN and Opencl

In the joint compilation of MNN and opencl, some things need to be paid attention to:

1. After modifying cmakelists in MNN

2. Modify the file in OpenCLWarpper.cpp in source/backend/opencl/core/runtime. Otherwise, no error will be reported during the compilation process, but the following error will be reported during the execution process:

OpenCL init error, fallback ..

For example, we use the liunx system of Allwinner T507 for development, and we need to add and modify the opencl link library under liunx

static const std::vector<std::string> gOpencl_library_paths = {

#if defined(__APPLE__) || defined(__MACOSX)
    "libOpenCL.so", "/System/Library/Frameworks/OpenCL.framework/OpenCL"
#elif defined(__ANDROID__)
    "libOpenCL.so",
    "libGLES_mali.so",
    "libmali.so",
#if defined(__aarch64__)
    // Qualcomm Adreno
    "/system/vendor/lib64/libOpenCL.so",
    "/system/lib64/libOpenCL.so",
    // Mali
    "/system/vendor/lib64/egl/libGLES_mali.so",
    "/system/lib64/egl/libGLES_mali.so",
#else
    // Qualcomm Adreno
    "/system/vendor/lib/libOpenCL.so", "/system/lib/libOpenCL.so",
    // Mali
    "/system/vendor/lib/egl/libGLES_mali.so", "/system/lib/egl/libGLES_mali.so",
    // other
    "/system/vendor/lib/libPVROCL.so", "/data/data/org.pocl.libs/files/lib/libpocl.so"
#endif
#elif defined(__linux__)
    // "/usr/lib/libOpenCL.so",
    // "/usr/local/lib/libOpenCL.so",
    // "/usr/local/lib/libpocl.so",
    // "/usr/lib64/libOpenCL.so",
    // "/usr/lib32/libOpenCL.so",
    // "libOpenCL.so"
    "/gzy_mnt/SDK/aarch64-linux-gnu-7.4.1/lib64/libmali.so.0",   //添加opencl动态链接库的路径
    "/gzy_mnt/SDK/aarch64-linux-gnu-7.4.1/lib64/libOpenCL.so.2"
/*
 *  0: System32, 1: SysWOW64
 *  --------------------------------------
 *  | Real CPU /          |  x64  |  x86  |
 *  |        / Target CPU |       |       |
 *  --------------------------------------
 *  |         x64         | 0 / 1 |   1   |
 *  --------------------------------------
 *  |         x86         | Error |   0   |
 *  --------------------------------------
 *  0 / 1: 0 if OpenCL.dll (System32, 64bit on x64), otherwise 1 (SysWOW64, 32bit compatible on 64bit OS)
 */
#elif defined(_WIN64)
    "C:/Windows/System32/OpenCL.dll",
    "C:/Windows/SysWOW64/OpenCL.dll"
#elif defined(_WIN32)
    "C:/Windows/SysWOW64/OpenCL.dll",
    "C:/Windows/System32/OpenCL.dll"
#endif
};

Then when cross-compiling, please refer to the previous link

3. Use MNN for CPU and GPU (opencl) on Allwinner T507 (GPU: mail31) to conduct model time-consuming comparison test.

The performance of the gpu is still relatively low

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324108677&siteId=291194637