Skip to content

Conversation

@vladimir-dudnik
Copy link
Contributor

new function,
cv::ocl::attachContext(String& platformName, void* platformID, void* context, void* deviceID)
which allow to attach externally created OpenCL context to OpenCV.

…* platformID, void* context, void* deviceID) which allow to attach externally created OpenCL context to OpenCV.
@vladimir-dudnik
Copy link
Contributor Author

@alalek @vpisarev @SergeySivolgin please review new function, cv::ocl::attachContext, which allows to attach externally created OpenCL context to OpenCV

Copy link
Member

Choose a reason for hiding this comment

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

If there is something wrong with OpenCL runtimes (you assume it and try to check this by "platformName"), then you may receive exception/crash during execution of this function, because pointer d is alien for OpenCV OpenCL runtime.
CV_OclDbgAssert is misused here. Errors should be raised anyway.
You didn't initialize pl variable, so if you bypass this error then value of this variable is undefined for code below.

I still believe that initializeContextFromHandle is enough. If you want to guard from mismatched OpenCL dlls you may try to use GetModuleHangle("OpenCL.dll) near LoadLibrary to bypass it (and you can use library same as user - in case of lazy OpenCL initialization).

Copy link
Contributor

Choose a reason for hiding this comment

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

rows & cols can be retrieved using clGetImageInfo() and should better be retrieved this way

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this function convert clBuffer not a clImage

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alalek Alexander, please take a look on new func convertFromBuffer. This function converts clBuffer allocated at user OpenCL code to UMat.

@vladimir-dudnik
Copy link
Contributor Author

@alalek @vpisarev please take a look, I've finished with attachContext, convertFromBuffer and sample opencl-interop

Copy link
Member

Choose a reason for hiding this comment

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

Code duplication is bad idea. Try to move all pieces (similar code for Mat) into header file

@vladimir-dudnik
Copy link
Contributor Author

@alalek @vpisarev @SergeySivolgin added convertFromImage func and updated sample

@alalek
Copy link
Member

alalek commented Jun 16, 2015

@vladimir-dudnik Could you add specification to API with requirements for input objects lifetime and input objects content modification? (Is there copy / move / map logic? sync / async "copy" processing?)

P.S. Please use doxygen supported comments. Example:
https://github.com/Itseez/opencv/blob/master/modules/core/include/opencv2/core/base.hpp#L322

Copy link
Member

Choose a reason for hiding this comment

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

cl_mem_obj --> cl_mem_buffer in convertFromBuffer
cl_mem_obj --> cl_mem_image in convertFromImage
?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added doxygen style comments

Copy link
Contributor

Choose a reason for hiding this comment

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

we don't need a separate header file. Use forward declaration:

// a.cpp
void func()
{ /* impl */}

and it can be used in:

// b.cpp
// forward declaration
void func();

static void func2()
{
    func(); // usage
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, done with fwd decls

Copy link
Member

Choose a reason for hiding this comment

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

It is dangerous, because you will not receive any compiler warning if you change implementation
It is better to add this include file before implementation into umatrix.cpp to track contract and implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not clear what do you mean? The linker will not resolve this ref if API changed.

Copy link
Member

Choose a reason for hiding this comment

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

Right, C++ name mangling save us in this case (but it will not help with extern "C")
Anyway, It is unclear and unnecessary code duplication.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TMBK declaration of functions in corresponding header file is better in case they are reffered from more than one compile unit. But different design policy might be used, do not know if "we do not need separate header file" stands for OpenCV design policy.

@alalek
Copy link
Member

alalek commented Jun 17, 2015

Great job!
👍

@SergeySivolgin
Copy link

I think we can merge this PR.

@alalek
Copy link
Member

alalek commented Jun 19, 2015

Are there any way to squash these 30+ commits? If no, I can do it manually before merge.

@alalek
Copy link
Member

alalek commented Jun 19, 2015

Merged as commit:
217dd63

mshabunin pushed a commit to mshabunin/opencv that referenced this pull request Aug 25, 2015
mshabunin pushed a commit to mshabunin/opencv that referenced this pull request Aug 25, 2015
Commits:
added new function, cv::ocl::attachContext(String& platformName, void* platformID, void* context, void* deviceID) which allow to attach externally created OpenCL context to OpenCV.
add definitions of clRetainDevice, clRetainContext funcs
removed definitions for clRetainContext, clRetainDevice
fixed build issue under Linux
fixed uninitialized vars, replace dbgassert in error handling
remove function which is not ready yet
add new function, cv::ocl::convertFromBuffer(int rows, int cols, int type, void* cl_mem_obj, UMat& dst, UMatUsageFlags usageFlags = cv::USAGE_DEFAULT) which attaches user allocated OpenCL clBuffer to UMat
uncommented clGetMemObjectInfo definition (otherwise prevent opencv build)
fixed build issue on linux and android
add step parameter to cv::ocl::convertFromBuffer func
suppress compile-time warning
added sample opencl-opencv interoperability (showcase for cv::ocl::convertFromBuffer func)
CMakeLists.txt modified to not create sample build script if OpenCL SDK not found in system
fixed build issue (apple opencl include dir and spaces in CMake file)
added call to clRetainContext for attachContext func and call to clRetainMemObject for convertFromBuffer func
uncommented clRetainMemObject definition
added comments and cleanup
add local path to cmake modules search dirs (instead of replacing)
remove REQUIRED for find_package call (sample build together with opencv). need to try standalone sample build
opencl-interop sample moved to standalone build
set minimum version requirement for sample's cmake to 3.1
put cmake_minimum_required under condition, so do not check if samples not builded
remove code dups for setSize, updateContinuityFlag, and finalizeHdr
commented out cmake_minimum_required(VERSION 3.1)
add safety check for cmake version
add convertFromImage func and update opencl-interop sample
uncommented clGetImageInfo defs
uncommented clEnqueueCopyImageToBuffer defs
fixed clEnqueueCopyImageToBuffer defs
add doxygen comments
remove doxygen @fn tag
try to restart buildbot
add doxygen comments to directx interop funcs
remove internal header, use fwd declarations in affected compile units instead
mshabunin pushed a commit to mshabunin/opencv that referenced this pull request Aug 25, 2015
Commits:
added new function, cv::ocl::attachContext(String& platformName, void* platformID, void* context, void* deviceID) which allow to attach externally created OpenCL context to OpenCV.
add definitions of clRetainDevice, clRetainContext funcs
removed definitions for clRetainContext, clRetainDevice
fixed build issue under Linux
fixed uninitialized vars, replace dbgassert in error handling
remove function which is not ready yet
add new function, cv::ocl::convertFromBuffer(int rows, int cols, int type, void* cl_mem_obj, UMat& dst, UMatUsageFlags usageFlags = cv::USAGE_DEFAULT) which attaches user allocated OpenCL clBuffer to UMat
uncommented clGetMemObjectInfo definition (otherwise prevent opencv build)
fixed build issue on linux and android
add step parameter to cv::ocl::convertFromBuffer func
suppress compile-time warning
added sample opencl-opencv interoperability (showcase for cv::ocl::convertFromBuffer func)
CMakeLists.txt modified to not create sample build script if OpenCL SDK not found in system
fixed build issue (apple opencl include dir and spaces in CMake file)
added call to clRetainContext for attachContext func and call to clRetainMemObject for convertFromBuffer func
uncommented clRetainMemObject definition
added comments and cleanup
add local path to cmake modules search dirs (instead of replacing)
remove REQUIRED for find_package call (sample build together with opencv). need to try standalone sample build
opencl-interop sample moved to standalone build
set minimum version requirement for sample's cmake to 3.1
put cmake_minimum_required under condition, so do not check if samples not builded
remove code dups for setSize, updateContinuityFlag, and finalizeHdr
commented out cmake_minimum_required(VERSION 3.1)
add safety check for cmake version
add convertFromImage func and update opencl-interop sample
uncommented clGetImageInfo defs
uncommented clEnqueueCopyImageToBuffer defs
fixed clEnqueueCopyImageToBuffer defs
add doxygen comments
remove doxygen @fn tag
try to restart buildbot
add doxygen comments to directx interop funcs
remove internal header, use fwd declarations in affected compile units instead
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.

5 participants