Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr

目录

[jni ncnn 推理报错:](#jni ncnn 推理报错:)

[Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr](#Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr)


jni ncnn 推理报错:

Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr

代码调用正常,所以是析构时报错,解决方法:

jni/cls_mobilenet.cpp

cpp 复制代码
MobileNetInference::~MobileNetInference() {
    net_.clear(); // <-- 必须先 clear
    #if NCNN_VULKAN
        ncnn::destroy_gpu_instance();
    #endif
}

// 加载模型
bool MobileNetInference::load_model(AAssetManager* mgr,const std::string& param_path,
                                    const std::string& bin_path) {

    ncnn::set_cpu_powersave(2);
    net_.opt = ncnn::Option();

#if NCNN_VULKAN
    if (use_gpu_) {
        // 创建 GPU 实例 --- 注意:最好在全局只创建一次(这里示例化创建)
        ncnn::create_gpu_instance();
        net_.opt.use_vulkan_compute = true;
    } else {
        net_.opt.use_vulkan_compute = false;
    }
#endif

    // 使用你设置的线程数而不是 get_big_cpu_count()(或至少赋值)
    net_.opt.num_threads = num_threads_;

    net_.opt.num_threads = ncnn::get_big_cpu_count();

    // 1. 加载参数文件
    int ret = net_.load_param(mgr, param_path.c_str());
    if (ret != 0) {
        return false;
    }

    // 2. 加载模型权重
    ret = net_.load_model(mgr, bin_path.c_str());
    if (ret != 0) {
        return false;
    }

    model_loaded_ = true;

    const std::vector<const char*>& input_names = net_.input_names();
    const std::vector<const char*>& output_names = net_.output_names();

    std::cout << "Input names: ";
    for (auto name : input_names) {
        std::cout << name << " ";
    }

    std::cout << "Output names: ";
    for (auto name : output_names) {
        std::cout << name << " ";
    }

    std::cout << "Model loaded successfully from:" << std::endl;
    std::cout << "  - " << param_path << std::endl;
    std::cout << "  - " << bin_path << std::endl;
    std::cout << "Using " << (use_gpu_ ? "GPU (Vulkan)" : "CPU")
              << " with " << num_threads_ << " threads." << std::endl;

    return true;
}
相关推荐
皮卡狮7 小时前
高阶数据结构:红黑树
c++
Java面试题总结7 小时前
go从零单排之方法
开发语言·后端·golang
Jay_Franklin7 小时前
Python一站式科研工作流:从数据分析到报告生成
开发语言·python·论文笔记
小堃学编程7 小时前
【项目实战】基于protobuf的发布订阅式消息队列(1)—— 准备工作
java·大数据·开发语言
垫脚摸太阳7 小时前
二分查找经典算法题--数的范围
数据结构·算法
噜啦噜啦嘞好7 小时前
算法篇:二分查找
数据结构·c++·算法·leetcode
setmoon2147 小时前
C++中的构建器模式
开发语言·c++·算法
2301_815482937 小时前
C++中的桥接模式变体
开发语言·c++·算法
ZHOUPUYU7 小时前
PHP性能分析与调优:从定位瓶颈到实战优化
开发语言·后端·html·php
yunyun321237 小时前
C++与量子计算模拟
开发语言·c++·算法