You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Holoscan C++中FormatConverterOp的pool参数配置及GXF_CONTEXT_INVALID错误排查求助

Holoscan C++中FormatConverterOp的pool参数配置及GXF_CONTEXT_INVALID错误排查求助

我最近在把Holoscan的「Bring Your Own Model」示例从Python转成C++实现,卡在了FormatConverterOp的内存池配置环节,折腾了好一阵都没搞定,想请教下各位大佬!

具体情况是这样的:
我需要用FormatConverterOp做视频帧的预处理,参考Python版本的配置,在C里给这个算子加了YAML配置,还自己加了pool参数(因为看资料说C版本的算子需要指定独立的内存空间):

preprocessor: #<< FormatConverterOp
  out_tensor_name: source_video
  out_dtype: "float32"
  resize_width: 256
  resize_height: 256
  pool: host_allocator #<< 我自己加的配置

接下来我尝试创建对应的内存分配器,一开始用UnboundedAllocator,代码如下:

// 先尝试创建UnboundedAllocator
shared_ptr<UnboundedAllocator> uba( new UnboundedAllocator("host_allocator", component));

这里的component需要是nvidia::gxf::UnboundedAllocator*类型,我就天真地直接new了一个:

shared_ptr<nvidia::gxf::UnboundedAllocator> component( new nvidia::gxf::UnboundedAllocator());

结果运行时直接报GXF_CONTEXT_INVALID错误,查文档说这个错误是上下文无效,但我尝试手动创建GXF上下文后还是没用:

// 尝试手动创建上下文的代码
global shared_ptr<nvidia::gxf::UnboundedAllocator> component;
gxf_context_t context;
shared_ptr<holoscan::UnboundedAllocator> uba;

void Ap_UsModel::compose() {
  component = shared_ptr<nvidia::gxf::UnboundedAllocator>(new nvidia::gxf::UnboundedAllocator());
  context = component->context();
  gxf_result_t err = GxfContextCreate(&context);
  std::cout << "After err '" << err << "': Context ptr: '" << (&context) << "'." << std::endl;
  uba = shared_ptr<UnboundedAllocator>(new UnboundedAllocator("host_allocator", component.get()));
  
  // 创建FormatConverterOp
  shared_ptr<holoscan::ops::FormatConverterOp> op_formatter = make_operator<holoscan::ops::FormatConverterOp>("preprocessor", from_config("preprocessor"));
  // ... 其他代码
}

打印出来err是0,上下文指针看起来也有效,但还是报同样的GXF上下文错误,错误日志是:

[info] [fragment.cpp:778] Loading extensions from configs...
[info] [gxf_executor.cpp:329] Creating context
After err '0': Context ptr: '0x641469c12aa0'.
[error] [gxf_resource.cpp:49] GXF call 'GxfComponentType(gxf_context_, gxf_cid_, &gxf_tid_)' in line 49 of file /workspace/holoscan-sdk/src/core/gxf/gxf_resource.cpp failed with 'GXF_CONTEXT_INVALID' (12)

后来我换成普通的Allocator试试,代码改成这样:

this->allocator = std::shared_ptr<Allocator>(new Allocator());
holoscan::ArgList al = from_config("preprocessor");
// 直接把Allocator作为pool参数添加
al.add(holoscan::Arg("pool", &allocator));
shared_ptr<holoscan::ops::FormatConverterOp> op_formatter = make_operator<holoscan::ops::FormatConverterOp>("preprocessor", al);

结果又遇到参数类型不匹配的错误,提示:

Unable to convert argument type 'PSt10shared_ptrIN8holoscan9AllocatorEE' to parameter type 'St10shared_ptrIN8holoscan9AllocatorEE' for 'pool'

我猜测这个错误和指针的前缀P有关,但试了各种指针转换和解引用都没解决,反而出现更多基础错误。

有没有大佬成功在C++里跑通FormatConverterOp的?能不能指点下正确的内存池(Allocator)创建和关联方式,还有这个GXF上下文的问题到底怎么解决?

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.08 03:08:12