From 5e56e8e6d66066e6869b074b0f31969afca47186 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Fri, 7 Jan 2022 12:18:56 -0600 Subject: [PATCH 01/19] Changed building to use scikit-build and cmake to build dpctl The change to _dlpack was to fix incorrect path to includes (relative to current dir). --- .gitignore | 1 + CMakeLists.txt | 25 ++ dpctl/CMakeLists.txt | 56 +++ dpctl/cmake/copy_generated_headers.cmake | 3 + dpctl/memory/CMakeLists.txt | 6 + dpctl/program/CMakeLists.txt | 6 + dpctl/tensor/CMakeLists.txt | 6 + dpctl/tensor/_dlpack.pxd | 2 +- dpctl/tensor/_dlpack.pyx | 2 +- dpctl/utils/CMakeLists.txt | 6 + libsyclinterface/CMakeLists.txt | 71 ++-- setup.py | 448 +---------------------- 12 files changed, 164 insertions(+), 468 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 dpctl/CMakeLists.txt create mode 100644 dpctl/cmake/copy_generated_headers.cmake create mode 100644 dpctl/memory/CMakeLists.txt create mode 100644 dpctl/program/CMakeLists.txt create mode 100644 dpctl/tensor/CMakeLists.txt create mode 100644 dpctl/utils/CMakeLists.txt diff --git a/.gitignore b/.gitignore index 97cccfe031..ae22979595 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ __pycache__/ # CMake build and local install directory build +_skbuild build_cmake install diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000000..a8c03c3383 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required(VERSION 3.21 FATAL_ERROR) + +project(dpctl + LANGUAGES CXX + DESCRIPTION "Python interface for XPU programming" +) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED True) + +find_package(IntelDPCPP REQUIRED) + +add_subdirectory(libsyclinterface) + +file(GLOB _dpctl_capi_headers dpctl/apis/include/*.h*) +install(FILES ${_dpctl_capi_headers} + DESTINATION dpctl/include + COMPONENT DpctlCAPIHeaders +) + +add_subdirectory(dpctl) + +if (DPCTL_GENERATE_DOCS) + add_subdirectory(docs) +endif() diff --git a/dpctl/CMakeLists.txt b/dpctl/CMakeLists.txt new file mode 100644 index 0000000000..f0240c79ee --- /dev/null +++ b/dpctl/CMakeLists.txt @@ -0,0 +1,56 @@ + +find_package(PythonExtensions REQUIRED) +find_package(NumPy REQUIRED) +find_package(Cython REQUIRED) + +# 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 copy ${CMAKE_SOURCE_DIR}/libsyclinterface/include/* ${DPCTL_INCLUDE_DIR}/syclinterface + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/apis/include/* ${DPCTL_INCLUDE_DIR} + DEPENDS DPCTLSyclInterface +) + +set(CMAKE_INSTALL_RPATH "$ORIGIN") + +function(build_dpctl_ext _trgt _src _dest) + add_cython_target(${_trgt} ${_src} CXX OUTPUT_VAR _generated_src) + add_library(${_trgt} MODULE ${_generated_src}) + target_include_directories(${_trgt} PRIVATE ${NumPy_INCLUDE_DIR} ${DPCTL_INCLUDE_DIR}) + add_dependencies(${_trgt} _build_time_create_dpctl_include) + target_link_libraries(${_trgt} DPCTLSyclInterface) + python_extension_module(${_trgt}) + get_filename_component(_name_wle ${_generated_src} NAME_WLE) + 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_generated_headers.cmake + COMMAND ${CMAKE_COMMAND} + -DSOURCE_FILE=${_generated_api_h} + -DDEST=${CMAKE_CURRENT_SOURCE_DIR} + -P ${CMAKE_SOURCE_DIR}/dpctl/cmake/copy_generated_headers.cmake + DEPENDS ${_trgt} + VERBATIM + COMMENT "Copying Cython-generated headers to destination" + ) + install(TARGETS ${_trgt} LIBRARY DESTINATION ${_dest}) +endfunction() + +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") +endforeach() + +add_subdirectory(program) +add_subdirectory(memory) +add_subdirectory(tensor) +add_subdirectory(utils) diff --git a/dpctl/cmake/copy_generated_headers.cmake b/dpctl/cmake/copy_generated_headers.cmake new file mode 100644 index 0000000000..242dc29257 --- /dev/null +++ b/dpctl/cmake/copy_generated_headers.cmake @@ -0,0 +1,3 @@ +if (EXISTS ${SOURCE_FILE}) + configure_file(${SOURCE_FILE} ${DEST} COPYONLY) +endif() diff --git a/dpctl/memory/CMakeLists.txt b/dpctl/memory/CMakeLists.txt new file mode 100644 index 0000000000..c4f6d8469f --- /dev/null +++ b/dpctl/memory/CMakeLists.txt @@ -0,0 +1,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/memory") +endforeach() diff --git a/dpctl/program/CMakeLists.txt b/dpctl/program/CMakeLists.txt new file mode 100644 index 0000000000..f10706ed9d --- /dev/null +++ b/dpctl/program/CMakeLists.txt @@ -0,0 +1,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") +endforeach() diff --git a/dpctl/tensor/CMakeLists.txt b/dpctl/tensor/CMakeLists.txt new file mode 100644 index 0000000000..855bba7e8a --- /dev/null +++ b/dpctl/tensor/CMakeLists.txt @@ -0,0 +1,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/tensor") + target_include_directories(${_trgt} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include) +endforeach() diff --git a/dpctl/tensor/_dlpack.pxd b/dpctl/tensor/_dlpack.pxd index 439880f7d2..58176ceb84 100644 --- a/dpctl/tensor/_dlpack.pxd +++ b/dpctl/tensor/_dlpack.pxd @@ -21,7 +21,7 @@ from ._usmarray cimport usm_ndarray -cdef extern from './include/dlpack/dlpack.h' nogil: +cdef extern from 'dlpack/dlpack.h' nogil: int device_CPU 'kDLCPU' int device_oneAPI 'kDLOneAPI' int device_OpenCL 'kDLOpenCL' diff --git a/dpctl/tensor/_dlpack.pyx b/dpctl/tensor/_dlpack.pyx index 7d4ebfa0c3..fe762a016a 100644 --- a/dpctl/tensor/_dlpack.pyx +++ b/dpctl/tensor/_dlpack.pyx @@ -39,7 +39,7 @@ import dpctl import dpctl.memory as dpmem -cdef extern from './include/dlpack/dlpack.h' nogil: +cdef extern from 'dlpack/dlpack.h' nogil: cdef int DLPACK_VERSION cdef enum DLDeviceType: diff --git a/dpctl/utils/CMakeLists.txt b/dpctl/utils/CMakeLists.txt new file mode 100644 index 0000000000..11b0930052 --- /dev/null +++ b/dpctl/utils/CMakeLists.txt @@ -0,0 +1,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/utils") +endforeach() diff --git a/libsyclinterface/CMakeLists.txt b/libsyclinterface/CMakeLists.txt index 3362e2b2a3..6ec3314c56 100644 --- a/libsyclinterface/CMakeLists.txt +++ b/libsyclinterface/CMakeLists.txt @@ -125,7 +125,7 @@ elseif(UNIX) "-fsycl " ) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CFLAGS}") - set(CMAKE_CXX_FLAGS "${CXXFLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXXFLAGS}") set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${CFLAGS} -ggdb3 -DDEBUG" ) @@ -157,8 +157,11 @@ add_library(DPCTLSyclInterface ) target_include_directories(DPCTLSyclInterface - PRIVATE + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include/ + ${CMAKE_CURRENT_SOURCE_DIR}/include/Support + ${CMAKE_CURRENT_SOURCE_DIR}/include/Config + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/helper/include/ ${IntelSycl_SYCL_INCLUDE_DIR} ) @@ -186,29 +189,55 @@ if(DPCTL_ENABLE_LO_PROGRAM_CREATION) ) endif() -install(TARGETS - DPCTLSyclInterface - LIBRARY - DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/ -) - # Install all headers -file(GLOB HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h") -foreach(HEADER ${HEADERS}) - install(FILES "${HEADER}" DESTINATION include) -endforeach() -# Install all headers in include/Support -file(GLOB HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/Support/*.h") -foreach(HEADER ${HEADERS}) - install(FILES "${HEADER}" DESTINATION include/Support) -endforeach() +file(GLOB MAIN_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h") +file(GLOB SUPPORT_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/Support/*.h") +file(GLOB CONFIG_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/Config/*.h") -# Install all headers in include/Config -file(GLOB HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/Config/*.h") -foreach(HEADER ${HEADERS}) - install(FILES "${HEADER}" DESTINATION include/Config) +if (0) +set(ALL_HEADERS) +foreach(HEADER ${MAIN_HEADERS}) + list(APPEND ALL_HEADERS ${HEADER}) +endforeach() +foreach(HEADER ${SUPPORT_HEADERS}) + list(APPEND ALL_HEADERS ${HEADER}) endforeach() +foreach(HEADER ${CONFIG_HEADERS}) + list(APPEND ALL_HEADERS ${HEADER}) +endforeach() +endif() + +set_target_properties(DPCTLSyclInterface + PROPERTIES PUBLIC_HEADER + "${MAIN_HEADERS}" +) + +if (SKBUILD) + set(_lib_destination dpctl) + set(_include_destination dpctl/include/syclinterface) +else() + set(_lib_destination ${CMAKE_INSTALL_PREFIX}/lib) + set(_include_destination ${CMAKE_INSTALL_PREFIX}/include) +endif() + +install(TARGETS + DPCTLSyclInterface + LIBRARY + DESTINATION ${_lib_destination} + PUBLIC_HEADER + DESTINATION ${_include_destination} +) +install( + FILES ${SUPPORT_HEADERS} + DESTINATION ${_include_destination}/Support + COMPONENT SupportHeaders +) +install( + FILES ${CONFIG_HEADERS} + DESTINATION ${_include_destination}/Config + COMPONENT ConfigHeaders +) # Enable code coverage related settings if(DPCTL_GENERATE_COVERAGE) diff --git a/setup.py b/setup.py index d88580e242..8a2ba5726e 100644 --- a/setup.py +++ b/setup.py @@ -14,459 +14,18 @@ # See the License for the specific language governing permissions and # limitations under the License. -import glob -import os -import os.path -import shutil -import sys - -import numpy as np -import setuptools.command.build_ext as orig_build_ext -import setuptools.command.develop as orig_develop -import setuptools.command.install as orig_install -from Cython.Build import cythonize -from setuptools import Extension, find_packages, setup +from setuptools import find_packages +from skbuild import setup import versioneer -IS_WIN = False -IS_LIN = False - -if "linux" in sys.platform: - IS_LIN = True -elif sys.platform in ["win32", "cygwin"]: - IS_WIN = True -else: - assert False, "We currently do not build for " + sys.platform - -# global variable used to pass value of --coverage option of develop command -# to build_ext command -_coverage = False -dpctl_sycl_interface_lib = "dpctl" -dpctl_sycl_interface_include = os.path.join("dpctl", "include") - # Get long description with open("README.md", "r", encoding="utf-8") as file: long_description = file.read() -def remove_empty(li): - return [el for el in li if el] - - -def get_sdl_cflags(): - cflags = [] - if IS_LIN: - cflags = [ - "-fstack-protector", - "-fPIC", - "-D_FORTIFY_SOURCE=2", - "-Wformat", - "-Wformat-security", - ] - # Add cflags from environment - cflags += remove_empty(os.getenv("CFLAGS", "").split(" ")) - - return cflags - - -def get_sdl_ldflags(): - ldflags = [] - if IS_LIN: - ldflags = ["-Wl,-z,noexecstack,-z,relro,-z,now"] - elif IS_WIN: - ldflags = [r"/NXCompat", r"/DynamicBase"] - # Add ldflags from environment - ldflags += remove_empty(os.getenv("LDFLAGS", "").split(" ")) - - return ldflags - - -def get_other_cxxflags(): - if IS_LIN: - return ["-O3", "-std=c++17"] - elif IS_WIN: - # FIXME: These are specific to MSVC and we should first make sure - # what compiler we are using. - return [r"/Ox", r"/std:c++17"] - - -def get_suppressed_warning_flags(): - if IS_LIN: - # PEP 590 renamed "tp_print" to "tp_vectorcall" and this causes a flood - # of deprecation warnings in the Cython generated module. This flag - # temporarily suppresses the warnings. The flag should not be needed - # once we move to Python 3.9 and/or Cython 0.30. - return ["-Wno-deprecated-declarations"] - elif IS_WIN: - return [] - - -def build_backend(l0_support, coverage, sycl_compiler_prefix): - import os.path - from importlib.util import module_from_spec, spec_from_file_location - - spec = spec_from_file_location( - "build_backend", os.path.join("scripts", "build_backend.py") - ) - builder_module = module_from_spec(spec) - spec.loader.exec_module(builder_module) - builder_module.build_backend( - l0_support=l0_support, - code_coverage=coverage, - sycl_compiler_prefix=sycl_compiler_prefix, - ) - - -def extensions(): - # Security flags - eca = get_sdl_cflags() - ela = get_sdl_ldflags() - libs = [] - libraries = [] - - if IS_LIN: - libs += ["rt", "DPCTLSyclInterface"] - libraries = [dpctl_sycl_interface_lib] - runtime_library_dirs = ["$ORIGIN"] - elif IS_WIN: - libs += ["DPCTLSyclInterface"] - libraries = [dpctl_sycl_interface_lib] - runtime_library_dirs = [] - - extension_args = { - "depends": [ - dpctl_sycl_interface_include, - ], - "include_dirs": [np.get_include(), dpctl_sycl_interface_include], - "extra_compile_args": ( - eca + get_other_cxxflags() + get_suppressed_warning_flags() - ), - "extra_link_args": ela, - "libraries": libs, - "library_dirs": libraries, - "runtime_library_dirs": runtime_library_dirs, - "language": "c++", - "define_macros": [], - } - - extensions = [ - Extension( - "dpctl._sycl_context", - [ - os.path.join("dpctl", "_sycl_context.pyx"), - ], - **extension_args, - ), - Extension( - "dpctl._sycl_device", - [ - os.path.join("dpctl", "_sycl_device.pyx"), - ], - **extension_args, - ), - Extension( - "dpctl._sycl_device_factory", - [ - os.path.join("dpctl", "_sycl_device_factory.pyx"), - ], - **extension_args, - ), - Extension( - "dpctl._sycl_event", - [ - os.path.join("dpctl", "_sycl_event.pyx"), - ], - **extension_args, - ), - Extension( - "dpctl._sycl_platform", - [ - os.path.join("dpctl", "_sycl_platform.pyx"), - ], - **extension_args, - ), - Extension( - "dpctl._sycl_queue", - [ - os.path.join("dpctl", "_sycl_queue.pyx"), - ], - **extension_args, - ), - Extension( - "dpctl._sycl_queue_manager", - [ - os.path.join("dpctl", "_sycl_queue_manager.pyx"), - ], - **extension_args, - ), - Extension( - "dpctl.memory._memory", - [ - os.path.join("dpctl", "memory", "_memory.pyx"), - ], - **extension_args, - ), - Extension( - "dpctl.program._program", - [ - os.path.join("dpctl", "program", "_program.pyx"), - ], - **extension_args, - ), - Extension( - "dpctl.utils._compute_follows_data", - [ - os.path.join("dpctl", "utils", "_compute_follows_data.pyx"), - ], - **extension_args, - ), - Extension( - "dpctl.tensor._usmarray", - [ - os.path.join("dpctl", "tensor", "_usmarray.pyx"), - ], - depends=extension_args["depends"] - + [os.path.join("libtensor", "include", "usm_array.hpp")], - language="c++", - include_dirs=( - extension_args["include_dirs"] - + [os.path.join("libtensor", "include")] - ), - extra_compile_args=extension_args["extra_compile_args"], - extra_link_args=extension_args["extra_link_args"], - libraries=extension_args["libraries"], - library_dirs=extension_args["library_dirs"], - runtime_library_dirs=extension_args["runtime_library_dirs"], - define_macros=extension_args["define_macros"], - ), - Extension( - "dpctl.tensor._dlpack", - [ - os.path.join("dpctl", "tensor", "_dlpack.pyx"), - ], - depends=extension_args["depends"], - language="c++", - include_dirs=extension_args["include_dirs"] - + [ - os.path.join("dpctl", "tensor"), - ], - extra_compile_args=extension_args["extra_compile_args"], - extra_link_args=extension_args["extra_link_args"], - libraries=extension_args["libraries"], - library_dirs=extension_args["library_dirs"], - runtime_library_dirs=extension_args["runtime_library_dirs"], - define_macros=extension_args["define_macros"], - ), - ] - return extensions - - -class build_ext(orig_build_ext.build_ext): - description = "Build dpctl native extensions" - - def finalize_options(self): - if _coverage: - pre_d = getattr(self, "define", None) - if pre_d is None: - self.define = "CYTHON_TRACE" - else: - self.define = ",".join((pre_d, "CYTHON_TRACE")) - super().finalize_options() - - def run(self): - return super().run() - - -def get_build_py(orig_build_py): - class build_py(orig_build_py): - def run(self): - dpctl_src_dir = self.get_package_dir("dpctl") - dpctl_build_dir = os.path.join(self.build_lib, "dpctl") - os.makedirs(dpctl_build_dir, exist_ok=True) - if IS_LIN: - for fn in glob.glob(os.path.join(dpctl_src_dir, "*.so*")): - # Check if the file already exists before copying. - # The check is needed when dealing with symlinks. - if not os.path.exists( - os.path.join(dpctl_build_dir, os.path.basename(fn)) - ): - shutil.copy( - src=fn, - dst=dpctl_build_dir, - follow_symlinks=False, - ) - elif IS_WIN: - for fn in glob.glob(os.path.join(dpctl_src_dir, "*.lib")): - shutil.copy(src=fn, dst=dpctl_build_dir) - - for fn in glob.glob(os.path.join(dpctl_src_dir, "*.dll")): - shutil.copy(src=fn, dst=dpctl_build_dir) - else: - raise NotImplementedError("Unsupported platform") - return super().run() - - return build_py - - -class install(orig_install.install): - description = "Installs dpctl into Python prefix" - user_options = orig_install.install.user_options + [ - ( - "level-zero-support=", - None, - "Whether to enable support for program creation " - "for Level-zero backend", - ), - ( - "sycl-compiler-prefix=", - None, - "Path to SYCL compiler installation. None means " - "read it off ONEAPI_ROOT environment variable or fail.", - ), - ] - - def initialize_options(self): - super().initialize_options() - self.level_zero_support = "True" - self.sycl_compiler_prefix = None - - def finalize_options(self): - if isinstance(self.level_zero_support, str): - self.level_zero_support = self.level_zero_support.capitalize() - if self.level_zero_support in ["True", "False", "0", "1"]: - self.level_zero_support = bool(eval(self.level_zero_support)) - else: - raise ValueError( - "--level-zero-support value is invalid, use True/False" - ) - if isinstance(self.sycl_compiler_prefix, str): - if not os.path.exists(os.path.join(self.sycl_compiler_prefix)): - raise ValueError( - "--sycl-compiler-prefix expects a path " - "to an existing directory" - ) - elif self.sycl_compiler_prefix is None: - pass - else: - raise ValueError( - "--sycl-compiler-prefix value is invalid, use a " - "path to compiler installation. To use oneAPI, use the " - "default value, but remember to activate the compiler " - "environment" - ) - super().finalize_options() - - def run(self): - build_backend(self.level_zero_support, False, self.sycl_compiler_prefix) - if _coverage: - pre_d = getattr(self, "define", None) - if pre_d is None: - self.define = "CYTHON_TRACE" - else: - self.define = ",".join((pre_d, "CYTHON_TRACE")) - cythonize(self.distribution.ext_modules) - ret = super().run() - if IS_LIN: - dpctl_build_dir = os.path.join( - os.path.dirname(__file__), self.build_lib, "dpctl" - ) - dpctl_install_dir = os.path.join(self.install_libbase, "dpctl") - for fn in glob.glob( - os.path.join(dpctl_install_dir, "*DPCTLSyclInterface.so*") - ): - os.remove(fn) - shutil.copy( - src=os.path.join(dpctl_build_dir, os.path.basename(fn)), - dst=dpctl_install_dir, - follow_symlinks=False, - ) - return ret - - -class develop(orig_develop.develop): - description = "Installs dpctl in place" - user_options = orig_develop.develop.user_options + [ - ( - "level-zero-support=", - None, - "Whether to enable support for program creation " - "for Level-zero backend", - ), - ( - "sycl-compiler-prefix=", - None, - "Path to SYCL compiler installation. None means " - "read it off ONEAPI_ROOT environment variable or fail.", - ), - ( - "coverage=", - None, - "Whether to generate coverage report " - "when building the backend library", - ), - ] - - def initialize_options(self): - super().initialize_options() - self.level_zero_support = "True" - self.coverage = "False" - self.sycl_compiler_prefix = None - - def finalize_options(self): - if isinstance(self.level_zero_support, str): - self.level_zero_support = self.level_zero_support.capitalize() - if self.level_zero_support in ["True", "False", "0", "1"]: - self.level_zero_support = bool(eval(self.level_zero_support)) - else: - raise ValueError( - "--level-zero-support value is invalid, use True/False" - ) - if isinstance(self.coverage, str): - self.coverage = self.coverage.capitalize() - if self.coverage in ["True", "False", "0", "1"]: - self.coverage = bool(eval(self.coverage)) - global _coverage - _coverage = self.coverage - else: - raise ValueError("--coverage value is invalid, use True/False") - if isinstance(self.sycl_compiler_prefix, str): - if not os.path.exists(os.path.join(self.sycl_compiler_prefix)): - raise ValueError( - "--sycl-compiler-prefix expects a path " - "to an existing directory" - ) - elif self.sycl_compiler_prefix is None: - pass - else: - raise ValueError( - "--sycl-compiler-prefix value is invalid, use a " - "path to compiler installation. To use oneAPI, use the " - "default value, but remember to activate the compiler " - "environment" - ) - super().finalize_options() - - def run(self): - build_backend( - self.level_zero_support, self.coverage, self.sycl_compiler_prefix - ) - if _coverage: - pre_d = getattr(self, "define", None) - if pre_d is None: - self.define = "CYTHON_TRACE" - else: - self.define = ",".join((pre_d, "CYTHON_TRACE")) - cythonize(self.distribution.ext_modules) - return super().run() - - def _get_cmdclass(): cmdclass = versioneer.get_cmdclass() - cmdclass["build_py"] = get_build_py(cmdclass["build_py"]) - cmdclass["install"] = install - cmdclass["develop"] = develop - cmdclass["build_ext"] = build_ext return cmdclass @@ -481,9 +40,8 @@ def _get_cmdclass(): author="Intel Corporation", url="https://github.com/IntelPython/dpctl", packages=find_packages(include=["*"]), - package_data={"dpctl": ["tests/*", "tests/helper/*.py"]}, + package_data={"dpctl": ["tests/*.*", "tests/helper/*.py"]}, include_package_data=True, - ext_modules=extensions(), zip_safe=False, setup_requires=["Cython"], install_requires=[ From 8e957b1cef2c2ff4e1c2a211a872f50f2837e2cc Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Fri, 14 Jan 2022 15:42:20 -0600 Subject: [PATCH 02/19] Use CMAKE_BINARY_DIR not CMAKE_CURRENT_BINARY_DIR to refer to location of checkout --- libsyclinterface/cmake/modules/GetLevelZeroHeaders.cmake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libsyclinterface/cmake/modules/GetLevelZeroHeaders.cmake b/libsyclinterface/cmake/modules/GetLevelZeroHeaders.cmake index 83bb8e61a5..1b1cca582e 100644 --- a/libsyclinterface/cmake/modules/GetLevelZeroHeaders.cmake +++ b/libsyclinterface/cmake/modules/GetLevelZeroHeaders.cmake @@ -32,7 +32,7 @@ function(get_level_zero_headers) COMMAND ${GIT_EXECUTABLE} fetch RESULT_VARIABLE result ERROR_VARIABLE error - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/level-zero + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/level-zero OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE ) @@ -65,7 +65,7 @@ function(get_level_zero_headers) RESULT_VARIABLE result OUTPUT_VARIABLE latest_tag ERROR_VARIABLE error - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/level-zero + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/level-zero OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE ) @@ -81,7 +81,7 @@ function(get_level_zero_headers) COMMAND ${GIT_EXECUTABLE} checkout ${latest_tag} RESULT_VARIABLE result ERROR_VARIABLE error - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/level-zero + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/level-zero OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE ) @@ -95,7 +95,7 @@ function(get_level_zero_headers) # Populate the path to the headers find_path(LEVEL_ZERO_INCLUDE_DIR NAMES zet_api.h - PATHS ${CMAKE_CURRENT_BINARY_DIR}/level-zero/include + PATHS ${CMAKE_BINARY_DIR}/level-zero/include NO_DEFAULT_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_PATH From 93f4d02120e68e5de05dadfd5f1b91954ee1e37b Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Sun, 23 Jan 2022 07:53:26 -0600 Subject: [PATCH 03/19] Activate internal API to make sycl::program available --- libsyclinterface/tests/dpcpp_kernels.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libsyclinterface/tests/dpcpp_kernels.hpp b/libsyclinterface/tests/dpcpp_kernels.hpp index 099ea1a2da..f4c0934d78 100644 --- a/libsyclinterface/tests/dpcpp_kernels.hpp +++ b/libsyclinterface/tests/dpcpp_kernels.hpp @@ -1,4 +1,8 @@ #pragma once +#ifndef __SYCL_INTERNAL_API +// make sure that sycl::program is defined and implemented +#define __SYCL_INTERNAL_API +#endif #include namespace dpcpp_kernels From 771af53559b176c3424d985f86796900aaed0bd0 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Sun, 23 Jan 2022 08:19:39 -0600 Subject: [PATCH 04/19] Replaced use of relative path in #include statements Modified CMakeLists.txt to add needed include directories for the dpctl_c_api_tests target --- libsyclinterface/helper/include/dpctl_utils_helper.h | 2 +- libsyclinterface/tests/CMakeLists.txt | 4 ++++ libsyclinterface/tests/test_helper.cpp | 2 +- libsyclinterface/tests/test_sycl_device_aspects.cpp | 2 +- libsyclinterface/tests/test_sycl_device_interface.cpp | 2 +- libsyclinterface/tests/test_sycl_device_manager.cpp | 2 +- libsyclinterface/tests/test_sycl_device_subdevices.cpp | 2 +- 7 files changed, 10 insertions(+), 6 deletions(-) diff --git a/libsyclinterface/helper/include/dpctl_utils_helper.h b/libsyclinterface/helper/include/dpctl_utils_helper.h index e789c73517..57a308f5f0 100644 --- a/libsyclinterface/helper/include/dpctl_utils_helper.h +++ b/libsyclinterface/helper/include/dpctl_utils_helper.h @@ -24,8 +24,8 @@ #pragma once -#include "../include/dpctl_sycl_enum_types.h" #include "Support/DllExport.h" +#include "dpctl_sycl_enum_types.h" #include /*! diff --git a/libsyclinterface/tests/CMakeLists.txt b/libsyclinterface/tests/CMakeLists.txt index c4926ffa2d..0755fb9217 100644 --- a/libsyclinterface/tests/CMakeLists.txt +++ b/libsyclinterface/tests/CMakeLists.txt @@ -51,6 +51,10 @@ if(DPCTL_GENERATE_COVERAGE) ${dpctl_sources} ${helper_sources} ) + target_include_directories(dpctl_c_api_tests + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../helper/include" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../include" + ) target_link_libraries(dpctl_c_api_tests ${CMAKE_THREAD_LIBS_INIT} GTest::GTest diff --git a/libsyclinterface/tests/test_helper.cpp b/libsyclinterface/tests/test_helper.cpp index 76c8d50932..ae4f60b75c 100644 --- a/libsyclinterface/tests/test_helper.cpp +++ b/libsyclinterface/tests/test_helper.cpp @@ -24,8 +24,8 @@ /// //===----------------------------------------------------------------------===// -#include "../helper/include/dpctl_utils_helper.h" #include "Config/dpctl_config.h" +#include "dpctl_utils_helper.h" #include #include #include diff --git a/libsyclinterface/tests/test_sycl_device_aspects.cpp b/libsyclinterface/tests/test_sycl_device_aspects.cpp index 8fdc1b34f6..90b29a8bac 100644 --- a/libsyclinterface/tests/test_sycl_device_aspects.cpp +++ b/libsyclinterface/tests/test_sycl_device_aspects.cpp @@ -1,8 +1,8 @@ -#include "../helper/include/dpctl_utils_helper.h" #include "Support/CBindingWrapping.h" #include "dpctl_sycl_device_interface.h" #include "dpctl_sycl_device_selector_interface.h" #include "dpctl_sycl_enum_types.h" +#include "dpctl_utils_helper.h" #include #include #include diff --git a/libsyclinterface/tests/test_sycl_device_interface.cpp b/libsyclinterface/tests/test_sycl_device_interface.cpp index b33e2c566f..a55bacecd7 100644 --- a/libsyclinterface/tests/test_sycl_device_interface.cpp +++ b/libsyclinterface/tests/test_sycl_device_interface.cpp @@ -24,11 +24,11 @@ /// //===----------------------------------------------------------------------===// -#include "../helper/include/dpctl_utils_helper.h" #include "dpctl_sycl_device_interface.h" #include "dpctl_sycl_device_selector_interface.h" #include "dpctl_sycl_platform_interface.h" #include "dpctl_utils.h" +#include "dpctl_utils_helper.h" #include #include diff --git a/libsyclinterface/tests/test_sycl_device_manager.cpp b/libsyclinterface/tests/test_sycl_device_manager.cpp index a7ca5ef6e1..87a5b1e6d9 100644 --- a/libsyclinterface/tests/test_sycl_device_manager.cpp +++ b/libsyclinterface/tests/test_sycl_device_manager.cpp @@ -24,11 +24,11 @@ /// //===----------------------------------------------------------------------===// -#include "../helper/include/dpctl_utils_helper.h" #include "dpctl_sycl_device_interface.h" #include "dpctl_sycl_device_manager.h" #include "dpctl_sycl_device_selector_interface.h" #include "dpctl_utils.h" +#include "dpctl_utils_helper.h" #include #include diff --git a/libsyclinterface/tests/test_sycl_device_subdevices.cpp b/libsyclinterface/tests/test_sycl_device_subdevices.cpp index 14252bdc88..41cef23784 100644 --- a/libsyclinterface/tests/test_sycl_device_subdevices.cpp +++ b/libsyclinterface/tests/test_sycl_device_subdevices.cpp @@ -25,13 +25,13 @@ /// //===----------------------------------------------------------------------===// -#include "../helper/include/dpctl_utils_helper.h" #include "Support/CBindingWrapping.h" #include "dpctl_sycl_device_interface.h" #include "dpctl_sycl_device_selector_interface.h" #include "dpctl_sycl_enum_types.h" #include "dpctl_sycl_platform_interface.h" #include "dpctl_utils.h" +#include "dpctl_utils_helper.h" #include #include From 18727b32b01d7e9d895771ffbee1248a71a79c89 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Mon, 24 Jan 2022 06:11:13 -0600 Subject: [PATCH 05/19] Ensure Cython files are built with security flags like before --- dpctl/CMakeLists.txt | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/dpctl/CMakeLists.txt b/dpctl/CMakeLists.txt index f0240c79ee..c858afc7ef 100644 --- a/dpctl/CMakeLists.txt +++ b/dpctl/CMakeLists.txt @@ -3,6 +3,68 @@ find_package(PythonExtensions REQUIRED) find_package(NumPy REQUIRED) find_package(Cython REQUIRED) +if(WIN32) + string(CONCAT WARNING_FLAGS + "-Wall " + "-Wextra " + "-Winit-self " + "-Wunused-function " + "-Wuninitialized " + "-Wmissing-declarations " + ) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Ox ${WARNING_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Ox ${WARNING_FLAGS}") + set(CMAKE_C_FLAGS_DEBUG + "${CMAKE_C_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG" + ) + set(CMAKE_CXX_FLAGS_DEBUG + "${CMAKE_CXX_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG" + ) + set(DPCTL_LDFLAGS "/NXCompat /DynamicBase") +elseif(UNIX) + string(CONCAT WARNING_FLAGS + "-Wall " + "-Wextra " + "-Winit-self " + "-Wunused-function " + "-Wuninitialized " + "-Wmissing-declarations " + "-fdiagnostics-color=auto " + "-Wno-deprecated-declarations " + ) + string(CONCAT SDL_FLAGS + "-fstack-protector " + "-fstack-protector-all " + "-fpic " + "-fPIC " + "-D_FORTIFY_SOURCE=2 " + "-Wformat " + "-Wformat-security " + "-fno-strict-overflow " + "-fno-delete-null-pointer-checks " + ) + string(CONCAT CFLAGS + "${WARNING_FLAGS}" + "${SDL_FLAGS}" + ) + string(CONCAT CXXFLAGS + "${WARNING_FLAGS}" + "${SDL_FLAGS}" + "-fsycl " + ) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 ${CFLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 ${CXXFLAGS}") + set(CMAKE_C_FLAGS_DEBUG + "${CMAKE_C_FLAGS_DEBUG} ${CFLAGS} -ggdb3 -DDEBUG" + ) + set(CMAKE_CXX_FLAGS_DEBUG + "${CMAKE_CXX_FLAGS_DEBUG} ${CXXFLAGS} -ggdb3 -DDEBUG" + ) + set(DPCTL_LDFLAGS "-z,noexecstack,-z,relro,-z,now") +else() + message(FATAL_ERROR "Unsupported system.") +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 @@ -21,6 +83,7 @@ function(build_dpctl_ext _trgt _src _dest) target_include_directories(${_trgt} PRIVATE ${NumPy_INCLUDE_DIR} ${DPCTL_INCLUDE_DIR}) add_dependencies(${_trgt} _build_time_create_dpctl_include) target_link_libraries(${_trgt} DPCTLSyclInterface) + target_link_options(${_trgt} PRIVATE "LINKER:${DPCTL_LDFLAGS}") python_extension_module(${_trgt}) get_filename_component(_name_wle ${_generated_src} NAME_WLE) get_filename_component(_generated_src_dir ${_generated_src} DIRECTORY) From 1f6b40f68005566fb3d175c2c3f3e168671d0055 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Mon, 24 Jan 2022 07:21:56 -0600 Subject: [PATCH 06/19] Target check launches ctest with DPCTL_VERBOSITY=warning This is needed so that the test checking for captured cerr stream does not fail. Removed dpcpp_kernels.cpp file (dpcpp linker fails on it) Used -fno-sycl-use-footer to work-around a bug getting in a way of collecting profiling data --- libsyclinterface/tests/CMakeLists.txt | 10 +-- libsyclinterface/tests/dpcpp_kernels.cpp | 89 ------------------------ 2 files changed, 2 insertions(+), 97 deletions(-) delete mode 100644 libsyclinterface/tests/dpcpp_kernels.cpp diff --git a/libsyclinterface/tests/CMakeLists.txt b/libsyclinterface/tests/CMakeLists.txt index 0755fb9217..dc180ec70d 100644 --- a/libsyclinterface/tests/CMakeLists.txt +++ b/libsyclinterface/tests/CMakeLists.txt @@ -4,7 +4,7 @@ find_package(Threads REQUIRED) # Emulate autotools like make check target to build tests set(CMAKE_CTEST_COMMAND ctest --progress --output-on-failure -j 4) -add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}) +add_custom_target(check COMMAND ${CMAKE_COMMAND} -E env DPCTL_VERBOSITY=warning ${CMAKE_CTEST_COMMAND}) enable_testing() include_directories( @@ -35,12 +35,11 @@ if(DPCTL_GENERATE_COVERAGE) list(REMOVE_ITEM dpctl_sources "${CMAKE_CURRENT_SOURCE_DIR}/../source/dpctl_vector_templ.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../source/dpcpp_kernels.cpp" ) # Add profiling flags set(CMAKE_CXX_FLAGS - "${CMAKE_CXX_FLAGS} -fprofile-instr-generate -fcoverage-mapping -DDPCTL_COVERAGE" + "${CMAKE_CXX_FLAGS} -fprofile-instr-generate -fcoverage-mapping -fno-sycl-use-footer -DDPCTL_COVERAGE" ) # Add all dpctl sources into a single executable so that we can run coverage @@ -94,10 +93,6 @@ if(DPCTL_GENERATE_COVERAGE) WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) else() - add_library(dpcpp_kernels - STATIC - ${CMAKE_CURRENT_SOURCE_DIR}/dpcpp_kernels.cpp - ) file(GLOB_RECURSE sources ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) add_executable(dpctl_c_api_tests EXCLUDE_FROM_ALL ${sources}) target_link_libraries(dpctl_c_api_tests @@ -105,7 +100,6 @@ else() GTest::GTest DPCTLSyclInterface ${LEVEL_ZERO_LIBRARY} - dpcpp_kernels ) endif() diff --git a/libsyclinterface/tests/dpcpp_kernels.cpp b/libsyclinterface/tests/dpcpp_kernels.cpp deleted file mode 100644 index 897aa86de4..0000000000 --- a/libsyclinterface/tests/dpcpp_kernels.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#include "dpcpp_kernels.hpp" -#include -#include - -template sycl::kernel -dpcpp_kernels::get_fill_kernel(sycl::queue &, size_t, int *, int); - -template sycl::kernel -dpcpp_kernels::get_fill_kernel(sycl::queue &, - size_t, - unsigned int *, - unsigned int); - -template sycl::kernel -dpcpp_kernels::get_fill_kernel(sycl::queue &, size_t, double *, double); - -template sycl::kernel -dpcpp_kernels::get_fill_kernel(sycl::queue &, size_t, float *, float); - -template sycl::kernel -dpcpp_kernels::get_range_kernel(sycl::queue &, size_t, int *); - -template sycl::kernel -dpcpp_kernels::get_range_kernel(sycl::queue &, - size_t, - unsigned int *); - -template sycl::kernel -dpcpp_kernels::get_range_kernel(sycl::queue &, size_t, float *); - -template sycl::kernel -dpcpp_kernels::get_range_kernel(sycl::queue &, size_t, double *); - -template sycl::kernel dpcpp_kernels::get_mad_kernel(sycl::queue &, - size_t, - int *, - int *, - int *, - int); - -template sycl::kernel -dpcpp_kernels::get_mad_kernel(sycl::queue &, - size_t, - unsigned int *, - unsigned int *, - unsigned int *, - unsigned int); - -template sycl::kernel dpcpp_kernels::get_local_sort_kernel(sycl::queue &, - size_t, - size_t, - int *, - size_t); - -template sycl::kernel -dpcpp_kernels::get_local_count_exceedance_kernel(sycl::queue &, - size_t, - size_t, - int *, - size_t, - int, - int *); - -template sycl::kernel -dpcpp_kernels::get_local_count_exceedance_kernel(sycl::queue &, - size_t, - size_t, - unsigned int *, - size_t, - unsigned int, - int *); - -template sycl::kernel -dpcpp_kernels::get_local_count_exceedance_kernel(sycl::queue &, - size_t, - size_t, - float *, - size_t, - float, - int *); - -template sycl::kernel -dpcpp_kernels::get_local_count_exceedance_kernel(sycl::queue &, - size_t, - size_t, - double *, - size_t, - double, - int *); From 49f111c485552e0aae785dee378f764608e6f882 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Mon, 24 Jan 2022 12:11:02 -0600 Subject: [PATCH 07/19] Use cmake_process_manifest_hook setup argument to clean destination folder Delete DPCTLSyclInterface library shared objects from dpctl/ folder from previous runs. Monkey-patch skbuild.setuptools._copy_file to not follows symbolic links, to ensure that versioned DPCTLSyclInterface ends up as the proper set of symbolic links pointing to a single physical shared object file. If symbolic links are followed, 3 identical copies of the library end up in the installation folder. Downstream dpctl users may end up with several instances of the library in their process space which may end up with errors is statuful functinality (queue manager) is used. --- setup.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 8a2ba5726e..a63fdba8ed 100644 --- a/setup.py +++ b/setup.py @@ -14,8 +14,14 @@ # See the License for the specific language governing permissions and # limitations under the License. +import os.path +import pathlib +import shutil + +import skbuild +import skbuild.setuptools_wrap +import skbuild.utils from setuptools import find_packages -from skbuild import setup import versioneer @@ -29,7 +35,51 @@ def _get_cmdclass(): return cmdclass -setup( +def cleanup_destination(cmake_manifest): + """Delete library files from dpctl/ folder before + letting skbuild copy them over to avoid errors. + """ + _to_unlink = [] + for fn in cmake_manifest: + bn = os.path.basename(fn) + # delete + if "DPCTLSyclInterface" in bn: + lib_fn = os.path.join("dpctl", bn) + if os.path.exists(lib_fn): + _to_unlink.append(lib_fn) + for fn in _to_unlink: + pathlib.Path(fn).unlink() + return cmake_manifest + + +def _patched_copy_file(src_file, dest_file, hide_listing=True): + """Copy ``src_file`` to ``dest_file`` ensuring parent directory exists. + + By default, message like `creating directory /path/to/package` and + `copying directory /src/path/to/package -> path/to/package` are displayed + on standard output. Setting ``hide_listing`` to False avoids message from + being displayed. + + NB: Patched here to not follows symbolic links + """ + # Create directory if needed + dest_dir = os.path.dirname(dest_file) + if dest_dir != "" and not os.path.exists(dest_dir): + if not hide_listing: + print("creating directory {}".format(dest_dir)) + skbuild.utils.mkdir_p(dest_dir) + + # Copy file + if not hide_listing: + print("copying {} -> {}".format(src_file, dest_file)) + shutil.copyfile(src_file, dest_file, follow_symlinks=False) + shutil.copymode(src_file, dest_file, follow_symlinks=False) + + +skbuild.setuptools_wrap._copy_file = _patched_copy_file + + +skbuild.setup( name="dpctl", version=versioneer.get_version(), cmdclass=_get_cmdclass(), @@ -54,4 +104,5 @@ def _get_cmdclass(): "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", ], + cmake_process_manifest_hook=cleanup_destination, ) From 4a51351919e5cb03d5b6a72aacbda4a25e6d0cb0 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Mon, 24 Jan 2022 15:17:40 -0600 Subject: [PATCH 08/19] Add build-time dependency on scikit-build, change build scripts --- conda-recipe/bld.bat | 2 +- conda-recipe/build.sh | 4 +++- conda-recipe/meta.yaml | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/conda-recipe/bld.bat b/conda-recipe/bld.bat index 1ece7b30da..a3cd4a4f70 100644 --- a/conda-recipe/bld.bat +++ b/conda-recipe/bld.bat @@ -4,7 +4,7 @@ set "LIB=%BUILD_PREFIX%\Library\lib;%BUILD_PREFIX%\compiler\lib;%LIB%" set "INCLUDE=%BUILD_PREFIX%\include;%INCLUDE%" "%PYTHON%" setup.py clean --all -set "INSTALL_CMD=install --sycl-compiler-prefix=%BUILD_PREFIX%\Library" +set "INSTALL_CMD=install -- -G Ninja -DDPCTL_DPCPP_HOME_DIR=%BUILD_PREFIX%\Library -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icx -DDPCTL_ENABLE_LO_PROGRAM_CREATION=ON" if NOT "%WHEELS_OUTPUT_FOLDER%"=="" ( rem Install and assemble wheel package from the build bits diff --git a/conda-recipe/build.sh b/conda-recipe/build.sh index 777bc6f513..41f2546eb1 100755 --- a/conda-recipe/build.sh +++ b/conda-recipe/build.sh @@ -6,7 +6,9 @@ export LDFLAGS="$LDFLAGS -Wl,-rpath,$PREFIX/lib" ${PYTHON} setup.py clean --all -INSTALL_CMD="install --sycl-compiler-prefix=$BUILD_PREFIX" +export CMAKE_GENERATOR="Unix Makefiles" +INSTALL_CMD="install -- -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icpx -DDPCTL_ENABLE_LO_PROGRAM_CREATION=ON -DDPCTL_DPCPP_HOME_DIR=${BUILD_PREFIX}" +echo "${PYTHON} setup.py ${INSTALL_CMD}" # Workaround for: # DPC++ launched by cmake does not see components of `dpcpp_cpp_rt`, diff --git a/conda-recipe/meta.yaml b/conda-recipe/meta.yaml index 08170e4d3a..ab01e3c178 100644 --- a/conda-recipe/meta.yaml +++ b/conda-recipe/meta.yaml @@ -22,12 +22,13 @@ requirements: - python - make # [unix] - ninja # [win] + - scikit-build - numpy 1.19 - wheel run: - python - {{ pin_compatible('numpy') }} - - dpcpp-cpp-rt >=2021.2 + - dpcpp-cpp-rt >=2022.0 test: requires: From a83d25ad6cb97c580091012e8943c90217232c7c Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Tue, 25 Jan 2022 11:04:47 -0600 Subject: [PATCH 09/19] Fixed GetNumDevices tests, added support for conversion of DPCTL_ALL_BACKENDS to sycl --- .../helper/source/dpctl_utils_helper.cpp | 2 + .../tests/test_sycl_device_manager.cpp | 59 +++++++++++++------ 2 files changed, 43 insertions(+), 18 deletions(-) diff --git a/libsyclinterface/helper/source/dpctl_utils_helper.cpp b/libsyclinterface/helper/source/dpctl_utils_helper.cpp index 212a5634fa..bf3f590bc6 100644 --- a/libsyclinterface/helper/source/dpctl_utils_helper.cpp +++ b/libsyclinterface/helper/source/dpctl_utils_helper.cpp @@ -96,6 +96,8 @@ backend DPCTL_DPCTLBackendTypeToSyclBackend(DPCTLSyclBackendType BeTy) return backend::level_zero; case DPCTLSyclBackendType::DPCTL_OPENCL: return backend::opencl; + case DPCTLSyclBackendType::DPCTL_ALL_BACKENDS: + return backend::all; default: throw std::runtime_error("Unsupported backend type"); } diff --git a/libsyclinterface/tests/test_sycl_device_manager.cpp b/libsyclinterface/tests/test_sycl_device_manager.cpp index 87a5b1e6d9..77b7a21b07 100644 --- a/libsyclinterface/tests/test_sycl_device_manager.cpp +++ b/libsyclinterface/tests/test_sycl_device_manager.cpp @@ -139,18 +139,30 @@ INSTANTIATE_TEST_SUITE_P( struct TestGetNumDevicesForDTy : public ::testing::TestWithParam { - size_t nDevices = 0; + int param; + sycl::info::device_type sycl_dty; + TestGetNumDevicesForDTy() { - cl::sycl::info::device_type sycl_dty = - DPCTL_DPCTLDeviceTypeToSyclDeviceType( - DPCTLSyclDeviceType(GetParam())); - - auto devices = cl::sycl::device::get_devices(sycl_dty); - EXPECT_TRUE(devices.size() == DPCTLDeviceMgr_GetNumDevices(GetParam())); + param = GetParam(); + DPCTLSyclDeviceType DTy = DPCTLSyclDeviceType(param); + sycl_dty = DPCTL_DPCTLDeviceTypeToSyclDeviceType(DTy); } }; +TEST_P(TestGetNumDevicesForDTy, ChkGetNumDevices) +{ + auto devices = sycl::device::get_devices(sycl_dty); + size_t nDevices = 0; + sycl::default_selector mRanker; + for (const sycl::device &d : devices) { + if (mRanker(d) < 0) + continue; + ++nDevices; + } + EXPECT_TRUE(nDevices == DPCTLDeviceMgr_GetNumDevices(param)); +} + INSTANTIATE_TEST_SUITE_P( GetDevices, TestGetNumDevicesForDTy, @@ -162,22 +174,33 @@ INSTANTIATE_TEST_SUITE_P( struct TestGetNumDevicesForBTy : public ::testing::TestWithParam { - size_t nDevices = 0; + int param; + sycl::backend sycl_bty; TestGetNumDevicesForBTy() { - cl::sycl::backend sycl_bty = DPCTL_DPCTLBackendTypeToSyclBackend( - DPCTLSyclBackendType(GetParam())); - - auto platforms = cl::sycl::platform::get_platforms(); - for (const auto &P : platforms) { - if (P.get_backend() == sycl_bty) { - auto devices = P.get_devices(); - EXPECT_TRUE(devices.size() == - DPCTLDeviceMgr_GetNumDevices(GetParam())); + param = GetParam(); + sycl_bty = + DPCTL_DPCTLBackendTypeToSyclBackend(DPCTLSyclBackendType(param)); + } +}; + +TEST_P(TestGetNumDevicesForBTy, ChkGetNumDevices) +{ + auto platforms = cl::sycl::platform::get_platforms(); + size_t nDevices = 0; + sycl::default_selector mRanker; + for (const auto &P : platforms) { + if ((P.get_backend() == sycl_bty) || (sycl_bty == sycl::backend::all)) { + auto devices = P.get_devices(); + for (const sycl::device &d : devices) { + if (mRanker(d) < 0) + continue; + ++nDevices; } } } -}; + EXPECT_TRUE(nDevices == DPCTLDeviceMgr_GetNumDevices(param)); +} INSTANTIATE_TEST_SUITE_P( GetDevices, From 571fe43c9771c9aa6c0a3ae7feb1579686dccbf1 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Mon, 24 Jan 2022 15:44:18 -0600 Subject: [PATCH 10/19] Generate coverage workflow uses scikit-build --- .github/workflows/generate-coverage.yaml | 34 ++++++++++++++---------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/.github/workflows/generate-coverage.yaml b/.github/workflows/generate-coverage.yaml index 776c1316fb..d21da02645 100644 --- a/.github/workflows/generate-coverage.yaml +++ b/.github/workflows/generate-coverage.yaml @@ -11,7 +11,7 @@ jobs: env: ONEAPI_ROOT: /opt/intel/oneapi - GTEST_ROOT: /home/runner/work/googletest-release-1.10.0/install + GTEST_ROOT: /home/runner/work/googletest-release-1.11.0/install steps: - name: Cancel Previous Runs @@ -29,8 +29,8 @@ jobs: - name: Install Intel OneAPI run: | - sudo apt-get install intel-oneapi-compiler-dpcpp-cpp=2021.3.0-3350 - sudo apt-get install intel-oneapi-tbb=2021.3.0-511 + sudo apt-get install intel-oneapi-compiler-dpcpp-cpp + sudo apt-get install intel-oneapi-tbb - name: Install CMake run: | @@ -39,7 +39,7 @@ jobs: - name: Setup Python uses: actions/setup-python@v2 with: - python-version: '3.8' + python-version: '3.9' architecture: x64 - name: Cache Gtest @@ -47,8 +47,8 @@ jobs: uses: actions/cache@v2 with: path: | - /home/runner/work/googletest-release-1.10.0/install - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('/home/runner/work/googletest-release-1.10.0/install/include/gtest/*') }} + /home/runner/work/googletest-release-1.11.0/install + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('/home/runner/work/googletest-release-1.11.0/install/include/gtest/*') }} restore-keys: | ${{ runner.os }}-build-${{ env.cache-name }}- ${{ runner.os }}-build- @@ -59,12 +59,12 @@ jobs: shell: bash -l {0} run: | cd /home/runner/work - wget https://github.com/google/googletest/archive/refs/tags/release-1.10.0.tar.gz - tar xf release-1.10.0.tar.gz - cd googletest-release-1.10.0 + wget https://github.com/google/googletest/archive/refs/tags/release-1.11.0.tar.gz + tar xf release-1.11.0.tar.gz + cd googletest-release-1.11.0 mkdir build cd build - cmake .. -DCMAKE_INSTALL_PREFIX=/home/runner/work/googletest-release-1.10.0/install + cmake .. -DCMAKE_INSTALL_PREFIX=/home/runner/work/googletest-release-1.11.0/install make && make install - name: Checkout repo @@ -79,14 +79,19 @@ jobs: - name: Install dpctl dependencies shell: bash -l {0} run: | - pip install numpy cython setuptools pytest pytest-cov coverage[toml] + pip install numpy cython setuptools pytest pytest-cov scikit-build coverage[toml] - name: Build dpctl with coverage shell: bash -l {0} run: | source /opt/intel/oneapi/setvars.sh - python setup.py develop --coverage=True - python -c "import dpctl; print(dpctl.__version__); dpctl.lsplatform()" + export _SAVED_PATH=${PATH} + export PATH=$(dirname $(dirname $(which icx)))/bin-llvm:${PATH} + python setup.py develop -- -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icpx -DDPCTL_ENABLE_LO_PROGRAM_CREATION=ON -DDPCTL_GENERATE_COVERAGE=ON -DDPCTL_BUILD_CAPI_TESTS=ON -DDPCTL_COVERAGE_REPORT_OUTPUT_DIR=$(pwd) + make -C $(find _skbuild -name tests) lcov-genhtml + export PATH=${_SAVED_PATH} + unset _SAVED_PATH + python -c "import dpctl; print(dpctl.__version__); dpctl.lsplatform()" || exit 1 pytest -q -ra --disable-warnings --cov-config pyproject.toml --cov dpctl --cov-report term-missing --pyargs dpctl -vv - name: Install coverall dependencies @@ -96,8 +101,9 @@ jobs: pip install coveralls==3.2.0 - name: Upload coverage data to coveralls.io + shell: bash -l {0} run: | - coveralls-lcov -v -n build_cmake/tests/dpctl.lcov > dpctl-c-api-coverage.json + coveralls-lcov -v -n $(find _skbuild -name tests)/dpctl.lcov > dpctl-c-api-coverage.json coveralls --service=github --merge=dpctl-c-api-coverage.json env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 25332b30aa53ad5705b8526938ea1d3d3baab9c1 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Tue, 25 Jan 2022 13:49:45 -0600 Subject: [PATCH 11/19] Vendor IntelDPCPPConfig.cmake Two reasons to do this: 1. to allow for providing hint env variables to help cmake find `SYCL_INCLUDE_DIR` and `SYCL_LIBRARY_DIR` for custom layouts of DPC++ installed into Python environment with conda 2. To allow use of nightly sycl bundles to build dpctl (bundle does not include IntelDPCPPConig.cmake) --- CMakeLists.txt | 2 +- cmake/IntelDPCPPConfig.cmake | 293 +++++++++++++++++++++++++++++++++++ 2 files changed, 294 insertions(+), 1 deletion(-) create mode 100644 cmake/IntelDPCPPConfig.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index a8c03c3383..e215bbbcce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ project(dpctl set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED True) -find_package(IntelDPCPP REQUIRED) +find_package(IntelDPCPP REQUIRED PATHS ${CMAKE_SOURCE_DIR}/cmake NO_DEFAULT_PATH) add_subdirectory(libsyclinterface) diff --git a/cmake/IntelDPCPPConfig.cmake b/cmake/IntelDPCPPConfig.cmake new file mode 100644 index 0000000000..8f683006be --- /dev/null +++ b/cmake/IntelDPCPPConfig.cmake @@ -0,0 +1,293 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +IntelDPCPPConfig +------- + +DPCPP Library to verify DPCPP/SYCL compatability of CMAKE_CXX_COMPILER +and passes relevant compiler flags. + +Result Variables +^^^^^^^^^^^^^^^^ + +This will define the following variables: + +``IntelDPCPP_FOUND`` + True if the system has the DPCPP library. +``SYCL_LANGUAGE_VERSION`` + The SYCL language spec version by Compiler. +``SYCL_INCLUDE_DIR`` + Include directories needed to use SYCL. +``SYCL_IMPLEMENTATION_ID`` + The SYCL compiler variant. +``SYCL_FLAGS`` + SYCL specific flags for the compiler. + +Cache Variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``SYCL_INCLUDE_DIR`` + The directory containing ``sycl.hpp``. +``SYCL_LIBRARY_DIR`` + The path to the SYCL library. +``SYCL_FLAGS`` + SYCL specific flags for the compiler. +``SYCL_LANGUAGE_VERSION`` + The SYCL language spec version by Compiler. + + +.. note:: + + For now, user needs to set -DCMAKE_CXX_COMPILER or environment of + CXX pointing to SYCL compatible compiler ( eg: icx, clang++, icpx) + + Note: do not set to DPCPP compiler. If set to a Compiler family + that supports dpcpp ( eg: IntelLLVM) both DPCPP and SYCL + features are enabled. + + And add this package to user's Cmake config file. + + .. code-block:: cmake + + find_package(IntelDPCPP REQUIRED) + +#]=======================================================================] + +include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) + +find_package(PkgConfig QUIET) +if(PKG_CONFIG_FOUND) + # TODO add dependency package module checks, if any +endif() + + +# TODO: can't use find_program to override the CMAKE_CXX_COMPILER as +# Platform/ files are executed, potentially for a different compiler. +# Safer approach is to make user to define CMAKE_CXX_COMPILER. + +string(COMPARE EQUAL "${CMAKE_CXX_COMPILER}" "" nocmplr) +if(nocmplr) + set(IntelDPCPP_FOUND False) + set(SYCL_REASON_FAILURE "SYCL: CMAKE_CXX_COMPILER not set!!") + set(IntelDPCPP_NOT_FOUND_MESSAGE "${SYCL_REASON_FAILURE}") +endif() + +# Check for known compiler family that supports SYCL + +if( NOT "x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xClang" AND + NOT "x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xIntelLLVM") + set(IntelDPCPP_FOUND False) + set(SYCL_REASON_FAILURE "Unsupported compiler family ${CMAKE_CXX_COMPILER_ID} and compiler ${CMAKE_CXX_COMPILER}!!") + set(IntelDPCPP_NOT_FOUND_MESSAGE "${SYCL_REASON_FAILURE}") + return() +endif() + +# Assume that CXX Compiler supports SYCL and then test to verify. +set(SYCL_COMPILER ${CMAKE_CXX_COMPILER}) + + +# Function to write a test case to verify SYCL features. + +function(SYCL_FEATURE_TEST_WRITE src) + + set(pp_if "#if") + set(pp_endif "#endif") + + set(SYCL_TEST_CONTENT "") + string(APPEND SYCL_TEST_CONTENT "#include \nusing namespace std;\n") + string(APPEND SYCL_TEST_CONTENT "int main(){\n") + + # Feature tests goes here + + string(APPEND SYCL_TEST_CONTENT "${pp_if} defined(SYCL_LANGUAGE_VERSION)\n") + string(APPEND SYCL_TEST_CONTENT "cout << \"SYCL_LANGUAGE_VERSION=\"< Date: Tue, 25 Jan 2022 13:52:52 -0600 Subject: [PATCH 12/19] os-llvm-sycl-build workload uses scikit-build --- .github/workflows/os-llvm-sycl-build.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/os-llvm-sycl-build.yml b/.github/workflows/os-llvm-sycl-build.yml index 47b183cd7e..8268bd0683 100644 --- a/.github/workflows/os-llvm-sycl-build.yml +++ b/.github/workflows/os-llvm-sycl-build.yml @@ -79,7 +79,7 @@ jobs: - name: Install dpctl dependencies shell: bash -l {0} run: | - pip install numpy cython setuptools pytest + pip install numpy cython setuptools pytest scikit-build - name: Checkout repo uses: actions/checkout@v2 @@ -97,5 +97,6 @@ jobs: export OCL_ICD_FILENAMES=libintelocl.so:libintelocl_emu.so clang++ --version sycl-ls - python setup.py develop --sycl-compiler-prefix=$(dirname $(dirname `which clang++`)) - python -m pytest -v dpctl/tests + python setup.py develop -- -G "Unix Makefiles" -DCMAKE_C_COMPILER:PATH=clang -DCMAKE_CXX_COMPILER:PATH=clang++ -DDPCTL_ENABLE_LO_PROGRAM_CREATION=ON -DDPCTL_DPCPP_HOME_DIR=$(dirname $(dirname $(which clang))) -DDPCTL_DPCPP_FROM_ONEAPI=OFF + python -c "import dpctl; dpctl.lsplatform()" || exit 1 + SYCL_ENABLE_HOST_DEVICE=1 python -m pytest -v dpctl/tests From 2e3f5cd9d9be00f6584276d18dafcdaf0fe83ca9 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Tue, 25 Jan 2022 14:24:56 -0600 Subject: [PATCH 13/19] Generate docs uses scikit-built setup command --- .github/workflows/generate-docs.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/generate-docs.yml b/.github/workflows/generate-docs.yml index 3f81a5eadc..052a82a304 100644 --- a/.github/workflows/generate-docs.yml +++ b/.github/workflows/generate-docs.yml @@ -49,7 +49,7 @@ jobs: if: ${{ !github.event.pull_request || github.event.action != 'closed' }} shell: bash -l {0} run: | - pip install numpy cython setuptools sphinx sphinx_rtd_theme pydot graphviz sphinxcontrib-programoutput + pip install numpy cython setuptools scikit-build sphinx sphinx_rtd_theme pydot graphviz sphinxcontrib-programoutput - name: Checkout repo uses: actions/checkout@v2 with: @@ -60,8 +60,8 @@ jobs: shell: bash -l {0} run: | source /opt/intel/oneapi/setvars.sh - python setup.py develop - python -c "import dpctl; print(dpctl.__version__)" + python setup.py develop -- -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icpx -DDPCTL_ENABLE_LO_PROGRAM_CREATION=ON -DDPCTL_DPCPP_HOME_DIR=${BUILD_PREFIX} + python -c "import dpctl; print(dpctl.__version__)" || exit 1 - name: Build docs if: ${{ !github.event.pull_request || github.event.action != 'closed' }} shell: bash -l {0} From d6618d6cd47d8550083bcb2871aadecba952937a Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Wed, 26 Jan 2022 09:46:52 -0600 Subject: [PATCH 14/19] Make the build work on Windows --- CMakeLists.txt | 2 +- cmake/IntelDPCPPConfig.cmake | 4 ++-- conda-recipe/bld.bat | 7 ++++--- conda-recipe/build.sh | 8 ++++---- conda-recipe/meta.yaml | 2 +- dpctl/CMakeLists.txt | 33 +++++++++++++++++++++++++++++++-- libsyclinterface/CMakeLists.txt | 20 ++++++-------------- 7 files changed, 49 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e215bbbcce..8aff7d1d70 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.21 FATAL_ERROR) +cmake_minimum_required(VERSION 3.21...3.22 FATAL_ERROR) project(dpctl LANGUAGES CXX diff --git a/cmake/IntelDPCPPConfig.cmake b/cmake/IntelDPCPPConfig.cmake index 8f683006be..2b73830f1e 100644 --- a/cmake/IntelDPCPPConfig.cmake +++ b/cmake/IntelDPCPPConfig.cmake @@ -201,7 +201,7 @@ if(SYCL_COMPILER) NAMES include HINTS - ${SYCL_PACKAGE_DIR} ENV SYCL_INCLUDE_DIR_HINT + ${SYCL_PACKAGE_DIR} $ENV{SYCL_INCLUDE_DIR_HINT} NO_DEFAULT_PATH ) @@ -210,7 +210,7 @@ if(SYCL_COMPILER) NAMES lib lib64 HINTS - ${SYCL_PACKAGE_DIR} ENV SYCL_LIBRARY_DIR_HINT + ${SYCL_PACKAGE_DIR} $ENV{SYCL_LIBRARY_DIR_HINT} NO_DEFAULT_PATH ) diff --git a/conda-recipe/bld.bat b/conda-recipe/bld.bat index a3cd4a4f70..ee34945ea7 100644 --- a/conda-recipe/bld.bat +++ b/conda-recipe/bld.bat @@ -4,16 +4,17 @@ set "LIB=%BUILD_PREFIX%\Library\lib;%BUILD_PREFIX%\compiler\lib;%LIB%" set "INCLUDE=%BUILD_PREFIX%\include;%INCLUDE%" "%PYTHON%" setup.py clean --all -set "INSTALL_CMD=install -- -G Ninja -DDPCTL_DPCPP_HOME_DIR=%BUILD_PREFIX%\Library -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icx -DDPCTL_ENABLE_LO_PROGRAM_CREATION=ON" +set "SKBUILD_ARGS=-- -G Ninja -DDPCTL_DPCPP_HOME_DIR=%BUILD_PREFIX%\Library -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icx -DDPCTL_ENABLE_LO_PROGRAM_CREATION=ON" +set "SYCL_INCLUDE_DIR_HINT=%BUILD_PREFIX%\Library\lib\clang\14.0.0" if NOT "%WHEELS_OUTPUT_FOLDER%"=="" ( rem Install and assemble wheel package from the build bits - "%PYTHON%" setup.py %INSTALL_CMD% bdist_wheel + "%PYTHON%" setup.py install bdist_wheel %SKBUILD_ARGS% if errorlevel 1 exit 1 copy dist\dpctl*.whl %WHEELS_OUTPUT_FOLDER% if errorlevel 1 exit 1 ) ELSE ( rem Only install - "%PYTHON%" setup.py %INSTALL_CMD% + "%PYTHON%" setup.py install %SKBUILD_ARGS% if errorlevel 1 exit 1 ) diff --git a/conda-recipe/build.sh b/conda-recipe/build.sh index 41f2546eb1..9d581001fe 100755 --- a/conda-recipe/build.sh +++ b/conda-recipe/build.sh @@ -7,8 +7,8 @@ export LDFLAGS="$LDFLAGS -Wl,-rpath,$PREFIX/lib" ${PYTHON} setup.py clean --all export CMAKE_GENERATOR="Unix Makefiles" -INSTALL_CMD="install -- -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icpx -DDPCTL_ENABLE_LO_PROGRAM_CREATION=ON -DDPCTL_DPCPP_HOME_DIR=${BUILD_PREFIX}" -echo "${PYTHON} setup.py ${INSTALL_CMD}" +SKBUILD_ARGS="-- -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icpx -DDPCTL_ENABLE_LO_PROGRAM_CREATION=ON -DDPCTL_DPCPP_HOME_DIR=${BUILD_PREFIX}" +echo "${PYTHON} setup.py install ${SKBUILD_ARGS}" # Workaround for: # DPC++ launched by cmake does not see components of `dpcpp_cpp_rt`, @@ -22,9 +22,9 @@ if [ -n "${WHEELS_OUTPUT_FOLDER}" ]; then else WHEELS_BUILD_ARGS="-p manylinux2014_x86_64" fi - ${PYTHON} setup.py ${INSTALL_CMD} bdist_wheel ${WHEELS_BUILD_ARGS} + ${PYTHON} setup.py install bdist_wheel ${WHEELS_BUILD_ARGS} ${SKBUILD_ARGS} cp dist/dpctl*.whl ${WHEELS_OUTPUT_FOLDER} else # Perform regular install - ${PYTHON} setup.py ${INSTALL_CMD} + ${PYTHON} setup.py install ${SKBUILD_ARGS} fi diff --git a/conda-recipe/meta.yaml b/conda-recipe/meta.yaml index ab01e3c178..c3087c303a 100644 --- a/conda-recipe/meta.yaml +++ b/conda-recipe/meta.yaml @@ -18,7 +18,7 @@ requirements: host: - setuptools - cython - - cmake + - cmake >=3.21 - python - make # [unix] - ninja # [win] diff --git a/dpctl/CMakeLists.txt b/dpctl/CMakeLists.txt index c858afc7ef..275fe83f80 100644 --- a/dpctl/CMakeLists.txt +++ b/dpctl/CMakeLists.txt @@ -11,6 +11,7 @@ if(WIN32) "-Wunused-function " "-Wuninitialized " "-Wmissing-declarations " + "-Wno-unused-parameter " ) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Ox ${WARNING_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Ox ${WARNING_FLAGS}") @@ -70,11 +71,39 @@ 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 copy ${CMAKE_SOURCE_DIR}/libsyclinterface/include/* ${DPCTL_INCLUDE_DIR}/syclinterface - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/apis/include/* ${DPCTL_INCLUDE_DIR} + COMMAND ${CMAKE_COMMAND} -E make_directory ${DPCTL_INCLUDE_DIR}/syclinterface/Support + COMMAND ${CMAKE_COMMAND} -E make_directory ${DPCTL_INCLUDE_DIR}/syclinterface/Config DEPENDS DPCTLSyclInterface ) +file(GLOB _syclinterface_h ${CMAKE_SOURCE_DIR}/libsyclinterface/include/*.h) +foreach(hf ${_syclinterface_h}) + add_custom_command(TARGET _build_time_create_dpctl_include + COMMAND ${CMAKE_COMMAND} -E copy ${hf} ${DPCTL_INCLUDE_DIR}/syclinterface + ) +endforeach() + +file(GLOB _syclinterface_Support_h ${CMAKE_SOURCE_DIR}/libsyclinterface/include/Support/*.h) +foreach(hf ${_syclinterface_Support_h}) + add_custom_command(TARGET _build_time_create_dpctl_include + COMMAND ${CMAKE_COMMAND} -E copy ${hf} ${DPCTL_INCLUDE_DIR}/syclinterface/Support + ) +endforeach() + +file(GLOB _syclinterface_Config_h ${CMAKE_SOURCE_DIR}/libsyclinterface/include/Config/*.h) +foreach(hf ${_syclinterface_Config_h}) + add_custom_command(TARGET _build_time_create_dpctl_include + COMMAND ${CMAKE_COMMAND} -E copy ${hf} ${DPCTL_INCLUDE_DIR}/syclinterface/Config + ) +endforeach() + +file(GLOB _apis_h ${CMAKE_CURRENT_SOURCE_DIR}/apis/include/*) +foreach(hf ${_apis_h}) + add_custom_command(TARGET _build_time_create_dpctl_include + COMMAND ${CMAKE_COMMAND} -E copy ${hf} ${DPCTL_INCLUDE_DIR} + ) +endforeach() + set(CMAKE_INSTALL_RPATH "$ORIGIN") function(build_dpctl_ext _trgt _src _dest) diff --git a/libsyclinterface/CMakeLists.txt b/libsyclinterface/CMakeLists.txt index 6ec3314c56..fd78f215a2 100644 --- a/libsyclinterface/CMakeLists.txt +++ b/libsyclinterface/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.10 FATAL_ERROR) +cmake_minimum_required(VERSION 3.10...3.22 FATAL_ERROR) project( "libDPCTLSYCLInterface" @@ -84,6 +84,7 @@ if(WIN32) "-Wunused-function " "-Wuninitialized " "-Wmissing-declarations " + "-Wno-deprecated-declarations " ) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS}") @@ -195,19 +196,6 @@ file(GLOB MAIN_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h") file(GLOB SUPPORT_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/Support/*.h") file(GLOB CONFIG_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/Config/*.h") -if (0) -set(ALL_HEADERS) -foreach(HEADER ${MAIN_HEADERS}) - list(APPEND ALL_HEADERS ${HEADER}) -endforeach() -foreach(HEADER ${SUPPORT_HEADERS}) - list(APPEND ALL_HEADERS ${HEADER}) -endforeach() -foreach(HEADER ${CONFIG_HEADERS}) - list(APPEND ALL_HEADERS ${HEADER}) -endforeach() -endif() - set_target_properties(DPCTLSyclInterface PROPERTIES PUBLIC_HEADER "${MAIN_HEADERS}" @@ -225,6 +213,10 @@ install(TARGETS DPCTLSyclInterface LIBRARY DESTINATION ${_lib_destination} + ARCHIVE + DESTINATION ${_lib_destination} + RUNTIME + DESTINATION ${_lib_destination} PUBLIC_HEADER DESTINATION ${_include_destination} ) From f9654563e657d5f928a5bb313864087f4513e362 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Wed, 26 Jan 2022 11:48:29 -0600 Subject: [PATCH 15/19] Set extra_require keyword for setup.py Two variants are provided: "docs" and "coverage". --- setup.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/setup.py b/setup.py index a63fdba8ed..c660f01180 100644 --- a/setup.py +++ b/setup.py @@ -97,6 +97,17 @@ def _patched_copy_file(src_file, dest_file, hide_listing=True): install_requires=[ "numpy", ], + extra_require={ + "docs": [ + "Cython", + "sphinx", + "sphinx_rtd_theme", + "pydot", + "graphviz", + "sphinxcontrib-programoutput", + ], + "coverage": ["Cython", "pytest", "pytest-cov", "coverage", "tomli"], + }, keywords="dpctl", classifiers=[ "Development Status :: 3 - Alpha", From 1ccf193a7ae01b164d2b1d1dad0f18372c628b83 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Wed, 26 Jan 2022 14:30:42 -0600 Subject: [PATCH 16/19] Added scripts/get_coverage.py Usage: ``` python scripts/gen_coverage.py ``` Builds coverage binaries, runs both ctests and pytest Allowed options can be retrived with `python scripts/gen_coverage.py --help`. Only Linux is supported, dependencies are assumed to be available. --- scripts/gen_coverage.py | 157 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 scripts/gen_coverage.py diff --git a/scripts/gen_coverage.py b/scripts/gen_coverage.py new file mode 100644 index 0000000000..1ed055f252 --- /dev/null +++ b/scripts/gen_coverage.py @@ -0,0 +1,157 @@ +import os +import subprocess +import sys + + +def run( + use_oneapi=True, + c_compiler=None, + cxx_compiler=None, + level_zero=True, + compiler_root=None, + run_pytest=False, + bin_llvm=None, +): + IS_LIN = False + + if "linux" in sys.platform: + IS_LIN = True + elif sys.platform in ["win32", "cygwin"]: + pass + else: + assert False, sys.platform + " not supported" + + if not IS_LIN: + raise RuntimeError( + "This scripts only supports coverage collection on Linux" + ) + setup_dir = os.path.dirname(os.path.dirname(__file__)) + cmake_args = [ + sys.executable, + "setup.py", + "develop", + "--", + "-G", + "Unix Makefiles", + "-DCMAKE_BUILD_TYPE=Debug", + "-DCMAKE_C_COMPILER:PATH=" + c_compiler, + "-DCMAKE_CXX_COMPILER:PATH=" + cxx_compiler, + "-DDPCTL_ENABLE_LO_PROGRAM_CREATION=" + ("ON" if level_zero else "OFF"), + "-DDPCTL_GENERATE_COVERAGE=ON", + "-DDPCTL_BUILD_CAPI_TESTS=ON", + "-DDPCTL_COVERAGE_REPORT_OUTPUT_DIR=" + setup_dir, + "-DDPCTL_DPCPP_FROM_ONEAPI:BOOL=" + ("ON" if use_oneapi else "OFF"), + ] + if compiler_root: + cmake_args += [ + "-DDPCTL_DPCPP_HOME_DIR:PATH=" + compiler_root, + ] + env = None + if bin_llvm: + env = { + "PATH": ":".join((os.environ.get("PATH", ""), bin_llvm)), + } + env.update({k: v for k, v in os.environ.items() if k != "PATH"}) + subprocess.check_call(cmake_args, shell=False, cwd=setup_dir, env=env) + test_dir = ( + subprocess.check_output( + ["find", "_skbuild", "-name", "tests"], cwd=setup_dir + ) + .decode("utf-8") + .strip("\n") + ) + subprocess.check_call( + ["make", "-C", test_dir, "lcov-genhtml"], cwd=setup_dir + ) + subprocess.check_call( + [ + "pytest", + "-q", + "-ra", + "--disable-warnings", + "--cov-config", + "pyproject.toml", + "--cov", + "dpctl", + "--cov-report", + "term-missing", + "--pyargs", + "dpctl", + "-vv", + ], + cwd=setup_dir, + shell=False, + ) + + +if __name__ == "__main__": + import argparse + + parser = argparse.ArgumentParser( + description="Driver to build dpctl and generate coverage" + ) + driver = parser.add_argument_group(title="Coverage driver arguments") + driver.add_argument("--c-compiler", help="Name of C compiler", default=None) + driver.add_argument( + "--cxx-compiler", help="Name of C++ compiler", default=None + ) + driver.add_argument( + "--not-oneapi", + help="Is one-API installation", + dest="oneapi", + action="store_false", + ) + driver.add_argument( + "--compiler-root", type=str, help="Path to compiler home directory" + ) + driver.add_argument( + "--no-level-zero", + help="Enable Level Zero support", + dest="level_zero", + action="store_false", + ) + driver.add_argument( + "--skip-pytest", + help="Run pytest and collect coverage", + dest="run_pytest", + action="store_false", + ) + driver.add_argument( + "--bin-llvm", help="Path to folder where llvm-cov can be found" + ) + args = parser.parse_args() + + if args.oneapi: + args.c_compiler = "icx" + args.cxx_compiler = "icpx" + args.compiler_root = None + icx_path = subprocess.check_output(["which", "icx"]) + bin_dir = os.path.dirname(os.path.dirname(icx_path)) + args.bin_llvm = os.path.join(bin_dir.decode("utf-8"), "bin-llvm") + else: + args_to_validate = [ + "c_compiler", + "cxx_compiler", + "compiler_root", + "bin_llvm", + ] + for p in args_to_validate: + arg = getattr(args, p, None) + if not isinstance(arg, str): + opt_name = p.replace("_", "-") + raise RuntimeError( + f"Option {opt_name} must be provided is " + "using non-default DPC++ layout" + ) + if not os.path.exists(arg): + raise RuntimeError(f"Path {arg} must exist") + + run( + use_oneapi=args.oneapi, + c_compiler=args.c_compiler, + cxx_compiler=args.cxx_compiler, + level_zero=args.level_zero, + compiler_root=args.compiler_root, + run_pytest=args.run_pytest, + bin_llvm=args.bin_llvm, + ) From c7529c6ce4affd5680b92230290673867897a11f Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Wed, 26 Jan 2022 14:56:13 -0600 Subject: [PATCH 17/19] Added script to drive setup.py develop for use of OS DPC++ sycl bundle Usage: ``` python scripts/build_sycl_nightly.py --c-compiler=$(which clang) --cxx-compiler=$(which clang++) --compiler-root=$(dirname $(dirname $(which clang))) ``` Option `--cmake-executable` can be used to use newer cmake --- scripts/build_sycl_nightly.py | 115 ++++++++++++++++++++++++++++++++++ scripts/environment.yml | 5 -- 2 files changed, 115 insertions(+), 5 deletions(-) create mode 100644 scripts/build_sycl_nightly.py delete mode 100644 scripts/environment.yml diff --git a/scripts/build_sycl_nightly.py b/scripts/build_sycl_nightly.py new file mode 100644 index 0000000000..5646c980bf --- /dev/null +++ b/scripts/build_sycl_nightly.py @@ -0,0 +1,115 @@ +import os +import subprocess +import sys + + +def run( + use_oneapi=True, + c_compiler=None, + cxx_compiler=None, + level_zero=True, + compiler_root=None, + cmake_executable=None, +): + IS_LIN = False + + if "linux" in sys.platform: + IS_LIN = True + elif sys.platform in ["win32", "cygwin"]: + pass + else: + assert False, sys.platform + " not supported" + + if not IS_LIN: + raise RuntimeError( + "This scripts only supports coverage collection on Linux" + ) + setup_dir = os.path.dirname(os.path.dirname(__file__)) + cmake_args = [ + sys.executable, + "setup.py", + "develop", + ] + if cmake_executable: + cmake_args += [ + "--cmake-executable=" + cmake_executable, + ] + cmake_args += [ + "--", + "-G", + "Unix Makefiles", + "-DCMAKE_BUILD_TYPE=Debug", + "-DCMAKE_C_COMPILER:PATH=" + c_compiler, + "-DCMAKE_CXX_COMPILER:PATH=" + cxx_compiler, + "-DDPCTL_ENABLE_LO_PROGRAM_CREATION=" + ("ON" if level_zero else "OFF"), + "-DDPCTL_DPCPP_FROM_ONEAPI:BOOL=" + ("ON" if use_oneapi else "OFF"), + ] + if compiler_root: + cmake_args += [ + "-DDPCTL_DPCPP_HOME_DIR:PATH=" + compiler_root, + ] + subprocess.check_call( + cmake_args, shell=False, cwd=setup_dir, env=os.environ + ) + + +if __name__ == "__main__": + import argparse + + parser = argparse.ArgumentParser( + description="Driver to build dpctl for in-place installation" + ) + driver = parser.add_argument_group(title="Coverage driver arguments") + driver.add_argument("--c-compiler", help="Name of C compiler", default=None) + driver.add_argument( + "--cxx-compiler", help="Name of C++ compiler", default=None + ) + driver.add_argument( + "--oneapi", + help="Is one-API installation", + dest="oneapi", + action="store_true", + ) + driver.add_argument( + "--compiler-root", type=str, help="Path to compiler home directory" + ) + driver.add_argument( + "--cmake-executable", type=str, help="Path to cmake executable" + ) + driver.add_argument( + "--no-level-zero", + help="Enable Level Zero support", + dest="level_zero", + action="store_false", + ) + args = parser.parse_args() + + if args.oneapi: + args.c_compiler = "icx" + args.cxx_compiler = "icpx" + args.compiler_root = None + else: + args_to_validate = [ + "c_compiler", + "cxx_compiler", + "compiler_root", + ] + for p in args_to_validate: + arg = getattr(args, p, None) + if not isinstance(arg, str): + opt_name = p.replace("_", "-") + raise RuntimeError( + f"Option {opt_name} must be provided is " + "using non-default DPC++ layout" + ) + if not os.path.exists(arg): + raise RuntimeError(f"Path {arg} must exist") + + run( + use_oneapi=args.oneapi, + c_compiler=args.c_compiler, + cxx_compiler=args.cxx_compiler, + level_zero=args.level_zero, + compiler_root=args.compiler_root, + cmake_executable=args.cmake_executable, + ) diff --git a/scripts/environment.yml b/scripts/environment.yml deleted file mode 100644 index 0a063c0a95..0000000000 --- a/scripts/environment.yml +++ /dev/null @@ -1,5 +0,0 @@ -channels: - - defaults -dependencies: - - python=3.7 - - conda-build From 51b41b834bfbba09a750aeae92d03fe48a18d5b5 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Thu, 27 Jan 2022 06:26:21 -0600 Subject: [PATCH 18/19] Updated quick start guide to reflect changes in setup --- docs/docfiles/user_guides/QuickStart.rst | 38 ++++++++++++++++-------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/docs/docfiles/user_guides/QuickStart.rst b/docs/docfiles/user_guides/QuickStart.rst index 37d6097e4b..fa967a2004 100644 --- a/docs/docfiles/user_guides/QuickStart.rst +++ b/docs/docfiles/user_guides/QuickStart.rst @@ -50,7 +50,7 @@ Dpctl can also be istalled from Pypi. .. code-block:: bash - python -m pip install --index-url https://pypi.anaconda.org/intel/simple --extra-index-url https://pypi.org/simple dpctl + python -m pip install --index-url https://pypi.anaconda.org/intel/simple dpctl .. note:: @@ -133,33 +133,41 @@ After building the conda package you may install it by executing: 3.18 instead. -Build and install with setuptools -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Build and install with scikit-build +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -To build using Python ``setuptools``, the following packages should be +To build using Python ``setuptools`` and ``scikit-build``, the following Python packages should be installed: - ``cython`` - ``numpy`` - ``cmake`` + - ``scikit-build`` - ``ninja`` (only on Windows) - ``gtest`` (optional to run C API tests) + - ``gmock`` (optional to run C API tests) - ``pytest`` (optional to run Python API tests) -Once the prerequisites are installed, building using ``setuptools`` involves The -usual steps +Once the prerequisites are installed, building using ``scikit-build`` involves the usual steps, to build and install: + +.. code-block:: bash -to build and install + python setup.py install -- -G Unix\ Makefiles -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icpx -DDPCTL_ENABLE_LO_PROGRAM_CREATION=ON + +, and to develop: .. code-block:: bash - python setup.py install + python setup.py develop -G Unix\ Makefiles -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icpx -DDPCTL_ENABLE_LO_PROGRAM_CREATION=ON + +On Windows, use ``icx`` for both C and CXX compilers, and use :code:`-G Ninja` for cmake generator. -, and to develop. +Developing on Linux can also be done using driver script: .. code-block:: bash - python setup.py develop + python scripts/build_sycl_nightly.py --oneapi + Building using custom dpcpp --------------------------- @@ -168,12 +176,18 @@ It is possible to build dpctl from source using .. _DPC++ toolchain: https://git instead of the DPC++ compiler that comes with oneAPI. One reason for doing this may be to enable support for CUDA devices. -Following steps in `Build and install with setuptools`_ use command line +Following steps in `Build and install with scikit-build`_ use command line option :code:`--sycl-compiler-prefix`, for example: .. code-block:: bash - python setup.py develop --sycl-compiler-prefix=${DPCPP_ROOT}/llvm/build + python setup.py develop -- -G Unix\ Makefiles -DCMAKE_C_COMPILER:PATH=clang -DCMAKE_CXX_COMPILER:PATH=clang++ -DDPCTL_ENABLE_LO_PROGRAM_CREATION=ONE -DDPCTL_DPCPP_HOME_DIR=${DPCPP_ROOT}/llvm/build -DDPCTL_DPCPP_FROM_ONEAPI=OFF + +Alterantively, the driver script can be used + +.. code-block:: bash + + python scripts/build_sycl_nightly.py --c-compiler=clang --cxx-compiler=clang++ --compiler-root=${DPCPP_ROOT}/llvm/build Available options and their descriptions can be retrieved using option :code:`--help`. From 91705105078f5c6fd71c9bff938ba910634ba252 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Thu, 27 Jan 2022 13:05:56 -0600 Subject: [PATCH 19/19] Fixed driver scripts to use abspath for sanitation Removed scripts/build_for_develop* as obsolete. Renamed scripts/build_sycl_nightly.py as scripts/build_locally.py Updated quick start guide to account for the renaming. --- docs/docfiles/user_guides/QuickStart.rst | 7 +- scripts/build_for_develop.bat | 66 ------------------- scripts/build_for_develop.sh | 6 -- ...build_sycl_nightly.py => build_locally.py} | 2 +- scripts/gen_coverage.py | 2 +- 5 files changed, 5 insertions(+), 78 deletions(-) delete mode 100644 scripts/build_for_develop.bat delete mode 100755 scripts/build_for_develop.sh rename scripts/{build_sycl_nightly.py => build_locally.py} (97%) diff --git a/docs/docfiles/user_guides/QuickStart.rst b/docs/docfiles/user_guides/QuickStart.rst index fa967a2004..8c58acd15a 100644 --- a/docs/docfiles/user_guides/QuickStart.rst +++ b/docs/docfiles/user_guides/QuickStart.rst @@ -166,7 +166,7 @@ Developing on Linux can also be done using driver script: .. code-block:: bash - python scripts/build_sycl_nightly.py --oneapi + python scripts/build_locally.py --oneapi Building using custom dpcpp @@ -176,8 +176,7 @@ It is possible to build dpctl from source using .. _DPC++ toolchain: https://git instead of the DPC++ compiler that comes with oneAPI. One reason for doing this may be to enable support for CUDA devices. -Following steps in `Build and install with scikit-build`_ use command line -option :code:`--sycl-compiler-prefix`, for example: +Following steps in `Build and install with scikit-build`_ use command line option to set relevant cmake variables, for example: .. code-block:: bash @@ -187,7 +186,7 @@ Alterantively, the driver script can be used .. code-block:: bash - python scripts/build_sycl_nightly.py --c-compiler=clang --cxx-compiler=clang++ --compiler-root=${DPCPP_ROOT}/llvm/build + python scripts/build_locally.py --c-compiler=clang --cxx-compiler=clang++ --compiler-root=${DPCPP_ROOT}/llvm/build Available options and their descriptions can be retrieved using option :code:`--help`. diff --git a/scripts/build_for_develop.bat b/scripts/build_for_develop.bat deleted file mode 100644 index 0273a9d62a..0000000000 --- a/scripts/build_for_develop.bat +++ /dev/null @@ -1,66 +0,0 @@ -REM check if oneAPI has been activated, only try activating if not -dpcpp.exe --version >nul 2>&1 -IF %ERRORLEVEL% NEQ 0 ( - set ERRORLEVEL= - call "%ONEAPI_ROOT%\compiler\latest\env\vars.bat" - IF ERRORLEVEL 1 exit /b 1 -) -REM conda uses %ERRORLEVEL% but FPGA scripts can set it. So it should be reseted. -set ERRORLEVEL= - -rmdir /S /Q build_cmake -mkdir build_cmake - -rmdir /S /Q install -mkdir install -cd install -set "INSTALL_PREFIX=%cd%" - -cd ..\build_cmake - -set "DPCPP_ROOT=%ONEAPI_ROOT%\compiler\latest\windows" - -if defined USE_GTEST ( - set "_BUILD_CAPI_TEST=ON" -) else ( - set "_BUILD_CAPI_TEST=OFF" -) -cmake -G Ninja ^ - -DCMAKE_BUILD_TYPE=Release ^ - "-DCMAKE_CXX_FLAGS=-Wno-unused-function /EHa" ^ - "-DCMAKE_INSTALL_PREFIX=%INSTALL_PREFIX%" ^ - "-DCMAKE_PREFIX_PATH=%INSTALL_PREFIX%" ^ - "-DDPCPP_ROOT=%DPCPP_ROOT%" ^ - "-DCMAKE_C_COMPILER:PATH=%DPCPP_ROOT%\bin\icx.exe" ^ - "-DCMAKE_CXX_COMPILER:PATH=%DPCPP_ROOT%\bin\dpcpp.exe" ^ - "-DBUILD_CAPI_TESTS=%_BUILD_CAPI_TEST%" ^ - "%cd%\..\dpctl-capi" -IF %ERRORLEVEL% NEQ 0 exit /b 1 - -ninja -n -IF %ERRORLEVEL% NEQ 0 exit /b 1 -if defined USE_GTEST ( - ninja check - IF %ERRORLEVEL% NEQ 0 exit /b 1 -) -ninja install -IF %ERRORLEVEL% NEQ 0 exit /b 1 - -cd .. -xcopy install\lib\*.lib dpctl /E /Y -xcopy install\bin\*.dll dpctl /E /Y - -mkdir dpctl\include -xcopy dpctl-capi\include dpctl\include /E /Y - - -REM required by _sycl_core(dpctl) -set "DPCTL_SYCL_INTERFACE_LIBDIR=dpctl" -set "DPCTL_SYCL_INTERFACE_INCLDIR=dpctl\include" -set "CC=icx.exe" -set "CXX=dpcpp.exe" - -python setup.py clean --all -python setup.py build_ext --inplace develop -python -m unittest dpctl.tests -IF %ERRORLEVEL% NEQ 0 exit /b 1 diff --git a/scripts/build_for_develop.sh b/scripts/build_for_develop.sh deleted file mode 100755 index 530c2a2991..0000000000 --- a/scripts/build_for_develop.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -set +xe - -python setup.py clean --all -python setup.py develop --coverage=True -pytest -q -ra --disable-warnings --cov dpctl --cov-report term-missing --pyargs dpctl -vv diff --git a/scripts/build_sycl_nightly.py b/scripts/build_locally.py similarity index 97% rename from scripts/build_sycl_nightly.py rename to scripts/build_locally.py index 5646c980bf..049079cc37 100644 --- a/scripts/build_sycl_nightly.py +++ b/scripts/build_locally.py @@ -24,7 +24,7 @@ def run( raise RuntimeError( "This scripts only supports coverage collection on Linux" ) - setup_dir = os.path.dirname(os.path.dirname(__file__)) + setup_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmake_args = [ sys.executable, "setup.py", diff --git a/scripts/gen_coverage.py b/scripts/gen_coverage.py index 1ed055f252..68ad75ea52 100644 --- a/scripts/gen_coverage.py +++ b/scripts/gen_coverage.py @@ -25,7 +25,7 @@ def run( raise RuntimeError( "This scripts only supports coverage collection on Linux" ) - setup_dir = os.path.dirname(os.path.dirname(__file__)) + setup_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) cmake_args = [ sys.executable, "setup.py",