diff --git a/.flake8 b/.flake8 index 485dd3020b..276ee08645 100644 --- a/.flake8 +++ b/.flake8 @@ -31,6 +31,6 @@ per-file-ignores = dpctl/utils/_compute_follows_data.pyx: E999, E225, E227 dpctl/utils/_onetrace_context.py: E501, W505 dpctl/tensor/_array_api.py: E501, W505 - examples/cython/sycl_buffer/syclbuffer/_buffer_example.pyx: E999, E225, E402 - examples/cython/usm_memory/blackscholes/blackscholes.pyx: E999, E225, E226, E402 + examples/cython/sycl_buffer/syclbuffer/_syclbuffer.pyx: E999, E225, E402 + examples/cython/usm_memory/blackscholes/_blackscholes_usm.pyx: E999, E225, E226, E402 examples/cython/use_dpctl_sycl/use_dpctl_sycl/_cython_api.pyx: E999, E225, E226, E402 diff --git a/.github/workflows/conda-package.yml b/.github/workflows/conda-package.yml index 87fceb1830..55e90d8062 100644 --- a/.github/workflows/conda-package.yml +++ b/.github/workflows/conda-package.yml @@ -549,7 +549,7 @@ jobs: - name: Install example requirements shell: bash -ex -l {0} env: - DPCPP_CMPLR: "dpcpp_linux-64>=2024.2" + DPCPP_CMPLR: "dpcpp_linux-64>=2025.0" run: | CHANNELS="${{ env.CHANNELS }}" . $CONDA/etc/profile.d/conda.sh @@ -569,6 +569,7 @@ jobs: ${{ env.DPCPP_CMPLR }} "${DPCTL_DEPENDS}" \ "sysroot_linux-64>=2.28" echo "Compiler installed" + conda list -n ${{ env.BUILD_ENV_NAME }} - name: Install dpctl shell: bash -l {0} run: | @@ -586,14 +587,8 @@ jobs: for d in $(find . -maxdepth 1 -type d -not -path ".") do pushd $d - export MKLROOT=${CONDA_PREFIX} - export TBBROOT=${CONDA_PREFIX} conda activate --stack build_env - CC=icx CXX=icpx python setup.py build_ext --inplace -G Ninja -- \ - -DTBB_LIBRARY_DIR=${TBBROOT}/lib \ - -DMKL_LIBRARY_DIR=${MKLROOT}/lib \ - -DMKL_INCLUDE_DIR=${MKLROOT}/include \ - -DTBB_INCLUDE_DIR=${TBBROOT}/include || exit 1 + CC=icx CXX=icpx python setup.py build_ext --inplace -G Ninja || exit 1 conda deactivate if [ -e tests ] then @@ -614,7 +609,7 @@ jobs: do pushd $d conda activate --stack ${{ env.BUILD_ENV_NAME }} - python setup.py build_ext --inplace || exit 1 + CC=icx CXX=icpx python setup.py develop -G Ninja || exit 1 conda deactivate python -m pytest tests || exit 1 popd diff --git a/examples/cython/sycl_buffer/CMakeLists.txt b/examples/cython/sycl_buffer/CMakeLists.txt new file mode 100644 index 0000000000..a30fbb2f35 --- /dev/null +++ b/examples/cython/sycl_buffer/CMakeLists.txt @@ -0,0 +1,46 @@ +cmake_minimum_required(VERSION 3.22...3.27 FATAL_ERROR) + +project(example_cython_syclbuffer VERSION 0.1 LANGUAGES CXX + DESCRIPTION "Example of Cython extension to work on host allocated NumPy array using SYCL buffers and SYCL functions.") +set(DPCTL_CMAKE_MODULES_PATH "${CMAKE_SOURCE_DIR}/../../../cmake") +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${DPCTL_CMAKE_MODULES_PATH}) + +find_package(IntelSYCL REQUIRED PATHS ${DPCTL_CMAKE_MODULES_PATH} NO_DEFAULT_PATH) + + +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}") +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED True) + +# Define CMAKE_INSTALL_xxx: LIBDIR, INCLUDEDIR +include(GNUInstallDirs) + +find_package(Python REQUIRED COMPONENTS Development.Module NumPy) +find_package(Dpctl REQUIRED) + +# -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) + +set(py_module_name _syclbuffer) + +set(_cy_source syclbuffer/_syclbuffer.pyx) +add_cython_target(${py_module_name} ${_cy_source} CXX OUTPUT_VAR _generated_cy_src) +Python_add_library(${py_module_name} MODULE WITH_SOABI ${_generated_cy_src}) +add_sycl_to_target(TARGET ${py_module_name} SOURCES ${_generated_cy_src}) +target_include_directories(${py_module_name} PUBLIC src ${Dpctl_INCLUDE_DIRS}) +target_link_libraries(${py_module_name} PRIVATE Python::NumPy) + +install(TARGETS ${py_module_name} DESTINATION syclbuffer) + +foreach(_src_fn ${_sources}) + get_source_file_property(_compile_options ${_src_fn} COMPILE_OPTIONS) + set(_combined_options ${_compile_options} "-O3") + set_source_files_properties(${_src_fn} + PROPERTIES + COMPILE_OPTIONS "${_combined_options}" + ) +endforeach() +target_link_options(${py_module_name} PRIVATE -fsycl-device-code-split=per_kernel) + +set(ignoreMe "${SKBUILD}") diff --git a/examples/cython/sycl_buffer/setup.py b/examples/cython/sycl_buffer/setup.py index e7d64bab4e..00e556063f 100644 --- a/examples/cython/sycl_buffer/setup.py +++ b/examples/cython/sycl_buffer/setup.py @@ -14,46 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import Extension, setup -from setuptools.command.build_ext import build_ext - -import dpctl - - -class custom_build_ext(build_ext): - def build_extensions(self): - self.compiler.set_executable("compiler_so", "icpx -fsycl -fPIC") - self.compiler.set_executable("compiler_cxx", "icpx -fsycl -fPIC") - self.compiler.set_executable( - "linker_so", - "icpx -fsycl -shared -fpic -fsycl-device-code-split=per_kernel", - ) - build_ext.build_extensions(self) - - -ext_modules = [ - Extension( - name="syclbuffer._syclbuffer", - sources=[ - "syclbuffer/_buffer_example.pyx", - ], - depends=[ - "src/use_sycl_buffer.hpp", - ], - include_dirs=[ - ".", - "./src", - dpctl.get_include(), - ], - extra_compile_args=[ - "-Wall", - "-Wextra", - "-fsycl", - ], - extra_link_args=["-fPIC"], - language="c++", - ) -] +from skbuild import setup setup( name="syclbuffer", @@ -68,6 +29,5 @@ def build_extensions(self): license="Apache 2.0", author="Intel Corporation", url="https://github.com/IntelPython/dpctl", - ext_modules=ext_modules, - cmdclass={"build_ext": custom_build_ext}, + packages=["syclbuffer"], ) diff --git a/examples/cython/sycl_buffer/syclbuffer/_buffer_example.pyx b/examples/cython/sycl_buffer/syclbuffer/_syclbuffer.pyx similarity index 100% rename from examples/cython/sycl_buffer/syclbuffer/_buffer_example.pyx rename to examples/cython/sycl_buffer/syclbuffer/_syclbuffer.pyx diff --git a/examples/cython/use_dpctl_sycl/CMakeLists.txt b/examples/cython/use_dpctl_sycl/CMakeLists.txt new file mode 100644 index 0000000000..9445ae08f3 --- /dev/null +++ b/examples/cython/use_dpctl_sycl/CMakeLists.txt @@ -0,0 +1,46 @@ +cmake_minimum_required(VERSION 3.22...3.27 FATAL_ERROR) + +project(example_cython_use_dpctl_sycl VERSION 0.1 LANGUAGES CXX + DESCRIPTION "Example of Cython extension to use Cython API to SYCL objects.") +set(DPCTL_CMAKE_MODULES_PATH "${CMAKE_SOURCE_DIR}/../../../cmake") +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${DPCTL_CMAKE_MODULES_PATH}) + +find_package(IntelSYCL REQUIRED PATHS ${DPCTL_CMAKE_MODULES_PATH} NO_DEFAULT_PATH) + + +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}") +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED True) + +# Define CMAKE_INSTALL_xxx: LIBDIR, INCLUDEDIR +include(GNUInstallDirs) + +find_package(Python REQUIRED COMPONENTS Development.Module NumPy) +find_package(Dpctl REQUIRED) + +# -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) + +set(py_module_name _cython_api) + +set(_cy_source use_dpctl_sycl/_cython_api.pyx) +add_cython_target(${py_module_name} ${_cy_source} CXX OUTPUT_VAR _generated_cy_src) +Python_add_library(${py_module_name} MODULE WITH_SOABI ${_generated_cy_src}) +add_sycl_to_target(TARGET ${py_module_name} SOURCES ${_generated_cy_src}) +target_include_directories(${py_module_name} PUBLIC include ${Dpctl_INCLUDE_DIRS}) +target_link_libraries(${py_module_name} PRIVATE Python::NumPy) + +install(TARGETS ${py_module_name} DESTINATION use_dpctl_sycl) + +foreach(_src_fn ${_sources}) + get_source_file_property(_compile_options ${_src_fn} COMPILE_OPTIONS) + set(_combined_options ${_compile_options} "-O3") + set_source_files_properties(${_src_fn} + PROPERTIES + COMPILE_OPTIONS "${_combined_options}" + ) +endforeach() +target_link_options(${py_module_name} PRIVATE -fsycl-device-code-split=per_kernel) + +set(ignoreMe "${SKBUILD}") diff --git a/examples/cython/use_dpctl_sycl/use_dpctl_sycl/utils.hpp b/examples/cython/use_dpctl_sycl/include/utils.hpp similarity index 100% rename from examples/cython/use_dpctl_sycl/use_dpctl_sycl/utils.hpp rename to examples/cython/use_dpctl_sycl/include/utils.hpp diff --git a/examples/cython/use_dpctl_sycl/setup.py b/examples/cython/use_dpctl_sycl/setup.py index 863590d856..4a3bbf79d4 100644 --- a/examples/cython/use_dpctl_sycl/setup.py +++ b/examples/cython/use_dpctl_sycl/setup.py @@ -14,40 +14,20 @@ # See the License for the specific language governing permissions and # limitations under the License. -import Cython.Build -import setuptools -from setuptools.command.build_ext import build_ext as build_ext_base +from skbuild import setup -import dpctl - - -class custom_build_ext(build_ext_base): - def build_extensions(self): - self.compiler.set_executable("compiler_so", "icx -fsycl -fPIC") - self.compiler.set_executable("compiler_cxx", "icpx -fsycl -fPIC") - self.compiler.set_executable( - "linker_so", - "icpx -fsycl -shared -fpic -fsycl-device-code-split=per_kernel", - ) - super().build_extensions() - - -ext = setuptools.Extension( - "use_dpctl_sycl._cython_api", - ["./use_dpctl_sycl/_cython_api.pyx"], - include_dirs=[dpctl.get_include(), "./use_dpctl_sycl"], - language="c++", -) - -(cythonized_ext,) = Cython.Build.cythonize( - [ - ext, - ] -) - -setuptools.setup( +setup( name="use_dpctl_sycl", version="0.0.0", - ext_modules=[cythonized_ext], - cmdclass={"build_ext": custom_build_ext}, + description="An example of Cython extension calling SYCL Cython API", + long_description=""" + Example of using SYCL to work on host allocated NumPy array using + SYCL buffers and SYCL functions. + + See README.md for more details. + """, + license="Apache 2.0", + author="Intel Corporation", + url="https://github.com/IntelPython/dpctl", + packages=["use_dpctl_sycl"], ) diff --git a/examples/cython/usm_memory/CMakeLists.txt b/examples/cython/usm_memory/CMakeLists.txt new file mode 100644 index 0000000000..0a422d26d1 --- /dev/null +++ b/examples/cython/usm_memory/CMakeLists.txt @@ -0,0 +1,56 @@ +cmake_minimum_required(VERSION 3.22...3.27 FATAL_ERROR) + +project(example_cython_blackscholes_usm VERSION 0.1 LANGUAGES CXX + DESCRIPTION "Example of Cython extension calling SYCL routines") +set(DPCTL_CMAKE_MODULES_PATH "${CMAKE_SOURCE_DIR}/../../../cmake") +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${DPCTL_CMAKE_MODULES_PATH}) + +find_package(IntelSYCL REQUIRED PATHS ${DPCTL_CMAKE_MODULES_PATH} NO_DEFAULT_PATH) + + +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}") +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED True) + +# Define CMAKE_INSTALL_xxx: LIBDIR, INCLUDEDIR +include(GNUInstallDirs) + +find_package(Python REQUIRED COMPONENTS Development.Module NumPy) +find_package(Dpctl REQUIRED) + +# -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) + +find_package(TBB REQUIRED) + +set(MKL_ARCH "intel64") +set(MKL_LINK "dynamic") +set(MKL_THREADING "tbb_thread") +set(MKL_INTERFACE "ilp64") +find_package(MKL REQUIRED) + +set(py_module_name _blackscholes_usm) + +set(_cy_source blackscholes/_blackscholes_usm.pyx) +add_cython_target(${py_module_name} ${_cy_source} CXX OUTPUT_VAR _generated_cy_src) +Python_add_library(${py_module_name} MODULE WITH_SOABI ${_generated_cy_src}) +add_sycl_to_target(TARGET ${py_module_name} SOURCES ${_generated_cy_src}) +target_compile_definitions(${py_module_name} PRIVATE -DMKL_ILP64) +target_include_directories(${py_module_name} PUBLIC src ${Dpctl_INCLUDE_DIRS}) +target_link_libraries(${py_module_name} PRIVATE MKL::MKL_SYCL Python::NumPy) + +install(TARGETS ${py_module_name} DESTINATION blackscholes) + +foreach(_src_fn ${_sources}) + get_source_file_property(_compile_options ${_src_fn} COMPILE_OPTIONS) + set(_combined_options ${_compile_options} "-O3") + set_source_files_properties(${_src_fn} + PROPERTIES + COMPILE_OPTIONS "${_combined_options}" + ) +endforeach() +target_link_options(${py_module_name} PRIVATE -fsycl-device-code-split=per_kernel) + +set(ignoreMe "${SKBUILD}") diff --git a/examples/cython/usm_memory/blackscholes/blackscholes.pyx b/examples/cython/usm_memory/blackscholes/_blackscholes_usm.pyx similarity index 100% rename from examples/cython/usm_memory/blackscholes/blackscholes.pyx rename to examples/cython/usm_memory/blackscholes/_blackscholes_usm.pyx diff --git a/examples/cython/usm_memory/setup.py b/examples/cython/usm_memory/setup.py index ae3c7b85c5..f09d146c73 100644 --- a/examples/cython/usm_memory/setup.py +++ b/examples/cython/usm_memory/setup.py @@ -14,65 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os.path -import sysconfig - -import numpy as np -from setuptools import Extension, setup -from setuptools.command.build_ext import build_ext - -import dpctl - - -class custom_build_ext(build_ext): - def build_extensions(self): - self.compiler.set_executable("compiler_so", "icpx -fsycl -fPIC") - self.compiler.set_executable("compiler_cxx", "icpx -fsycl -fPIC") - self.compiler.set_executable( - "linker_so", - "icpx -fsycl -shared -fpic -fsycl-device-code-split=per_kernel", - ) - build_ext.build_extensions(self) - - -ext_modules = [ - Extension( - name="blackscholes._blackscholes_usm", - sources=[ - "blackscholes/blackscholes.pyx", - ], - depends=[ - "src/sycl_black_scholes.hpp", - ], - include_dirs=[ - "./src", - np.get_include(), - dpctl.get_include(), - os.path.join(sysconfig.get_paths()["include"], ".."), - ], - library_dirs=[ - os.path.join(sysconfig.get_paths()["stdlib"], ".."), - ], - libraries=["sycl"] - + [ - "mkl_sycl", - "mkl_intel_ilp64", - "mkl_tbb_thread", - "mkl_core", - "tbb", - ], - runtime_library_dirs=[], - extra_compile_args=[ - "-Wall", - "-Wextra", - "-fsycl", - "-fno-fast-math", - ], - extra_link_args=["-fPIC"], - language="c++", - ) -] - +from skbuild import setup setup( name="blackscholes_usm", @@ -86,6 +28,5 @@ def build_extensions(self): license="Apache 2.0", author="Intel Corporation", url="https://github.com/IntelPython/dpctl", - ext_modules=ext_modules, - cmdclass={"build_ext": custom_build_ext}, + packages=["blackscholes"], ) diff --git a/examples/pybind11/onemkl_gemv/CMakeLists.txt b/examples/pybind11/onemkl_gemv/CMakeLists.txt index 46709840fb..08dda0b288 100644 --- a/examples/pybind11/onemkl_gemv/CMakeLists.txt +++ b/examples/pybind11/onemkl_gemv/CMakeLists.txt @@ -27,28 +27,21 @@ FetchContent_MakeAvailable(pybind11) find_package(Python REQUIRED COMPONENTS Development.Module NumPy) find_package(Dpctl REQUIRED) -find_library(mkl_core NAMES mkl_core PATHS ${MKL_LIBRARY_DIR} REQUIRED) -find_library(mkl_sycl NAMES mkl_sycl PATHS ${MKL_LIBRARY_DIR} REQUIRED) -find_library(mkl_intel_ilp64 NAMES mkl_intel_ilp64 PATHS ${MKL_LIBRARY_DIR} REQUIRED) -find_library(mkl_tbb_thread NAMES mkl_tbb_thread PATHS ${MKL_LIBRARY_DIR} REQUIRED) -find_library(tbb NAMES tbb PATHS ${TBB_LIBRARY_DIR} REQUIRED) -find_library(OpenCL NAMES OpenCL REQUIRED) +find_package(TBB REQUIRED) + +set(MKL_ARCH "intel64") +set(MKL_LINK "dynamic") +set(MKL_THREADING "tbb_thread") +set(MKL_INTERFACE "ilp64") +find_package(MKL REQUIRED) set(py_module_name _onemkl) set(_sources sycl_gemm/_onemkl.cpp) -pybind11_add_module(${py_module_name} - MODULE - ${_sources} -) +pybind11_add_module(${py_module_name} MODULE ${_sources}) add_sycl_to_target(TARGET ${py_module_name} SOURCES ${_sources}) -target_compile_definitions(${py_module_name} PRIVATE -DMKL_ILP64) -target_include_directories(${py_module_name} - PUBLIC ${MKL_INCLUDE_DIR} sycl_gemm -) -target_link_libraries(${py_module_name} - PRIVATE ${mkl_sycl} ${mkl_intel_ilp64} ${mkl_tbb_thread} ${mkl_core} ${tbb} -) +target_include_directories(${py_module_name} PUBLIC sycl_gemm) +target_link_libraries(${py_module_name} PRIVATE MKL::MKL_SYCL) install(TARGETS ${py_module_name} DESTINATION sycl_gemm) target_include_directories(${py_module_name} PUBLIC ${Dpctl_INCLUDE_DIRS}) @@ -70,11 +63,7 @@ add_executable(standalone_cpp target_compile_options(standalone_cpp PRIVATE -O3 -Wno-deprecated-declarations ) -target_include_directories(standalone_cpp - PUBLIC ${MKL_INCLUDE_DIR} ${TBB_INCLUDE_DIR} sycl_gemm - ) -target_link_libraries(standalone_cpp - PRIVATE ${mkl_sycl} ${mkl_intel_ilp64} ${mkl_tbb_thread} ${mkl_core} ${tbb} ${OpenCL} -) +target_include_directories(standalone_cpp PUBLIC sycl_gemm) +target_link_libraries(standalone_cpp PRIVATE MKL::MKL_SYCL) set(ignoreMe "${SKBUILD}")