Skip to content

Fix c interface #879

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
Aug 11, 2022
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
16 changes: 13 additions & 3 deletions .github/workflows/conda-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ jobs:
conda install -n examples -y ninja $CHANNELS || exit 1
conda install -n examples -y pybind11 cython scikit-build $CHANNELS || exit 1
conda install -n examples -y mkl-dpcpp mkl-devel-dpcpp dpcpp_cpp_rt $CHANNELS || exit 1
conda create -y -n build_env -c intel dpcpp_linux-64
conda create -y -n build_env -c intel gcc_linux-64 gxx_linux-64 dpcpp_linux-64
- name: Install dpctl
shell: bash -l {0}
run: |
Expand Down Expand Up @@ -424,7 +424,7 @@ jobs:
-DMKL_INCLUDE_DIR=${MKLROOT}/include \
-DTBB_INCLUDE_DIR=${TBBROOT}/include || exit 1
else
CC=dpcpp CXX=dpcpp LD_SHARED="dpcpp -shared" \
CC=dpcpp CXX=dpcpp LDSHARED="dpcpp -shared" \
python setup.py build_ext --inplace || exit 1
fi
conda deactivate
Expand All @@ -441,12 +441,22 @@ jobs:
do
pushd $d
conda activate --stack build_env
CC=dpcpp CXX=dpcpp LD_SHARED="dpcpp -shared" \
CC=dpcpp CXX=dpcpp LDSHARED="dpcpp -shared" \
python setup.py build_ext --inplace || exit 1
conda deactivate
LD_LIBRARY_PATH=${CONDA_PREFIX}/lib python run.py || exit 1
popd
done
cd ../c
for d in $(ls)
do
pushd $d
conda activate --stack build_env
python setup.py build_ext --inplace || exit 1
conda deactivate
python -m pytest tests || exit 1
popd
done
- name: Run Python examples
shell: bash -l {0}
run: |
Expand Down
2 changes: 1 addition & 1 deletion dpctl/_sycl_platform.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def lsplatform(verbosity=0):
cdef DPCTLSyclPlatformRef PRef = NULL

