From 271567047ce26e8a38ba4f59d6a4b87949f83a1a Mon Sep 17 00:00:00 2001 From: Alexander Kalistratov Date: Mon, 17 Jul 2023 18:00:22 +0200 Subject: [PATCH 1/3] Initial commit --- dpnp/CMakeLists.txt | 1 + .../extensions/sycl_ext/CMakeLists.txt | 72 +++ .../extensions/sycl_ext/dispatcher_utils.hpp | 558 ++++++++++++++++++ dpnp/backend/extensions/sycl_ext/sum_mean.cpp | 113 ++++ dpnp/backend/extensions/sycl_ext/sum_mean.hpp | 209 +++++++ dpnp/dpnp_iface_mathematical.py | 25 + 6 files changed, 978 insertions(+) create mode 100644 dpnp/backend/extensions/sycl_ext/CMakeLists.txt create mode 100644 dpnp/backend/extensions/sycl_ext/dispatcher_utils.hpp create mode 100644 dpnp/backend/extensions/sycl_ext/sum_mean.cpp create mode 100644 dpnp/backend/extensions/sycl_ext/sum_mean.hpp diff --git a/dpnp/CMakeLists.txt b/dpnp/CMakeLists.txt index 89524ab1c58..5ee84b28153 100644 --- a/dpnp/CMakeLists.txt +++ b/dpnp/CMakeLists.txt @@ -49,6 +49,7 @@ build_dpnp_cython_ext_with_backend(dparray ${CMAKE_CURRENT_SOURCE_DIR}/dparray.p add_subdirectory(backend) add_subdirectory(backend/extensions/lapack) add_subdirectory(backend/extensions/vm) +add_subdirectory(backend/extensions/sycl_ext) add_subdirectory(dpnp_algo) add_subdirectory(dpnp_utils) diff --git a/dpnp/backend/extensions/sycl_ext/CMakeLists.txt b/dpnp/backend/extensions/sycl_ext/CMakeLists.txt new file mode 100644 index 00000000000..9a18630eb3b --- /dev/null +++ b/dpnp/backend/extensions/sycl_ext/CMakeLists.txt @@ -0,0 +1,72 @@ +# ***************************************************************************** +# Copyright (c) 2016-2023, Intel Corporation +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# - Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# - Redistributions 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. +# +# 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 COPYRIGHT HOLDER 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. +# ***************************************************************************** + + +set(python_module_name _sycl_ext_impl) +pybind11_add_module(${python_module_name} MODULE + sum_mean.cpp +) + +if (WIN32) + if (${CMAKE_VERSION} VERSION_LESS "3.27") + # this is a work-around for target_link_options inserting option after -link option, cause + # linker to ignore it. + set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -fsycl-device-code-split=per_kernel") + endif() +endif() + +set_target_properties(${python_module_name} PROPERTIES CMAKE_POSITION_INDEPENDENT_CODE ON) + +target_include_directories(${python_module_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../include) +target_include_directories(${python_module_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../src) + +target_include_directories(${python_module_name} PUBLIC ${Dpctl_INCLUDE_DIRS}) +target_include_directories(${python_module_name} PUBLIC ${Dpctl_TENSOR_INCLUDE_DIR}) + +if (WIN32) + target_compile_options(${python_module_name} PRIVATE + /clang:-fno-approx-func + /clang:-fno-finite-math-only + ) +else() + target_compile_options(${python_module_name} PRIVATE + -fno-approx-func + -fno-finite-math-only + ) +endif() + +target_link_options(${python_module_name} PUBLIC -fsycl-device-code-split=per_kernel) +if (UNIX) + # this option is support on Linux only + target_link_options(${python_module_name} PUBLIC -fsycl-link-huge-device-code) +endif() + +if (DPNP_GENERATE_COVERAGE) + target_link_options(${python_module_name} PRIVATE -fprofile-instr-generate -fcoverage-mapping) +endif() + +install(TARGETS ${python_module_name} + DESTINATION "dpnp/backend/extensions/sycl_ext" +) diff --git a/dpnp/backend/extensions/sycl_ext/dispatcher_utils.hpp b/dpnp/backend/extensions/sycl_ext/dispatcher_utils.hpp new file mode 100644 index 00000000000..4bbb7a3c367 --- /dev/null +++ b/dpnp/backend/extensions/sycl_ext/dispatcher_utils.hpp @@ -0,0 +1,558 @@ +#include +#include + +namespace dpnp +{ +namespace backend +{ +namespace ext +{ +namespace sycl_ext +{ + +template