Skip to content

FIX: getting platformIDs in initializeContextFromD3D11Device - #14376

Merged
alalek merged 2 commits into
opencv:3.4from
masa-iwm:3.4
Apr 22, 2019
Merged

alalek merged 2 commits into
opencv:3.4from
masa-iwm:3.4

Conversation

@masa-iwm

Copy link
Copy Markdown
Contributor

This pullrequest changes

relates #13972

fix usage of clGetPlatformIDs in initializeContextFromD3D11Device

@alalek

alalek commented Apr 21, 2019

Copy link
Copy Markdown
Member

/cc @Mainvooid Could you take a look on this patch?

@Mainvooid

Mainvooid commented Apr 21, 2019 •

Copy link
Copy Markdown

This is not a bug, but the error message in line 269 is wrong.

CV_Error(cv::Error::OpenCLInitError, "OpenCL: Can't get number of platforms");

"OpenCL: Can't get number of platforms"
should be changed to
"OpenCL: Can't get platform ID"
@masa-iwm Can you revise and resubmit it?

@alalek

@masa-iwm

Copy link
Copy Markdown
Contributor Author

@Mainvooid Really? I think that platforms[i] will always be the value of the first platform.

status = clGetPlatformIDs(numPlatforms, &platforms[i], NULL);

In fact, samples/directx/d3d11_interop.cpp does not work property in my environment (OpenCL device No.0=Intel & No.1=NVIDIA, but primary DirectX device is NVIDIA), but it works correctly with my modified.

I think that your code does not specify platform index for clGetPlatformIDs in a for loop, and cannot specify platform index in clGetPlatformIDs.

@alalek

#endif
for (int i = 0; i < (int)numPlatforms; i++)
{
status = clGetPlatformIDs(numPlatforms, &platforms[i], NULL);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

&platforms[i]

Memory corruption was here if numPlatforms > 1

@Mainvooid

Copy link
Copy Markdown

@masa-iwm
I checked the documentation again, you are right. Since there is only one platform on my computer, I didn't find this error.
So it should be changed to the following code and placed in front.

status = clGetPlatformIDs(numPlatforms, &platforms[0], NULL);
if (status != CL_SUCCESS)
    CV_Error(cv::Error::OpenCLInitError, "OpenCL: Can't get platforms");

After this change, we can get a list of OCL platforms found outside the for loop and then check required extensions for each platform within the for loop.

@alalek
alalek merged commit 5c404bb into opencv:3.4 Apr 22, 2019
@alalek alalek mentioned this pull request Apr 22, 2019
SavyaSanchi-Sharma pushed a commit to SavyaSanchi-Sharma/opencv that referenced this pull request Jul 30, 2026
* fix getting platformIDs in initializeContextFromD3D11Device
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.

3 participants