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

使用OPENCL推理结果出现段错误,CPU结果正常。 #3057

Open
zhangshabao opened this issue Oct 22, 2024 · 1 comment
Open

使用OPENCL推理结果出现段错误,CPU结果正常。 #3057

zhangshabao opened this issue Oct 22, 2024 · 1 comment
Labels
question Further information is requested

Comments

@zhangshabao
Copy link

    初始化代码:
    _mnn_net->setCacheFile(".cache");
    _net_cfg.type = MNN_FORWARD_OPENCL;
    DEBUG_LOG(" setCacheFile end ");
    _mnn_session = _mnn_net->createSession(_net_cfg);
    _mnn_net->setSessionMode(MNN::Interpreter::Session_Release);
    _net_cfg.numThread = 4;

    for (int i = 0; i < 1; ++i) {
        auto outputTensor = _mnn_net->getSessionOutput(_mnn_session, NULL);
        MNN::Tensor* input    = _mnn_net->getSessionInput(_mnn_session, NULL);
        void* host = input->map(MNN::Tensor::MAP_TENSOR_WRITE,  input->getDimensionType());
        input->unmap(MNN::Tensor::MAP_TENSOR_WRITE,  input->getDimensionType(), host);
        _mnn_net->runSession(_mnn_session);
        host = outputTensor->map(MNN::Tensor::MAP_TENSOR_READ,  outputTensor->getDimensionType());
        outputTensor->unmap(MNN::Tensor::MAP_TENSOR_READ,  outputTensor->getDimensionType(), host);
    }
    推理代码:
     std::vector<float> inputTensorValues = substractMeanNormalize(inputImage, meanValues, normValues);

    auto input = _mnn_net->getSessionInput(_mnn_session, NULL);
    auto shape = input->shape();
    shape[0] = 1;
    shape[2] = inputImage.rows;
    shape[3] = inputImage.cols;

    _mnn_net->resizeTensor(input, shape);
    _mnn_net->resizeSession(_mnn_session);
    auto shapein = input->shape();
    std::vector<int> v = {1, (int)inputImage.channels(), inputImage.rows, inputImage.cols};
    auto nchwTensor = MNN::Tensor::create(v, halide_type_of<float>(), &inputTensorValues[0], MNN::Tensor::CAFFE);
    input->copyFromHostTensor(nchwTensor);
    delete nchwTensor;
    _mnn_net->runSession(_mnn_session);
    outputs = _mnn_net->getSessionOutputAll(_mnn_session);
    获取结果代码:
        out_dim.push_back(out_shape_c);
        out_dim.push_back(out_shape_h);
        out_dim.push_back(out_shape_w);
                float* data_ptr = tensor_ptr->host<float>();
            DEBUG_LOG(" *obj_angle_ptr :%f ",results[105600]);
    其中out_shape_c=67,out_shape_h=40,out_shape_w=40
@jxt1234 jxt1234 added the question Further information is requested label Oct 29, 2024
@jxt1234
Copy link
Collaborator

jxt1234 commented Oct 29, 2024

这个 tensor_ptr 是什么?如果使用 opencl ,不能直接使用 host ,需要用 map ,用完后 unmp

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

No branches or pull requests

2 participants