Skip to content
This repository has been archived by the owner on May 17, 2023. It is now read-only.

Improve selection of OpenCL platform and target device #2043

Closed
wants to merge 3 commits into from

Conversation

albelyakov
Copy link

No description provided.

@albelyakov albelyakov requested a review from a team as a code owner March 26, 2020 08:52

for(std::vector<std::string>::iterator extNameIt = m_requiredOclExtensions.begin(); extNameIt != m_requiredOclExtensions.end(); ++extNameIt)
{
isDeviceAppropriate = isDeviceAppropriate && (std::strstr(&extNamesBuffer[0], extNameIt->c_str()) != NULL);
Copy link
Contributor

Choose a reason for hiding this comment

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

why do you check the first extension only: extNamesBuffer[0]? the one you need might not be the first one.

Copy link
Author

Choose a reason for hiding this comment

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

& extNamesBuffer[0] was a way to access all vector elements. Changed it to vector.data()


bool isDeviceAppropriate = true;

for(std::vector<std::string>::iterator extNameIt = m_requiredOclExtensions.begin(); extNameIt != m_requiredOclExtensions.end(); ++extNameIt)
Copy link
Contributor

Choose a reason for hiding this comment

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

for (const auto& ext: m_requireOclExtensions) form would be preferable whenever possible.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, definitely.

for(std::vector<std::string>::iterator extNameIt = m_requiredOclExtensions.begin(); extNameIt != m_requiredOclExtensions.end(); ++extNameIt)
{
isDeviceAppropriate = isDeviceAppropriate && (std::strstr(&extNamesBuffer[0], extNameIt->c_str()) != NULL);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Well, you actually did not check for required extensions... You checked that the first extension reported is in your whitelist.

Copy link
Author

Choose a reason for hiding this comment

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

& extNamesBuffer[0] was a way to access all vector elements, so all of the extensions were checked. Changed it to vector.data()

}
}

_select_platform_loop_end:
Copy link
Contributor

Choose a reason for hiding this comment

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

you can achieve pretty the same without goto label. Just return from the function when you need to.

Copy link
Author

Choose a reason for hiding this comment

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

Changed.

continue;
}

size_t extNamesBufferSize = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

I would rename these variables to something more simple. extensionsNum and extensions would be better

Copy link
Author

Choose a reason for hiding this comment

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

Renamed.

*) For-each.
*) Defines.
*) vector.data usage instead of &vector[0].
Copy link
Contributor

@onabiull onabiull left a comment

Choose a reason for hiding this comment

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

I'm going to squash these commits to a single commit upon merge.
@dvrogozh your call?


if(strstr(platform, "Intel")) // Use only Intel platfroms
error = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, devices.size(), &devices[0], 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

&devices[0] -> devices.data()

#include "opencl_filter_dx11.h"
#include "sample_defs.h"

#include "stdexcept"

// INTEL DX9 sharing functions declared deprecated in OpenCL 1.2
Copy link
Contributor

Choose a reason for hiding this comment

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

why this is applicable for dx11.cpp file? both comment and pragma-warning?

@@ -10,11 +10,9 @@ include_directories (

set( LDFLAGS "${LDFLAGS} -Wl,--version-script=${PLUGINS_COMMON_PATH}/mfx_plugin.map" )

# for clCreateFromGLTexture2D and clCreateFromGLTexture3D in CL/cl_gl.h
set( CFLAGS "-DCL_USE_DEPRECATED_OPENCL_1_1_APIS" )
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need CL_USE_DEPRECATED_OPENCL_1_1_APIS?

#include <va/va.h>
#define CL_USE_DEPRECATED_OPENCL_1_1_APIS 1
#endif

#undef CL_VERSION_1_2
Copy link
Contributor

Choose a reason for hiding this comment

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

where do we define CL_VERSION_1_2 and why do we need undef?

#include <CL/cl_d3d11.h>

using std::endl;

#define INIT_CL_EXT_FUNC(x) x = (x ## _fn)clGetExtensionFunctionAddress(#x);
#define SAFE_OCL_FREE(P, FREE_FUNC) { if (P) { FREE_FUNC(P); P = NULL; } }

#define MAX_PLATFORMS 32
Copy link
Contributor

Choose a reason for hiding this comment

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

please, check whether we need these 2 defines? I thought we've moved to std::vector?

onabiull pushed a commit to onabiull/MediaSDK that referenced this pull request Jul 30, 2020
Remove outdated include and defines. Amendment for Intel-Media-SDK#2190.
Includes changes from Intel-Media-SDK#2043

Co-authored-by: abelaykov <belaykov.alexander.a@gmail.com>
onabiull pushed a commit that referenced this pull request Jul 31, 2020
Remove outdated include and defines. Amendment for #2190.
Includes changes from #2043

Co-authored-by: abelaykov <belaykov.alexander.a@gmail.com>
@onabiull
Copy link
Contributor

Changes merged with minimal modifications as part of #2243.

@onabiull onabiull closed this Jul 31, 2020
onabiull pushed a commit to onabiull/MediaSDK that referenced this pull request Aug 3, 2020
Remove outdated include and defines. Amendment for Intel-Media-SDK#2190.
Includes changes from Intel-Media-SDK#2043

Co-authored-by: abelaykov <belaykov.alexander.a@gmail.com>
onabiull pushed a commit that referenced this pull request Aug 3, 2020
Remove outdated include and defines. Amendment for #2190.
Includes changes from #2043

Co-authored-by: abelaykov <belaykov.alexander.a@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants