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] Save kernel cache & tuned params immediatelly #6440

Merged

Conversation

zhaoyang-star
Copy link
Collaborator

@zhaoyang-star zhaoyang-star commented Jul 9, 2021

【问题1】
单线程单个模型运行时,在 APP 环境下无法保存 cache 文件。

【原因分析】

  • 原始版本中,将 kernel cache 和 tuned 参数文件保存到磁盘的操作是发生在 CLRuntime 全局单例类的析构函数中。在 adb shell 环境下,CLRuntime 单例类的析构函数在程序结束时一定会被调用到,因此可以正常触发保存文件操作;
  • 但是当在APP环境下,当APP退出时,CLRuntime 全局单例类的析构函数并不会被执行到,因此无法触发保存文件操作。

【解决方法】
将保存文件操作提前,放在RuntimeProgram类的析构函数内执行,确保 APP 退出时一定执行保存文件操作。

【问题2】
在一个线程内,串行执行 2 个模型,在 adb shell 环境下只保存了第1个模型对应的 cache 文件,无法保存第2个模型对应的 cache 文件。
【原因分析】
SetBinaryPathName函数中,对kernel_path_name_变量是直接通过push_back赋值,然后在GetBinaryPathName函数中,通过at(0)/at(1)方法获得的永远都是第一个path/name。因此需要在push_backclear数据。
【解决方法】
push_back前执行clear

【问题3】
在N个线程下,每个线程有自己的 predictor,并行执行N个模型,在 adb shell 环境下无法正常保存N个模型的对应的N个 cache file。
【原因分析】
CLRuntime是一个单例类,因此该类的成员变量并不是线程安全的,也就会出现binary_path_name_只保存了其中一个模型对应的设置。
【解决方法】
通过定义一个thread_local的实例,实现该实例在每个线程内是唯一的。

@paddle-bot-old
Copy link

paddle-bot-old bot commented Jul 9, 2021

Thanks for your contribution!

@zhaoyang-star zhaoyang-star requested a review from xiebaiyuan July 9, 2021 05:38
lite/core/program.cc Outdated Show resolved Hide resolved
xiebaiyuan
xiebaiyuan previously approved these changes Jul 12, 2021
Copy link
Collaborator

@xiebaiyuan xiebaiyuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@xiebaiyuan xiebaiyuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
关于localthread,需要充分测试。

Copy link
Collaborator

@xiebaiyuan xiebaiyuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@xiebaiyuan xiebaiyuan self-requested a review July 19, 2021 06:44
Copy link
Collaborator

@xiebaiyuan xiebaiyuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not work on app

Copy link
Collaborator

@xiebaiyuan xiebaiyuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zhaoyang-star zhaoyang-star merged commit b6f578a into PaddlePaddle:develop Jul 21, 2021
@zhaoyang-star zhaoyang-star deleted the SaveProgramAfterFirstRun branch July 21, 2021 12:44
zhaoyang-star added a commit to zhaoyang-star/Paddle-Lite that referenced this pull request Jul 22, 2021
…addlePaddle#6440)

* move save to destructor of RuntimeProgram

* fix multi models executed in sequential way in one thread

* support multi-thread executation
zhaoyang-star added a commit that referenced this pull request Jul 22, 2021
…lti-threads (#6542)

* [OpenCL] Save kernel cache & tuned params for APP and multi-threads (#6440)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants