Skip to content

Depend on the source headers directly #1587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
# set_property(GLOBAL PROPERTY GLOBAL_DEPENDS_DEBUG_MODE 1)

if (UNIX)
add_link_options("-fuse-ld=lld")
endif()

# Option to generate code coverage report using llvm-cov and lcov.
option(DPCTL_GENERATE_COVERAGE
"Build dpctl with coverage instrumentation"
Expand Down Expand Up @@ -47,9 +51,14 @@ endif()

add_subdirectory(libsyclinterface)

file(GLOB _dpctl_capi_headers dpctl/apis/include/*.h*)
install(FILES ${_dpctl_capi_headers}
DESTINATION dpctl/include
add_library(DpctlCAPI INTERFACE)
target_include_directories(DpctlCAPI INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/dpctl/apis/include)
target_link_libraries(DpctlCAPI INTERFACE DPCTLSyclInterfaceHeaders)

install(DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/dpctl/apis/include/
DESTINATION ${CMAKE_INSTALL_PREFIX}/dpctl/include
FILES_MATCHING REGEX "\\.h(pp)?$"
)

# Define CMAKE_INSTALL_xxx: LIBDIR, INCLUDEDIR
Expand Down
2 changes: 1 addition & 1 deletion docs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function(_setup_doxygen)
if(DPCTL_ENABLE_DOXYGEN_HTML)
set(GENERATE_HTML "YES")
endif()
set(DOXYGEN_INPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../libsyclinterface/include)
set(DOXYGEN_INPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../libsyclinterface/include/syclinterface)
set(DOXYGEN_OUTPUT_DIR ${DOC_OUTPUT_DIR}/doxygen)
set(DOXYGEN_INDEX_FILE ${DOXYGEN_OUTPUT_DIR}/xml/index.xml)
set(DOXYFILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
Expand Down
145 changes: 48 additions & 97 deletions dpctl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
find_package(Python REQUIRED COMPONENTS Development.Module NumPy)

# -t is to only Cythonize sources with timestamps newer than existing CXX files (if present)
# -w is to set working directory (and correctly set __pyx_f[] array of filenames)
set(CYTHON_FLAGS "-t -w \"${CMAKE_SOURCE_DIR}\"")
find_package(Cython REQUIRED)

Expand Down Expand Up @@ -74,64 +76,6 @@ endif()

# at build time create include/ directory and copy header files over
set(DPCTL_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
add_custom_target(_build_time_create_dpctl_include ALL
COMMAND ${CMAKE_COMMAND} -E make_directory ${DPCTL_INCLUDE_DIR}
COMMAND ${CMAKE_COMMAND} -E make_directory ${DPCTL_INCLUDE_DIR}/syclinterface
COMMAND ${CMAKE_COMMAND} -E make_directory ${DPCTL_INCLUDE_DIR}/syclinterface/Support
COMMAND ${CMAKE_COMMAND} -E make_directory ${DPCTL_INCLUDE_DIR}/syclinterface/Config
DEPENDS DPCTLSyclInterface
)

set(_copied_header_files)
file(GLOB _syclinterface_h ${CMAKE_SOURCE_DIR}/libsyclinterface/include/*.h*)
foreach(hf ${_syclinterface_h})
get_filename_component(_header_name ${hf} NAME)
set(_target_header_file ${DPCTL_INCLUDE_DIR}/syclinterface/${_header_name})
list(APPEND _copied_header_files ${_target_header_file})
add_custom_command(OUTPUT ${_target_header_file}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${hf} ${_target_header_file}
DEPENDS ${hf} _build_time_create_dpctl_include
VERBATIM
)
endforeach()

file(GLOB _syclinterface_Support_h ${CMAKE_SOURCE_DIR}/libsyclinterface/include/Support/*.h)
foreach(hf ${_syclinterface_Support_h})
get_filename_component(_header_name ${hf} NAME)
set(_target_header_file ${DPCTL_INCLUDE_DIR}/syclinterface/Support/${_header_name})
list(APPEND _copied_header_files ${_target_header_file})
add_custom_command(OUTPUT ${_target_header_file}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${hf} ${_target_header_file}
DEPENDS ${hf} _build_time_create_dpctl_include
)
endforeach()

file(GLOB _syclinterface_Config_h ${CMAKE_SOURCE_DIR}/libsyclinterface/include/Config/*.h)
foreach(hf ${_syclinterface_Config_h})
get_filename_component(_header_name ${hf} NAME)
set(_target_header_file ${DPCTL_INCLUDE_DIR}/syclinterface/Config/${_header_name})
list(APPEND _copied_header_files ${_target_header_file})
add_custom_command(OUTPUT ${_target_header_file}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${hf} ${_target_header_file}
DEPENDS ${hf} _build_time_create_dpctl_include
)
endforeach()

file(GLOB _apis_h ${CMAKE_CURRENT_SOURCE_DIR}/apis/include/*)
foreach(hf ${_apis_h})
get_filename_component(_header_name ${hf} NAME)
set(_target_header_file ${DPCTL_INCLUDE_DIR}/${_header_name})
list(APPEND _copied_header_files ${_target_header_file})
add_custom_command(OUTPUT ${_target_header_file}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${hf} ${_target_header_file}
DEPENDS ${hf} _build_time_create_dpctl_include
)
endforeach()

add_custom_target(
_build_time_create_dpctl_include_copy ALL
DEPENDS ${_copied_header_files}
)

set(CMAKE_INSTALL_RPATH "$ORIGIN")

Expand All @@ -140,29 +84,29 @@ function(build_dpctl_ext _trgt _src _dest)
cmake_parse_arguments(BUILD_DPCTL_EXT "${options}" "" "" ${ARGN})
add_cython_target(${_trgt} ${_src} CXX OUTPUT_VAR _generated_src)
set(_cythonize_trgt "${_trgt}_cythonize_pyx")
add_custom_target(${_cythonize_trgt} DEPENDS ${_src})
Python_add_library(${_trgt} MODULE WITH_SOABI ${_generated_src})
if (BUILD_DPCTL_EXT_SYCL)
add_sycl_to_target(TARGET ${_trgt} SOURCES ${_generated_src})
if(_dpctl_sycl_targets)
# make fat binary
if(_dpctl_sycl_targets)
# make fat binary
target_compile_options(
${_trgt}
PRIVATE
-fsycl-targets=${_dpctl_sycl_targets}
)
target_link_options(
${_trgt}
PRIVATE
-fsycl-targets=${_dpctl_sycl_targets}
)
endif()
target_link_options(
${_trgt}
PRIVATE
-fsycl-targets=${_dpctl_sycl_targets}
)
endif()
endif()
target_include_directories(${_trgt} PRIVATE ${NumPy_INCLUDE_DIR} ${DPCTL_INCLUDE_DIR})
add_dependencies(${_trgt} _build_time_create_dpctl_include_copy ${_cythonize_trgt})
target_link_libraries(${_trgt} PRIVATE Python::NumPy)
if (DPCTL_GENERATE_COVERAGE)
target_compile_definitions(${_trgt} PRIVATE CYTHON_TRACE=1 CYTHON_TRACE_NOGIL=1)
# target_compile_options(${_trgt} PRIVATE -fno-sycl-use-footer)
if (BUILD_DPCTL_EXT_SYCL)
target_compile_options(${_trgt} PRIVATE -fno-sycl-use-footer)
endif()
endif()
target_link_libraries(${_trgt} PRIVATE DPCTLSyclInterface)
set(_linker_options "LINKER:${DPCTL_LDFLAGS}")
Expand All @@ -171,49 +115,56 @@ function(build_dpctl_ext _trgt _src _dest)
get_filename_component(_generated_src_dir ${_generated_src} DIRECTORY)
set(_generated_public_h "${_generated_src_dir}/${_name_wle}.h")
set(_generated_api_h "${_generated_src_dir}/${_name_wle}_api.h")
set(_copy_trgt "${_trgt}_copy_capi_include")
add_custom_target(
${_copy_trgt} ALL
COMMAND ${CMAKE_COMMAND}
-DSOURCE_FILE=${_generated_public_h}
-DDEST=${CMAKE_CURRENT_SOURCE_DIR}
-P ${CMAKE_SOURCE_DIR}/dpctl/cmake/copy_existing.cmake
COMMAND ${CMAKE_COMMAND}
-DSOURCE_FILE=${_generated_api_h}
-DDEST=${CMAKE_CURRENT_SOURCE_DIR}
-P ${CMAKE_SOURCE_DIR}/dpctl/cmake/copy_existing.cmake
DEPENDS ${_trgt}
VERBATIM
COMMENT "Copying Cython-generated headers to dpctl"
)

# TODO: create separate folder inside build folder that contains only
# headers related to this target and appropriate folder structure to
# eliminate shadow dependencies
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})

install(TARGETS ${_trgt}
LIBRARY DESTINATION ${_dest})
install(FILES
${_generated_api_h}
DESTINATION ${CMAKE_INSTALL_PREFIX}/dpctl/include/${_dest}
OPTIONAL)
install(FILES
${_generated_public_h}
DESTINATION ${CMAKE_INSTALL_PREFIX}/dpctl/include/${_dest}
OPTIONAL)
if (DPCTL_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}/dpctl/cmake/copy_existing.cmake
DEPENDS ${_trgt}
VERBATIM
COMMENT "Copying Cython-generated source to dpctl"
)
get_filename_component(_original_src_dir ${_src} DIRECTORY)
file(RELATIVE_PATH _rel_dir ${CMAKE_SOURCE_DIR} ${_original_src_dir})
install(FILES
${_generated_src}
DESTINATION ${CMAKE_INSTALL_PREFIX}/${_rel_dir}
)
endif()
install(TARGETS ${_trgt} LIBRARY DESTINATION ${_dest})

# Create target with headers only, because python is managing all the
# library imports at runtime
set(_trgt_headers ${_trgt}_headers)
add_library(${_trgt_headers} INTERFACE)
add_dependencies(${_trgt_headers} ${_trgt})
get_target_property(_trgt_headers_dir ${_trgt} INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories(${_trgt_headers} INTERFACE ${_trgt_headers_dir})
endfunction()

file(GLOB _cython_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.pyx)
list(REMOVE_ITEM _cython_sources ${CMAKE_CURRENT_SOURCE_DIR}/_sycl_queue.pyx)
foreach(_cy_file ${_cython_sources})
get_filename_component(_trgt ${_cy_file} NAME_WLE)
build_dpctl_ext(${_trgt} ${_cy_file} "dpctl")
target_link_libraries(DpctlCAPI INTERFACE ${_trgt}_headers)
endforeach()

set(_cy_file ${CMAKE_CURRENT_SOURCE_DIR}/_sycl_queue.pyx)
get_filename_component(_trgt ${_cy_file} NAME_WLE)
build_dpctl_ext(${_trgt} ${_cy_file} "dpctl" SYCL)
# _sycl_queue include _host_task_util.hpp
target_include_directories(${_trgt} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(DpctlCAPI INTERFACE ${_trgt}_headers)

add_subdirectory(program)
add_subdirectory(memory)
Expand Down
28 changes: 14 additions & 14 deletions dpctl/apis/include/dpctl_capi.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@
#else
#define CYTHON_EXTERN_C
#endif
#include "../_sycl_device.h"
#include "../_sycl_device_api.h"
#include "../_sycl_context.h"
#include "../_sycl_context_api.h"
#include "../_sycl_event.h"
#include "../_sycl_event_api.h"
#include "../_sycl_queue.h"
#include "../_sycl_queue_api.h"
#include "../memory/_memory.h"
#include "../memory/_memory_api.h"
#include "../tensor/_usmarray.h"
#include "../tensor/_usmarray_api.h"
#include "../program/_program.h"
#include "../program/_program_api.h"
#include "dpctl/_sycl_device.h"
#include "dpctl/_sycl_device_api.h"
#include "dpctl/_sycl_context.h"
#include "dpctl/_sycl_context_api.h"
#include "dpctl/_sycl_event.h"
#include "dpctl/_sycl_event_api.h"
#include "dpctl/_sycl_queue.h"
#include "dpctl/_sycl_queue_api.h"
#include "dpctl/memory/_memory.h"
#include "dpctl/memory/_memory_api.h"
#include "dpctl/tensor/_usmarray.h"
#include "dpctl/tensor/_usmarray_api.h"
#include "dpctl/program/_program.h"
#include "dpctl/program/_program_api.h"

// clang-format on

Expand Down
3 changes: 0 additions & 3 deletions dpctl/cmake/copy_existing.cmake

This file was deleted.

1 change: 1 addition & 0 deletions dpctl/memory/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ 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/memory")
target_link_libraries(DpctlCAPI INTERFACE ${_trgt}_headers)
endforeach()
1 change: 1 addition & 0 deletions dpctl/program/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ 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")
target_link_libraries(DpctlCAPI INTERFACE ${_trgt}_headers)
endforeach()
18 changes: 6 additions & 12 deletions dpctl/tensor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,18 @@ foreach(_cy_file ${_cython_sources})
get_filename_component(_trgt ${_cy_file} NAME_WLE)
build_dpctl_ext(${_trgt} ${_cy_file} "dpctl/tensor")
target_include_directories(${_trgt} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(DpctlCAPI INTERFACE ${_trgt}_headers)
endforeach()

# TODO: do we need to write this dependencies explicitly? Does it even work this
# way?
add_custom_target(_usmarray_deps SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/_slicing.pxi
${CMAKE_CURRENT_SOURCE_DIR}/_types.pxi
${CMAKE_CURRENT_SOURCE_DIR}/_stride_utils.pxi
)
add_dependencies(_usmarray _usmarray_deps)

add_custom_target(_dpctl4pybind11_deps
DEPENDS
_usmarray_copy_capi_include
_memory_copy_capi_include
_sycl_device_copy_capi_include
_sycl_queue_copy_capi_include
_sycl_context_copy_capi_include
_sycl_event_copy_capi_include
)

if(WIN32)
if (${CMAKE_VERSION} VERSION_LESS "3.23")
# this is a work-around for target_link_options inserting option after -link option, cause
Expand Down Expand Up @@ -242,7 +235,6 @@ foreach(python_module_name ${_py_trgts})
target_link_options(${python_module_name} PRIVATE -fsycl-device-code-split=per_kernel)
target_include_directories(${python_module_name}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../include
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/include
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/
)
Expand Down Expand Up @@ -270,6 +262,8 @@ foreach(python_module_name ${_py_trgts})
-fsycl-targets=${_dpctl_sycl_targets}
)
endif()
add_dependencies(${python_module_name} _dpctl4pybind11_deps)
# 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)
install(TARGETS ${python_module_name} DESTINATION "dpctl/tensor")
endforeach()
16 changes: 1 addition & 15 deletions dpctl/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@ foreach(_cy_file ${_cython_sources})
build_dpctl_ext(${_trgt} ${_cy_file} "dpctl/utils")
endforeach()

add_custom_target(_dpctl4pybind11_header_ready
DEPENDS
_usmarray_copy_capi_include
_memory_copy_capi_include
_sycl_device_copy_capi_include
_sycl_queue_copy_capi_include
_sycl_context_copy_capi_include
_sycl_event_copy_capi_include
)

set(python_module_name _device_queries)
set(_module_src ${CMAKE_CURRENT_SOURCE_DIR}/src/device_queries.cpp)
pybind11_add_module(${python_module_name} MODULE
Expand Down Expand Up @@ -44,9 +34,5 @@ if(_dpctl_sycl_targets)
-fsycl-targets=${_dpctl_sycl_targets}
)
endif()
target_include_directories(${python_module_name}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../include
)
add_dependencies(${python_module_name} _dpctl4pybind11_header_ready)
target_link_libraries(${python_module_name} PRIVATE DpctlCAPI)
install(TARGETS ${python_module_name} DESTINATION "dpctl/utils")
Loading