diff --git a/CMakeLists.txt b/CMakeLists.txt index 69b9c4a5d..9dc03b043 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,8 @@ #Minimum CMake version cmake_minimum_required(VERSION 3.2) +project(VisionCpp) + if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release diff --git a/cmake/Modules/ComputeCppCompilerChecks.cmake b/cmake/Modules/ComputeCppCompilerChecks.cmake new file mode 100644 index 000000000..b6eb8961c --- /dev/null +++ b/cmake/Modules/ComputeCppCompilerChecks.cmake @@ -0,0 +1,50 @@ +cmake_minimum_required(VERSION 3.4.3) + +if(CMAKE_COMPILER_IS_GNUCXX) + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8) + message(FATAL_ERROR "host compiler - gcc version must be > 4.8") + endif() +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + if (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 3.6) + message(FATAL_ERROR "host compiler - clang version must be > 3.6") + endif() +endif() + +if(MSVC) + set(ComputeCpp_STL_CHECK_SRC __STL_check) + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${ComputeCpp_STL_CHECK_SRC}.cpp + "#include \n" + "int main() { return 0; }\n") + execute_process( + COMMAND ${ComputeCpp_DEVICE_COMPILER_EXECUTABLE} + ${COMPUTECPP_DEVICE_COMPILER_FLAGS} + -isystem ${ComputeCpp_INCLUDE_DIRS} + -o ${ComputeCpp_STL_CHECK_SRC}.sycl + -c ${ComputeCpp_STL_CHECK_SRC}.cpp + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + RESULT_VARIABLE ComputeCpp_STL_CHECK_RESULT + ERROR_QUIET + OUTPUT_QUIET) + if(NOT ${ComputeCpp_STL_CHECK_RESULT} EQUAL 0) + # Try disabling compiler version checks + execute_process( + COMMAND ${ComputeCpp_DEVICE_COMPILER_EXECUTABLE} + ${COMPUTECPP_DEVICE_COMPILER_FLAGS} + -D_ALLOW_COMPILER_AND_STL_VERSION_MISMATCH + -isystem ${ComputeCpp_INCLUDE_DIRS} + -o ${ComputeCpp_STL_CHECK_SRC}.cpp.sycl + -c ${ComputeCpp_STL_CHECK_SRC}.cpp + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + RESULT_VARIABLE ComputeCpp_STL_CHECK_RESULT + ERROR_QUIET + OUTPUT_QUIET) + if(NOT ${ComputeCpp_STL_CHECK_RESULT} EQUAL 0) + message(STATUS "Device compiler cannot consume hosted STL headers. Using any parts of the STL will likely result in device compiler errors.") + else() + message(STATUS "Device compiler does not meet certain STL version requirements. Disabling version checks and hoping for the best.") + list(APPEND COMPUTECPP_DEVICE_COMPILER_FLAGS -D_ALLOW_COMPILER_AND_STL_VERSION_MISMATCH) + endif() + endif() + file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/${ComputeCpp_STL_CHECK_SRC}.cpp + ${CMAKE_CURRENT_BINARY_DIR}/${ComputeCpp_STL_CHECK_SRC}.cpp.sycl) +endif(MSVC) diff --git a/cmake/Modules/ComputeCppIRMap.cmake b/cmake/Modules/ComputeCppIRMap.cmake new file mode 100644 index 000000000..98a24ed76 --- /dev/null +++ b/cmake/Modules/ComputeCppIRMap.cmake @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 3.4.3) + +# These should match the types of IR output by compute++ +set(IR_MAP_spir bc) +set(IR_MAP_spir64 bc) +set(IR_MAP_spir32 bc) +set(IR_MAP_spirv spv) +set(IR_MAP_spirv64 spv) +set(IR_MAP_spirv32 spv) +set(IR_MAP_aorta-x86_64 o) +set(IR_MAP_aorta-aarch64 o) +set(IR_MAP_aorta-rcar-cve o) +set(IR_MAP_custom-spir64 bc) +set(IR_MAP_custom-spir32 bc) +set(IR_MAP_custom-spirv64 spv) +set(IR_MAP_custom-spirv32 spv) +set(IR_MAP_ptx64 s) +set(IR_MAP_amdgcn s) diff --git a/cmake/Modules/FindComputeCpp.cmake b/cmake/Modules/FindComputeCpp.cmake index 9788e10c8..510c98951 100644 --- a/cmake/Modules/FindComputeCpp.cmake +++ b/cmake/Modules/FindComputeCpp.cmake @@ -1,424 +1,450 @@ -#.rst: -# FindComputeCpp -#--------------- -# -# Copyright 2016-2018 Codeplay Software Ltd. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use these files except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -######################### -# FindComputeCpp.cmake -######################### -# -# Tools for finding and building with ComputeCpp. -# -# User must define ComputeCpp_DIR pointing to the ComputeCpp -# installation. -# -# Latest version of this file can be found at: -# https://github.com/codeplaysoftware/computecpp-sdk - -cmake_minimum_required(VERSION 3.4.3) -include(FindPackageHandleStandardArgs) - -# Check that a supported host compiler can be found -if(CMAKE_COMPILER_IS_GNUCXX) - # Require at least gcc 4.8 - if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8) - message(FATAL_ERROR - "host compiler - gcc version must be at least 4.8") - endif() -elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - # Require at least clang 3.6 - if (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 3.6) - message(FATAL_ERROR - "host compiler - clang version must be at least 3.6") - endif() -endif() - -set(COMPUTECPP_USER_FLAGS "" CACHE STRING "User flags for compute++") -mark_as_advanced(COMPUTECPP_USER_FLAGS) - -set(COMPUTECPP_BITCODE "spir64" CACHE STRING - "Bitcode type to use as SYCL target in compute++") -mark_as_advanced(COMPUTECPP_BITCODE) - -find_package(OpenCL REQUIRED) - -# Find ComputeCpp package - -# Try to read the environment variable -if(DEFINED ComputeCpp_DIR) - set(computecpp_find_hint ${ComputeCpp_DIR}) -elseif(DEFINED ENV{COMPUTECPP_DIR}) - set(computecpp_find_hint $ENV{COMPUTECPP_DIR}) -endif() - -find_program(ComputeCpp_DEVICE_COMPILER_EXECUTABLE compute++ - PATHS ${computecpp_find_hint} - PATH_SUFFIXES bin) - -find_program(ComputeCpp_INFO_EXECUTABLE computecpp_info - PATHS ${computecpp_find_hint} - PATH_SUFFIXES bin) - -find_library(COMPUTECPP_RUNTIME_LIBRARY - NAMES ComputeCpp ComputeCpp_vs2015 - PATHS ${computecpp_find_hint} - PATH_SUFFIXES lib - DOC "ComputeCpp Runtime Library") - -find_library(COMPUTECPP_RUNTIME_LIBRARY_DEBUG - NAMES ComputeCpp ComputeCpp_vs2015_d - PATHS ${computecpp_find_hint} - PATH_SUFFIXES lib - DOC "ComputeCpp Debug Runtime Library") - -find_path(ComputeCpp_INCLUDE_DIRS - NAMES "CL/sycl.hpp" - PATHS ${computecpp_find_hint}/include - DOC "The ComputeCpp include directory") -get_filename_component(ComputeCpp_INCLUDE_DIRS ${ComputeCpp_INCLUDE_DIRS} ABSOLUTE) - -get_filename_component(computecpp_canonical_root_dir "${ComputeCpp_INCLUDE_DIRS}/.." ABSOLUTE) -set(ComputeCpp_ROOT_DIR "${computecpp_canonical_root_dir}" CACHE PATH - "The root of the ComputeCpp install") - -execute_process(COMMAND ${ComputeCpp_INFO_EXECUTABLE} "--dump-version" - OUTPUT_VARIABLE ComputeCpp_VERSION - RESULT_VARIABLE ComputeCpp_INFO_EXECUTABLE_RESULT OUTPUT_STRIP_TRAILING_WHITESPACE) -if(NOT ComputeCpp_INFO_EXECUTABLE_RESULT EQUAL "0") - message(FATAL_ERROR "Package version - Error obtaining version!") -endif() - -execute_process(COMMAND ${ComputeCpp_INFO_EXECUTABLE} "--dump-is-supported" - OUTPUT_VARIABLE COMPUTECPP_PLATFORM_IS_SUPPORTED - RESULT_VARIABLE ComputeCpp_INFO_EXECUTABLE_RESULT OUTPUT_STRIP_TRAILING_WHITESPACE) -if(NOT ComputeCpp_INFO_EXECUTABLE_RESULT EQUAL "0") - message(FATAL_ERROR "platform - Error checking platform support!") -else() - mark_as_advanced(COMPUTECPP_PLATFORM_IS_SUPPORTED) - if (COMPUTECPP_PLATFORM_IS_SUPPORTED) - message(STATUS "platform - your system can support ComputeCpp") - else() - message(WARNING "platform - your system CANNOT support ComputeCpp") - endif() -endif() - -execute_process(COMMAND ${ComputeCpp_INFO_EXECUTABLE} - "--dump-device-compiler-flags" - OUTPUT_VARIABLE COMPUTECPP_DEVICE_COMPILER_FLAGS - RESULT_VARIABLE ComputeCpp_INFO_EXECUTABLE_RESULT OUTPUT_STRIP_TRAILING_WHITESPACE) -list(APPEND COMPUTECPP_DEVICE_COMPILER_FLAGS "-sycl-target ${COMPUTECPP_BITCODE}") - -if(NOT ComputeCpp_INFO_EXECUTABLE_RESULT EQUAL "0") - message(FATAL_ERROR "compute++ flags - Error obtaining compute++ flags!") -else() - mark_as_advanced(COMPUTECPP_COMPILER_FLAGS) -endif() - -find_package_handle_standard_args(ComputeCpp - REQUIRED_VARS ComputeCpp_ROOT_DIR - ComputeCpp_DEVICE_COMPILER_EXECUTABLE - ComputeCpp_INFO_EXECUTABLE - COMPUTECPP_RUNTIME_LIBRARY - COMPUTECPP_RUNTIME_LIBRARY_DEBUG - ComputeCpp_INCLUDE_DIRS - VERSION_VAR ComputeCpp_VERSION) -mark_as_advanced(ComputeCpp_ROOT_DIR - ComputeCpp_DEVICE_COMPILER_EXECUTABLE - ComputeCpp_INFO_EXECUTABLE - COMPUTECPP_RUNTIME_LIBRARY - COMPUTECPP_RUNTIME_LIBRARY_DEBUG - ComputeCpp_INCLUDE_DIRS - ComputeCpp_VERSION) - -if(NOT ComputeCpp_FOUND) - return() -endif() - -if(CMAKE_CROSSCOMPILING) - if(NOT SDK_DONT_USE_TOOLCHAIN) - list(APPEND COMPUTECPP_DEVICE_COMPILER_FLAGS --gcc-toolchain=${SDK_TOOLCHAIN_DIR}) - endif() - list(APPEND COMPUTECPP_DEVICE_COMPILER_FLAGS --sysroot=${SDK_SYSROOT_DIR}) - list(APPEND COMPUTECPP_DEVICE_COMPILER_FLAGS -target ${SDK_TARGET_TRIPLE}) -endif() - -separate_arguments(COMPUTECPP_DEVICE_COMPILER_FLAGS) -list(REMOVE_ITEM COMPUTECPP_DEVICE_COMPILER_FLAGS "-emit-llvm") -message(STATUS "compute++ flags - ${COMPUTECPP_DEVICE_COMPILER_FLAGS}") - -if(NOT TARGET OpenCL::OpenCL) - add_library(OpenCL::OpenCL UNKNOWN IMPORTED) - set_target_properties(OpenCL::OpenCL PROPERTIES - IMPORTED_LOCATION "${OpenCL_LIBRARIES}" - INTERFACE_INCLUDE_DIRECTORIES "${OpenCL_INCLUDE_DIRS}" - ) -endif() - -add_library(ComputeCpp::ComputeCpp UNKNOWN IMPORTED) -set_target_properties(ComputeCpp::ComputeCpp PROPERTIES - IMPORTED_LOCATION_DEBUG "${COMPUTECPP_RUNTIME_LIBRARY_DEBUG}" - IMPORTED_LOCATION_RELWITHDEBINFO "${COMPUTECPP_RUNTIME_LIBRARY_DEBUG}" - IMPORTED_LOCATION "${COMPUTECPP_RUNTIME_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${ComputeCpp_INCLUDE_DIRS}" - INTERFACE_LINK_LIBRARIES "OpenCL::OpenCL" -) - -# This property allows targets to specify that their sources should be -# compiled with the integration header included after the user's -# sources, not before (e.g. when an enum is used in a kernel name, this -# is not technically valid SYCL code but can work with ComputeCpp) -define_property( - TARGET PROPERTY COMPUTECPP_INCLUDE_AFTER - BRIEF_DOCS "Include integration header after user source" - FULL_DOCS "Changes compiler arguments such that the source file is - actually the integration header, and the .cpp file is included on - the command line so that it is seen by the compiler first. Enables - non-standards-conformant SYCL code to compile with ComputeCpp." -) -define_property( - TARGET PROPERTY INTERFACE_COMPUTECPP_FLAGS - BRIEF_DOCS "Interface compile flags to provide compute++" - FULL_DOCS "Set additional compile flags to pass to compute++ when compiling - any target which links to this one." -) -define_property( - SOURCE PROPERTY COMPUTECPP_SOURCE_FLAGS - BRIEF_DOCS "Source file compile flags for compute++" - FULL_DOCS "Set additional compile flags for compiling the SYCL integration - header for the given source file." -) - -#################### -# __build_ir -#################### -# -# Adds a custom target for running compute++ and adding a dependency for the -# resulting integration header. -# -# TARGET : Name of the target. -# SOURCE : Source file to be compiled. -# COUNTER : Counter included in name of custom target. Different counter -# values prevent duplicated names of custom target when source files with -# the same name, but located in different directories, are used for the -# same target. -# -function(__build_ir) - set(options) - set(one_value_args - TARGET - SOURCE - COUNTER - ) - set(multi_value_args) - cmake_parse_arguments(SDK_BUILD_IR - "${options}" - "${one_value_args}" - "${multi_value_args}" - ${ARGN} - ) - get_filename_component(sourceFileName ${SDK_BUILD_IR_SOURCE} NAME) - - # Set the path to the integration header. - set(outputSyclFile ${CMAKE_CURRENT_BINARY_DIR}/${sourceFileName}.sycl) - set(depFileName ${CMAKE_CURRENT_BINARY_DIR}/${sourceFileName}.sycl.d) - - set(include_directories "$") - set(compile_definitions "$") - set(generated_include_directories - $<$:-I\"$\">) - set(generated_compile_definitions - $<$:-D$>) - - # Obtain language standard of the file - set(device_compiler_cxx_standard) - get_target_property(targetCxxStandard ${SDK_BUILD_IR_TARGET} CXX_STANDARD) - if (targetCxxStandard MATCHES 17) - set(device_compiler_cxx_standard "-std=c++1z") - elseif (targetCxxStandard MATCHES 14) - set(device_compiler_cxx_standard "-std=c++14") - elseif (targetCxxStandard MATCHES 11) - set(device_compiler_cxx_standard "-std=c++11") - elseif (targetCxxStandard MATCHES 98) - message(FATAL_ERROR "SYCL applications cannot be compiled using C++98") - else () - set(device_compiler_cxx_standard "") - endif() - - get_property(source_compile_flags - SOURCE ${SDK_BUILD_IR_SOURCE} - PROPERTY COMPUTECPP_SOURCE_FLAGS - ) - if(source_compile_flags) - list(APPEND target_compile_flags ${source_compile_flags}) - endif() - - set(COMPUTECPP_DEVICE_COMPILER_FLAGS - ${device_compiler_cxx_standard} - ${COMPUTECPP_DEVICE_COMPILER_FLAGS} - ${COMPUTECPP_USER_FLAGS} - ${target_compile_flags} - ) - separate_arguments(COMPUTECPP_DEVICE_COMPILER_FLAGS) - - set(ir_dependencies ${SDK_BUILD_IR_SOURCE}) - get_target_property(target_libraries ${SDK_BUILD_IR_TARGET} LINK_LIBRARIES) - if(target_libraries) - foreach(library ${target_libraries}) - list(APPEND ir_dependencies ${library}) - endforeach() - endif() - - # Depfile support was only added in CMake 3.7 - # CMake throws an error if it is unsupported by the generator (i. e. not ninja) - if((NOT CMAKE_VERSION VERSION_LESS 3.7.0) AND - CMAKE_GENERATOR MATCHES "Ninja") - file(RELATIVE_PATH relOutputFile ${CMAKE_BINARY_DIR} ${outputSyclFile}) - set(generate_depfile -MMD -MF ${depFileName} -MT ${relOutputFile}) - set(enable_depfile DEPFILE ${depFileName}) - endif() - - # Add custom command for running compute++ - add_custom_command( - OUTPUT ${outputSyclFile} - COMMAND ${ComputeCpp_DEVICE_COMPILER_EXECUTABLE} - ${COMPUTECPP_DEVICE_COMPILER_FLAGS} - ${device_compiler_includes} - ${generated_include_directories} - ${generated_compile_definitions} - -o ${outputSyclFile} - -c ${SDK_BUILD_IR_SOURCE} - ${generate_depfile} - DEPENDS ${ir_dependencies} - IMPLICIT_DEPENDS CXX ${SDK_BUILD_IR_SOURCE} - ${enable_depfile} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMENT "Building ComputeCpp integration header file ${outputSyclFile}") - - # Name: (user-defined name)_(source file)_(counter)_ih - set(headerTargetName - ${SDK_BUILD_IR_TARGET}_${sourceFileName}_${SDK_BUILD_IR_COUNTER}_ih) - - if(NOT MSVC) - # Add a custom target for the generated integration header - add_custom_target(${headerTargetName} DEPENDS ${outputSyclFile}) - add_dependencies(${SDK_BUILD_IR_TARGET} ${headerTargetName}) - endif() - - # This property can be set on a per-target basis to indicate that the - # integration header should appear after the main source listing - get_property(includeAfter TARGET ${SDK_BUILD_IR_TARGET} - PROPERTY COMPUTECPP_INCLUDE_AFTER) - - if(includeAfter) - # Change the source file to the integration header - e.g. - # g++ -c source_file_name.cpp.sycl - get_target_property(current_sources ${SDK_BUILD_IR_TARGET} SOURCES) - # Remove absolute path to source file - list(REMOVE_ITEM current_sources ${SDK_BUILD_IR_SOURCE}) - # Remove relative path to source file - string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" - rel_source_file ${SDK_BUILD_IR_SOURCE} - ) - list(REMOVE_ITEM current_sources ${rel_source_file}) - # Add SYCL header to source list - list(APPEND current_sources ${outputSyclFile}) - set_property(TARGET ${SDK_BUILD_IR_TARGET} - PROPERTY SOURCES ${current_sources}) - # CMake/gcc don't know what language a .sycl file is, so tell them - set_property(SOURCE ${outputSyclFile} PROPERTY LANGUAGE CXX) - set(includedFile ${SDK_BUILD_IR_SOURCE}) - set(cppFile ${outputSyclFile}) - else() - set_property(SOURCE ${outputSyclFile} PROPERTY HEADER_FILE_ONLY ON) - set(includedFile ${outputSyclFile}) - set(cppFile ${SDK_BUILD_IR_SOURCE}) - endif() - - # Force inclusion of the integration header for the host compiler - if(MSVC) - # Group SYCL files inside Visual Studio - source_group("SYCL" FILES ${outputSyclFile}) - - if(includeAfter) - # Allow the source file to be edited using Visual Studio. - # It will be added as a header file so it won't be compiled. - set_property(SOURCE ${SDK_BUILD_IR_SOURCE} PROPERTY HEADER_FILE_ONLY true) - endif() - - # Add both source and the sycl files to the VS solution. - target_sources(${SDK_BUILD_IR_TARGET} PUBLIC ${SDK_BUILD_IR_SOURCE} ${outputSyclFile}) - - # NOTE: The Visual Studio generators parse compile flags differently, - # hence the different argument syntax - if(CMAKE_GENERATOR MATCHES "Visual Studio") - set(forceIncludeFlags "/FI\"${includedFile}\" /TP") - else() - set(forceIncludeFlags /FI ${includedFile} /TP) - endif() - else() - set(forceIncludeFlags "-include ${includedFile} -x c++") - endif() - - set_property( - SOURCE ${cppFile} - APPEND_STRING PROPERTY COMPILE_FLAGS "${forceIncludeFlags}" - ) - -endfunction(__build_ir) - -####################### -# add_sycl_to_target -####################### -# -# Adds a SYCL compilation custom command associated with an existing -# target and sets a dependancy on that new command. -# -# TARGET : Name of the target to add SYCL to. -# SOURCES : Source files to be compiled for SYCL. -# -function(add_sycl_to_target) - set(options) - set(one_value_args - TARGET - ) - set(multi_value_args - SOURCES - ) - cmake_parse_arguments(SDK_ADD_SYCL - "${options}" - "${one_value_args}" - "${multi_value_args}" - ${ARGN} - ) - set(fileCounter 0) - # Add custom target to run compute++ and generate the integration header - foreach(sourceFile ${SDK_ADD_SYCL_SOURCES}) - if(NOT IS_ABSOLUTE ${sourceFile}) - set(sourceFile "${CMAKE_CURRENT_SOURCE_DIR}/${sourceFile}") - endif() - __build_ir( - TARGET ${SDK_ADD_SYCL_TARGET} - SOURCE ${sourceFile} - COUNTER ${fileCounter} - ) - MATH(EXPR fileCounter "${fileCounter} + 1") - endforeach() - set_property(TARGET ${SDK_ADD_SYCL_TARGET} - APPEND PROPERTY LINK_LIBRARIES ComputeCpp::ComputeCpp) - set_property(TARGET ${SDK_ADD_SYCL_TARGET} - APPEND PROPERTY INTERFACE_LINK_LIBRARIES ComputeCpp::ComputeCpp) -endfunction(add_sycl_to_target) +#.rst: +# FindComputeCpp +#--------------- +# +# Copyright 2016-2018 Codeplay Software Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use these files except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +######################### +# FindComputeCpp.cmake +######################### +# +# Tools for finding and building with ComputeCpp. +# +# User must define ComputeCpp_DIR pointing to the ComputeCpp +# installation. +# +# Latest version of this file can be found at: +# https://github.com/codeplaysoftware/computecpp-sdk + +cmake_minimum_required(VERSION 3.4.3) +include(FindPackageHandleStandardArgs) +include(ComputeCppIRMap) + +set(COMPUTECPP_USER_FLAGS "" CACHE STRING "User flags for compute++") +separate_arguments(COMPUTECPP_USER_FLAGS) +mark_as_advanced(COMPUTECPP_USER_FLAGS) + +set(COMPUTECPP_BITCODE "spir64" CACHE STRING + "Bitcode type to use as SYCL target in compute++") +mark_as_advanced(COMPUTECPP_BITCODE) + +find_package(OpenCL REQUIRED) + +# Find ComputeCpp package + +if(DEFINED ComputeCpp_DIR) + set(computecpp_find_hint ${ComputeCpp_DIR}) +elseif(DEFINED ENV{COMPUTECPP_DIR}) + set(computecpp_find_hint $ENV{COMPUTECPP_DIR}) +endif() + +# Used for running executables on the host +set(computecpp_host_find_hint ${computecpp_find_hint}) + +if(CMAKE_CROSSCOMPILING) + # ComputeCpp_HOST_DIR is used to find executables that are run on the host + if(DEFINED ComputeCpp_HOST_DIR) + set(computecpp_host_find_hint ${ComputeCpp_HOST_DIR}) + elseif(DEFINED ENV{COMPUTECPP_HOST_DIR}) + set(computecpp_host_find_hint $ENV{COMPUTECPP_HOST_DIR}) + endif() +endif() + +find_program(ComputeCpp_DEVICE_COMPILER_EXECUTABLE compute++ + HINTS ${computecpp_host_find_hint} + PATH_SUFFIXES bin + NO_SYSTEM_ENVIRONMENT_PATH) + +find_program(ComputeCpp_INFO_EXECUTABLE computecpp_info + HINTS ${computecpp_host_find_hint} + PATH_SUFFIXES bin + NO_SYSTEM_ENVIRONMENT_PATH) + +find_library(COMPUTECPP_RUNTIME_LIBRARY + NAMES ComputeCpp ComputeCpp_vs2015 + HINTS ${computecpp_find_hint} + PATH_SUFFIXES lib + DOC "ComputeCpp Runtime Library") + +find_library(COMPUTECPP_RUNTIME_LIBRARY_DEBUG + NAMES ComputeCpp ComputeCpp_vs2015_d + HINTS ${computecpp_find_hint} + PATH_SUFFIXES lib + DOC "ComputeCpp Debug Runtime Library") + +find_path(ComputeCpp_INCLUDE_DIRS + NAMES "CL/sycl.hpp" + HINTS ${computecpp_find_hint}/include + DOC "The ComputeCpp include directory") +get_filename_component(ComputeCpp_INCLUDE_DIRS ${ComputeCpp_INCLUDE_DIRS} ABSOLUTE) + +get_filename_component(computecpp_canonical_root_dir "${ComputeCpp_INCLUDE_DIRS}/.." ABSOLUTE) +set(ComputeCpp_ROOT_DIR "${computecpp_canonical_root_dir}" CACHE PATH + "The root of the ComputeCpp install") + +if(NOT ComputeCpp_INFO_EXECUTABLE) + message(WARNING "Can't find computecpp_info - check ComputeCpp_DIR") +else() + execute_process(COMMAND ${ComputeCpp_INFO_EXECUTABLE} "--dump-version" + OUTPUT_VARIABLE ComputeCpp_VERSION + RESULT_VARIABLE ComputeCpp_INFO_EXECUTABLE_RESULT OUTPUT_STRIP_TRAILING_WHITESPACE) + if(NOT ComputeCpp_INFO_EXECUTABLE_RESULT EQUAL "0") + message(WARNING "Package version - Error obtaining version!") + endif() + + execute_process(COMMAND ${ComputeCpp_INFO_EXECUTABLE} "--dump-is-supported" + OUTPUT_VARIABLE COMPUTECPP_PLATFORM_IS_SUPPORTED + RESULT_VARIABLE ComputeCpp_INFO_EXECUTABLE_RESULT OUTPUT_STRIP_TRAILING_WHITESPACE) + if(NOT ComputeCpp_INFO_EXECUTABLE_RESULT EQUAL "0") + message(WARNING "platform - Error checking platform support!") + else() + mark_as_advanced(COMPUTECPP_PLATFORM_IS_SUPPORTED) + if (COMPUTECPP_PLATFORM_IS_SUPPORTED) + message(STATUS "platform - your system can support ComputeCpp") + else() + message(WARNING "platform - your system CANNOT support ComputeCpp") + endif() + endif() +endif() + +find_package_handle_standard_args(ComputeCpp + REQUIRED_VARS ComputeCpp_ROOT_DIR + ComputeCpp_DEVICE_COMPILER_EXECUTABLE + ComputeCpp_INFO_EXECUTABLE + COMPUTECPP_RUNTIME_LIBRARY + COMPUTECPP_RUNTIME_LIBRARY_DEBUG + ComputeCpp_INCLUDE_DIRS + VERSION_VAR ComputeCpp_VERSION) +mark_as_advanced(ComputeCpp_ROOT_DIR + ComputeCpp_DEVICE_COMPILER_EXECUTABLE + ComputeCpp_INFO_EXECUTABLE + COMPUTECPP_RUNTIME_LIBRARY + COMPUTECPP_RUNTIME_LIBRARY_DEBUG + ComputeCpp_INCLUDE_DIRS + ComputeCpp_VERSION) + +if(NOT ComputeCpp_FOUND) + return() +endif() + +list(APPEND COMPUTECPP_DEVICE_COMPILER_FLAGS -O2 -mllvm -inline-threshold=1000 -intelspirmetadata) +mark_as_advanced(COMPUTECPP_DEVICE_COMPILER_FLAGS) + +if(CMAKE_CROSSCOMPILING) + if(NOT COMPUTECPP_DONT_USE_TOOLCHAIN) + list(APPEND COMPUTECPP_DEVICE_COMPILER_FLAGS --gcc-toolchain=${COMPUTECPP_TOOLCHAIN_DIR}) + endif() + list(APPEND COMPUTECPP_DEVICE_COMPILER_FLAGS --sysroot=${COMPUTECPP_SYSROOT_DIR}) + list(APPEND COMPUTECPP_DEVICE_COMPILER_FLAGS -target ${COMPUTECPP_TARGET_TRIPLE}) +endif() + +list(APPEND COMPUTECPP_DEVICE_COMPILER_FLAGS -sycl-target ${COMPUTECPP_BITCODE}) +message(STATUS "compute++ flags - ${COMPUTECPP_DEVICE_COMPILER_FLAGS}") + +if(NOT TARGET OpenCL::OpenCL) + add_library(OpenCL::OpenCL UNKNOWN IMPORTED) + set_target_properties(OpenCL::OpenCL PROPERTIES + IMPORTED_LOCATION "${OpenCL_LIBRARIES}" + INTERFACE_INCLUDE_DIRECTORIES "${OpenCL_INCLUDE_DIRS}" + ) +endif() + +if(NOT TARGET ComputeCpp::ComputeCpp) + add_library(ComputeCpp::ComputeCpp UNKNOWN IMPORTED) + set_target_properties(ComputeCpp::ComputeCpp PROPERTIES + IMPORTED_LOCATION_DEBUG "${COMPUTECPP_RUNTIME_LIBRARY_DEBUG}" + IMPORTED_LOCATION_RELWITHDEBINFO "${COMPUTECPP_RUNTIME_LIBRARY_DEBUG}" + IMPORTED_LOCATION "${COMPUTECPP_RUNTIME_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${ComputeCpp_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES "OpenCL::OpenCL" + ) +endif() + +# This property allows targets to specify that their sources should be +# compiled with the integration header included after the user's +# sources, not before (e.g. when an enum is used in a kernel name, this +# is not technically valid SYCL code but can work with ComputeCpp) +define_property( + TARGET PROPERTY COMPUTECPP_INCLUDE_AFTER + BRIEF_DOCS "Include integration header after user source" + FULL_DOCS "Changes compiler arguments such that the source file is + actually the integration header, and the .cpp file is included on + the command line so that it is seen by the compiler first. Enables + non-standards-conformant SYCL code to compile with ComputeCpp." +) +define_property( + TARGET PROPERTY INTERFACE_COMPUTECPP_FLAGS + BRIEF_DOCS "Interface compile flags to provide compute++" + FULL_DOCS "Set additional compile flags to pass to compute++ when compiling + any target which links to this one." +) +define_property( + SOURCE PROPERTY COMPUTECPP_SOURCE_FLAGS + BRIEF_DOCS "Source file compile flags for compute++" + FULL_DOCS "Set additional compile flags for compiling the SYCL integration + header for the given source file." +) + +#################### +# __build_ir +#################### +# +# Adds a custom target for running compute++ and adding a dependency for the +# resulting integration header and kernel binary. +# +# TARGET : Name of the target. +# SOURCE : Source file to be compiled. +# COUNTER : Counter included in name of custom target. Different counter +# values prevent duplicated names of custom target when source files with +# the same name, but located in different directories, are used for the +# same target. +# +function(__build_ir) + set(options) + set(one_value_args + TARGET + SOURCE + COUNTER + ) + set(multi_value_args) + cmake_parse_arguments(SDK_BUILD_IR + "${options}" + "${one_value_args}" + "${multi_value_args}" + ${ARGN} + ) + get_filename_component(sourceFileName ${SDK_BUILD_IR_SOURCE} NAME) + + # Set the path to the integration header. + # The .sycl filename must depend on the target so that different targets + # using the same source file will be generated with a different rule. + set(baseSyclName ${CMAKE_CURRENT_BINARY_DIR}/${SDK_BUILD_IR_TARGET}_${sourceFileName}) + set(outputSyclFile ${baseSyclName}.sycl) + set(outputDeviceFile ${baseSyclName}.${IR_MAP_${COMPUTECPP_BITCODE}}) + set(depFileName ${baseSyclName}.sycl.d) + + set(include_directories "$") + set(compile_definitions "$") + set(generated_include_directories + $<$:-I\"$\">) + set(generated_compile_definitions + $<$:-D$>) + + # Obtain language standard of the file + set(device_compiler_cxx_standard) + get_target_property(targetCxxStandard ${SDK_BUILD_IR_TARGET} CXX_STANDARD) + if (targetCxxStandard MATCHES 17) + set(device_compiler_cxx_standard "-std=c++1z") + elseif (targetCxxStandard MATCHES 14) + set(device_compiler_cxx_standard "-std=c++14") + elseif (targetCxxStandard MATCHES 11) + set(device_compiler_cxx_standard "-std=c++11") + elseif (targetCxxStandard MATCHES 98) + message(FATAL_ERROR "SYCL applications cannot be compiled using C++98") + else () + set(device_compiler_cxx_standard "") + endif() + + get_property(source_compile_flags + SOURCE ${SDK_BUILD_IR_SOURCE} + PROPERTY COMPUTECPP_SOURCE_FLAGS + ) + separate_arguments(source_compile_flags) + if(source_compile_flags) + list(APPEND computecpp_source_flags ${source_compile_flags}) + endif() + + list(APPEND COMPUTECPP_DEVICE_COMPILER_FLAGS + ${device_compiler_cxx_standard} + ${COMPUTECPP_USER_FLAGS} + ${computecpp_source_flags} + ) + + set(ir_dependencies ${SDK_BUILD_IR_SOURCE}) + get_target_property(target_libraries ${SDK_BUILD_IR_TARGET} LINK_LIBRARIES) + if(target_libraries) + foreach(library ${target_libraries}) + if(TARGET ${library}) + list(APPEND ir_dependencies ${library}) + endif() + endforeach() + endif() + + # Depfile support was only added in CMake 3.7 + # CMake throws an error if it is unsupported by the generator (i. e. not ninja) + if((NOT CMAKE_VERSION VERSION_LESS 3.7.0) AND + CMAKE_GENERATOR MATCHES "Ninja") + file(RELATIVE_PATH relOutputFile ${CMAKE_BINARY_DIR} ${outputDeviceFile}) + set(generate_depfile -MMD -MF ${depFileName} -MT ${relOutputFile}) + set(enable_depfile DEPFILE ${depFileName}) + endif() + + # Add custom command for running compute++ + add_custom_command( + OUTPUT ${outputDeviceFile} ${outputSyclFile} + COMMAND ${ComputeCpp_DEVICE_COMPILER_EXECUTABLE} + ${COMPUTECPP_DEVICE_COMPILER_FLAGS} + ${generated_include_directories} + ${generated_compile_definitions} + -sycl-ih ${outputSyclFile} + -o ${outputDeviceFile} + -c ${SDK_BUILD_IR_SOURCE} + ${generate_depfile} + DEPENDS ${ir_dependencies} + IMPLICIT_DEPENDS CXX ${SDK_BUILD_IR_SOURCE} + ${enable_depfile} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Building ComputeCpp integration header file ${outputSyclFile}") + + # Name: (user-defined name)_(source file)_(counter)_ih + set(headerTargetName + ${SDK_BUILD_IR_TARGET}_${sourceFileName}_${SDK_BUILD_IR_COUNTER}_ih) + + if(NOT MSVC) + # Add a custom target for the generated integration header + add_custom_target(${headerTargetName} DEPENDS ${outputDeviceFile} ${outputSyclFile}) + add_dependencies(${SDK_BUILD_IR_TARGET} ${headerTargetName}) + endif() + + # This property can be set on a per-target basis to indicate that the + # integration header should appear after the main source listing + get_target_property(includeAfter ${SDK_ADD_SYCL_TARGET} COMPUTECPP_INCLUDE_AFTER) + + if(includeAfter) + # Change the source file to the integration header - e.g. + # g++ -c source_file_name.cpp.sycl + get_target_property(current_sources ${SDK_BUILD_IR_TARGET} SOURCES) + # Remove absolute path to source file + list(REMOVE_ITEM current_sources ${SDK_BUILD_IR_SOURCE}) + # Remove relative path to source file + string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" + rel_source_file ${SDK_BUILD_IR_SOURCE} + ) + list(REMOVE_ITEM current_sources ${rel_source_file}) + # Add SYCL header to source list + list(APPEND current_sources ${outputSyclFile}) + set_property(TARGET ${SDK_BUILD_IR_TARGET} + PROPERTY SOURCES ${current_sources}) + # CMake/gcc don't know what language a .sycl file is, so tell them + set_property(SOURCE ${outputSyclFile} PROPERTY LANGUAGE CXX) + set(includedFile ${SDK_BUILD_IR_SOURCE}) + set(cppFile ${outputSyclFile}) + else() + set_property(SOURCE ${outputSyclFile} PROPERTY HEADER_FILE_ONLY ON) + set(includedFile ${outputSyclFile}) + set(cppFile ${SDK_BUILD_IR_SOURCE}) + endif() + + # Force inclusion of the integration header for the host compiler + if(MSVC) + # Group SYCL files inside Visual Studio + source_group("SYCL" FILES ${outputSyclFile}) + + if(includeAfter) + # Allow the source file to be edited using Visual Studio. + # It will be added as a header file so it won't be compiled. + set_property(SOURCE ${SDK_BUILD_IR_SOURCE} PROPERTY HEADER_FILE_ONLY true) + endif() + + # Add both source and the sycl files to the VS solution. + target_sources(${SDK_BUILD_IR_TARGET} PUBLIC ${SDK_BUILD_IR_SOURCE} ${outputSyclFile}) + + set(forceIncludeFlags "/FI${includedFile} /TP") + else() + set(forceIncludeFlags "-include ${includedFile} -x c++") + endif() + + set_property( + SOURCE ${cppFile} + APPEND_STRING PROPERTY COMPILE_FLAGS "${forceIncludeFlags}" + ) + +endfunction(__build_ir) + +####################### +# add_sycl_to_target +####################### +# +# Adds a SYCL compilation custom command associated with an existing +# target and sets a dependancy on that new command. +# +# TARGET : Name of the target to add SYCL to. +# SOURCES : Source files to be compiled for SYCL. +# +function(add_sycl_to_target) + set(options) + set(one_value_args + TARGET + ) + set(multi_value_args + SOURCES + ) + cmake_parse_arguments(SDK_ADD_SYCL + "${options}" + "${one_value_args}" + "${multi_value_args}" + ${ARGN} + ) + + # If the CXX compiler is set to compute++ enable the driver. + get_filename_component(cmakeCxxCompilerFileName "${CMAKE_CXX_COMPILER}" NAME) + if("${cmakeCxxCompilerFileName}" STREQUAL "compute++") + if(MSVC) + message(FATAL_ERROR "The compiler driver is not supported by this system, + revert the CXX compiler to your default host compiler.") + endif() + + get_target_property(includeAfter ${SDK_ADD_SYCL_TARGET} COMPUTECPP_INCLUDE_AFTER) + if(includeAfter) + list(APPEND COMPUTECPP_USER_FLAGS -fsycl-ih-last) + endif() + list(INSERT COMPUTECPP_DEVICE_COMPILER_FLAGS 0 -sycl-driver) + # Prepend COMPUTECPP_DEVICE_COMPILER_FLAGS and append COMPUTECPP_USER_FLAGS + foreach(prop COMPILE_OPTIONS INTERFACE_COMPILE_OPTIONS) + get_target_property(target_compile_options ${SDK_ADD_SYCL_TARGET} ${prop}) + if(NOT target_compile_options) + set(target_compile_options "") + endif() + set_property( + TARGET ${SDK_ADD_SYCL_TARGET} + PROPERTY ${prop} + ${COMPUTECPP_DEVICE_COMPILER_FLAGS} + ${target_compile_options} + ${COMPUTECPP_USER_FLAGS} + ) + endforeach() + else() + set(fileCounter 0) + list(INSERT COMPUTECPP_DEVICE_COMPILER_FLAGS 0 -sycl) + # Add custom target to run compute++ and generate the integration header + foreach(sourceFile ${SDK_ADD_SYCL_SOURCES}) + if(NOT IS_ABSOLUTE ${sourceFile}) + set(sourceFile "${CMAKE_CURRENT_SOURCE_DIR}/${sourceFile}") + endif() + __build_ir( + TARGET ${SDK_ADD_SYCL_TARGET} + SOURCE ${sourceFile} + COUNTER ${fileCounter} + ) + MATH(EXPR fileCounter "${fileCounter} + 1") + endforeach() + endif() + + set_property(TARGET ${SDK_ADD_SYCL_TARGET} + APPEND PROPERTY LINK_LIBRARIES ComputeCpp::ComputeCpp) + set_property(TARGET ${SDK_ADD_SYCL_TARGET} + APPEND PROPERTY INTERFACE_LINK_LIBRARIES ComputeCpp::ComputeCpp) +endfunction(add_sycl_to_target) diff --git a/cmake/Modules/examples.cmake b/cmake/Modules/examples.cmake index dcaf4526a..cbd0853ad 100644 --- a/cmake/Modules/examples.cmake +++ b/cmake/Modules/examples.cmake @@ -1,5 +1,8 @@ # include common configs include(common) +if(POLICY CMP0058) + cmake_policy(SET CMP0058 NEW) +endif() project(visioncpp-Examples CXX) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/example) diff --git a/examples/bayer_filter.cpp b/examples/bayer_filter.cpp index 4c10d82a8..13350aac9 100644 --- a/examples/bayer_filter.cpp +++ b/examples/bayer_filter.cpp @@ -196,7 +196,7 @@ struct BayerRGGBToBGR { // main program int main(int argc, char **argv) { // Load the - cv::Mat bayer = cv::imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE); + cv::Mat bayer = cv::imread(argv[1], cv::ImreadModes::IMREAD_GRAYSCALE); if (!bayer.data) { std::cout << "Image not loaded, BayerRGGB image required as input" diff --git a/examples/depth_map_from_2_images.cpp b/examples/depth_map_from_2_images.cpp index 955e8b00d..79a0a0aa1 100644 --- a/examples/depth_map_from_2_images.cpp +++ b/examples/depth_map_from_2_images.cpp @@ -32,6 +32,7 @@ // include OpenCV for camera display #include +#include // include VisionCpp #include @@ -105,9 +106,9 @@ struct Stereo_BMA { int main(int argc, char** argv) { // load images left and write in gray scale cv::Mat input_l = - cv::imread("../data/tsukuba_l.png", CV_LOAD_IMAGE_GRAYSCALE); + cv::imread("../data/tsukuba_l.png", cv::ImreadModes::IMREAD_GRAYSCALE ); cv::Mat input_r = - cv::imread("../data/tsukuba_r.png", CV_LOAD_IMAGE_GRAYSCALE); + cv::imread("../data/tsukuba_r.png", cv::ImreadModes::IMREAD_GRAYSCALE ); if (!input_l.data || !input_r.data) { // check if we succeeded std::cout << "Loading image failed." << std::endl; diff --git a/tests/include/common.hpp b/tests/include/common.hpp index f1e6a31ec..38d811d22 100644 --- a/tests/include/common.hpp +++ b/tests/include/common.hpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include // used to generate test names #define GLUE_HELPER(x, y) x##_##y diff --git a/tests/operators/OP_BGRToRGB/OP_BGRToRGB.hpp b/tests/operators/OP_BGRToRGB/OP_BGRToRGB.hpp index e952668fc..bdf151500 100644 --- a/tests/operators/OP_BGRToRGB/OP_BGRToRGB.hpp +++ b/tests/operators/OP_BGRToRGB/OP_BGRToRGB.hpp @@ -18,6 +18,7 @@ // limitations under the License. #include "../../include/common.hpp" +#include "opencv2/core.hpp" template void run_test(QUEUE &q, DATA data, int i) { @@ -33,7 +34,7 @@ void run_test(QUEUE &q, DATA data, int i) { [](unsigned char *dataMem) { delete[] dataMem; }); // 2) create gold_standard image - cvtColor(frame, ref, CV_BGR2RGB); + cvtColor(frame, ref, cv::COLOR_BGR2RGB); { // 3) define graph diff --git a/tests/operators/OP_CVBGRToGRAY/OP_CVBGRToGRAY.hpp b/tests/operators/OP_CVBGRToGRAY/OP_CVBGRToGRAY.hpp index 43ed4912d..015aa1549 100644 --- a/tests/operators/OP_CVBGRToGRAY/OP_CVBGRToGRAY.hpp +++ b/tests/operators/OP_CVBGRToGRAY/OP_CVBGRToGRAY.hpp @@ -18,6 +18,7 @@ // limitations under the License. #include "../../include/common.hpp" +#include "opencv2/core.hpp" template void run_test(QUEUE &q, DATA data, int i) { @@ -33,7 +34,7 @@ void run_test(QUEUE &q, DATA data, int i) { [](unsigned char *dataMem) { delete[] dataMem; }); // 2) create gold_standard image - cvtColor(frame, ref, CV_BGR2GRAY); + cvtColor(frame, ref, cv::COLOR_BGR2GRAY); { // 3) define graph auto node = visioncpp::point_operation(data); diff --git a/tests/operators/OP_CVBGRToRGB/OP_CVBGRToRGB.hpp b/tests/operators/OP_CVBGRToRGB/OP_CVBGRToRGB.hpp index c0ebea8cf..f7d977c90 100644 --- a/tests/operators/OP_CVBGRToRGB/OP_CVBGRToRGB.hpp +++ b/tests/operators/OP_CVBGRToRGB/OP_CVBGRToRGB.hpp @@ -18,6 +18,7 @@ // limitations under the License. #include "../../include/common.hpp" +#include "opencv2/core.hpp" template void run_test(QUEUE &q, DATA data, int i) { @@ -33,7 +34,7 @@ void run_test(QUEUE &q, DATA data, int i) { [](float *dataMem) { delete[] dataMem; }); // 2) create gold_standard image - cvtColor(frame, ref, CV_BGR2RGB); + cvtColor(frame, ref, cv::COLOR_BGR2RGB); // that should being it down to 0.0 to 1.0 ref /= 255.0f; diff --git a/tests/operators/OP_UnsignedBGRToFloatRGB/OP_UnsignedBGRToFloatRGB.hpp b/tests/operators/OP_UnsignedBGRToFloatRGB/OP_UnsignedBGRToFloatRGB.hpp index 24c5258bf..e8c63d94a 100644 --- a/tests/operators/OP_UnsignedBGRToFloatRGB/OP_UnsignedBGRToFloatRGB.hpp +++ b/tests/operators/OP_UnsignedBGRToFloatRGB/OP_UnsignedBGRToFloatRGB.hpp @@ -33,7 +33,7 @@ void run_test(QUEUE &q, DATA data, int i) { [](float *dataMem) { delete[] dataMem; }); // 2) create gold_standard image - cvtColor(frame, ref, CV_BGR2RGB); + cvtColor(frame, ref, cv::COLOR_BGRA2GRAY); ref = ref / 255.0f; {