Skip to content

Commit 755b6b5

Browse files
Cleanup/examples (#681)
* addressed deprecation warnings in examples/cython/sycl_buffer/use_sycl_buffer.cpp * addressed deprecaton warnings in examples/pybind11/use_dpctl_syclqueue/pybind11_example.cpp * Do not use numpy.distutils * Simplify setup by using setuptools alone (no numpy.distutils) * Do not use numpy.distutils, use setuptools instead * Streamlined example using newer syntax
1 parent 749be95 commit 755b6b5

File tree

9 files changed

+157
-217
lines changed

9 files changed

+157
-217
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
_buffer_example.cpp
2+
*.cpython*.so
3+
*~

examples/cython/sycl_buffer/setup.py

Lines changed: 46 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -14,74 +14,50 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
from os import environ
18-
from os.path import dirname, join
19-
20-
from Cython.Build import cythonize
21-
22-
23-
def configuration(parent_package="", top_path=None):
24-
import numpy as np
25-
from numpy.distutils.misc_util import Configuration
26-
27-
import dpctl
28-
29-
config = Configuration("", parent_package, top_path)
30-
31-
oneapi_root = environ.get("ONEAPI_ROOT", None)
32-
if not oneapi_root:
33-
raise ValueError(
34-
"ONEAPI_ROOT must be set, typical value is /opt/intel/oneapi"
17+
import numpy as np
18+
from setuptools import Extension, setup
19+
20+
import dpctl
21+
22+
setup(
23+
name="syclbuffer",
24+
version="0.0.0",
25+
description="An example of Cython extension calling SYCL routines",
26+
long_description="""
27+
Example of using SYCL to work on host allocated NumPy array using
28+
SYCL buffers by calling oneMKL functions.
29+
30+
See README.md for more details.
31+
""",
32+
license="Apache 2.0",
33+
author="Intel Corporation",
34+
url="https://github.com/IntelPython/dpctl",
35+
ext_modules=[
36+
Extension(
37+
name="syclbuffer",
38+
sources=[
39+
"_buffer_example.pyx",
40+
"use_sycl_buffer.cpp",
41+
],
42+
include_dirs=[".", np.get_include(), dpctl.get_include()],
43+
libraries=["sycl"]
44+
+ [
45+
"mkl_sycl",
46+
"mkl_intel_ilp64",
47+
"mkl_tbb_thread",
48+
"mkl_core",
49+
"tbb",
50+
"iomp5",
51+
],
52+
runtime_library_dirs=[],
53+
extra_compile_args=[
54+
"-Wall",
55+
"-Wextra",
56+
"-fsycl",
57+
"-fsycl-unnamed-lambda",
58+
],
59+
extra_link_args=["-fPIC"],
60+
language="c++",
3561
)
36-
37-
mkl_info = {
38-
"include_dirs": [join(oneapi_root, "mkl", "include")],
39-
"library_dirs": [
40-
join(oneapi_root, "mkl", "lib"),
41-
join(oneapi_root, "mkl", "lib", "intel64"),
42-
],
43-
"libraries": [
44-
"mkl_sycl",
45-
"mkl_intel_ilp64",
46-
"mkl_tbb_thread",
47-
"mkl_core",
48-
"tbb",
49-
"iomp5",
50-
],
51-
}
52-
53-
mkl_include_dirs = mkl_info.get("include_dirs")
54-
mkl_library_dirs = mkl_info.get("library_dirs")
55-
mkl_libraries = mkl_info.get("libraries")
56-
57-
pdir = dirname(__file__)
58-
wdir = join(pdir)
59-
60-
eca = ["-Wall", "-Wextra", "-fsycl", "-fsycl-unnamed-lambda"]
61-
62-
config.add_extension(
63-
name="syclbuffer",
64-
sources=[
65-
join(pdir, "_buffer_example.pyx"),
66-
join(wdir, "use_sycl_buffer.cpp"),
67-
join(wdir, "use_sycl_buffer.h"),
68-
],
69-
include_dirs=[wdir, np.get_include(), dpctl.get_include()]
70-
+ mkl_include_dirs,
71-
libraries=["sycl"] + mkl_libraries,
72-
runtime_library_dirs=mkl_library_dirs,
73-
extra_compile_args=eca, # + ['-O0', '-g', '-ggdb'],
74-
extra_link_args=["-fPIC"],
75-
language="c++",
76-
)
77-
78-
config.ext_modules = cythonize(
79-
config.ext_modules, include_path=[pdir, wdir]
80-
)
81-
return config
82-
83-
84-
if __name__ == "__main__":
85-
from numpy.distutils.core import setup
86-
87-
setup(configuration=configuration)
62+
],
63+
)

examples/cython/sycl_buffer/use_sycl_buffer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ int c_columnwise_total_no_mkl(DPCTLSyclQueueRef q_ref,
123123
sycl::nd_range<2>(global, local), [=](sycl::nd_item<2> it) {
124124
size_t i = it.get_global_id(0);
125125
size_t j = it.get_global_id(1);
126-
double group_sum = sycl::ONEAPI::reduce(
126+
double group_sum = sycl::reduce_over_group(
127127
it.get_group(), (i < n) ? mat_acc[it.get_global_id()] : 0.0,
128128
std::plus<double>());
129129
if (it.get_local_id(0) == 0) {
130-
sycl::ONEAPI::atomic_ref<
131-
double, sycl::ONEAPI::memory_order::relaxed,
132-
sycl::ONEAPI::memory_scope::system,
130+
sycl::ext::oneapi::atomic_ref<
131+
double, sycl::ext::oneapi::memory_order::relaxed,
132+
sycl::ext::oneapi::memory_scope::system,
133133
sycl::access::address_space::global_space>(ct_acc[j]) +=
134134
group_sum;
135135
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
_buffer_example.cpp
2+
*.cpython*.so
3+
*~

examples/cython/sycl_direct_linkage/setup.py

Lines changed: 50 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -14,74 +14,54 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
from os import environ
18-
from os.path import dirname, join
19-
20-
from Cython.Build import cythonize
21-
22-
23-
def configuration(parent_package="", top_path=None):
24-
import numpy as np
25-
from numpy.distutils.misc_util import Configuration
26-
27-
import dpctl
28-
29-
config = Configuration("", parent_package, top_path)
30-
31-
oneapi_root = environ.get("ONEAPI_ROOT", None)
32-
if not oneapi_root:
33-
raise ValueError(
34-
"ONEAPI_ROOT must be set, typical value is /opt/intel/oneapi"
17+
import numpy as np
18+
from setuptools import Extension, setup
19+
20+
import dpctl
21+
22+
setup(
23+
name="syclbuffer",
24+
version="0.0.0",
25+
description="An example of Cython extension calling SYCL routines",
26+
long_description="""
27+
Example of using SYCL to work on host allocated NumPy array using
28+
SYCL buffers by calling oneMKL functions.
29+
30+
This extension create SYCL queue in the scope of the function call
31+
incurring large performance overhead. See `sycl_buffer/` example,
32+
where user-constructed `dpctl.SyclQueue` can be given by the user.
33+
34+
See README.md for more details.
35+
""",
36+
license="Apache 2.0",
37+
author="Intel Corporation",
38+
url="https://github.com/IntelPython/dpctl",
39+
ext_modules=[
40+
Extension(
41+
name="syclbuffer_naive",
42+
sources=[
43+
"_buffer_example.pyx",
44+
"sycl_function.cpp",
45+
],
46+
include_dirs=[".", np.get_include(), dpctl.get_include()],
47+
libraries=["sycl"]
48+
+ [
49+
"mkl_sycl",
50+
"mkl_intel_ilp64",
51+
"mkl_tbb_thread",
52+
"mkl_core",
53+
"tbb",
54+
"iomp5",
55+
],
56+
runtime_library_dirs=[],
57+
extra_compile_args=[
58+
"-Wall",
59+
"-Wextra",
60+
"-fsycl",
61+
"-fsycl-unnamed-lambda",
62+
],
63+
extra_link_args=["-fPIC"],
64+
language="c++",
3565
)
36-
37-
mkl_info = {
38-
"include_dirs": [join(oneapi_root, "mkl", "include")],
39-
"library_dirs": [
40-
join(oneapi_root, "mkl", "lib"),
41-
join(oneapi_root, "mkl", "lib", "intel64"),
42-
],
43-
"libraries": [
44-
"mkl_sycl",
45-
"mkl_intel_ilp64",
46-
"mkl_tbb_thread",
47-
"mkl_core",
48-
"tbb",
49-
"iomp5",
50-
],
51-
}
52-
53-
mkl_include_dirs = mkl_info.get("include_dirs")
54-
mkl_library_dirs = mkl_info.get("library_dirs")
55-
mkl_libraries = mkl_info.get("libraries")
56-
57-
pdir = dirname(__file__)
58-
wdir = join(pdir)
59-
60-
eca = ["-Wall", "-Wextra", "-fsycl", "-fsycl-unnamed-lambda"]
61-
62-
config.add_extension(
63-
name="syclbuffer_naive",
64-
sources=[
65-
join(pdir, "_buffer_example.pyx"),
66-
join(pdir, "sycl_function.cpp"),
67-
join(pdir, "sycl_function.hpp"),
68-
],
69-
include_dirs=[wdir, np.get_include(), dpctl.get_include()]
70-
+ mkl_include_dirs,
71-
libraries=["sycl"] + mkl_libraries,
72-
runtime_library_dirs=mkl_library_dirs,
73-
extra_compile_args=eca, # + ['-O0', '-g', '-ggdb'],
74-
extra_link_args=["-fPIC"],
75-
language="c++",
76-
)
77-
78-
config.ext_modules = cythonize(
79-
config.ext_modules, include_path=[pdir, wdir]
80-
)
81-
return config
82-
83-
84-
if __name__ == "__main__":
85-
from numpy.distutils.core import setup
86-
87-
setup(configuration=configuration)
66+
],
67+
)

examples/cython/usm_memory/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
blackscholes.cpp
2+
*~
3+
*.cpython*.so

examples/cython/usm_memory/setup.py

Lines changed: 45 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -14,74 +14,49 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
from os import environ
18-
from os.path import dirname, join
19-
20-
from Cython.Build import cythonize
21-
22-
23-
def configuration(parent_package="", top_path=None):
24-
import numpy as np
25-
from numpy.distutils.misc_util import Configuration
26-
27-
import dpctl
28-
29-
config = Configuration("", parent_package, top_path)
30-
31-
oneapi_root = environ.get("ONEAPI_ROOT", None)
32-
if not oneapi_root:
33-
raise ValueError(
34-
"ONEAPI_ROOT must be set, typical value is /opt/intel/oneapi"
17+
import numpy as np
18+
from setuptools import Extension, setup
19+
20+
import dpctl
21+
22+
setup(
23+
name="blackscholes_usm",
24+
version="0.0.0",
25+
description="An example of Cython extension calling SYCL routines",
26+
long_description="""
27+
Example of using SYCL to work on usm allocations.
28+
29+
See README.md for more details.
30+
""",
31+
license="Apache 2.0",
32+
author="Intel Corporation",
33+
url="https://github.com/IntelPython/dpctl",
34+
ext_modules=[
35+
Extension(
36+
name="blackscholes_usm",
37+
sources=[
38+
"blackscholes.pyx",
39+
"sycl_blackscholes.cpp",
40+
],
41+
include_dirs=[".", np.get_include(), dpctl.get_include()],
42+
libraries=["sycl"]
43+
+ [
44+
"mkl_sycl",
45+
"mkl_intel_ilp64",
46+
"mkl_tbb_thread",
47+
"mkl_core",
48+
"tbb",
49+
"iomp5",
50+
],
51+
runtime_library_dirs=[],
52+
extra_compile_args=[
53+
"-Wall",
54+
"-Wextra",
55+
"-fsycl",
56+
"-fsycl-unnamed-lambda",
57+
],
58+
extra_link_args=["-fPIC"],
59+
language="c++",
3560
)
36-
37-
mkl_info = {
38-
"include_dirs": [join(oneapi_root, "mkl", "include")],
39-
"library_dirs": [
40-
join(oneapi_root, "mkl", "lib"),
41-
join(oneapi_root, "mkl", "lib", "intel64"),
42-
],
43-
"libraries": [
44-
"mkl_sycl",
45-
"mkl_intel_ilp64",
46-
"mkl_tbb_thread",
47-
"mkl_core",
48-
"tbb",
49-
"iomp5",
50-
],
51-
}
52-
53-
mkl_include_dirs = mkl_info.get("include_dirs")
54-
mkl_library_dirs = mkl_info.get("library_dirs")
55-
mkl_libraries = mkl_info.get("libraries")
56-
57-
pdir = dirname(__file__)
58-
wdir = join(pdir)
59-
60-
eca = ["-Wall", "-Wextra", "-fsycl", "-fsycl-unnamed-lambda"]
61-
62-
config.add_extension(
63-
name="blackscholes_usm",
64-
sources=[
65-
join(pdir, "blackscholes.pyx"),
66-
join(wdir, "sycl_blackscholes.cpp"),
67-
join(wdir, "sycl_blackscholes.hpp"),
68-
],
69-
include_dirs=[wdir, np.get_include(), dpctl.get_include()]
70-
+ mkl_include_dirs,
71-
libraries=["sycl"] + mkl_libraries,
72-
runtime_library_dirs=mkl_library_dirs,
73-
extra_compile_args=eca, # + ['-O0', '-g', '-ggdb'],
74-
extra_link_args=["-fPIC"],
75-
language="c++",
76-
)
77-
78-
config.ext_modules = cythonize(
79-
config.ext_modules, include_path=[pdir, wdir]
80-
)
81-
return config
82-
83-
84-
if __name__ == "__main__":
85-
from numpy.distutils.core import setup
86-
87-
setup(configuration=configuration)
61+
],
62+
)

0 commit comments

Comments
 (0)