Skip to content

Cleanup/examples #681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/cython/sycl_buffer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_buffer_example.cpp
*.cpython*.so
*~
116 changes: 46 additions & 70 deletions examples/cython/sycl_buffer/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,74 +14,50 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from os import environ
from os.path import dirname, join

from Cython.Build import cythonize


def configuration(parent_package="", top_path=None):
import numpy as np
from numpy.distutils.misc_util import Configuration

import dpctl

config = Configuration("", parent_package, top_path)

oneapi_root = environ.get("ONEAPI_ROOT", None)
if not oneapi_root:
raise ValueError(
"ONEAPI_ROOT must be set, typical value is /opt/intel/oneapi"
import numpy as np
from setuptools import Extension, setup

import dpctl

setup(
name="syclbuffer",
version="0.0.0",
description="An example of Cython extension calling SYCL routines",
long_description="""
Example of using SYCL to work on host allocated NumPy array using
SYCL buffers by calling oneMKL functions.

See README.md for more details.
""",
license="Apache 2.0",
author="Intel Corporation",
url="https://github.com/IntelPython/dpctl",
ext_modules=[
Extension(
name="syclbuffer",
sources=[
"_buffer_example.pyx",
"use_sycl_buffer.cpp",
],
include_dirs=[".", np.get_include(), dpctl.get_include()],
libraries=["sycl"]
+ [
"mkl_sycl",
"mkl_intel_ilp64",
"mkl_tbb_thread",
"mkl_core",
"tbb",
"iomp5",
],
runtime_library_dirs=[],
extra_compile_args=[
"-Wall",
"-Wextra",
"-fsycl",
"-fsycl-unnamed-lambda",
],
extra_link_args=["-fPIC"],
language="c++",
)

mkl_info = {
"include_dirs": [join(oneapi_root, "mkl", "include")],
"library_dirs": [
join(oneapi_root, "mkl", "lib"),
join(oneapi_root, "mkl", "lib", "intel64"),
],
"libraries": [
"mkl_sycl",
"mkl_intel_ilp64",
"mkl_tbb_thread",
"mkl_core",
"tbb",
"iomp5",
],
}

mkl_include_dirs = mkl_info.get("include_dirs")
mkl_library_dirs = mkl_info.get("library_dirs")
mkl_libraries = mkl_info.get("libraries")

pdir = dirname(__file__)
wdir = join(pdir)

eca = ["-Wall", "-Wextra", "-fsycl", "-fsycl-unnamed-lambda"]

config.add_extension(
name="syclbuffer",
sources=[
join(pdir, "_buffer_example.pyx"),
join(wdir, "use_sycl_buffer.cpp"),
join(wdir, "use_sycl_buffer.h"),
],
include_dirs=[wdir, np.get_include(), dpctl.get_include()]
+ mkl_include_dirs,
libraries=["sycl"] + mkl_libraries,
runtime_library_dirs=mkl_library_dirs,
extra_compile_args=eca, # + ['-O0', '-g', '-ggdb'],
extra_link_args=["-fPIC"],
language="c++",
)

config.ext_modules = cythonize(
config.ext_modules, include_path=[pdir, wdir]
)
return config


if __name__ == "__main__":
from numpy.distutils.core import setup

setup(configuration=configuration)
],
)
8 changes: 4 additions & 4 deletions examples/cython/sycl_buffer/use_sycl_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ int c_columnwise_total_no_mkl(DPCTLSyclQueueRef q_ref,
sycl::nd_range<2>(global, local), [=](sycl::nd_item<2> it) {
size_t i = it.get_global_id(0);
size_t j = it.get_global_id(1);
double group_sum = sycl::ONEAPI::reduce(
double group_sum = sycl::reduce_over_group(
it.get_group(), (i < n) ? mat_acc[it.get_global_id()] : 0.0,
std::plus<double>());
if (it.get_local_id(0) == 0) {
sycl::ONEAPI::atomic_ref<
double, sycl::ONEAPI::memory_order::relaxed,
sycl::ONEAPI::memory_scope::system,
sycl::ext::oneapi::atomic_ref<
double, sycl::ext::oneapi::memory_order::relaxed,
sycl::ext::oneapi::memory_scope::system,
sycl::access::address_space::global_space>(ct_acc[j]) +=
group_sum;
}
Expand Down
3 changes: 3 additions & 0 deletions examples/cython/sycl_direct_linkage/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_buffer_example.cpp
*.cpython*.so
*~
120 changes: 50 additions & 70 deletions examples/cython/sycl_direct_linkage/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,74 +14,54 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from os import environ
from os.path import dirname, join

from Cython.Build import cythonize


def configuration(parent_package="", top_path=None):
import numpy as np
from numpy.distutils.misc_util import Configuration

import dpctl

config = Configuration("", parent_package, top_path)

oneapi_root = environ.get("ONEAPI_ROOT", None)
if not oneapi_root:
raise ValueError(
"ONEAPI_ROOT must be set, typical value is /opt/intel/oneapi"
import numpy as np
from setuptools import Extension, setup

import dpctl

setup(
name="syclbuffer",
version="0.0.0",
description="An example of Cython extension calling SYCL routines",
long_description="""
Example of using SYCL to work on host allocated NumPy array using
SYCL buffers by calling oneMKL functions.

This extension create SYCL queue in the scope of the function call
incurring large performance overhead. See `sycl_buffer/` example,
where user-constructed `dpctl.SyclQueue` can be given by the user.

See README.md for more details.
""",
license="Apache 2.0",
author="Intel Corporation",
url="https://github.com/IntelPython/dpctl",
ext_modules=[
Extension(
name="syclbuffer_naive",
sources=[
"_buffer_example.pyx",
"sycl_function.cpp",
],
include_dirs=[".", np.get_include(), dpctl.get_include()],
libraries=["sycl"]
+ [
"mkl_sycl",
"mkl_intel_ilp64",
"mkl_tbb_thread",
"mkl_core",
"tbb",
"iomp5",
],
runtime_library_dirs=[],
extra_compile_args=[
"-Wall",
"-Wextra",
"-fsycl",
"-fsycl-unnamed-lambda",
],
extra_link_args=["-fPIC"],
language="c++",
)

mkl_info = {
"include_dirs": [join(oneapi_root, "mkl", "include")],
"library_dirs": [
join(oneapi_root, "mkl", "lib"),
join(oneapi_root, "mkl", "lib", "intel64"),
],
"libraries": [
"mkl_sycl",
"mkl_intel_ilp64",
"mkl_tbb_thread",
"mkl_core",
"tbb",
"iomp5",
],
}

mkl_include_dirs = mkl_info.get("include_dirs")
mkl_library_dirs = mkl_info.get("library_dirs")
mkl_libraries = mkl_info.get("libraries")

pdir = dirname(__file__)
wdir = join(pdir)

eca = ["-Wall", "-Wextra", "-fsycl", "-fsycl-unnamed-lambda"]

config.add_extension(
name="syclbuffer_naive",
sources=[
join(pdir, "_buffer_example.pyx"),
join(pdir, "sycl_function.cpp"),
join(pdir, "sycl_function.hpp"),
],
include_dirs=[wdir, np.get_include(), dpctl.get_include()]
+ mkl_include_dirs,
libraries=["sycl"] + mkl_libraries,
runtime_library_dirs=mkl_library_dirs,
extra_compile_args=eca, # + ['-O0', '-g', '-ggdb'],
extra_link_args=["-fPIC"],
language="c++",
)

config.ext_modules = cythonize(
config.ext_modules, include_path=[pdir, wdir]
)
return config


if __name__ == "__main__":
from numpy.distutils.core import setup

setup(configuration=configuration)
],
)
3 changes: 3 additions & 0 deletions examples/cython/usm_memory/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
blackscholes.cpp
*~
*.cpython*.so
115 changes: 45 additions & 70 deletions examples/cython/usm_memory/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,74 +14,49 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from os import environ
from os.path import dirname, join

from Cython.Build import cythonize


def configuration(parent_package="", top_path=None):
import numpy as np
from numpy.distutils.misc_util import Configuration

import dpctl

config = Configuration("", parent_package, top_path)

oneapi_root = environ.get("ONEAPI_ROOT", None)
if not oneapi_root:
raise ValueError(
"ONEAPI_ROOT must be set, typical value is /opt/intel/oneapi"
import numpy as np
from setuptools import Extension, setup

import dpctl

setup(
name="blackscholes_usm",
version="0.0.0",
description="An example of Cython extension calling SYCL routines",
long_description="""
Example of using SYCL to work on usm allocations.

See README.md for more details.
""",
license="Apache 2.0",
author="Intel Corporation",
url="https://github.com/IntelPython/dpctl",
ext_modules=[
Extension(
name="blackscholes_usm",
sources=[
"blackscholes.pyx",
"sycl_blackscholes.cpp",
],
include_dirs=[".", np.get_include(), dpctl.get_include()],
libraries=["sycl"]
+ [
"mkl_sycl",
"mkl_intel_ilp64",
"mkl_tbb_thread",
"mkl_core",
"tbb",
"iomp5",
],
runtime_library_dirs=[],
extra_compile_args=[
"-Wall",
"-Wextra",
"-fsycl",
"-fsycl-unnamed-lambda",
],
extra_link_args=["-fPIC"],
language="c++",
)

mkl_info = {
"include_dirs": [join(oneapi_root, "mkl", "include")],
"library_dirs": [
join(oneapi_root, "mkl", "lib"),
join(oneapi_root, "mkl", "lib", "intel64"),
],
"libraries": [
"mkl_sycl",
"mkl_intel_ilp64",
"mkl_tbb_thread",
"mkl_core",
"tbb",
"iomp5",
],
}

mkl_include_dirs = mkl_info.get("include_dirs")
mkl_library_dirs = mkl_info.get("library_dirs")
mkl_libraries = mkl_info.get("libraries")

pdir = dirname(__file__)
wdir = join(pdir)

eca = ["-Wall", "-Wextra", "-fsycl", "-fsycl-unnamed-lambda"]

config.add_extension(
name="blackscholes_usm",
sources=[
join(pdir, "blackscholes.pyx"),
join(wdir, "sycl_blackscholes.cpp"),
join(wdir, "sycl_blackscholes.hpp"),
],
include_dirs=[wdir, np.get_include(), dpctl.get_include()]
+ mkl_include_dirs,
libraries=["sycl"] + mkl_libraries,
runtime_library_dirs=mkl_library_dirs,
extra_compile_args=eca, # + ['-O0', '-g', '-ggdb'],
extra_link_args=["-fPIC"],
language="c++",
)

config.ext_modules = cythonize(
config.ext_modules, include_path=[pdir, wdir]
)
return config


if __name__ == "__main__":
from numpy.distutils.core import setup

setup(configuration=configuration)
],
)
Loading