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

How to run with OpenGL backend on RPi4 #3230

Open
dimkastan opened this issue Feb 12, 2025 · 2 comments
Open

How to run with OpenGL backend on RPi4 #3230

dimkastan opened this issue Feb 12, 2025 · 2 comments
Labels
wontfix This will not be worked on

Comments

@dimkastan
Copy link

Dear all, first of all thanks for sharing your implementation.
I am trying to run a Yolov5 on a RPI4 using OpenGL backend an I am getting the following error:

Can't open file:/sys/devices/system/cpu/cpufreq/ondemand/affected_cpus
CPU Group: [ 0  1  2  3 ], 600000 - 1600000
The device supports: i8sdot:0, fp16:0, i8mm: 0, sve2: 0
not support half 
Segmentation fault

More specifically:

On a headless RPI4, I compiled the MNN with OpenGL support and tried to run a Yolo network (f32 bit)

When running my program I get:

Can't open file:/sys/devices/system/cpu/cpufreq/ondemand/affected_cpus
CPU Group: [ 0  1  2  3 ], 600000 - 1600000
The device supports: i8sdot:0, fp16:0, i8mm: 0, sve2: 0
not support half 
Segmentation fault

To enable the GL backend in my code I used the following commands:

    MNN::ScheduleConfig config;
    config.type = MNN_FORWARD_OPENGL;  // Use OpenGL backend
    int numThread = 4;  // Default number of threads

    if (argc > 3) {  // Check if the third argument (argv[3]) exists
        numThread = atoi(argv[3]);
        if (numThread <= 0) {
            std::cerr << "Invalid number of threads specified. Using default: 4\n";
            numThread = 4;
        }
    }
    config.numThread = numThread;
    // Force full precision (FP32)
    MNN::BackendConfig backendConfig;
    backendConfig.precision = MNN::BackendConfig::Precision_Normal;
    config.backendConfig = &backendConfig;
    auto session = interpreter->createSession(config);

and I compiled using:

 g++ -std=c++11 -Wl,--no-as-needed -o mnn_test mnn_model_test.cpp -I/home/pi/mytest/MNN-3.0.4/include -L/home/pi/mytest/MNN-3.0.4/build/source/backend/opengl -lMNN_GL -L/home/pi/mytest/MNN-3.0.4/build -lMNN -lGLEW -lGLESv2 -lEGL

and exported the following env variable:

 export EGL_PLATFORM=surfaceless

the LDD command returns:

	linux-vdso.so.1 (0x0000007fa41a8000)
	libMNN_GL.so => /home/pi/mytest/MNN-3.0.4/build/source/backend/opengl/libMNN_GL.so (0x0000007fa4128000)
	libMNN.so => /home/pi/mytest/MNN-3.0.4/build/libMNN.so (0x0000007fa3ee4000)
	libGLEW.so.2.1 => /lib/aarch64-linux-gnu/libGLEW.so.2.1 (0x0000007fa3e0b000)
	libGLESv2.so.2 => /lib/aarch64-linux-gnu/libGLESv2.so.2 (0x0000007fa3dd6000)
	libEGL.so.1 => /lib/aarch64-linux-gnu/libEGL.so.1 (0x0000007fa3db1000)
	libstdc++.so.6 => /lib/aarch64-linux-gnu/libstdc++.so.6 (0x0000007fa3bd9000)
	libm.so.6 => /lib/aarch64-linux-gnu/libm.so.6 (0x0000007fa3b2e000)
	libgcc_s.so.1 => /lib/aarch64-linux-gnu/libgcc_s.so.1 (0x0000007fa3b0a000)
	libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000007fa3996000)
	libpthread.so.0 => /lib/aarch64-linux-gnu/libpthread.so.0 (0x0000007fa3965000)
	libGL.so.1 => /lib/aarch64-linux-gnu/libGL.so.1 (0x0000007fa386e000)
	libX11.so.6 => /lib/aarch64-linux-gnu/libX11.so.6 (0x0000007fa371f000)
	libGLdispatch.so.0 => /lib/aarch64-linux-gnu/libGLdispatch.so.0 (0x0000007fa3594000)
	libdl.so.2 => /lib/aarch64-linux-gnu/libdl.so.2 (0x0000007fa3580000)
	/lib/ld-linux-aarch64.so.1 (0x0000007fa4178000)
	libGLX.so.0 => /lib/aarch64-linux-gnu/libGLX.so.0 (0x0000007fa353d000)
	libxcb.so.1 => /lib/aarch64-linux-gnu/libxcb.so.1 (0x0000007fa3505000)
	libXau.so.6 => /lib/aarch64-linux-gnu/libXau.so.6 (0x0000007fa34f1000)
	libXdmcp.so.6 => /lib/aarch64-linux-gnu/libXdmcp.so.6 (0x0000007fa34db000)
	libbsd.so.0 => /lib/aarch64-linux-gnu/libbsd.so.0 (0x0000007fa34b6000)
	libmd.so.0 => /lib/aarch64-linux-gnu/libmd.so.0 (0x0000007fa349a000)

My model was extracted using the ultralytics python SDK

When running GetMNNInfo I get:

Can't open file:/sys/devices/system/cpu/cpufreq/ondemand/affected_cpus
CPU Group: [ 0  1  2  3 ], 600000 - 1600000
The device supports: i8sdot:0, fp16:0, i8mm: 0, sve2: 0
Model default dimensionFormat is NCHW
Model Inputs:
[ images ]: dimensionFormat: NCHW, size: [ 1,3,640,640 ], type is float
Model Outputs:
[ onnx::Sigmoid_361 ]
[ onnx::Sigmoid_405 ]
[ output0 ]
Model Version: 3.0.4 
Model bizCode: {"description": "Ultralytics 0p8GFLOPS-92p5 model ", "author": "Ultralytics", "date": "2025-02-12T08:38:39.595401", "version": "8.3.74", "license": "AGPL-3.0 License (https://ultralytics.com/license)", "docs": "https://docs.ultralytics.com", "stride": 32, "task": "detect", "batch": 1, "imgsz": [640, 640], "names": {"0": "person"}, "args": {"batch": 1, "half": false, "int8": false}}

Please note that with CPU backend the network runs properly.

Any help/support will be highly appreciated!

@dimkastan
Copy link
Author

Dear all,

I converted the model using the MNN converter and got the following error when running with OpenGL backend.

./mnn_test model_fp32.mnn
Can't open file:/sys/devices/system/cpu/cpufreq/ondemand/affected_cpus
CPU Group: [ 0 1 2 3 ], 600000 - 1600000
The device supports: i8sdot:0, fp16:0, i8mm: 0, sve2: 0
eglChooseConfig error !!!
mContext error !!!
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_M_construct null not valid
Aborted

Any suggestion or comment is welcome!

@jxt1234
Copy link
Collaborator

jxt1234 commented Feb 16, 2025

OpenGL Backend is deprecated now. You can use Vulkan or OpenCL Backend instead to enable GPU compute.

@jxt1234 jxt1234 added the wontfix This will not be worked on label Feb 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants