Skip to content

Commit

Permalink
Merge pull request #1907 from IntelPython/backport-to-maintenance-0.1…
Browse files Browse the repository at this point in the history
…8.x/gh-1893
  • Loading branch information
oleksandr-pavlyk authored Nov 21, 2024
2 parents 74e8957 + a295c11 commit 472f6ca
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 64 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ option(DPCTL_TARGET_CUDA
"Build DPCTL to target CUDA devices"
OFF
)
option(DPCTL_WITH_REDIST "Build DPCTL assuming DPC++ redistributable is installed into Python prefix" OFF)

find_package(IntelSYCL REQUIRED PATHS ${CMAKE_SOURCE_DIR}/cmake NO_DEFAULT_PATH)

Expand Down
2 changes: 1 addition & 1 deletion conda-recipe/bld.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if DEFINED OVERRIDE_INTEL_IPO (
set "CMAKE_ARGS=%CMAKE_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"
Expand Down
8 changes: 2 additions & 6 deletions conda-recipe/build.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -22,7 +22,7 @@ export CMAKE_GENERATOR=Ninja
# Make CMake verbose
export VERBOSE=1

CMAKE_ARGS="${CMAKE_ARGS} -DDPCTL_LEVEL_ZERO_INCLUDE_DIR=${PREFIX}/include/level_zero"
CMAKE_ARGS="${CMAKE_ARGS} -DDPCTL_LEVEL_ZERO_INCLUDE_DIR=${PREFIX}/include/level_zero -DDPCTL_WITH_REDIST=ON"

# -wnx flags mean: --wheel --no-isolation --skip-dependency-check
${PYTHON} -m build -w -n -x
Expand All @@ -43,7 +43,3 @@ ${PYTHON} -m pip install dist/dpctl*.whl \
if [[ -d "${WHEELS_OUTPUT_FOLDER}" ]]; then
cp dist/dpctl*.whl "${WHEELS_OUTPUT_FOLDER[@]}"
fi

# need to create this folder so ensure that .dpctl-post-link.sh can work correctly
mkdir -p $PREFIX/etc/OpenCL/vendors
echo "dpctl creates symbolic link to system installed /etc/OpenCL/vendors/intel.icd as a work-around." > $PREFIX/etc/OpenCL/vendors/.dpctl_readme
5 changes: 3 additions & 2 deletions conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ requirements:
- pip >=24.0
- level-zero-devel >=1.16
- pybind11 >=2.12
- {{ pin_compatible('dpcpp-cpp-rt', min_pin='x.x', max_pin='x') }}
- {{ pin_compatible('intel-sycl-rt', min_pin='x.x', max_pin='x') }}
- {{ pin_compatible('intel-cmplr-lib-rt', min_pin='x.x', max_pin='x') }}
# Ensure we are using latest version of setuptools, since we don't need
# editable environments for release.
- setuptools >=69
Expand All @@ -51,7 +52,7 @@ requirements:
- tomli # [py<311]
run:
- python
- {{ pin_compatible('dpcpp-cpp-rt', min_pin='x.x', max_pin='x') }}
- {{ pin_compatible('intel-sycl-rt', min_pin='x.x', max_pin='x') }}
- {{ pin_compatible('intel-cmplr-lib-rt', min_pin='x.x', max_pin='x') }}
- numpy

Expand Down
10 changes: 9 additions & 1 deletion dpctl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ set(CMAKE_INSTALL_RPATH "$ORIGIN")

function(build_dpctl_ext _trgt _src _dest)
set(options SYCL)
cmake_parse_arguments(BUILD_DPCTL_EXT "${options}" "" "" ${ARGN})
cmake_parse_arguments(BUILD_DPCTL_EXT "${options}" "RELATIVE_PATH" "" ${ARGN})
add_cython_target(${_trgt} ${_src} CXX OUTPUT_VAR _generated_src)
set(_cythonize_trgt "${_trgt}_cythonize_pyx")
Python_add_library(${_trgt} MODULE WITH_SOABI ${_generated_src})
Expand Down Expand Up @@ -146,6 +146,14 @@ function(build_dpctl_ext _trgt _src _dest)
get_filename_component(_generated_src_dir_dir ${_generated_src_dir} DIRECTORY)
# TODO: do not set directory if we did not generate header
target_include_directories(${_trgt} INTERFACE ${_generated_src_dir_dir})
set(_rpath_value "$ORIGIN")
if (BUILD_DPCTL_EXT_RELATIVE_PATH)
set(_rpath_value "${_rpath_value}/${BUILD_DPCTL_EXT_RELATIVE_PATH}")
endif()
if (DPCTL_WITH_REDIST)
set(_rpath_value "${_rpath_value}:${_rpath_value}/../../..")
endif()
set_target_properties(${_trgt} PROPERTIES INSTALL_RPATH ${_rpath_value})

install(TARGETS ${_trgt}
LIBRARY DESTINATION ${_dest})
Expand Down
2 changes: 1 addition & 1 deletion dpctl/memory/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

set(_cy_file ${CMAKE_CURRENT_SOURCE_DIR}/_memory.pyx)
get_filename_component(_trgt ${_cy_file} NAME_WLE)
build_dpctl_ext(${_trgt} ${_cy_file} "dpctl/memory" SYCL)
build_dpctl_ext(${_trgt} ${_cy_file} "dpctl/memory" SYCL RELATIVE_PATH "..")
# _memory include _opaque_smart_ptr.hpp
target_include_directories(${_trgt} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(DpctlCAPI INTERFACE ${_trgt}_headers)
2 changes: 1 addition & 1 deletion dpctl/program/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
file(GLOB _cython_sources *.pyx)
foreach(_cy_file ${_cython_sources})
get_filename_component(_trgt ${_cy_file} NAME_WLE)
build_dpctl_ext(${_trgt} ${_cy_file} "dpctl/program")
build_dpctl_ext(${_trgt} ${_cy_file} "dpctl/program" RELATIVE_PATH "..")
target_link_libraries(DpctlCAPI INTERFACE ${_trgt}_headers)
endforeach()
9 changes: 8 additions & 1 deletion dpctl/tensor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
file(GLOB _cython_sources *.pyx)
foreach(_cy_file ${_cython_sources})
get_filename_component(_trgt ${_cy_file} NAME_WLE)
build_dpctl_ext(${_trgt} ${_cy_file} "dpctl/tensor")
build_dpctl_ext(${_trgt} ${_cy_file} "dpctl/tensor" RELATIVE_PATH "..")
target_include_directories(${_trgt} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(DpctlCAPI INTERFACE ${_trgt}_headers)
endforeach()
Expand Down Expand Up @@ -284,5 +284,12 @@ foreach(python_module_name ${_py_trgts})
# TODO: update source so they refernece individual libraries instead of
# dpctl4pybind11.hpp. It will allow to simplify dependency tree
target_link_libraries(${python_module_name} PRIVATE DpctlCAPI)
if (DPCTL_WITH_REDIST)
set_target_properties(
${python_module_name}
PROPERTIES
INSTALL_RPATH "$ORIGIN/../../../.."
)
endif()
install(TARGETS ${python_module_name} DESTINATION "dpctl/tensor")
endforeach()
100 changes: 50 additions & 50 deletions dpctl/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,71 @@
file(GLOB _cython_sources *.pyx)
foreach(_cy_file ${_cython_sources})
get_filename_component(_trgt ${_cy_file} NAME_WLE)
build_dpctl_ext(${_trgt} ${_cy_file} "dpctl/utils")
build_dpctl_ext(${_trgt} ${_cy_file} "dpctl/utils" RELATIVE_PATH "..")
endforeach()

set(_pybind11_targets)

set(python_module_name _device_queries)
set(_module_src ${CMAKE_CURRENT_SOURCE_DIR}/src/device_queries.cpp)
pybind11_add_module(${python_module_name} MODULE
${_module_src}
)
add_sycl_to_target(TARGET ${python_module_name} SOURCES ${_module_src})
if(DPCTL_GENERATE_COVERAGE)
if(DPCTL_GENERATE_COVERAGE_FOR_PYBIND11_EXTENSIONS)
target_compile_options(${python_module_name}
PRIVATE -fprofile-instr-generate -fcoverage-mapping
)
endif()
target_link_options(${python_module_name}
PRIVATE -fprofile-instr-generate -fcoverage-mapping
)
endif()
if(_dpctl_sycl_targets)
# make fat binary
target_compile_options(
${python_module_name}
PRIVATE
-fsycl-targets=${_dpctl_sycl_targets}
)
target_link_options(
${python_module_name}
PRIVATE
-fsycl-targets=${_dpctl_sycl_targets}
)
endif()
target_link_libraries(${python_module_name} PRIVATE DpctlCAPI)
install(TARGETS ${python_module_name} DESTINATION "dpctl/utils")
list(APPEND _pybind11_targets ${python_module_name})


set(python_module_name _seq_order_keeper)
set(_module_src ${CMAKE_CURRENT_SOURCE_DIR}/src/order_keeper.cpp)
pybind11_add_module(${python_module_name} MODULE
${_module_src}
)
target_include_directories(${python_module_name} PRIVATE ${CUMAKE_CURRENT_SOURCE_DIR}/src)
target_include_directories(${python_module_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
add_sycl_to_target(TARGET ${python_module_name} SOURCES ${_module_src})
if(DPCTL_GENERATE_COVERAGE)
if(DPCTL_GENERATE_COVERAGE_FOR_PYBIND11_EXTENSIONS)
target_compile_options(${python_module_name}
PRIVATE -fprofile-instr-generate -fcoverage-mapping
)
endif()
target_link_options(${python_module_name}
PRIVATE -fprofile-instr-generate -fcoverage-mapping
)
endif()
if(_dpctl_sycl_targets)
# make fat binary
target_compile_options(
${python_module_name}
PRIVATE
-fsycl-targets=${_dpctl_sycl_targets}
)
target_link_options(
${python_module_name}
list(APPEND _pybind11_targets ${python_module_name})

set(_linker_options "LINKER:${DPCTL_LDFLAGS}")
foreach(python_module_name ${_pybind11_targets})
target_compile_options(${python_module_name} PRIVATE -fno-sycl-id-queries-fit-in-int)
target_link_options(${python_module_name} PRIVATE -fsycl-device-code-split=per_kernel)
target_include_directories(${python_module_name}
PRIVATE
-fsycl-targets=${_dpctl_sycl_targets}
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/include
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/
)
endif()
target_link_libraries(${python_module_name} PRIVATE DpctlCAPI)
install(TARGETS ${python_module_name} DESTINATION "dpctl/utils")
target_link_options(${python_module_name} PRIVATE ${_linker_options})
if(DPCTL_GENERATE_COVERAGE)
if(DPCTL_GENERATE_COVERAGE_FOR_PYBIND11_EXTENSIONS)
target_compile_options(${python_module_name}
PRIVATE -fprofile-instr-generate -fcoverage-mapping
)
endif()
target_link_options(${python_module_name}
PRIVATE -fprofile-instr-generate -fcoverage-mapping
)
endif()
if(_dpctl_sycl_targets)
# make fat binary
target_compile_options(
${python_module_name}
PRIVATE
-fsycl-targets=${_dpctl_sycl_targets}
)
target_link_options(
${python_module_name}
PRIVATE
-fsycl-targets=${_dpctl_sycl_targets}
)
endif()
# TODO: update source so they refernece individual libraries instead of
# dpctl4pybind11.hpp. It will allow to simplify dependency tree
target_link_libraries(${python_module_name} PRIVATE DpctlCAPI)
if (DPCTL_WITH_REDIST)
set_target_properties(
${python_module_name}
PROPERTIES
INSTALL_RPATH "$ORIGIN/../../../.."
)
endif()
install(TARGETS ${python_module_name} DESTINATION "dpctl/utils")
endforeach()
5 changes: 5 additions & 0 deletions libsyclinterface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ target_include_directories(DPCTLSyclInterfaceHeaders INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/include
)

if (DPCTL_WITH_REDIST)
cmake_path(RELATIVE_PATH CMAKE_SOURCE_DIR BASE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE _relative_path)
set_target_properties(DPCTLSyclInterface PROPERTIES INSTALL_RPATH "$ORIGIN/${_relative_path}/../../")
endif()

install(TARGETS
DPCTLSyclInterface
LIBRARY
Expand Down
2 changes: 1 addition & 1 deletion libsyclinterface/cmake/modules/FindIntelSyclCompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ if(${clangxx_result} MATCHES "0")
if("x${CMAKE_SYSTEM_NAME}" STREQUAL "xWindows")
find_file(
IntelSyclCompiler_SYCL_LIBRARY
NAMES "sycl.lib" "sycl6.lib" "sycl7.lib"
NAMES "sycl.lib" "sycl6.lib" "sycl7.lib" "sycl8.lib"
PATHS ${IntelSyclCompiler_LIBRARY_DIR}
)
find_file(
Expand Down

0 comments on commit 472f6ca

Please sign in to comment.