-
Notifications
You must be signed in to change notification settings - Fork 465
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
【Hackthon_4th 180】Support HORIZON BPU Backend for FastDeploy #1822
Conversation
@DefTruth 有空可以帮review下嘛 |
好的,这两天会整体review一下哈,感谢您的贡献~ |
FastDeploy.cmake.in
Outdated
@@ -167,6 +168,23 @@ if(ENABLE_RKNPU2_BACKEND) | |||
list(APPEND FASTDEPLOY_LIBS ${RKNPU2_LIB}) | |||
endif() | |||
|
|||
if(ENABLE_HORIZON_BACKEND) | |||
set(DNN_PATH "~/.horizon/ddk/xj3_aarch64/dnn/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个路径不能是绝对路径,可以参考paddlelite.cmake的处理。不属于系统so的,需要从云端下载,并安装到用户的编译环境。可以打包一下成tgz提供给我们哈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
系统的package和编译器都打包好了,我怎么发你呢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seyosum 贴个下载链接到这个评论即可
FastDeploy.cmake.in
Outdated
@@ -167,6 +168,23 @@ if(ENABLE_RKNPU2_BACKEND) | |||
list(APPEND FASTDEPLOY_LIBS ${RKNPU2_LIB}) | |||
endif() | |||
|
|||
if(ENABLE_HORIZON_BACKEND) | |||
set(DNN_PATH "~/.horizon/ddk/xj3_aarch64/dnn/") | |||
set(APPSDK_PATH "~/.horizon/ddk/xj3_aarch64/appsdk/appuser/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
cmake/horizon.cmake
Outdated
@@ -0,0 +1,12 @@ | |||
set(DNN_PATH "~/.horizon/ddk/xj3_aarch64/dnn/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上,不能是绝对路径,请参考paddlelite.cmake的处理
set(APPSDK_LIB_PATH ${APPSDK_PATH}/lib/hbbpu) | ||
set(BPU_libs dnn cnn_intf hbrt_bernoulli_aarch64) | ||
|
||
include_directories(${DNN_PATH}/include |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里需要使用 ExternalProject_Add 的方式进行下载和配置
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这块目前我还没搞清楚ExternalProject_Add这个的用法,之前没用过😂😂😂,我了解下之后更新吧
set(CMAKE_CXX_STANDARD 14) | ||
|
||
# 指定下载解压后的fastdeploy库路径 | ||
set(FASTDEPLOY_INSTALL_DIR "/home/xuhao/Hackathon/FastDeploy/build/fastdeploy-0.0.0") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个路径不能hardcode,参考其他examples的写法,可以让用户设置
@@ -110,6 +118,9 @@ std::vector<Backend> GetAvailableBackends() { | |||
#ifdef ENABLE_RKNPU2_BACKEND | |||
backends.push_back(Backend::RKNPU2); | |||
#endif | |||
#ifdef ENABLE_HORIZON_BACKEND |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个宏也需要在fastdeploy/core/config.h.in中增加下,可参考已有写法。
} | ||
bool HorizonBackend::Init(const RuntimeOption& runtime_option){ | ||
// Init model from file | ||
if (!this->LoadModel((char*)runtime_option.model_file.data())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FastDeploy统一不使用this关键字
} | ||
|
||
int ret = -1; | ||
if(!this->infer_init){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
类私有成员使用下划线结尾
input_mems_ = (hbDNNTensor*)malloc(sizeof(hbDNNTensor) * input_count); | ||
output_mems_ = (hbDNNTensor*)malloc(sizeof(hbDNNTensor) * output_count); | ||
|
||
for(uint32_t i = 0; i < input_count; i++){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以参考Paddle Lite后端中的写法,增加推理benchmark宏,以支持benchmark功能,对推理块进行包裹。
RUNTIME_PROFILE_LOOP_BEGIN(1) |
更详细的说明,还可以参考这个PR:
编译带benchmark功能的SDK,需要-DENABLE_BENCHMARK=ON
@@ -65,6 +65,10 @@ void RuntimeOption::UseRKNPU2(fastdeploy::rknpu2::CpuName rknpu2_name, | |||
device = Device::RKNPU; | |||
} | |||
|
|||
void RuntimeOption::UseHorizon(){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UseHorizon()是指硬件的含义?是否应该提供UseHorizonNPUBackend() API设置backend=Backend::HORIZONNPU?可以参考Sophgo/RKNPU2的写法。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UseHorizon()这块指的是使用地平线backends,我理解之后会有不同的芯片,目前还没有改这部分,之后如果有新增的话可以考虑加参数。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果是使用具体的推理后端,需要提供类似UseHorizonNPUBackend()来明确语义,Backend强调的是推理后端,比如UseCpu(), UseGpu(), UseKunlunXin()这些则是强调硬件(CPU/GPU/昆仑芯XPU等),强调硬件的接口会执行一些和硬件相关的初始化配置,比如UseGpu(), UseKunlunXin()需要指定device_id,UseKunlunXin()还需要指定L3 Cache size等。带Backend后缀的接口,则强调的是使用哪个推理后端,比如UsePaddleInferBackend(), UsePaddleLiteBackend()等。硬件配置 + 后端配置,形成一个完整的推理条件组合。举个例子:
// CPU + Paddle Inference
option.UseCpu();
option.UsePaddleInferBackend();
// CPU + OpenVINO
option.UseCpu();
option.UseOpenVINOBackend();
// GPU + Paddle Inference
option.UseGpu(); // device_id默认为0
option.UsePaddleInferBackend();
因此建议把硬件API和推理后端API区分开来,在地平线:
option.UseHorizon(); // 一般理解这个指定是硬件
option.UseHorizonNPUBackend(); // 指的是使用哪个推理后端
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这块我大致理解了,增加了这部分内容,infer demo也同步改啦
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seyosum LGTM ~
FastDeploy.cmake.in
Outdated
set(APPSDK_LIB_PATH ${APPSDK_PATH}/lib/hbbpu) | ||
set(BPU_libs dnn cnn_intf hbrt_bernoulli_aarch64) | ||
|
||
include_directories(${DNN_PATH}/include |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个include路径,在编译FD SDK后使用,是必须的吗?如果是必须的需要添加到FASTDEPLOY_INCS中,不是单独include_directories,参考:
list(APPEND FASTDEPLOY_INCS ${LITE_DIR}/include)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个是非必须的,我改下这块
model.GetPreprocessor().DisableNormalize(); | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
代码风格,需要先安装pre-commit check一下。
cd FastDeploy
sh ./commit-prepare.sh
# then commit your codes
return; | ||
} | ||
// print res | ||
// std::cout << res.Str() << std::endl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
删除无用代码
model.GetPostprocessor().ApplyNMS(); | ||
fastdeploy::vision::DetectionResult res; | ||
auto im = cv::imread(image_file); | ||
for(int i = 0; i < 100; i++){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
案例中不需要保留测速代码
fastdeploy/fastdeploy_model.cc
Outdated
} else if (runtime_option.device == Device::TIMVX) { | ||
} else if (runtime_option.device == Device::SUNRISENPU){ | ||
return CreateHorizonBackend(); | ||
}else if (runtime_option.device == Device::TIMVX) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
代码风格,else if前需要空格
PR types(PR类型)
Add Horizon backend
Description
1、Add Horizon backend
2、Clas model inference
3、PPYOLOE inference