Skip to content

Rewrote OpenCL-OpenGL-interop device discovery routine without extensions and with Apple support#26281

Merged
asmorkalov merged 7 commits intoopencv:4.xfrom
kallaballa:clgl_device_discovery
Oct 18, 2024
Merged

Rewrote OpenCL-OpenGL-interop device discovery routine without extensions and with Apple support#26281
asmorkalov merged 7 commits intoopencv:4.xfrom
kallaballa:clgl_device_discovery

Conversation

@kallaballa
Copy link
Copy Markdown
Contributor

@kallaballa kallaballa commented Oct 9, 2024

WIP

Issue: #26273
Supersedes: #26274

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

@kallaballa
Copy link
Copy Markdown
Contributor Author

Build error seems to be an unrelated timeout. checking.

@kallaballa
Copy link
Copy Markdown
Contributor Author

Build error is an unrelated case of: #24731

@kallaballa
Copy link
Copy Markdown
Contributor Author

kallaballa commented Oct 10, 2024

Will have access to a Mac this evening to do final testing on that plarform.

@kallaballa
Copy link
Copy Markdown
Contributor Author

kallaballa commented Oct 11, 2024

Works on linux/nvidia, linux/intel and mac - currently can't test on windows. I think this is ready.

{
AutoBuffer<char> extensionStr;
try {
devices = new cl_device_id[devCnt];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's use std::vector<> or cv::AutoBuffer for locals to prevent leaks.

char* extensions = nullptr;

try {
extensions = new char[extensionSize];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The same on memory management.

@asmorkalov asmorkalov self-assigned this Oct 14, 2024
@asmorkalov asmorkalov added this to the 4.11.0 milestone Oct 14, 2024
Comment on lines +1697 to +1724
std::string devString;

if(extensions != nullptr) {
devString = extensions;
delete[] extensions;
}
else {
CV_Error(cv::Error::OpenCLInitError, "OpenCL: Unexpected error during device extensions gathering");
}

size_t oldPos = 0;
size_t spacePos = devString.find(' ', oldPos); // extensions string is space delimited
while (spacePos != devString.npos) {
if (strcmp(GL_SHARING_EXTENSION,
devString.substr(oldPos, spacePos - oldPos).c_str())
== 0) {
// Device supports context sharing with OpenGL
devUsed = i;
sharingSupported = true;
break;
}
do {
oldPos = spacePos + 1;
spacePos = devString.find(' ', oldPos);
} while (spacePos == oldPos);
}
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's extract extension search as dedicated static function. It should make the code more readable.

@asmorkalov
Copy link
Copy Markdown
Contributor

Works with Ubuntu 18.04 and NVIDIA GF1080.

@asmorkalov asmorkalov merged commit e026a5a into opencv:4.x Oct 18, 2024
@asmorkalov asmorkalov mentioned this pull request Oct 23, 2024
@kallaballa
Copy link
Copy Markdown
Contributor Author

I'd still perform the proposals from review. should i?

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.

2 participants