Skip to content

Commit

Permalink
Merge pull request #1935 from IntelPython/triage-example-warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandr-pavlyk authored Dec 17, 2024
2 parents d6e1042 + ac978f1 commit d9b9e0c
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 170 deletions.
4 changes: 2 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 4 additions & 9 deletions .github/workflows/conda-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: |
Expand All @@ -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
Expand All @@ -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
Expand Down
46 changes: 46 additions & 0 deletions examples/cython/sycl_buffer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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}")
44 changes: 2 additions & 42 deletions examples/cython/sycl_buffer/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"],
)
46 changes: 46 additions & 0 deletions examples/cython/use_dpctl_sycl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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}")
46 changes: 13 additions & 33 deletions examples/cython/use_dpctl_sycl/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)
56 changes: 56 additions & 0 deletions examples/cython/usm_memory/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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}")
63 changes: 2 additions & 61 deletions examples/cython/usm_memory/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"],
)
Loading

0 comments on commit d9b9e0c

Please sign in to comment.