From fe9319cf2849fae091b2b055f8493d97bfa65398 Mon Sep 17 00:00:00 2001 From: Anton <100830759+antonwolfy@users.noreply.github.com> Date: Mon, 2 Dec 2024 21:14:47 +0100 Subject: [PATCH] Introduce `DPNP_WITH_REDIST` cmake option (#2199) The PR proposes to introduce `DPNP_WITH_REDIST` cmake options, defaulting to `OFF`. If set, cmake script add to RUNPATH an entry relative to `$ORIGIN` that would point to `$PREFIX/lib`, hence allowing native extensions to find DPC++ redistributable libraries. `conda-recipe/build.sh` is modified to set `DPNP_WITH_REDIST=TRUE`. It closes #2200. - [x] Have you provided a meaningful PR description? - [ ] Have you added a test, reproducer or referred to issue with a reproducer? - [x] Have you tested your changes locally for CPU and GPU devices? - [x] Have you made sure that new changes do not introduce compiler warnings? - [ ] Have you checked performance impact of proposed changes? - [ ] If this PR is a work in progress, are you filing the PR as a draft? --- CMakeLists.txt | 5 +++-- conda-recipe/bld.bat | 2 +- conda-recipe/build.sh | 3 ++- dpnp/CMakeLists.txt | 11 +++++++---- dpnp/backend/CMakeLists.txt | 4 ++++ dpnp/backend/extensions/blas/CMakeLists.txt | 4 ++++ dpnp/backend/extensions/fft/CMakeLists.txt | 4 ++++ dpnp/backend/extensions/lapack/CMakeLists.txt | 4 ++++ dpnp/backend/extensions/statistics/CMakeLists.txt | 4 ++++ dpnp/backend/extensions/ufunc/CMakeLists.txt | 4 ++++ dpnp/backend/extensions/vm/CMakeLists.txt | 4 ++++ 11 files changed, 41 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3205a6121ae..46d3e65b7e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,8 +6,9 @@ project(dpnp DESCRIPTION "NumPy-like API accelerated by SYCL." ) -option(DPNP_GENERATE_COVERAGE "Enable build DPNP with coverage instrumentation" FALSE) -option(DPNP_BACKEND_TESTS "Enable building of DPNP backend test suite" FALSE) +option(DPNP_GENERATE_COVERAGE "Enable build DPNP with coverage instrumentation" OFF) +option(DPNP_BACKEND_TESTS "Enable building of DPNP backend test suite" OFF) +option(DPNP_WITH_REDIST "Build DPNP assuming DPC++ redistributable is installed into Python prefix" OFF) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED True) diff --git a/conda-recipe/bld.bat b/conda-recipe/bld.bat index 922b6949d2f..3dcdf754e27 100644 --- a/conda-recipe/bld.bat +++ b/conda-recipe/bld.bat @@ -16,7 +16,7 @@ if DEFINED OVERRIDE_INTEL_IPO ( set "SKBUILD_ARGS=%SKBUILD_ARGS% -DCMAKE_INTERPROCEDURAL_OPTIMIZATION:BOOL=FALSE" ) -FOR %%V IN (14.0.0 14 15.0.0 15 16.0.0 16 17.0.0 17) DO @( +FOR %%V IN (17.0.0 17 18.0.0 18 19.0.0 19) DO @( REM set DIR_HINT if directory exists IF EXIST "%BUILD_PREFIX%\Library\lib\clang\%%V\" ( SET "SYCL_INCLUDE_DIR_HINT=%BUILD_PREFIX%\Library\lib\clang\%%V" diff --git a/conda-recipe/build.sh b/conda-recipe/build.sh index fa4b5a1c6e6..d4523cae7be 100755 --- a/conda-recipe/build.sh +++ b/conda-recipe/build.sh @@ -1,7 +1,7 @@ #!/bin/bash # This is necessary to help DPC++ find Intel libraries such as SVML, IRNG, etc in build prefix -export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${BUILD_PREFIX}/lib" +export LIBRARY_PATH="$LIBRARY_PATH:${BUILD_PREFIX}/lib" # Intel LLVM must cooperate with compiler and sysroot from conda echo "--gcc-toolchain=${BUILD_PREFIX} --sysroot=${BUILD_PREFIX}/${HOST}/sysroot -target ${HOST}" > icpx_for_conda.cfg @@ -18,6 +18,7 @@ export DPL_ROOT_HINT=$PREFIX export MKL_ROOT_HINT=$PREFIX SKBUILD_ARGS=(-- "-DCMAKE_C_COMPILER:PATH=icx" "-DCMAKE_CXX_COMPILER:PATH=icpx" "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON") SKBUILD_ARGS=("${SKBUILD_ARGS[@]}" "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON") +SKBUILD_ARGS=("${SKBUILD_ARGS[@]}" "-DDPNP_WITH_REDIST:BOOL=ON") # Build wheel package WHEELS_BUILD_ARGS=("-p" "manylinux_2_28_x86_64") diff --git a/dpnp/CMakeLists.txt b/dpnp/CMakeLists.txt index d4ac718954a..d49b0a90a91 100644 --- a/dpnp/CMakeLists.txt +++ b/dpnp/CMakeLists.txt @@ -1,6 +1,5 @@ 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}") @@ -41,15 +40,19 @@ function(build_dpnp_cython_ext _trgt _src _dest) VERBATIM COMMENT "Copying Cython-generated source for target ${_trgt} to dpnp source layout" ) endif() + + set(_rpath_value "$ORIGIN/..") + if (DPNP_WITH_REDIST) + set(_rpath_value "${_rpath_value}:$ORIGIN/../../../../") + endif() + set_target_properties(${_trgt} PROPERTIES INSTALL_RPATH ${_rpath_value}) + 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} PRIVATE dpnp_backend_library) - if (UNIX) - set_target_properties(${_trgt} PROPERTIES INSTALL_RPATH "$ORIGIN/..") - endif() endfunction() add_subdirectory(backend) diff --git a/dpnp/backend/CMakeLists.txt b/dpnp/backend/CMakeLists.txt index 1924ad64027..2a4a0fef370 100644 --- a/dpnp/backend/CMakeLists.txt +++ b/dpnp/backend/CMakeLists.txt @@ -100,6 +100,10 @@ add_library(dpnp_backend_library INTERFACE IMPORTED GLOBAL) target_include_directories(dpnp_backend_library BEFORE INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/src) target_link_libraries(dpnp_backend_library INTERFACE ${_trgt}) +if (DPNP_WITH_REDIST) + set_target_properties(${python_module_name} PROPERTIES INSTALL_RPATH "$ORIGIN/../../../") +endif() + if (DPNP_BACKEND_TESTS) add_subdirectory(tests) endif() diff --git a/dpnp/backend/extensions/blas/CMakeLists.txt b/dpnp/backend/extensions/blas/CMakeLists.txt index 1695785e794..0aafd1ba8b4 100644 --- a/dpnp/backend/extensions/blas/CMakeLists.txt +++ b/dpnp/backend/extensions/blas/CMakeLists.txt @@ -93,6 +93,10 @@ else() target_link_libraries(${python_module_name} PUBLIC MKL::MKL_SYCL::BLAS) endif() +if (DPNP_WITH_REDIST) + set_target_properties(${python_module_name} PROPERTIES INSTALL_RPATH "$ORIGIN/../../../../../../") +endif() + install(TARGETS ${python_module_name} DESTINATION "dpnp/backend/extensions/blas" ) diff --git a/dpnp/backend/extensions/fft/CMakeLists.txt b/dpnp/backend/extensions/fft/CMakeLists.txt index 939848a12d6..f9fd08a30cc 100644 --- a/dpnp/backend/extensions/fft/CMakeLists.txt +++ b/dpnp/backend/extensions/fft/CMakeLists.txt @@ -89,6 +89,10 @@ else() target_link_libraries(${python_module_name} PUBLIC MKL::MKL_SYCL::DFT) endif() +if (DPNP_WITH_REDIST) + set_target_properties(${python_module_name} PROPERTIES INSTALL_RPATH "$ORIGIN/../../../../../../") +endif() + install(TARGETS ${python_module_name} DESTINATION "dpnp/backend/extensions/fft" ) diff --git a/dpnp/backend/extensions/lapack/CMakeLists.txt b/dpnp/backend/extensions/lapack/CMakeLists.txt index 8d5dd5342b5..de37e25443e 100644 --- a/dpnp/backend/extensions/lapack/CMakeLists.txt +++ b/dpnp/backend/extensions/lapack/CMakeLists.txt @@ -107,6 +107,10 @@ else() target_link_libraries(${python_module_name} PUBLIC MKL::MKL_SYCL::LAPACK) endif() +if (DPNP_WITH_REDIST) + set_target_properties(${python_module_name} PROPERTIES INSTALL_RPATH "$ORIGIN/../../../../../../") +endif() + install(TARGETS ${python_module_name} DESTINATION "dpnp/backend/extensions/lapack" ) diff --git a/dpnp/backend/extensions/statistics/CMakeLists.txt b/dpnp/backend/extensions/statistics/CMakeLists.txt index 2b784555630..26dda280008 100644 --- a/dpnp/backend/extensions/statistics/CMakeLists.txt +++ b/dpnp/backend/extensions/statistics/CMakeLists.txt @@ -84,6 +84,10 @@ if (DPNP_GENERATE_COVERAGE) target_link_options(${python_module_name} PRIVATE -fprofile-instr-generate -fcoverage-mapping) endif() +if (DPNP_WITH_REDIST) + set_target_properties(${python_module_name} PROPERTIES INSTALL_RPATH "$ORIGIN/../../../../../../") +endif() + install(TARGETS ${python_module_name} DESTINATION "dpnp/backend/extensions/statistics" ) diff --git a/dpnp/backend/extensions/ufunc/CMakeLists.txt b/dpnp/backend/extensions/ufunc/CMakeLists.txt index cb85bd6213e..c7158548b65 100644 --- a/dpnp/backend/extensions/ufunc/CMakeLists.txt +++ b/dpnp/backend/extensions/ufunc/CMakeLists.txt @@ -103,6 +103,10 @@ if (DPNP_GENERATE_COVERAGE) target_link_options(${python_module_name} PRIVATE -fprofile-instr-generate -fcoverage-mapping) endif() +if (DPNP_WITH_REDIST) + set_target_properties(${python_module_name} PROPERTIES INSTALL_RPATH "$ORIGIN/../../../../../../") +endif() + install(TARGETS ${python_module_name} DESTINATION "dpnp/backend/extensions/ufunc" ) diff --git a/dpnp/backend/extensions/vm/CMakeLists.txt b/dpnp/backend/extensions/vm/CMakeLists.txt index 0bbf6476aa5..79b2238b74d 100644 --- a/dpnp/backend/extensions/vm/CMakeLists.txt +++ b/dpnp/backend/extensions/vm/CMakeLists.txt @@ -120,6 +120,10 @@ else() target_link_libraries(${python_module_name} PUBLIC MKL::MKL_SYCL::VM) endif() +if (DPNP_WITH_REDIST) + set_target_properties(${python_module_name} PROPERTIES INSTALL_RPATH "$ORIGIN/../../../../../../") +endif() + install(TARGETS ${python_module_name} DESTINATION "dpnp/backend/extensions/vm" )