if not isinstance(verbosity, int):
print(
warnings.warn(
"Illegal verbosity level. Accepted values are 0, 1, or 2. "
"Using the default verbosity level of 0."
)
Expand Down
21 changes: 21 additions & 0 deletions examples/c/py_sycl_ls/py_sycl_ls/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Data Parallel Control (dpctl)
#
# Copyright 2022 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ._py_sycl_ls import sycl_ls

__all__ = [
"sycl_ls",
]
20 changes: 20 additions & 0 deletions examples/c/py_sycl_ls/py_sycl_ls/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Data Parallel Control (dpctl)
#
# Copyright 2020-2021 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from py_sycl_ls import sycl_ls

if __name__ == "__main__":
sycl_ls()
61 changes: 61 additions & 0 deletions examples/c/py_sycl_ls/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Data Parallel Control (dpctl)
#
# Copyright 2022 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os.path
import sysconfig

from setuptools import Extension, setup

import dpctl

setup(
name="py_sycl_ls",
version="0.0.1",
description="An example of C extension calling SYCLInterface routines",
long_description="""
Example of using SYCLInterface.

See README.md for more details.
""",
license="Apache 2.0",
author="Intel Corporation",
url="https://github.com/IntelPython/dpctl",
ext_modules=[
Extension(
name="py_sycl_ls._py_sycl_ls",
sources=[
"src/py_sycl-ls.c",
],
include_dirs=[
dpctl.get_include(),
os.path.join(sysconfig.get_paths()["include"], ".."),
],
library_dirs=[
os.path.join(dpctl.get_include(), ".."),
],
libraries=["DPCTLSyclInterface"],
runtime_library_dirs=[
os.path.join(dpctl.get_include(), ".."),
],
extra_compile_args=[
"-Wall",
"-Wextra",
],
extra_link_args=["-fPIC"],
language="c",
)
],
)
89 changes: 89 additions & 0 deletions examples/c/py_sycl_ls/src/py_sycl-ls.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//==- py_sycl-ls.c - Example of C extension working with -===//
// DPCTLSyclInterface C-interface library.
//
// Data Parallel Control (dpctl)
//
// Copyright 2022 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// This file implements C Python extension using DPCTLSyclInterface library.
///
//===----------------------------------------------------------------------===//

// clang-format off
#include "Python.h"
#include "dpctl_capi.h"
#include "syclinterface/dpctl_sycl_platform_interface.h"
#include "syclinterface/dpctl_sycl_platform_manager.h"
#include "syclinterface/dpctl_utils.h"
// clang-format on

PyObject *sycl_ls(PyObject *self_unused, PyObject *args)
{
DPCTLPlatformVectorRef PVRef = NULL;
size_t psz = 0;

(void)(self_unused); // avoid unused arguments warning
(void)(args);
PVRef = DPCTLPlatform_GetPlatforms();

if (PVRef) {
psz = DPCTLPlatformVector_Size(PVRef);

for (size_t i = 0; i < psz; ++i) {
DPCTLSyclPlatformRef PRef = DPCTLPlatformVector_GetAt(PVRef, i);
const char *pl_info = DPCTLPlatformMgr_GetInfo(PRef, 2);

printf("Platform: %ld::\n%s\n", i, pl_info);

DPCTLCString_Delete(pl_info);
DPCTLPlatform_Delete(PRef);
}

DPCTLPlatformVector_Delete(PVRef);
}

Py_RETURN_NONE;
}

static PyMethodDef SyclLSMethods[] = {
{"sycl_ls", sycl_ls, METH_NOARGS, "Output information about SYCL platform"},
{NULL, NULL, 0, NULL} /* Sentinel */
};

static struct PyModuleDef syclls_module = {
PyModuleDef_HEAD_INIT,
"_py_sycl_ls", /* name of module */
"", /* module documentation, may be NULL */
-1, /* size of per-interpreter state of the module,
or -1 if the module keeps state in global variables. */
SyclLSMethods,
NULL,
NULL,
NULL,
NULL};

PyMODINIT_FUNC PyInit__py_sycl_ls(void)
{
PyObject *m;

import_dpctl();

m = PyModule_Create(&syclls_module);

return m;
}
26 changes: 26 additions & 0 deletions examples/c/py_sycl_ls/tests/test_sycl_ls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Data Parallel Control (dpctl)
#
# Copyright 2022 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import subprocess
import sys


def test_sycl_ls():
r = subprocess.run(
[sys.executable, "-m", "py_sycl_ls"], capture_output=True, check=True
)
assert r.stdout
assert not r.stderr
4 changes: 3 additions & 1 deletion examples/cython/sycl_buffer/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@
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",
"iomp5",
],
runtime_library_dirs=[],
extra_compile_args=[
Expand Down
15 changes: 6 additions & 9 deletions examples/cython/sycl_buffer/use_sycl_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ int c_columnwise_total(DPCTLSyclQueueRef q_ref,
ev.wait_and_throw();
} catch (sycl::exception const &e) {
std::cout << "\t\tCaught synchronous SYCL exception during fill:\n"
<< e.what() << std::endl
<< "OpenCL status: " << e.get_cl_code() << std::endl;
<< e.what() << std::endl;
goto cleanup;
}

Expand All @@ -72,8 +71,7 @@ int c_columnwise_total(DPCTLSyclQueueRef q_ref,
q.wait();
} catch (sycl::exception const &e) {
std::cout << "\t\tCaught synchronous SYCL exception during GEMV:\n"
<< e.what() << std::endl
<< "OpenCL status: " << e.get_cl_code() << std::endl;
<< e.what() << std::endl;
goto cleanup;
}
}
Expand Down Expand Up @@ -127,11 +125,10 @@ int c_columnwise_total_no_mkl(DPCTLSyclQueueRef q_ref,
it.get_group(), (i < n) ? mat_acc[it.get_global_id()] : 0.0,
std::plus<double>());
if (it.get_local_id(0) == 0) {
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;
sycl::atomic_ref<double, sycl::memory_order::relaxed,
sycl::memory_scope::system,
sycl::access::address_space::global_space>(
ct_acc[j]) += group_sum;
}
});
});
Expand Down
4 changes: 3 additions & 1 deletion examples/cython/sycl_direct_linkage/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@
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",
"iomp5",
],
runtime_library_dirs=[],
extra_compile_args=[
Expand Down
6 changes: 2 additions & 4 deletions examples/cython/sycl_direct_linkage/sycl_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ int c_columnwise_total(cl::sycl::queue &q,
ev.wait_and_throw();
} catch (sycl::exception const &e) {
std::cout << "\t\tCaught synchronous SYCL exception during fill:\n"
<< e.what() << std::endl
<< "OpenCL status: " << e.get_cl_code() << std::endl;
<< e.what() << std::endl;
goto cleanup;
}

Expand All @@ -68,8 +67,7 @@ int c_columnwise_total(cl::sycl::queue &q,
q.wait();
} catch (sycl::exception const &e) {
std::cout << "\t\tCaught synchronous SYCL exception during GEMV:\n"
<< e.what() << std::endl
<< "OpenCL status: " << e.get_cl_code() << std::endl;
<< e.what() << std::endl;
goto cleanup;
}
}
Expand Down
4 changes: 3 additions & 1 deletion examples/cython/usm_memory/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@
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",
"iomp5",
],
runtime_library_dirs=[],
extra_compile_args=[
Expand Down
8 changes: 3 additions & 5 deletions libsyclinterface/include/dpctl_sycl_device_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,9 @@ DPCTLDevice_GetMaxWorkItemSizes3d(__dpctl_keep const DPCTLSyclDeviceRef DRef);
* @return Returns the valid result if device exists else returns NULL.
* @ingroup DeviceInterface
*/
DPCTL_API
__dpctl_keep size_t *
DPCTLDevice_GetMaxWorkItemSizes(__dpctl_keep const DPCTLSyclDeviceRef DRef)
__attribute__((deprecated("DPCTLDevice_GetMaxWorkItemSizes is deprecated ",
"Use DPCTLDevice_WorkItemSizes3d instead")));
[[deprecated("Use DPCTLDevice_WorkItemSizes3d instead")]] DPCTL_API
__dpctl_keep size_t *
DPCTLDevice_GetMaxWorkItemSizes(__dpctl_keep const DPCTLSyclDeviceRef DRef);

/*!
* @brief Wrapper for get_info<info::device::max_work_group_size>().
Expand Down