From 5a496a91b293f7cd79059afe5452d1b7856753ea Mon Sep 17 00:00:00 2001 From: Tom Lin Date: Thu, 28 Jul 2022 19:29:46 +0100 Subject: [PATCH] Fixup oneDPL inclusion --- CMakeLists.txt | 14 ++++++++++++++ cmake/register_models.cmake | 4 ---- cmake/shim_onedpl.cmake | 27 --------------------------- src/dpl_shim.h | 2 +- src/std-data/STDDataStream.cpp | 8 ++++---- src/std-data/model.cmake | 7 ++++--- src/std-indices/STDIndicesStream.cpp | 8 ++++---- src/std-indices/model.cmake | 5 ++++- src/std-ranges/STDRangesStream.cpp | 8 ++++---- src/std-ranges/model.cmake | 5 ++++- 10 files changed, 39 insertions(+), 49 deletions(-) delete mode 100644 cmake/shim_onedpl.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index f2af1e3..eb9e57b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,10 +102,24 @@ if (USE_ONEDPL) GIT_REPOSITORY https://github.com/oneapi-src/oneDPL.git GIT_TAG oneDPL-2021.7.0-release ) + string(TOLOWER ${USE_ONEDPL} ONEDPL_BACKEND) + # XXX oneDPL looks for omp instead of openmp, which mismatches(!) with ONEDPL_PAR_BACKEND if using find_package + if (ONEDPL_BACKEND STREQUAL "openmp") + set(ONEDPL_BACKEND omp) + endif () # Not using FetchContent_MakeAvailable (CMake>= 3.14) because we need EXCLUDE_FROM_ALL FetchContent_GetProperties(oneDPL) if (NOT oneDPL_POPULATED) FetchContent_Populate(oneDPL) + if (USE_TBB) + macro(find_package NAME) + if ("${NAME}" STREQUAL "TBB") + message(STATUS "Discarding oneDPL's call to find_package(${NAME} ${ARGN})") + else () + _find_package(${NAME} ${ARGN}) + endif () + endmacro() + endif () add_subdirectory(${onedpl_SOURCE_DIR} ${onedpl_BINARY_DIR} EXCLUDE_FROM_ALL) endif () endif() diff --git a/cmake/register_models.cmake b/cmake/register_models.cmake index 9432313..f180c03 100644 --- a/cmake/register_models.cmake +++ b/cmake/register_models.cmake @@ -71,10 +71,6 @@ macro(register_definitions) list(APPEND IMPL_DEFINITIONS ${ARGN}) endmacro() -macro(register_directories) - list(APPEND IMPL_DIRECTORIES ${ARGN}) -endmacro() - macro(register_flag_required NAME DESCRIPTION) list(APPEND CUSTOM_FLAGS_TRIPLE "${NAME}" "${DESCRIPTION}" ON "") endmacro() diff --git a/cmake/shim_onedpl.cmake b/cmake/shim_onedpl.cmake deleted file mode 100644 index 861d069..0000000 --- a/cmake/shim_onedpl.cmake +++ /dev/null @@ -1,27 +0,0 @@ - - -if (USE_ONEDPL) - # # XXX see https://www.intel.com/content/www/us/en/develop/documentation/oneapi-dpcpp-library-guide/top/oneapi-dpc-library-onedpl-overview.html - # # this is to avoid the system TBB headers (if exists) from having precedence which isn't compatible with oneDPL's par implementation - # register_definitions( - # PSTL_USE_PARALLEL_POLICIES=0 - # _GLIBCXX_USE_TBB_PAR_BACKEND=0 - # ) - register_definitions(USE_ONEDPL) - if (USE_ONEDPL STREQUAL "TBB") - register_definitions(ONEDPL_USE_TBB_BACKEND=1) - # TBB will either be linked later (USE_TBB==ON) or via extra libraries, don't do anything here - elseif (USE_ONEDPL STREQUAL "OPENMP") - register_definitions(ONEDPL_USE_OPENMP_BACKEND=1) - # Link OpenMP via CMAKE - find_package(OpenMP REQUIRED) - register_link_library(OpenMP::OpenMP_CXX) - elseif (USE_ONEDPL STREQUAL "SYCL") - register_definitions(ONEDPL_USE_DPCPP_BACKEND=1) - # This needs a SYCL compiler, will fail if CXX doesn't SYCL2020 - register_append_cxx_flags(ANY -fsycl-unnamed-lambda -fsycl) - else () - message(FATAL_ERROR "Unsupported USE_ONEDPL backend: ${USE_ONEDPL}, see USE_ONEDPL flag description for available values.") - endif () - register_directories(ANY ${onedpl_SOURCE_DIR}/include) -endif () \ No newline at end of file diff --git a/src/dpl_shim.h b/src/dpl_shim.h index 89012a3..e47ae99 100644 --- a/src/dpl_shim.h +++ b/src/dpl_shim.h @@ -15,7 +15,7 @@ #include #include -#ifdef ONEDPL_USE_DPCPP_BACKEND +#if ONEDPL_USE_DPCPP_BACKEND #include diff --git a/src/std-data/STDDataStream.cpp b/src/std-data/STDDataStream.cpp index 2bb6a33..b6641de 100644 --- a/src/std-data/STDDataStream.cpp +++ b/src/std-data/STDDataStream.cpp @@ -24,13 +24,13 @@ STDDataStream::STDDataStream(const int ARRAY_SIZE, int device) #endif { std::cout << "Backing storage typeid: " << typeid(a).name() << std::endl; -#if USE_ONEDPL +#ifdef USE_ONEDPL std::cout << "Using oneDPL backend: "; -#if defined(ONEDPL_USE_DPCPP_BACKEND) +#if ONEDPL_USE_DPCPP_BACKEND std::cout << "SYCL USM (device=" << exe_policy.queue().get_device().get_info() << ")"; -#elif defined(ONEDPL_USE_TBB_BACKEND) +#elif ONEDPL_USE_TBB_BACKEND std::cout << "TBB " TBB_VERSION_STRING; -#elif defined(ONEDPL_USE_OPENMP_BACKEND) +#elif ONEDPL_USE_OPENMP_BACKEND std::cout << "OpenMP"; #else std::cout << "Default"; diff --git a/src/std-data/model.cmake b/src/std-data/model.cmake index f2fecba..3d2399d 100644 --- a/src/std-data/model.cmake +++ b/src/std-data/model.cmake @@ -41,9 +41,6 @@ register_flag_optional(USE_ONEDPL macro(setup) set(CMAKE_CXX_STANDARD 17) - - include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/shim_onedpl.cmake) - if (NVHPC_OFFLOAD) set(NVHPC_FLAGS -stdpar -gpu=${NVHPC_OFFLOAD}) # propagate flags to linker so that it links with the gpu stuff as well @@ -56,4 +53,8 @@ macro(setup) if (USE_TBB) register_link_library(TBB::tbb) endif () + if (USE_ONEDPL) + register_definitions(USE_ONEDPL) + register_link_library(oneDPL) + endif () endmacro() diff --git a/src/std-indices/STDIndicesStream.cpp b/src/std-indices/STDIndicesStream.cpp index 7cacde3..9d98a1b 100644 --- a/src/std-indices/STDIndicesStream.cpp +++ b/src/std-indices/STDIndicesStream.cpp @@ -32,13 +32,13 @@ noexcept : array_size{ARRAY_SIZE}, range(0, array_size), #endif { std::cout << "Backing storage typeid: " << typeid(a).name() << std::endl; -#if USE_ONEDPL +#ifdef USE_ONEDPL std::cout << "Using oneDPL backend: "; -#if defined(ONEDPL_USE_DPCPP_BACKEND) +#if ONEDPL_USE_DPCPP_BACKEND std::cout << "SYCL USM (device=" << exe_policy.queue().get_device().get_info() << ")"; -#elif defined(ONEDPL_USE_TBB_BACKEND) +#elif ONEDPL_USE_TBB_BACKEND std::cout << "TBB " TBB_VERSION_STRING; -#elif defined(ONEDPL_USE_OPENMP_BACKEND) +#elif ONEDPL_USE_OPENMP_BACKEND std::cout << "OpenMP"; #else std::cout << "Default"; diff --git a/src/std-indices/model.cmake b/src/std-indices/model.cmake index 36e2ed8..befa933 100644 --- a/src/std-indices/model.cmake +++ b/src/std-indices/model.cmake @@ -41,7 +41,6 @@ register_flag_optional(USE_ONEDPL macro(setup) set(CMAKE_CXX_STANDARD 17) - include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/shim_onedpl.cmake) if (NVHPC_OFFLOAD) set(NVHPC_FLAGS -stdpar -gpu=${NVHPC_OFFLOAD}) # propagate flags to linker so that it links with the gpu stuff as well @@ -54,4 +53,8 @@ macro(setup) if (USE_TBB) register_link_library(TBB::tbb) endif () + if (USE_ONEDPL) + register_definitions(USE_ONEDPL) + register_link_library(oneDPL) + endif () endmacro() diff --git a/src/std-ranges/STDRangesStream.cpp b/src/std-ranges/STDRangesStream.cpp index 29993bc..3ea32e4 100644 --- a/src/std-ranges/STDRangesStream.cpp +++ b/src/std-ranges/STDRangesStream.cpp @@ -32,13 +32,13 @@ noexcept : array_size{ARRAY_SIZE}, #endif { std::cout << "Backing storage typeid: " << typeid(a).name() << std::endl; -#if USE_ONEDPL +#ifdef USE_ONEDPL std::cout << "Using oneDPL backend: "; -#if defined(ONEDPL_USE_DPCPP_BACKEND) +#if ONEDPL_USE_DPCPP_BACKEND std::cout << "SYCL USM (device=" << exe_policy.queue().get_device().get_info() << ")"; -#elif defined(ONEDPL_USE_TBB_BACKEND) +#elif ONEDPL_USE_TBB_BACKEND std::cout << "TBB " TBB_VERSION_STRING; -#elif defined(ONEDPL_USE_OPENMP_BACKEND) +#elif ONEDPL_USE_OPENMP_BACKEND std::cout << "OpenMP"; #else std::cout << "Default"; diff --git a/src/std-ranges/model.cmake b/src/std-ranges/model.cmake index 2d90afc..268cc14 100644 --- a/src/std-ranges/model.cmake +++ b/src/std-ranges/model.cmake @@ -33,11 +33,14 @@ macro(setup) unset(CMAKE_CXX_STANDARD) # drop any existing standard we have set by default # and append our own: register_append_cxx_flags(ANY -std=c++2a) - include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/shim_onedpl.cmake) if (USE_VECTOR) register_definitions(USE_VECTOR) endif () if (USE_TBB) register_link_library(TBB::tbb) endif () + if (USE_ONEDPL) + register_definitions(USE_ONEDPL) + register_link_library(oneDPL) + endif () endmacro()