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] fix opencl multi-thread CL_INVALID_CONTEXT #10529

Merged
merged 1 commit into from
Jul 24, 2024
Merged

[OpenCL] fix opencl multi-thread CL_INVALID_CONTEXT #10529

merged 1 commit into from
Jul 24, 2024

Conversation

wasupandceacar
Copy link
Contributor

PR devices

OpenCL

PR types

Bug fixes

PR changes

Backends

Description

Fix CL_INVALID_CONTEXT error when the model does predictions in multiple threads.

Previous issues: #9931 #10267

Caused by

thread_local CLRuntime cl_runtime_;

Use local_thread here will lead to different opencl contexts in different threads, as mentioned in #9931 (comment). Also, this is not a good solution, as discussed in #7888 (comment), which will cause other bugs.

New solution: Use single instance, all threads share a global CLRuntime.

Copy link

paddle-bot bot commented Jul 2, 2024

Thanks for your contribution!

@wasupandceacar
Copy link
Contributor Author

@zhupengyang
@hong19860320

@wasupandceacar
Copy link
Contributor Author

@zhupengyang @hong19860320

@wasupandceacar
Copy link
Contributor Author

@zhupengyang @hong19860320 一直没人啊老铁

@wasupandceacar
Copy link
Contributor Author

@zhupengyang @hong19860320

@wasupandceacar
Copy link
Contributor Author

@zhupengyang @hong19860320 你们这还有没有人维护

@wasupandceacar
Copy link
Contributor Author

@hong19860320 @zhupengyang 两周了还没人回复?

@wasupandceacar
Copy link
Contributor Author

@hong19860320 @zhupengyang
是没人 review 得了还是怎么了,吱个声,我看比我新的 pr 都 merge 了

Copy link
Collaborator

@zhupengyang zhupengyang left a comment

Choose a reason for hiding this comment

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

LGTM

@hong19860320 hong19860320 merged commit 0bc42cd into PaddlePaddle:develop Jul 24, 2024
44 of 45 checks passed
@xiebaiyuan
Copy link
Collaborator

建议测试一下两个线程同时跑两个OpenCL模型的情况。 隐约记得之前 @zhaoyang-star 添加这个是为了解决这个问题。

hong19860320 pushed a commit that referenced this pull request Aug 26, 2024
* [Doc] fix doc/index.rst (#10530)

Co-authored-by: chenhuan09 <chenhuan09@baidu.com>

* [PASS] xpu__fc_fuse_pass batchnorm fusion (#10532)

* [XPU] modify xpu_fc_pass to fused bn to xpu_fc

* [XPU] add int8 support for bn fc fusion

* [XPU] fix codestyle

* [XPU] remove unused code

* [OpenCL] Fix multi-thread CL_INVALID_CONTEXT (#10529)

* [Metal] Fix project build metal shader bugs (#10544)

* [Metal] Fix concat error, fix fetch typo error (#10541)
* [Metal] fix build_xcode.sh error, add building with metal option (#10542)

* [XPU] Add greedy L3 tune strategy (#10546)

* support search gan model. 1.add pixel_unshuffle support &2.enable fill_constant calc offline on arm and opencl & 3.enable reshape_calc_offline_pass on arm and opencl  (#10537)

* support search gan model.
1. add pixel_unshuffle support
2. enable fill_constant calc offline on arm and opencl
3. enable reshape_calc_offline_pass on arm and opencl
4. use chinese comments
5. add test for new kernel.
test=develop

* support search gan model.
1. add pixel_unshuffle support
2. enable fill_constant calc offline on arm and opencl
3. enable reshape_calc_offline_pass on arm and opencl
4. use chinese comments
5. add test for new kernel.
test=develop

* support search gan model.
1. add pixel_unshuffle support
2. enable fill_constant calc offline on arm and opencl
3. enable reshape_calc_offline_pass on arm and opencl
4. use chinese comments
5. add test for new kernel.
6. fix metal pre-commit
test=develop

* [Doc] Update python_demo.md (#10555)

* [OpenCL] fix opencl init bugs & optimize :do not create opencl when user do not use Use opencl. auto enable opencl when opencl model load and opencl check or config. (#10557)

* [OpenCL]do not init OpenCL runtime if use a arm only model, when LITE_WITH_OPENCL ENABLED

test=develop

* [OpenCL] fix opencl init bugs. reduce opencl memory when not use opencl models
1. add one way to allow use to close opencl, to reduce memory.
2. create opencl runtime and context when use , avoid of static loading.
3. if use an arm model , do not create opencl runtime / context.
4. when find opencl target kernel , create opencl.
test=develop

* [OpenCL] fix opencl init bugs. do not create opencl when user do not use Use opencl. auto enable opencl when opencl model load and opencl check or config.

1. create opencl runtime and context when use , avoid of static loading.
2. if use an arm model , do not create opencl runtime / context.
3. when find opencl target kernel , create opencl.
4. when opencl env check found, enable opencl
test=develop

* [OpenCL] fix opencl init bugs. do not create opencl when user do not use Use opencl. auto enable opencl when opencl model load and opencl check or config.
5. default make option on, to let user feel nothing. add api for Professional users
test=develop

* [OpenCL] fix opencl init bugs. do not create opencl when user do not use Use opencl. auto enable opencl when opencl model load and opencl check or config.
5. only reset flag once
test=develop

* [OpenCL] fix opencl init bugs. do not create opencl when user do not use Use opencl. auto enable opencl when opencl model load and opencl check or config.
6.fix pr review
test=develop

* [OpenCL] fix opencl init bugs. do not create opencl when user do not use Use opencl. auto enable opencl when opencl model load and opencl check or config.
6.fix pr review
test=develop

* [OpenCL] fix opencl init bugs. do not create opencl when user do not use Use opencl. auto enable opencl when opencl model load and opencl check or config.
6.fix pr review
test=develop

* [OpenCL] fix opencl init bugs. do not create opencl when user do not use Use opencl. auto enable opencl when opencl model load and opencl check or config.
6.fix pr review
test=develop

* [OpenCL] fix opencl init bugs. do not create opencl when user do not use Use opencl. auto enable opencl when opencl model load and opencl check or config.
6.fix pr review
test=develop

* [OpenCL] fix opencl init bugs. do not create opencl when user do not use Use opencl. auto enable opencl when opencl model load and opencl check or config.
6.fix pr review
test=develop

* [OpenCL] fix opencl init bugs. do not create opencl when user do not use Use opencl. auto enable opencl when opencl model load and opencl check or config.
6.fix pr review
test=develop

* [OpenCL] fix opencl init bugs. do not create opencl when user do not use Use opencl. auto enable opencl when opencl model load and opencl check or config.
6.fix pr review
test=develop

---------

Co-authored-by: cmcamdy <1027740945@qq.com>
Co-authored-by: chenhuan09 <chenhuan09@baidu.com>
Co-authored-by: GaoYuYang <gaomeyy@gmail.com>
Co-authored-by: wasupandceacar <wasupandceacar@gmail.com>
Co-authored-by: newway <237745+newway@users.noreply.github.com>
Co-authored-by: xiebaiyuan <xiebaiyuan@139.com>
Co-authored-by: Kayzwer <68285002+Kayzwer@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants