-
Notifications
You must be signed in to change notification settings - Fork 30
Dpctl c api constructors added, dpctl/include restructured #685
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7b191c9
Family of make_Sycl*( Ref ) functions
oleksandr-pavlyk 3691cfb
Reorg of dpctl/include folder
oleksandr-pavlyk ca3ee4d
Streamlined pybind11 examples using dpctl4pybind11.hpp
oleksandr-pavlyk fd35965
Changed include of dpctl_sycl_types.h to include of syclinterface.h
oleksandr-pavlyk 3b18c73
Make sure to include dpctl4pybind11.hpp in the manifest
oleksandr-pavlyk 5f040b5
Added tests to make_Sycl* C-API functions
oleksandr-pavlyk 0e38e21
Added documenting C++ comment
oleksandr-pavlyk e880143
Per PR feedback: dpctl/include/syclinterface.h -> dpctl/include/dpctl…
oleksandr-pavlyk d42e403
Added type caster for event and context
oleksandr-pavlyk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
//===----------- dpctl4pybind11.h - Headers for type pybind11 casters -*-C-*- | ||
//===// | ||
// | ||
// 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. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// | ||
/// \file | ||
/// This file defines imports for dcptl's Python C-API | ||
//===----------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
|
||
#include "dpctl_capi.h" | ||
#include <CL/sycl.hpp> | ||
#include <pybind11/pybind11.h> | ||
|
||
namespace py = pybind11; | ||
|
||
namespace pybind11 | ||
{ | ||
namespace detail | ||
{ | ||
|
||
/* This type caster associates ``sycl::queue`` C++ class with | ||
* :class:`dpctl.SyclQueue` for the purposes of generation of | ||
* Python bindings by pybind11. | ||
*/ | ||
template <> struct type_caster<sycl::queue> | ||
oleksandr-pavlyk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
public: | ||
PYBIND11_TYPE_CASTER(sycl::queue, _("dpctl.SyclQueue")); | ||
|
||
bool load(handle src, bool) | ||
{ | ||
PyObject *source = src.ptr(); | ||
if (PyObject_TypeCheck(source, &PySyclQueueType)) { | ||
DPCTLSyclQueueRef QRef = | ||
get_queue_ref(reinterpret_cast<PySyclQueueObject *>(source)); | ||
sycl::queue *q = reinterpret_cast<sycl::queue *>(QRef); | ||
value = *q; | ||
return true; | ||
} | ||
else { | ||
throw std::runtime_error( | ||
"Input is of unexpected type, expected dpctl.SyclQueue"); | ||
} | ||
} | ||
|
||
static handle cast(sycl::queue src, return_value_policy, handle) | ||
{ | ||
auto tmp = make_SyclQueue(reinterpret_cast<DPCTLSyclQueueRef>(&src)); | ||
return handle(reinterpret_cast<PyObject *>(tmp)); | ||
} | ||
}; | ||
} // namespace detail | ||
} // namespace pybind11 | ||
|
||
namespace pybind11 | ||
{ | ||
namespace detail | ||
{ | ||
/* This type caster associates ``sycl::device`` C++ class with | ||
* :class:`dpctl.SyclDevice` for the purposes of generation of | ||
* Python bindings by pybind11. | ||
*/ | ||
template <> struct type_caster<sycl::device> | ||
{ | ||
public: | ||
PYBIND11_TYPE_CASTER(sycl::device, _("dpctl.SyclDevice")); | ||
|
||
bool load(handle src, bool) | ||
{ | ||
PyObject *source = src.ptr(); | ||
if (PyObject_TypeCheck(source, &PySyclDeviceType)) { | ||
DPCTLSyclDeviceRef DRef = | ||
get_device_ref(reinterpret_cast<PySyclDeviceObject *>(source)); | ||
sycl::device *d = reinterpret_cast<sycl::device *>(DRef); | ||
value = *d; | ||
return true; | ||
} | ||
else { | ||
throw std::runtime_error( | ||
"Input is of unexpected type, expected dpctl.SyclDevice"); | ||
} | ||
} | ||
|
||
static handle cast(sycl::device src, return_value_policy, handle) | ||
{ | ||
auto tmp = make_SyclDevice(reinterpret_cast<DPCTLSyclDeviceRef>(&src)); | ||
return handle(reinterpret_cast<PyObject *>(tmp)); | ||
} | ||
}; | ||
} // namespace detail | ||
} // namespace pybind11 | ||
|
||
namespace pybind11 | ||
{ | ||
namespace detail | ||
{ | ||
/* This type caster associates ``sycl::context`` C++ class with | ||
* :class:`dpctl.SyclContext` for the purposes of generation of | ||
* Python bindings by pybind11. | ||
*/ | ||
template <> struct type_caster<sycl::context> | ||
{ | ||
public: | ||
PYBIND11_TYPE_CASTER(sycl::context, _("dpctl.SyclContext")); | ||
|
||
bool load(handle src, bool) | ||
{ | ||
PyObject *source = src.ptr(); | ||
if (PyObject_TypeCheck(source, &PySyclContextType)) { | ||
DPCTLSyclContextRef CRef = get_context_ref( | ||
reinterpret_cast<PySyclContextObject *>(source)); | ||
sycl::context *ctx = reinterpret_cast<sycl::context *>(CRef); | ||
value = *ctx; | ||
return true; | ||
} | ||
else { | ||
throw std::runtime_error( | ||
"Input is of unexpected type, expected dpctl.SyclContext"); | ||
} | ||
} | ||
|
||
static handle cast(sycl::context src, return_value_policy, handle) | ||
{ | ||
auto tmp = | ||
make_SyclContext(reinterpret_cast<DPCTLSyclContextRef>(&src)); | ||
return handle(reinterpret_cast<PyObject *>(tmp)); | ||
} | ||
}; | ||
} // namespace detail | ||
} // namespace pybind11 | ||
|
||
namespace pybind11 | ||
{ | ||
namespace detail | ||
{ | ||
/* This type caster associates ``sycl::event`` C++ class with | ||
* :class:`dpctl.SyclEvent` for the purposes of generation of | ||
* Python bindings by pybind11. | ||
*/ | ||
template <> struct type_caster<sycl::event> | ||
{ | ||
public: | ||
PYBIND11_TYPE_CASTER(sycl::event, _("dpctl.SyclEvent")); | ||
|
||
bool load(handle src, bool) | ||
{ | ||
PyObject *source = src.ptr(); | ||
if (PyObject_TypeCheck(source, &PySyclEventType)) { | ||
DPCTLSyclEventRef ERef = | ||
get_event_ref(reinterpret_cast<PySyclEventObject *>(source)); | ||
sycl::event *ev = reinterpret_cast<sycl::event *>(ERef); | ||
value = *ev; | ||
return true; | ||
} | ||
else { | ||
throw std::runtime_error( | ||
"Input is of unexpected type, expected dpctl.SyclEvent"); | ||
} | ||
} | ||
|
||
static handle cast(sycl::event src, return_value_policy, handle) | ||
{ | ||
auto tmp = make_SyclEvent(reinterpret_cast<DPCTLSyclEventRef>(&src)); | ||
return handle(reinterpret_cast<PyObject *>(tmp)); | ||
} | ||
}; | ||
} // namespace detail | ||
} // namespace pybind11 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.