Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot run MNN with OpenCL backend #105

Closed
chunseoklee opened this issue Jun 5, 2019 · 10 comments
Closed

Cannot run MNN with OpenCL backend #105

chunseoklee opened this issue Jun 5, 2019 · 10 comments

Comments

@chunseoklee
Copy link

devices : odroid-xu4
os : ubuntu mate 16.04

I try to run mobilenet model using MNN with OpenCL backend.

I have compiled MNN with the following cmake setting on odroid natively.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3aeb607..3f59447 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,7 +20,7 @@ else()
 endif()
 
 # build options
-option(MNN_BUILD_HARD "Build -mfloat-abi=hard or not" OFF)
+option(MNN_BUILD_HARD "Build -mfloat-abi=hard or not" ON)
 option(MNN_BUILD_SHARED_LIBS "MNN build shared or static lib" ON)
 option(MNN_FORBID_MULTI_THREAD "Disable Multi Thread" OFF)
 option(MNN_OPENMP "Enable Multiple Thread Linux|Android" ON)
@@ -54,7 +54,7 @@ endif()
 
 # backend options
 option(MNN_METAL "Enable Metal" OFF)
-option(MNN_OPENCL "Enable OpenCL" OFF)
+option(MNN_OPENCL "Enable OpenCL" ON)
 option(MNN_OPENGL "Enable OpenGL" OFF)
 option(MNN_VULKAN "Enable Vulkan" OFF)
 option(MNN_ARM82 "Enable ARM82" OFF)

But running with OpenCL backend always fail.

root@odroid /h/t/M/build# ./MNNV2Basic.out ./mobilenet.mnn 1 0 3
Use extra forward type: 3

Open Model ./mobilenet.mnn
Can't Find type=3 backend, use 3 instead
Create Backend Failed because no creator for 3
Invalide Session!!
test_main, 170, cost time: 1.346000 ms

Please help.

@jxt1234
Copy link
Collaborator

jxt1234 commented Jun 5, 2019

Two way to solve:

  1. Install opencl driver, Disable MNN_USE_OPENCL_WRAPPER

  2. Find your opencl's so , add the path to
    source/backend/opencl/core/runtime/OpenCLWrapper.cpp

@liushuan
Copy link

liushuan commented Jun 5, 2019

使用 方法 2 不能解决问题呢? 我也遇到了同样的问题,平台是RK3399

@liushuan
Copy link

liushuan commented Jun 6, 2019

目前可以通过在程序里面添加这个解决该问题。
#inlcude<dlfcn.h>

auto handle = dlopen("libMNN_CL.so", RTLD_NOW);
FUNC_PRINT_ALL(handle, p);

@PhilipXue
Copy link

@liushuan 你好,请问能详细讲下你的解决方法吗?这段代码需要添加到哪里?(我在benchmark.cpp中添加后编译不过)

/MNN/include/MNNDefine.h:27:38: error: expected constructor, destructor, or type conversion before ‘(’ token
 #define MNN_PRINT(format, ...) printf(format, ##__VA_ARGS__)

@liushuan
Copy link

@PhilipXue 你好,我是直接添加到了main() 方法的开始位置。

@li-qing li-qing closed this as completed Jun 17, 2019
@chunseoklee
Copy link
Author

@jxt1234 reopened since I still have issues.

Install opencl driver, Disable MNN_USE_OPENCL_WRAPPER

MNN_USE_OPENCL_WRAPPER is enabled on android build. I built MNN on linux.

Find your opencl's so , add the path to
source/backend/opencl/core/runtime/OpenCLWrapper.cpp

Applied, But did not make any change.

AFAIK, To enable opencl backend, the function below should be executed :

static const auto __opencl_global_initializer = []() {
    MNNInsertExtraBackendCreator(MNN_FORWARD_OPENCL, new CLBackendCreator, true);
    return true;
}();

When I run MNN with gdb, I found that the function not called.

@jxt1234
Copy link
Collaborator

jxt1234 commented Jul 4, 2019

Currently on linux the code will not be automatic executed. Please dlopen the libMNN_CL.so in your main code, and link -dl , like this:
#inlcude<dlfcn.h>
int main() {
auto handle = dlopen("libMNN_CL.so", RTLD_NOW);

/Run MNN/
}

@chunseoklee
Copy link
Author

@jxt1234 Thanks for help

@xuguozhi
Copy link

solved!

@Echosanmao
Copy link

我在用.tflite生成.mnn时报错,check failed:creator not_supported_op[MUL]
这个问题大家有遇到过吗?
求教!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants