mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2025-10-27 13:37:38 +00:00
Create OpenCL imported target
This commit is contained in:
@@ -2099,8 +2099,6 @@ if(ENABLE_OPENCL)
|
|||||||
if(NOT OPENCL_FOUND)
|
if(NOT OPENCL_FOUND)
|
||||||
message(STATUS "Processing blocks using OpenCL will not be built.")
|
message(STATUS "Processing blocks using OpenCL will not be built.")
|
||||||
endif()
|
endif()
|
||||||
else()
|
|
||||||
set(OPENCL_FOUND FALSE)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# Copyright (C) 2011-2018 (see AUTHORS file for a list of contributors)
|
# Copyright (C) 2011-2019 (see AUTHORS file for a list of contributors)
|
||||||
#
|
#
|
||||||
# This file is part of GNSS-SDR.
|
# This file is part of GNSS-SDR.
|
||||||
#
|
#
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
#
|
#
|
||||||
# - Try to find OpenCL
|
# - Try to find OpenCL
|
||||||
# This module tries to find an OpenCL implementation on your system. It supports
|
# This module tries to find an OpenCL implementation on your system. It supports
|
||||||
# AMD / ATI, Apple and NVIDIA implementations, but shoudl work, too.
|
# AMD / ATI, Apple and NVIDIA implementations.
|
||||||
#
|
#
|
||||||
# Once done this will define
|
# Once done this will define
|
||||||
# OPENCL_FOUND - system has OpenCL
|
# OPENCL_FOUND - system has OpenCL
|
||||||
@@ -35,85 +35,189 @@ endif()
|
|||||||
|
|
||||||
include(FindPackageHandleStandardArgs)
|
include(FindPackageHandleStandardArgs)
|
||||||
|
|
||||||
set(OPENCL_VERSION_STRING "0.1.0")
|
function(_FIND_OPENCL_VERSION)
|
||||||
set(OPENCL_VERSION_MAJOR 0)
|
include(CheckSymbolExists)
|
||||||
set(OPENCL_VERSION_MINOR 1)
|
include(CMakePushCheckState)
|
||||||
set(OPENCL_VERSION_PATCH 0)
|
set(CMAKE_REQUIRED_QUIET ${OPENCL_FIND_QUIETLY})
|
||||||
|
|
||||||
if(APPLE)
|
cmake_push_check_state()
|
||||||
find_library(OPENCL_LIBRARIES OpenCL DOC "OpenCL lib for OSX")
|
foreach(VERSION "2_2" "2_1" "2_0" "1_2" "1_1" "1_0")
|
||||||
find_path(OPENCL_INCLUDE_DIRS OpenCL/cl.h DOC "Include for OpenCL on OSX")
|
set(CMAKE_REQUIRED_INCLUDES "${OPENCL_INCLUDE_DIR}")
|
||||||
find_path(_OPENCL_CPP_INCLUDE_DIRS OpenCL/cl.hpp DOC "Include for OpenCL CPP bindings on OSX")
|
|
||||||
|
|
||||||
else()
|
if(APPLE)
|
||||||
if(WIN32)
|
check_symbol_exists(
|
||||||
find_path(OPENCL_INCLUDE_DIRS CL/cl.h)
|
CL_VERSION_${VERSION}
|
||||||
find_path(_OPENCL_CPP_INCLUDE_DIRS CL/cl.hpp)
|
"${OPENCL_INCLUDE_DIR}/Headers/cl.h"
|
||||||
|
OPENCL_VERSION_${VERSION}
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
check_symbol_exists(
|
||||||
|
CL_VERSION_${VERSION}
|
||||||
|
"${OPENCL_INCLUDE_DIR}/CL/cl.h"
|
||||||
|
OPENCL_VERSION_${VERSION}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
# The AMD SDK currently installs both x86 and x86_64 libraries
|
if(OPENCL_VERSION_${VERSION})
|
||||||
# This is only a hack to find out architecture
|
string(REPLACE "_" "." VERSION "${VERSION}")
|
||||||
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
|
set(OPENCL_VERSION_STRING ${VERSION} PARENT_SCOPE)
|
||||||
set(OPENCL_LIB_DIR "$ENV{ATISTREAMSDKROOT}/lib/x86_64")
|
string(REGEX MATCHALL "[0-9]+" version_components "${VERSION}")
|
||||||
set(OPENCL_LIB_DIR "$ENV{ATIINTERNALSTREAMSDKROOT}/lib/x86_64")
|
list(GET version_components 0 major_version)
|
||||||
else()
|
list(GET version_components 1 minor_version)
|
||||||
set(OPENCL_LIB_DIR "$ENV{ATISTREAMSDKROOT}/lib/x86")
|
set(OPENCL_VERSION_MAJOR ${major_version} PARENT_SCOPE)
|
||||||
set(OPENCL_LIB_DIR "$ENV{ATIINTERNALSTREAMSDKROOT}/lib/x86")
|
set(OPENCL_VERSION_MINOR ${minor_version} PARENT_SCOPE)
|
||||||
endif()
|
break()
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
cmake_pop_check_state()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
# find out if the user asked for a 64-bit build, and use the corresponding
|
find_path(OPENCL_INCLUDE_DIR
|
||||||
# 64 or 32 bit NVIDIA library paths to the search:
|
NAMES
|
||||||
string(REGEX MATCH "Win64" ISWIN64 ${CMAKE_GENERATOR})
|
CL/cl.h OpenCL/cl.h
|
||||||
if("${ISWIN64}" STREQUAL "Win64")
|
PATHS
|
||||||
find_library(OPENCL_LIBRARIES OpenCL.lib ${OPENCL_LIB_DIR} $ENV{CUDA_LIB_PATH} $ENV{CUDA_PATH}/lib/x64)
|
ENV "PROGRAMFILES(X86)"
|
||||||
else()
|
ENV AMDAPPSDKROOT
|
||||||
find_library(OPENCL_LIBRARIES OpenCL.lib ${OPENCL_LIB_DIR} $ENV{CUDA_LIB_PATH} $ENV{CUDA_PATH}/lib/Win32)
|
ENV INTELOCLSDKROOT
|
||||||
endif()
|
ENV NVSDKCOMPUTE_ROOT
|
||||||
|
ENV CUDA_PATH
|
||||||
|
ENV ATISTREAMSDKROOT
|
||||||
|
ENV OCL_ROOT
|
||||||
|
/usr/local/cuda/include
|
||||||
|
PATH_SUFFIXES
|
||||||
|
include
|
||||||
|
OpenCL/common/inc
|
||||||
|
"AMD APP/include"
|
||||||
|
)
|
||||||
|
|
||||||
get_filename_component(_OPENCL_INC_CAND ${OPENCL_LIB_DIR}/../../include ABSOLUTE)
|
find_path(_OPENCL_CPP_INCLUDE_DIRS
|
||||||
|
NAMES
|
||||||
|
CL/cl.hpp OpenCL/cl.hpp
|
||||||
|
PATHS
|
||||||
|
ENV "PROGRAMFILES(X86)"
|
||||||
|
ENV AMDAPPSDKROOT
|
||||||
|
ENV INTELOCLSDKROOT
|
||||||
|
ENV NVSDKCOMPUTE_ROOT
|
||||||
|
ENV CUDA_PATH
|
||||||
|
ENV ATISTREAMSDKROOT
|
||||||
|
ENV OCL_ROOT
|
||||||
|
/usr/local/cuda/include
|
||||||
|
PATH_SUFFIXES
|
||||||
|
include
|
||||||
|
OpenCL/common/inc
|
||||||
|
"AMD APP/include"
|
||||||
|
)
|
||||||
|
|
||||||
# On Win32 search relative to the library
|
set(OPENCL_INCLUDE_DIRS ${OPENCL_INCLUDE_DIR})
|
||||||
find_path(OPENCL_INCLUDE_DIRS CL/cl.h PATHS "${_OPENCL_INC_CAND}" $ENV{CUDA_INC_PATH} $ENV{CUDA_PATH}/include)
|
if(_OPENCL_CPP_INCLUDE_DIRS)
|
||||||
find_path(_OPENCL_CPP_INCLUDE_DIRS CL/cl.hpp PATHS "${_OPENCL_INC_CAND}" $ENV{CUDA_INC_PATH} $ENV{CUDA_PATH}/include)
|
set(OPENCL_HAS_CPP_BINDINGS TRUE)
|
||||||
|
list(APPEND OPENCL_INCLUDE_DIRS ${_OPENCL_CPP_INCLUDE_DIRS})
|
||||||
else()
|
# This is often the same, so clean up
|
||||||
# Unix style platforms
|
list(REMOVE_DUPLICATES OPENCL_INCLUDE_DIRS)
|
||||||
find_library(OPENCL_LIBRARIES OpenCL
|
|
||||||
ENV LD_LIBRARY_PATH
|
|
||||||
)
|
|
||||||
|
|
||||||
get_filename_component(OPENCL_LIB_DIR ${OPENCL_LIBRARIES} PATH)
|
|
||||||
get_filename_component(_OPENCL_INC_CAND ${OPENCL_LIB_DIR}/../../include ABSOLUTE)
|
|
||||||
|
|
||||||
# The AMD SDK currently does not place its headers
|
|
||||||
# in /usr/include, therefore also search relative
|
|
||||||
# to the library
|
|
||||||
find_path(OPENCL_INCLUDE_DIRS CL/cl.h PATHS ${_OPENCL_INC_CAND} "/usr/local/cuda/include")
|
|
||||||
find_path(_OPENCL_CPP_INCLUDE_DIRS CL/cl.hpp PATHS ${_OPENCL_INC_CAND} "/usr/local/cuda/include")
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
_FIND_OPENCL_VERSION()
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
|
||||||
|
find_library(OPENCL_LIBRARY
|
||||||
|
NAMES OpenCL
|
||||||
|
PATHS
|
||||||
|
ENV "PROGRAMFILES(X86)"
|
||||||
|
ENV AMDAPPSDKROOT
|
||||||
|
ENV INTELOCLSDKROOT
|
||||||
|
ENV CUDA_PATH
|
||||||
|
ENV NVSDKCOMPUTE_ROOT
|
||||||
|
ENV ATISTREAMSDKROOT
|
||||||
|
ENV OCL_ROOT
|
||||||
|
PATH_SUFFIXES
|
||||||
|
"AMD APP/lib/x86"
|
||||||
|
lib/x86
|
||||||
|
lib/Win32
|
||||||
|
OpenCL/common/lib/Win32
|
||||||
|
)
|
||||||
|
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||||
|
find_library(OPENCL_LIBRARY
|
||||||
|
NAMES OpenCL
|
||||||
|
PATHS
|
||||||
|
ENV "PROGRAMFILES(X86)"
|
||||||
|
ENV AMDAPPSDKROOT
|
||||||
|
ENV INTELOCLSDKROOT
|
||||||
|
ENV CUDA_PATH
|
||||||
|
ENV NVSDKCOMPUTE_ROOT
|
||||||
|
ENV ATISTREAMSDKROOT
|
||||||
|
ENV OCL_ROOT
|
||||||
|
PATH_SUFFIXES
|
||||||
|
"AMD APP/lib/x86_64"
|
||||||
|
lib/x86_64
|
||||||
|
lib/x64
|
||||||
|
OpenCL/common/lib/x64
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
|
||||||
|
find_library(OPENCL_LIBRARY
|
||||||
|
NAMES OpenCL
|
||||||
|
PATHS
|
||||||
|
ENV AMDAPPSDKROOT
|
||||||
|
ENV CUDA_PATH
|
||||||
|
ENV LD_LIBRARY_PATH
|
||||||
|
PATH_SUFFIXES
|
||||||
|
lib/x86
|
||||||
|
lib
|
||||||
|
)
|
||||||
|
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||||
|
find_library(OPENCL_LIBRARY
|
||||||
|
NAMES OpenCL
|
||||||
|
PATHS
|
||||||
|
ENV AMDAPPSDKROOT
|
||||||
|
ENV CUDA_PATH
|
||||||
|
ENV LD_LIBRARY_PATH
|
||||||
|
PATH_SUFFIXES
|
||||||
|
lib/x86_64
|
||||||
|
lib/x64
|
||||||
|
lib
|
||||||
|
lib64
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(OPENCL_LIBRARIES ${OPENCL_LIBRARY})
|
||||||
|
|
||||||
find_package_handle_standard_args(OPENCL DEFAULT_MSG OPENCL_LIBRARIES OPENCL_INCLUDE_DIRS)
|
find_package_handle_standard_args(OPENCL DEFAULT_MSG OPENCL_LIBRARIES OPENCL_INCLUDE_DIRS)
|
||||||
|
|
||||||
if(_OPENCL_CPP_INCLUDE_DIRS)
|
|
||||||
set(OPENCL_HAS_CPP_BINDINGS TRUE)
|
|
||||||
list(APPEND OPENCL_INCLUDE_DIRS ${_OPENCL_CPP_INCLUDE_DIRS})
|
|
||||||
# This is often the same, so clean up
|
|
||||||
list(REMOVE_DUPLICATES OPENCL_INCLUDE_DIRS)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
mark_as_advanced(
|
mark_as_advanced(
|
||||||
OPENCL_INCLUDE_DIRS
|
OPENCL_INCLUDE_DIRS
|
||||||
|
OPENCL_LIBRARIES
|
||||||
)
|
)
|
||||||
|
|
||||||
set_package_properties(OPENCL PROPERTIES
|
set_package_properties(OPENCL PROPERTIES
|
||||||
URL "https://www.khronos.org/opencl/"
|
URL "https://www.khronos.org/opencl/"
|
||||||
DESCRIPTION "Library for parallel programming"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if(OPENCL_INCLUDE_DIRS AND OPENCL_LIBRARIES)
|
if(OPENCL_FOUND AND OPENCL_VERSION_STRING)
|
||||||
set( OPENCL_FOUND TRUE )
|
set_package_properties(OPENCL PROPERTIES
|
||||||
add_definitions( -DOPENCL=1 )
|
DESCRIPTION "Library for parallel programming (found: v${OPENCL_VERSION_STRING})"
|
||||||
|
)
|
||||||
else()
|
else()
|
||||||
set( OPENCL_FOUND FALSE )
|
set_package_properties(OPENCL PROPERTIES
|
||||||
add_definitions( -DOPENCL=0 )
|
DESCRIPTION "Library for parallel programming"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(OPENCL_FOUND AND NOT TARGET OpenCL::OpenCL)
|
||||||
|
if(OPENCL_LIBRARY MATCHES "/([^/]+)\\.framework$")
|
||||||
|
add_library(OpenCL::OpenCL INTERFACE IMPORTED)
|
||||||
|
set_target_properties(OpenCL::OpenCL PROPERTIES
|
||||||
|
INTERFACE_LINK_LIBRARIES "${OPENCL_LIBRARY}"
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
add_library(OpenCL::OpenCL UNKNOWN IMPORTED)
|
||||||
|
set_target_properties(OpenCL::OpenCL PROPERTIES
|
||||||
|
IMPORTED_LOCATION "${OPENCL_LIBRARY}"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
set_target_properties(OpenCL::OpenCL PROPERTIES
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES "${OPENCL_INCLUDE_DIRS}"
|
||||||
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -49,16 +49,6 @@ if(OPENCL_FOUND)
|
|||||||
set(ACQ_GR_BLOCKS_HEADERS ${ACQ_GR_BLOCKS_HEADERS} pcps_opencl_acquisition_cc.h)
|
set(ACQ_GR_BLOCKS_HEADERS ${ACQ_GR_BLOCKS_HEADERS} pcps_opencl_acquisition_cc.h)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
if(OPENCL_FOUND)
|
|
||||||
include_directories(${OPENCL_INCLUDE_DIRS})
|
|
||||||
if(OS_IS_MACOSX)
|
|
||||||
set(OPT_LIBRARIES ${OPT_LIBRARIES} "-framework OpenCL")
|
|
||||||
else()
|
|
||||||
set(OPT_LIBRARIES ${OPT_LIBRARIES} ${OPENCL_LIBRARIES})
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
list(SORT ACQ_GR_BLOCKS_HEADERS)
|
list(SORT ACQ_GR_BLOCKS_HEADERS)
|
||||||
list(SORT ACQ_GR_BLOCKS_SOURCES)
|
list(SORT ACQ_GR_BLOCKS_SOURCES)
|
||||||
|
|
||||||
@@ -84,7 +74,6 @@ target_link_libraries(acquisition_gr_blocks
|
|||||||
channel_libs
|
channel_libs
|
||||||
acquisition_libs
|
acquisition_libs
|
||||||
core_system_parameters
|
core_system_parameters
|
||||||
${OPT_LIBRARIES}
|
|
||||||
PRIVATE
|
PRIVATE
|
||||||
Gflags::gflags
|
Gflags::gflags
|
||||||
Glog::glog
|
Glog::glog
|
||||||
@@ -101,7 +90,7 @@ target_include_directories(acquisition_gr_blocks
|
|||||||
)
|
)
|
||||||
|
|
||||||
if(OPENCL_FOUND)
|
if(OPENCL_FOUND)
|
||||||
target_include_directories(acquisition_gr_blocks PUBLIC ${OPENCL_INCLUDE_DIRS})
|
target_link_libraries(acquisition_gr_blocks PUBLIC OpenCL::OpenCL)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(ENABLE_CLANG_TIDY)
|
if(ENABLE_CLANG_TIDY)
|
||||||
|
|||||||
@@ -63,6 +63,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
|
#define CL_SILENCE_DEPRECATION
|
||||||
#include "opencl/cl.hpp"
|
#include "opencl/cl.hpp"
|
||||||
#else
|
#else
|
||||||
#include <CL/cl.hpp>
|
#include <CL/cl.hpp>
|
||||||
|
|||||||
@@ -73,12 +73,6 @@ if(OPENCL_FOUND)
|
|||||||
opencl/fft_setup.cc # Needs OpenCL
|
opencl/fft_setup.cc # Needs OpenCL
|
||||||
opencl/fft_kernelstring.cc # Needs OpenCL
|
opencl/fft_kernelstring.cc # Needs OpenCL
|
||||||
)
|
)
|
||||||
include_directories(${OPENCL_INCLUDE_DIRS})
|
|
||||||
if(OS_IS_MACOSX)
|
|
||||||
set(OPT_LIBRARIES ${OPT_LIBRARIES} "-framework OpenCL")
|
|
||||||
else()
|
|
||||||
set(OPT_LIBRARIES ${OPT_LIBRARIES} ${OPENCL_LIBRARIES})
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
list(SORT GNSS_SPLIBS_HEADERS)
|
list(SORT GNSS_SPLIBS_HEADERS)
|
||||||
@@ -105,7 +99,6 @@ target_link_libraries(algorithms_libs
|
|||||||
Gflags::gflags
|
Gflags::gflags
|
||||||
Gnuradio::runtime
|
Gnuradio::runtime
|
||||||
Gnuradio::blocks
|
Gnuradio::blocks
|
||||||
${OPT_LIBRARIES}
|
|
||||||
PRIVATE
|
PRIVATE
|
||||||
core_system_parameters
|
core_system_parameters
|
||||||
Volk::volk ${ORC_LIBRARIES}
|
Volk::volk ${ORC_LIBRARIES}
|
||||||
@@ -113,6 +106,13 @@ target_link_libraries(algorithms_libs
|
|||||||
Glog::glog
|
Glog::glog
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(OPENCL_FOUND)
|
||||||
|
target_link_libraries(algorithms_libs PUBLIC OpenCL::OpenCL)
|
||||||
|
target_include_directories(algorithms_libs PUBLIC
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/opencl
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
target_include_directories(algorithms_libs
|
target_include_directories(algorithms_libs
|
||||||
PUBLIC
|
PUBLIC
|
||||||
${CMAKE_SOURCE_DIR}/src/core/interfaces
|
${CMAKE_SOURCE_DIR}/src/core/interfaces
|
||||||
@@ -145,7 +145,7 @@ add_library(gnss_sdr_flags gnss_sdr_flags.cc gnss_sdr_flags.h)
|
|||||||
if(${FILESYSTEM_FOUND})
|
if(${FILESYSTEM_FOUND})
|
||||||
target_compile_definitions(gnss_sdr_flags PRIVATE -DHAS_STD_FILESYSTEM=1)
|
target_compile_definitions(gnss_sdr_flags PRIVATE -DHAS_STD_FILESYSTEM=1)
|
||||||
if(${find_experimental})
|
if(${find_experimental})
|
||||||
add_definitions(-DHAS_STD_FILESYSTEM_EXPERIMENTAL=1)
|
target_compile_definitions(gnss_sdr_flags PRIVATE -DHAS_STD_FILESYSTEM_EXPERIMENTAL=1)
|
||||||
endif()
|
endif()
|
||||||
target_link_libraries(gnss_sdr_flags PRIVATE std::filesystem)
|
target_link_libraries(gnss_sdr_flags PRIVATE std::filesystem)
|
||||||
else()
|
else()
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -57,6 +57,7 @@ extern "C"
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
|
#define CL_SILENCE_DEPRECATION
|
||||||
#include <OpenCL/opencl.h>
|
#include <OpenCL/opencl.h>
|
||||||
#else
|
#else
|
||||||
#include <CL/cl.h>
|
#include <CL/cl.h>
|
||||||
|
|||||||
Reference in New Issue
Block a user