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

readmap崩溃 #3025

Open
SeanYangyong opened this issue Sep 10, 2024 · 6 comments
Open

readmap崩溃 #3025

SeanYangyong opened this issue Sep 10, 2024 · 6 comments
Labels
mnncv mnn's cv lib stale User The user ask question about how to use. Or don't use MNN correctly and cause bug.

Comments

@SeanYangyong
Copy link

平台(如果交叉编译请再附上交叉编译目标平台):

Android 小米12 pro

Github版本:

2.9.3版本

编译日志:

崩溃

正常运行一会儿后,很容易发生崩溃。不清楚是哪里的问题。
代码如下:

    MNN::Express::VARP image = MNN::CV::imdecode(srcbuf, MNN::CV::IMREAD_COLOR);
    if (image.get() == nullptr || image == nullptr) {
        MNN_PRINT("decode_image_ is nullptr");
        return nullptr;
    }

    auto img = image->readMap<uint8_t>();
@SeanYangyong
Copy link
Author

无标题
在此崩溃前,还打印有个错误,但是image->getInfo()->size并不为0,image并不为空

@jxt1234
Copy link
Collaborator

jxt1234 commented Sep 12, 2024

完整测试代码是?

@SeanYangyong
Copy link
Author

Picture::SPtr decodePicture(void *data, int size) {
    auto pic = std::make_shared<Picture>();
    int x = 0;
    int y = 0;
    int channels = 0;
    int bitcount = 3;
    auto start = utils::CurrentMillionSecond();
    std::vector<uint8_t> srcbuf((uint8_t*)data, (uint8_t*)data + size);
    MNN::Express::VARP image = MNN::CV::imdecode(srcbuf, MNN::CV::IMREAD_COLOR);

    auto img = image->readMap<uint8_t>();
    auto info = image->getInfo();
    int img_data_size = image->getInfo()->size;
    x = info->dim[1];
    y = info->dim[0];
    channels = info->dim[2];
    if (img != nullptr) {
        if (channels == 3) {
            pic->allocData(PICTURE_FORMAT(x, y, PIXFMT_E_RGB24, x * 3, 0, 0, 0));
        } else if (channels == 4) {
            pic->allocData(PICTURE_FORMAT(x, y, PIXFMT_E_RGBA, x * 4, 0, 0, 0));
        }
        memcpy(pic->data(), img, x*y*channels);
    } else {
        loge(TAG"load png failed!");
    }
    srcbuf.clear();
    return pic;
}

起了一个线程,不断decodePicture,将jpg图片的数据解码

@SeanYangyong
Copy link
Author

好像是推理和读取解析数据不在同一个线程,就容易导致崩溃。readMap和推理以及内存操作这些是不是最好在同一个线程中?

@jxt1234
Copy link
Collaborator

jxt1234 commented Sep 18, 2024

  1. Express / Module API 不是线程安全的,不同线程中调用需要绑定同一个 executor https://mnn-docs.readthedocs.io/en/latest/inference/module.html#id1
  2. MNN::CV 使用的是 Express ,因此并非线程安全,同样需要先创建一个 Executor ,在调用 MNN::CV 相关函数时绑定该 Executor 。这个 mnn 后面会优化相关 api。

@jxt1234 jxt1234 added User The user ask question about how to use. Or don't use MNN correctly and cause bug. mnncv mnn's cv lib labels Sep 18, 2024
Copy link

Marking as stale. No activity in 60 days.

@github-actions github-actions bot added the stale label Nov 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mnncv mnn's cv lib stale User The user ask question about how to use. Or don't use MNN correctly and cause bug.
Projects
None yet
Development

No branches or pull requests

2 participants