-
Notifications
You must be signed in to change notification settings - Fork 26
Refactor dpnp includes and add extension example #2941
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
base: master
Are you sure you want to change the base?
Changes from all commits
82a59d1
1547e62
22fe46e
82d90b9
c735f53
5ce4ee9
a84e5fc
4c05f49
020e5ea
f162a9d
4a4e5d2
d0127f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| _skbuild | ||
| build_cython | ||
| cython_debug | ||
| dpnp.egg-info | ||
| *.egg-info | ||
|
|
||
| # Byte-compiled / optimized / DLL files | ||
| __pycache__/ | ||
|
|
@@ -27,9 +27,13 @@ dpnp_pytest.* | |
| # Build examples | ||
| example3 | ||
|
|
||
| # moved cmake scripts | ||
| dpnp/resources/cmake | ||
|
|
||
| *dpnp_backend* | ||
| dpnp/include/dpnp/tensor/*.h | ||
| dpnp/**/*.cpython*.so | ||
| dpnp/**/*.pyd | ||
| *~ | ||
| core | ||
| *.so | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have a pattern with |
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -327,6 +327,21 @@ else() | |||||||||||||||||
| message(FATAL_ERROR "Unsupported system.") | ||||||||||||||||||
| endif() | ||||||||||||||||||
|
|
||||||||||||||||||
| # install dpnp-config.cmake for find_package() support | ||||||||||||||||||
| install( | ||||||||||||||||||
| FILES ${CMAKE_SOURCE_DIR}/cmake/dpnp-config.cmake | ||||||||||||||||||
| DESTINATION dpnp/resources/cmake | ||||||||||||||||||
| ) | ||||||||||||||||||
| install(FILES ${CMAKE_SOURCE_DIR}/cmake/dpnp-config.cmake DESTINATION lib/cmake/dpnp) | ||||||||||||||||||
|
Comment on lines
+331
to
+335
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can reduce duplication:
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
| # install dpnp4pybind11.hpp and usm_ndarray_constants.h into include folder | ||||||||||||||||||
| install( | ||||||||||||||||||
| DIRECTORY ${CMAKE_SOURCE_DIR}/dpnp/include/ | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It actually means the recurses into ALL subdirs. But there is another rule at So the same files might be written twice to the same location.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might need to specify explicitly: install(FILES
${CMAKE_SOURCE_DIR}/dpnp/include/dpnp4pybind11.hpp
${CMAKE_SOURCE_DIR}/dpnp/include/usm_ndarray_constants.h
DESTINATION dpnp/include)or to add |
||||||||||||||||||
| DESTINATION dpnp/include | ||||||||||||||||||
| FILES_MATCHING | ||||||||||||||||||
| REGEX "\\.(h|hpp)$" | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| # Define flags for CMAKE_BUILD_TYPE=Coverage | ||||||||||||||||||
| set(CMAKE_C_FLAGS_COVERAGE "${CMAKE_C_FLAGS_DEBUG} -O1 -g1 -DDEBUG") | ||||||||||||||||||
| set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_DEBUG} -O1 -g1 -DDEBUG") | ||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,63 @@ | ||||||
| #.rst: | ||||||
| # | ||||||
| # Find the include directory for ``dpnp4pybind11.hpp`` and dpnp tensor kernels. | ||||||
| # | ||||||
| # This module sets the following variables: | ||||||
| # | ||||||
| # ``Dpnp_FOUND`` | ||||||
| # True if DPNP was found. | ||||||
| # ``Dpnp_INCLUDE_DIR`` | ||||||
| # The include directory needed to use dpnp. | ||||||
| # ``Dpnp_TENSOR_INCLUDE_DIR`` | ||||||
| # The include directory for tensor kernels implementation. | ||||||
| # ``Dpnp_VERSION`` | ||||||
| # The version of dpnp found. | ||||||
| # | ||||||
| # The module will also explicitly define two cache variables: | ||||||
| # | ||||||
| # ``Dpnp_INCLUDE_DIR`` | ||||||
| # ``Dpnp_TENSOR_INCLUDE_DIR`` | ||||||
| # | ||||||
|
|
||||||
| if(NOT Dpnp_FOUND) | ||||||
| find_package(Python 3.10 REQUIRED COMPONENTS Interpreter Development.Module) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to have upper limit also?
Suggested change
|
||||||
|
|
||||||
| if(Python_EXECUTABLE) | ||||||
| execute_process( | ||||||
| COMMAND "${Python_EXECUTABLE}" -m dpnp --include-dir | ||||||
| OUTPUT_VARIABLE _dpnp_include_dir | ||||||
| OUTPUT_STRIP_TRAILING_WHITESPACE | ||||||
| ERROR_QUIET | ||||||
| ) | ||||||
| execute_process( | ||||||
| COMMAND "${Python_EXECUTABLE}" -c "import dpnp; print(dpnp.__version__)" | ||||||
| OUTPUT_VARIABLE Dpnp_VERSION | ||||||
| OUTPUT_STRIP_TRAILING_WHITESPACE | ||||||
| ERROR_QUIET | ||||||
| ) | ||||||
| endif() | ||||||
| endif() | ||||||
|
|
||||||
| find_path( | ||||||
| Dpnp_INCLUDE_DIR | ||||||
| dpnp4pybind11.hpp | ||||||
| PATHS "${_dpnp_include_dir}" "${Python_INCLUDE_DIRS}" | ||||||
| PATH_SUFFIXES dpnp/include | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to use |
||||||
| ) | ||||||
| get_filename_component(_dpnp_dir "${Dpnp_INCLUDE_DIR}" DIRECTORY) | ||||||
|
|
||||||
| find_path(Dpnp_TENSOR_INCLUDE_DIR kernels PATHS "${_dpnp_dir}/tensor/libtensor/include") | ||||||
|
|
||||||
| set(Dpnp_INCLUDE_DIRS ${Dpnp_INCLUDE_DIR}) | ||||||
|
|
||||||
| # handle the QUIETLY and REQUIRED arguments and set Dpnp_FOUND to TRUE if | ||||||
| # all listed variables are TRUE | ||||||
| include(FindPackageHandleStandardArgs) | ||||||
| find_package_handle_standard_args( | ||||||
| Dpnp | ||||||
| REQUIRED_VARS Dpnp_INCLUDE_DIR Dpnp_TENSOR_INCLUDE_DIR | ||||||
| VERSION_VAR Dpnp_VERSION | ||||||
| ) | ||||||
|
|
||||||
| mark_as_advanced(Dpnp_INCLUDE_DIR) | ||||||
| mark_as_advanced(Dpnp_TENSOR_INCLUDE_DIR) | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,7 +41,7 @@ def _dpnp_dir() -> str: | |
|
|
||
| def get_include_dir() -> str: | ||
| """Returns path to dpnp include directory containing dpnp4pybind11.hpp""" | ||
| return os.path.join(_dpnp_dir(), "backend", "include") | ||
| return os.path.join(_dpnp_dir(), "include") | ||
|
|
||
|
|
||
| def print_include_flags() -> None: | ||
|
|
@@ -61,6 +61,13 @@ def print_tensor_include_flags() -> None: | |
| print("-I " + libtensor_dir) | ||
|
|
||
|
|
||
| def print_cmake_dir() -> None: | ||
| """Prints directory with dpnp-config.cmake""" | ||
| dpnp_dir = _dpnp_dir() | ||
| cmake_dir = os.path.join(dpnp_dir, "resources", "cmake") | ||
| print(cmake_dir) | ||
|
|
||
|
|
||
| def main() -> None: | ||
| """Main entry-point.""" | ||
| parser = argparse.ArgumentParser() | ||
|
|
@@ -84,6 +91,11 @@ def main() -> None: | |
| action="store_true", | ||
| help="Path to dpnp libtensor include directory.", | ||
| ) | ||
| parser.add_argument( | ||
| "--cmakedir", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to test |
||
| action="store_true", | ||
| help="CMake module directory, ideal for setting -DDpnp_ROOT in CMake.", | ||
| ) | ||
| args = parser.parse_args() | ||
| if not sys.argv[1:]: | ||
| parser.print_help() | ||
|
|
@@ -95,6 +107,8 @@ def main() -> None: | |
| print_tensor_include_flags() | ||
| if args.tensor_include_dir: | ||
| print(get_tensor_include_dir()) | ||
| if args.cmakedir: | ||
| print_cmake_dir() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an option we can add a dedicated env file to
dpnp/enviromentsfolder and install all the requirements inSetup minicondastep