From ee68d26f9970f1c400d4c5dbe062586d920988b6 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 10 Jun 2015 14:09:24 +0300 Subject: [PATCH] ocl: update generator scripts --- .../opencv2/core/opencl/runtime/opencl_gl.hpp | 65 +++++++++++++++++++ .../opencl/runtime/opencl_gl_wrappers.hpp | 47 ++++++++++++++ .../src/opencl/runtime/generator/generate.sh | 2 + .../src/opencl/runtime/generator/parser_cl.py | 32 +++++---- .../generator/template/opencl_gl.hpp.in | 17 +++++ .../generator/template/opencl_gl_impl.hpp.in | 11 ++++ .../template/opencl_gl_wrappers.hpp.in | 5 ++ .../core/src/opencl/runtime/opencl_core.cpp | 26 ++++++++ 8 files changed, 194 insertions(+), 11 deletions(-) create mode 100644 modules/core/include/opencv2/core/opencl/runtime/opencl_gl.hpp create mode 100644 modules/core/include/opencv2/core/opencl/runtime/opencl_gl_wrappers.hpp create mode 100644 modules/core/src/opencl/runtime/generator/template/opencl_gl.hpp.in create mode 100644 modules/core/src/opencl/runtime/generator/template/opencl_gl_impl.hpp.in create mode 100644 modules/core/src/opencl/runtime/generator/template/opencl_gl_wrappers.hpp.in diff --git a/modules/core/include/opencv2/core/opencl/runtime/opencl_gl.hpp b/modules/core/include/opencv2/core/opencl/runtime/opencl_gl.hpp new file mode 100644 index 0000000000..7c7a82e9ea --- /dev/null +++ b/modules/core/include/opencv2/core/opencl/runtime/opencl_gl.hpp @@ -0,0 +1,65 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the OpenCV Foundation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef __OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_HPP__ +#define __OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_HPP__ + +#if defined HAVE_OPENCL && defined HAVE_OPENGL + +#include "opencl_core.hpp" + +#if defined(HAVE_OPENCL_STATIC) + +#if defined __APPLE__ +#include +#else +#include +#endif + +#else // HAVE_OPENCL_STATIC + +#include "autogenerated/opencl_gl.hpp" + +#endif // HAVE_OPENCL_STATIC + +#endif // defined HAVE_OPENCL && defined HAVE_OPENGL + +#endif // __OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_HPP__ diff --git a/modules/core/include/opencv2/core/opencl/runtime/opencl_gl_wrappers.hpp b/modules/core/include/opencv2/core/opencl/runtime/opencl_gl_wrappers.hpp new file mode 100644 index 0000000000..9327d2ede6 --- /dev/null +++ b/modules/core/include/opencv2/core/opencl/runtime/opencl_gl_wrappers.hpp @@ -0,0 +1,47 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the OpenCV Foundation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef __OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_WRAPPERS_HPP__ +#define __OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_WRAPPERS_HPP__ + +#include "autogenerated/opencl_gl_wrappers.hpp" + +#endif // __OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_WRAPPERS_HPP__ diff --git a/modules/core/src/opencl/runtime/generator/generate.sh b/modules/core/src/opencl/runtime/generator/generate.sh index 8649e99843..d9d6f0e3e8 100644 --- a/modules/core/src/opencl/runtime/generator/generate.sh +++ b/modules/core/src/opencl/runtime/generator/generate.sh @@ -3,4 +3,6 @@ echo "Generate files for CL runtime..." python parser_cl.py opencl_core < sources/cl.h python parser_clamdblas.py < sources/clAmdBlas.h python parser_clamdfft.py < sources/clAmdFft.h + +python parser_cl.py opencl_gl < sources/cl_gl.h echo "Generate files for CL runtime... Done" diff --git a/modules/core/src/opencl/runtime/generator/parser_cl.py b/modules/core/src/opencl/runtime/generator/parser_cl.py index 87eeb27236..e6c738bef7 100644 --- a/modules/core/src/opencl/runtime/generator/parser_cl.py +++ b/modules/core/src/opencl/runtime/generator/parser_cl.py @@ -8,9 +8,10 @@ from common import remove_comments, getTokens, getParameters, postProcessParamet try: if len(sys.argv) > 1: - outfile = open('../../../../include/opencv2/core/opencl/runtime/autogenerated/' + sys.argv[1] + '.hpp', 'wb') - outfile_impl = open('../autogenerated/' + sys.argv[1] + '_impl.hpp', 'wb') - outfile_wrappers = open('../../../../include/opencv2/core/opencl/runtime/autogenerated/' + sys.argv[1] + '_wrappers.hpp', 'wb') + module_name = sys.argv[1] + outfile = open('../../../../include/opencv2/core/opencl/runtime/autogenerated/%s.hpp' % module_name, 'wb') + outfile_impl = open('../autogenerated/%s_impl.hpp' % module_name, 'wb') + outfile_wrappers = open('../../../../include/opencv2/core/opencl/runtime/autogenerated/%s_wrappers.hpp' % module_name, 'wb') if len(sys.argv) > 2: f = open(sys.argv[2], "r") else: @@ -95,7 +96,7 @@ pprint(fns) from common import * -filterFileName='./filter/opencl_core_functions.list' +filterFileName = './filter/%s_functions.list' % module_name numEnabled = readFunctionFilter(fns, filterFileName) functionsFilter = generateFilterNames(fns) @@ -108,18 +109,27 @@ ctx['CL_REMAP_DYNAMIC'] = generateRemapDynamic(fns) ctx['CL_FN_DECLARATIONS'] = generateFnDeclaration(fns) sys.stdout = outfile -ProcessTemplate('template/opencl_core.hpp.in', ctx) +ProcessTemplate('template/%s.hpp.in' % module_name, ctx) ctx['CL_FN_INLINE_WRAPPERS'] = generateInlineWrappers(fns) sys.stdout = outfile_wrappers -ProcessTemplate('template/opencl_core_wrappers.hpp.in', ctx) +ProcessTemplate('template/%s_wrappers.hpp.in' % module_name, ctx) -ctx['CL_FN_ENTRY_DEFINITIONS'] = generateStructDefinitions(fns) -ctx['CL_FN_ENTRY_LIST'] = generateListOfDefinitions(fns) -ctx['CL_FN_ENUMS'] = generateEnums(fns) -ctx['CL_FN_SWITCH'] = generateTemplates(15, 'opencl_fn', 'opencl_check_fn', 'CL_API_CALL') +if module_name == 'opencl_core': + ctx['CL_FN_ENTRY_DEFINITIONS'] = generateStructDefinitions(fns) + ctx['CL_FN_ENTRY_LIST'] = generateListOfDefinitions(fns) + ctx['CL_FN_ENUMS'] = generateEnums(fns) + ctx['CL_FN_SWITCH'] = generateTemplates(15, 'opencl_fn', 'opencl_check_fn', 'CL_API_CALL') +else: + lprefix = module_name + '_fn' + enumprefix = module_name.upper() + '_FN' + fn_list_name = module_name + '_fn_list' + ctx['CL_FN_ENTRY_DEFINITIONS'] = generateStructDefinitions(fns, lprefix=lprefix, enumprefix=enumprefix) + ctx['CL_FN_ENTRY_LIST'] = generateListOfDefinitions(fns, fn_list_name) + ctx['CL_FN_ENUMS'] = generateEnums(fns, prefix=enumprefix) + ctx['CL_FN_SWITCH'] = generateTemplates(15, lprefix, '%s_check_fn' % module_name, 'CL_API_CALL') ctx['CL_NUMBER_OF_ENABLED_FUNCTIONS'] = '// number of enabled functions: %d' % (numEnabled) sys.stdout = outfile_impl -ProcessTemplate('template/opencl_core_impl.hpp.in', ctx) +ProcessTemplate('template/%s_impl.hpp.in' % module_name, ctx) diff --git a/modules/core/src/opencl/runtime/generator/template/opencl_gl.hpp.in b/modules/core/src/opencl/runtime/generator/template/opencl_gl.hpp.in new file mode 100644 index 0000000000..28c342f3a1 --- /dev/null +++ b/modules/core/src/opencl/runtime/generator/template/opencl_gl.hpp.in @@ -0,0 +1,17 @@ +#ifndef __OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_HPP__ +#error "Invalid usage" +#endif + +@CL_REMAP_ORIGIN@ + +#if defined __APPLE__ +#include +#include +#else +#include +#include +#endif + +@CL_REMAP_DYNAMIC@ + +@CL_FN_DECLARATIONS@ diff --git a/modules/core/src/opencl/runtime/generator/template/opencl_gl_impl.hpp.in b/modules/core/src/opencl/runtime/generator/template/opencl_gl_impl.hpp.in new file mode 100644 index 0000000000..14586017a4 --- /dev/null +++ b/modules/core/src/opencl/runtime/generator/template/opencl_gl_impl.hpp.in @@ -0,0 +1,11 @@ +@CL_FN_ENUMS@ + +namespace { +@CL_FN_SWITCH@ +} // anonymous namespace + +@CL_FN_ENTRY_DEFINITIONS@ + +@CL_FN_ENTRY_LIST@ + +@CL_NUMBER_OF_ENABLED_FUNCTIONS@ diff --git a/modules/core/src/opencl/runtime/generator/template/opencl_gl_wrappers.hpp.in b/modules/core/src/opencl/runtime/generator/template/opencl_gl_wrappers.hpp.in new file mode 100644 index 0000000000..0aeefb4f44 --- /dev/null +++ b/modules/core/src/opencl/runtime/generator/template/opencl_gl_wrappers.hpp.in @@ -0,0 +1,5 @@ +#ifndef __OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_WRAPPERS_HPP__ +#error "Invalid usage" +#endif + +@CL_FN_INLINE_WRAPPERS@ diff --git a/modules/core/src/opencl/runtime/opencl_core.cpp b/modules/core/src/opencl/runtime/opencl_core.cpp index 43f6b13b6e..971c0770e5 100644 --- a/modules/core/src/opencl/runtime/opencl_core.cpp +++ b/modules/core/src/opencl/runtime/opencl_core.cpp @@ -279,4 +279,30 @@ static void* opencl_check_fn(int ID) return func; } +#ifdef HAVE_OPENGL + +#include "opencv2/core/opencl/runtime/opencl_gl.hpp" + +static void* opencl_gl_check_fn(int ID); + +#include "autogenerated/opencl_gl_impl.hpp" + +static void* opencl_gl_check_fn(int ID) +{ + const struct DynamicFnEntry* e = NULL; + assert(ID >= 0 && ID < (int)(sizeof(opencl_gl_fn_list)/sizeof(opencl_gl_fn_list[0]))); + e = opencl_gl_fn_list[ID]; + void* func = CV_CL_GET_PROC_ADDRESS(e->fnName); + if (!func) + { + throw cv::Exception(cv::Error::OpenCLApiCallError, + cv::format("OpenCL function is not available: [%s]", e->fnName), + CV_Func, __FILE__, __LINE__); + } + *(e->ppFn) = func; + return func; +} + +#endif // HAVE_OPENGL + #endif