Skip to content

Commit 948bc65

Browse files
Merge pull request #879 from IntelPython/fix-c-interface
2 parents b68b1e4 + ed13b2e commit 948bc65

File tree

13 files changed

+251
-25
lines changed

13 files changed

+251
-25
lines changed

.github/workflows/conda-package.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ jobs:
393393
conda install -n examples -y ninja $CHANNELS || exit 1
394394
conda install -n examples -y pybind11 cython scikit-build $CHANNELS || exit 1
395395
conda install -n examples -y mkl-dpcpp mkl-devel-dpcpp dpcpp_cpp_rt $CHANNELS || exit 1
396-
conda create -y -n build_env -c intel dpcpp_linux-64
396+
conda create -y -n build_env -c intel gcc_linux-64 gxx_linux-64 dpcpp_linux-64
397397
- name: Install dpctl
398398
shell: bash -l {0}
399399
run: |
@@ -424,7 +424,7 @@ jobs:
424424
-DMKL_INCLUDE_DIR=${MKLROOT}/include \
425425
-DTBB_INCLUDE_DIR=${TBBROOT}/include || exit 1
426426
else
427-
CC=dpcpp CXX=dpcpp LD_SHARED="dpcpp -shared" \
427+
CC=dpcpp CXX=dpcpp LDSHARED="dpcpp -shared" \
428428
python setup.py build_ext --inplace || exit 1
429429
fi
430430
conda deactivate
@@ -441,12 +441,22 @@ jobs:
441441
do
442442
pushd $d
443443
conda activate --stack build_env
444-
CC=dpcpp CXX=dpcpp LD_SHARED="dpcpp -shared" \
444+
CC=dpcpp CXX=dpcpp LDSHARED="dpcpp -shared" \
445445
python setup.py build_ext --inplace || exit 1
446446
conda deactivate
447447
LD_LIBRARY_PATH=${CONDA_PREFIX}/lib python run.py || exit 1
448448
popd
449449
done
450+
cd ../c
451+
for d in $(ls)
452+
do
453+
pushd $d
454+
conda activate --stack build_env
455+
python setup.py build_ext --inplace || exit 1
456+
conda deactivate
457+
python -m pytest tests || exit 1
458+
popd
459+
done
450460
- name: Run Python examples
451461
shell: bash -l {0}
452462
run: |

dpctl/_sycl_platform.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def lsplatform(verbosity=0):
349349
cdef DPCTLSyclPlatformRef PRef = NULL
350350

