Skip to content

Commit

Permalink
Use IntelSYCL cmake script (#1611)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonwolfy authored Oct 31, 2023
1 parent 5d8cf2d commit d389bd4
Show file tree
Hide file tree
Showing 6 changed files with 400 additions and 28 deletions.
10 changes: 3 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
cmake_minimum_required(VERSION 3.21...3.26 FATAL_ERROR)

if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24")
cmake_policy(SET CMP0135 NEW)
endif()
cmake_minimum_required(VERSION 3.21...3.27 FATAL_ERROR)

project(dpnp
DESCRIPTION "NumPy-like API accelerated by SYCL."
Expand All @@ -27,7 +23,7 @@ endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${DPCTL_MODULE_PATH})


find_package(IntelDPCPP REQUIRED)
find_package(IntelSYCL REQUIRED PATHS ${CMAKE_SOURCE_DIR}/dpnp/backend/cmake/Modules NO_DEFAULT_PATH)
find_package(TBB QUIET)
if(TBB_FOUND)
find_package(TBB REQUIRED)
Expand Down Expand Up @@ -77,7 +73,7 @@ FetchContent_Declare(
)
FetchContent_MakeAvailable(pybind11)

find_package(PythonExtensions REQUIRED)
find_package(Python REQUIRED COMPONENTS Development.Module)
find_package(NumPy REQUIRED)

set(CYTHON_FLAGS "-t -w \"${CMAKE_SOURCE_DIR}\"")
Expand Down
33 changes: 20 additions & 13 deletions dpnp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,46 +1,53 @@

function(build_dpnp_cython_ext _trgt _src _dest)
set(options SYCL)
cmake_parse_arguments(BUILD_DPNP_EXT "${options}" "" "" ${ARGN})
add_cython_target(${_trgt} ${_src} CXX OUTPUT_VAR _generated_src)
message(STATUS "Using ${_trgt}")
add_library(${_trgt} MODULE ${_generated_src})

Python_add_library(${_trgt} MODULE WITH_SOABI ${_generated_src})
set(_trgt_deps "${_trgt}_deps")
add_custom_target(${_trgt_deps} DEPENDS ${_src})
add_dependencies(${_trgt} ${_trgt_deps})

if (BUILD_DPNP_EXT_SYCL)
add_sycl_to_target(TARGET ${_trgt} SOURCES ${_generated_src})
endif()

if (DPNP_GENERATE_COVERAGE)
target_compile_definitions(${_trgt} PRIVATE CYTHON_TRACE=1 CYTHON_TRACE_NOGIL=1)
target_compile_options(${_trgt} PRIVATE "-fno-sycl-use-footer")
endif()
target_compile_definitions(${_trgt} PRIVATE NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION)

# NumPy
target_compile_definitions(${_trgt} PRIVATE NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION)
target_include_directories(${_trgt} PRIVATE ${NumPy_INCLUDE_DIR})

# Dpctl
target_include_directories(${_trgt} PRIVATE ${Dpctl_INCLUDE_DIR})
target_link_directories(${_trgt} PRIVATE ${Dpctl_INCLUDE_DIR}/..)
target_link_libraries(${_trgt} DPCTLSyclInterface)
target_link_libraries(${_trgt} PRIVATE DPCTLSyclInterface)

set(_linker_options "LINKER:${DPNP_LDFLAGS}")
target_link_options(${_trgt} PRIVATE ${_linker_options})
python_extension_module(${_trgt})

if (DPNP_GENERATE_COVERAGE)
set(_copy_cxx_trgt "${_trgt}_copy_cxx")
add_custom_target(
${_copy_cxx_trgt} ALL
COMMAND ${CMAKE_COMMAND}
-DSOURCE_FILE=${_generated_src}
-DDEST=${CMAKE_CURRENT_SOURCE_DIR}
-P ${CMAKE_SOURCE_DIR}/dpnp/cmake/copy_existing.cmake
DEPENDS ${_trgt}
VERBATIM
COMMENT "Copying Cython-generated source for target ${_trgt} to dpnp source layout"
${_copy_cxx_trgt} ALL COMMAND ${CMAKE_COMMAND}
-DSOURCE_FILE=${_generated_src}
-DDEST=${CMAKE_CURRENT_SOURCE_DIR}
-P ${CMAKE_SOURCE_DIR}/dpnp/cmake/copy_existing.cmake
DEPENDS ${_trgt}
VERBATIM COMMENT "Copying Cython-generated source for target ${_trgt} to dpnp source layout"
)
endif()
install(TARGETS ${_trgt} LIBRARY DESTINATION ${_dest})
endfunction()

function(build_dpnp_cython_ext_with_backend _trgt _src _dest)
build_dpnp_cython_ext(${_trgt} ${_src} ${_dest})
target_link_libraries(${_trgt} dpnp_backend_library)
target_link_libraries(${_trgt} PRIVATE dpnp_backend_library)
if (UNIX)
set_target_properties(${_trgt} PROPERTIES INSTALL_RPATH "$ORIGIN/..")
endif()
Expand Down
Loading

0 comments on commit d389bd4

Please sign in to comment.