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

关于UE Vulkan渲染管线的数据 传给 MNN Vulkan后端做推理? #3134

Open
Sodiride123 opened this issue Dec 21, 2024 · 1 comment
Labels
User The user ask question about how to use. Or don't use MNN correctly and cause bug.

Comments

@Sodiride123
Copy link

您好,
我当前在UE里面用Vulkan做了一个渲染管线,现在想把每一帧的数据传给MNN做推理,我现在可以拿到UE侧VkBuffer相关数据,请问下如何正确的让MNN Vulkan后端 接收 将UE侧的数据。目前我理解的流程是:

  1. 在创建session的时候,我用的是UE渲染管线的那套Vulkan上下文,确保推理和渲染都在同一个vulkan实例里面。
  2. 从session拿到inputTensor。
  3. (问题在这一步)我的理解是拿到并且强转inputTensor里的deviceId()类型,例如MNN::VulkanBuffer* handle = (MNN::VulkanBuffer*)(inputTensor->deviceId()), 有点不太懂这一步之后怎么把UE那边的数据传进来?
@jxt1234
Copy link
Collaborator

jxt1234 commented Dec 22, 2024

基于 vulkan buffer (-DMNN_VULKAN_IMAGE=false)模式的话是支持传输的。需要加载如下头文件:

#define MNN_VULKAN
#include <MNN/MNNSharedContext.h>
  1. 创建 MNN Module 或 Session 时传入 DeviceContext :
        MNN::ScheduleConfig config;
        MNN::BackendConfig bnConfig;
        MNNVulkanContext mShareContext;
        mShareContext.iQueueFamilyIndex = mDevice->queueFamilyIndex();
        mShareContext.pDevice = mDevice->get();
        mShareContext.pInstance = mInstance->get();
        mShareContext.pPhysicalDevice = mDevice->physicalDevice();
        mShareContext.pQueue = mDevice->queue();
        bnConfig.sharedContext = &mShareContext;
        config.backendConfig = &bnConfig;
        /*创建 session 或者 module */
  1. 获取 vulkan 内存,然后用 vulkan 的API复制数据过去,或者直接使用输出的数据
MNNVulkanTensorContent dst;
tensor->getDeviceInfo(&dst, MNN_FORWARD_VULKAN);

3.同步(获取的Vulkan内存有可能并没有计算完成,此时需要先同步 )

tensor->wait

@jxt1234 jxt1234 added the User The user ask question about how to use. Or don't use MNN correctly and cause bug. label Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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