351351
if not isinstance(verbosity, int):
352-
print(
352+
warnings.warn(
353353
"Illegal verbosity level. Accepted values are 0, 1, or 2. "
354354
"Using the default verbosity level of 0."
355355
)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Data Parallel Control (dpctl)
2+
#
3+
# Copyright 2022 Intel Corporation
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
from ._py_sycl_ls import sycl_ls
18+
19+
__all__ = [
20+
"sycl_ls",
21+
]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Data Parallel Control (dpctl)
2+
#
3+
# Copyright 2020-2021 Intel Corporation
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
from py_sycl_ls import sycl_ls
18+
19+
if __name__ == "__main__":
20+
sycl_ls()

examples/c/py_sycl_ls/setup.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Data Parallel Control (dpctl)
2+
#
3+
# Copyright 2022 Intel Corporation
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import os.path
18+
import sysconfig
19+
20+
from setuptools import Extension, setup
21+
22+
import dpctl
23+
24+
setup(
25+
name="py_sycl_ls",
26+
version="0.0.1",
27+
description="An example of C extension calling SYCLInterface routines",
28+
long_description="""
29+
Example of using SYCLInterface.
30+
31+
See README.md for more details.
32+
""",
33+
license="Apache 2.0",
34+
author="Intel Corporation",
35+
url="https://github.com/IntelPython/dpctl",
36+
ext_modules=[
37+
Extension(
38+
name="py_sycl_ls._py_sycl_ls",
39+
sources=[
40+
"src/py_sycl-ls.c",
41+
],
42+
include_dirs=[
43+
dpctl.get_include(),
44+
os.path.join(sysconfig.get_paths()["include"], ".."),
45+
],
46+
library_dirs=[
47+
os.path.join(dpctl.get_include(), ".."),
48+
],
49+
libraries=["DPCTLSyclInterface"],
50+
runtime_library_dirs=[
51+
os.path.join(dpctl.get_include(), ".."),
52+
],
53+
extra_compile_args=[
54+
"-Wall",
55+
"-Wextra",
56+
],
57+
extra_link_args=["-fPIC"],
58+
language="c",
59+
)
60+
],
61+
)
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
//==- py_sycl-ls.c - Example of C extension working with -===//
2+
// DPCTLSyclInterface C-interface library.
3+
//
4+
// Data Parallel Control (dpctl)
5+
//
6+
// Copyright 2022 Intel Corporation
7+
//
8+
// Licensed under the Apache License, Version 2.0 (the "License");
9+
// you may not use this file except in compliance with the License.
10+
// You may obtain a copy of the License at
11+
//
12+
// http://www.apache.org/licenses/LICENSE-2.0
13+
//
14+
// Unless required by applicable law or agreed to in writing, software
15+
// distributed under the License is distributed on an "AS IS" BASIS,
16+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
// See the License for the specific language governing permissions and
18+
// limitations under the License.
19+
//
20+
//===----------------------------------------------------------------------===//
21+
///
22+
/// \file
23+
/// This file implements C Python extension using DPCTLSyclInterface library.
24+
///
25+
//===----------------------------------------------------------------------===//
26+
27+
// clang-format off
28+
#include "Python.h"
29+
#include "dpctl_capi.h"
30+
#include "syclinterface/dpctl_sycl_platform_interface.h"
31+
#include "syclinterface/dpctl_sycl_platform_manager.h"
32+
#include "syclinterface/dpctl_utils.h"
33+
// clang-format on
34+
35+
PyObject *sycl_ls(PyObject *self_unused, PyObject *args)
36+
{
37+
DPCTLPlatformVectorRef PVRef = NULL;
38+
size_t psz = 0;
39+
40+
(void)(self_unused); // avoid unused arguments warning
41+
(void)(args);
42+
PVRef = DPCTLPlatform_GetPlatforms();
43+
44+
if (PVRef) {
45+
psz = DPCTLPlatformVector_Size(PVRef);
46+
47+
for (size_t i = 0; i < psz; ++i) {
48+
DPCTLSyclPlatformRef PRef = DPCTLPlatformVector_GetAt(PVRef, i);
49+
const char *pl_info = DPCTLPlatformMgr_GetInfo(PRef, 2);
50+
51+
printf("Platform: %ld::\n%s\n", i, pl_info);
52+
53+
DPCTLCString_Delete(pl_info);
54+
DPCTLPlatform_Delete(PRef);
55+
}
56+
57+
DPCTLPlatformVector_Delete(PVRef);
58+
}
59+
60+
Py_RETURN_NONE;
61+
}
62+
63+
static PyMethodDef SyclLSMethods[] = {
64+
{"sycl_ls", sycl_ls, METH_NOARGS, "Output information about SYCL platform"},
65+
{NULL, NULL, 0, NULL} /* Sentinel */
66+
};
67+
68+
static struct PyModuleDef syclls_module = {
69+
PyModuleDef_HEAD_INIT,
70+
"_py_sycl_ls", /* name of module */
71+
"", /* module documentation, may be NULL */
72+
-1, /* size of per-interpreter state of the module,
73+
or -1 if the module keeps state in global variables. */
74+
SyclLSMethods,
75+
NULL,
76+
NULL,
77+
NULL,
78+
NULL};
79+
80+
PyMODINIT_FUNC PyInit__py_sycl_ls(void)
81+
{
82+
PyObject *m;
83+
84+
import_dpctl();
85+
86+
m = PyModule_Create(&syclls_module);
87+
88+
return m;
89+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Data Parallel Control (dpctl)
2+
#
3+
# Copyright 2022 Intel Corporation
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import subprocess
18+
import sys
19+
20+
21+
def test_sycl_ls():
22+
r = subprocess.run(
23+
[sys.executable, "-m", "py_sycl_ls"], capture_output=True, check=True
24+
)
25+
assert r.stdout
26+
assert not r.stderr

examples/cython/sycl_buffer/setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,16 @@
4848
dpctl.get_include(),
4949
os.path.join(sysconfig.get_paths()["include"], ".."),
5050
],
51+
library_dirs=[
52+
os.path.join(sysconfig.get_paths()["stdlib"], ".."),
53+
],
5154
libraries=["sycl"]
5255
+ [
5356
"mkl_sycl",
5457
"mkl_intel_ilp64",
5558
"mkl_tbb_thread",
5659
"mkl_core",
5760
"tbb",
58-
"iomp5",
5961
],
6062
runtime_library_dirs=[],
6163
extra_compile_args=[

examples/cython/sycl_buffer/use_sycl_buffer.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ int c_columnwise_total(DPCTLSyclQueueRef q_ref,
6060
ev.wait_and_throw();
6161
} catch (sycl::exception const &e) {
6262
std::cout << "\t\tCaught synchronous SYCL exception during fill:\n"
63-
<< e.what() << std::endl
64-
<< "OpenCL status: " << e.get_cl_code() << std::endl;
63+
<< e.what() << std::endl;
6564
goto cleanup;
6665
}
6766

@@ -72,8 +71,7 @@ int c_columnwise_total(DPCTLSyclQueueRef q_ref,
7271
q.wait();
7372
} catch (sycl::exception const &e) {
7473
std::cout << "\t\tCaught synchronous SYCL exception during GEMV:\n"
75-
<< e.what() << std::endl
76-
<< "OpenCL status: " << e.get_cl_code() << std::endl;
74+
<< e.what() << std::endl;
7775
goto cleanup;
7876
}
7977
}
@@ -127,11 +125,10 @@ int c_columnwise_total_no_mkl(DPCTLSyclQueueRef q_ref,
127125
it.get_group(), (i < n) ? mat_acc[it.get_global_id()] : 0.0,
128126
std::plus<double>());
129127
if (it.get_local_id(0) == 0) {
130-
sycl::ext::oneapi::atomic_ref<
131-
double, sycl::ext::oneapi::memory_order::relaxed,
132-
sycl::ext::oneapi::memory_scope::system,
133-
sycl::access::address_space::global_space>(ct_acc[j]) +=
134-
group_sum;
128+
sycl::atomic_ref<double, sycl::memory_order::relaxed,
129+
sycl::memory_scope::system,
130+
sycl::access::address_space::global_space>(
131+
ct_acc[j]) += group_sum;
135132
}
136133
});
137134
});

examples/cython/sycl_direct_linkage/setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,16 @@
5252
dpctl.get_include(),
5353
os.path.join(sysconfig.get_paths()["include"], ".."),
5454
],
55+
library_dirs=[
56+
os.path.join(sysconfig.get_paths()["stdlib"], ".."),
57+
],
5558
libraries=["sycl"]
5659
+ [
5760
"mkl_sycl",
5861
"mkl_intel_ilp64",
5962
"mkl_tbb_thread",
6063
"mkl_core",
6164
"tbb",
62-
"iomp5",
6365
],
6466
runtime_library_dirs=[],
6567
extra_compile_args=[

0 commit comments

Comments
 (0)