-
Notifications
You must be signed in to change notification settings - Fork 40
Migrate host_task object management to a thread pool based approach
#2359
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
Open
ndgrigorian
wants to merge
5
commits into
master
Choose a base branch
from
feature/drop-host-task-object-management
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bbf7d44
Migrate host_tasks to a thread pool based approach
ndgrigorian 0ea8159
Deprecate APIs which require events from Python object management
ndgrigorian e9b784b
Merge branch 'master' into feature/drop-host-task-object-management
ndgrigorian bba7b6e
address review comments
ndgrigorian f412bf7
Apply review feedback
ndgrigorian 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
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,134 @@ | ||
| //===--- _async_dec_ref.hpp - Implements async DECREF ---------------------===// | ||
| // | ||
| // Data Parallel Control (dpctl) | ||
| // | ||
| // Copyright 2022 Intel Corporation | ||
|
ndgrigorian marked this conversation as resolved.
|
||
| // | ||
| // 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 a utility function to decrement reference counts for a | ||
| /// given array of Python objects once a given array of sycl events has | ||
| /// completed. | ||
| /// | ||
| /// N.B.: The deferred work acquires the GIL, so queue wait, event wait and | ||
| /// other synchronization mechanisms should be called after releasing the GIL to | ||
| /// avoid deadlocks. | ||
| /// | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #pragma once | ||
| #include <exception> | ||
| #include <stddef.h> | ||
| #include <sycl/sycl.hpp> | ||
| #include <utility> | ||
| #include <vector> | ||
|
|
||
| #include "Python.h" | ||
|
|
||
| #include "detail/keep_alive_pool.hpp" | ||
| #include "syclinterface/dpctl_data_types.h" | ||
| #include "syclinterface/dpctl_sycl_type_casters.hpp" | ||
|
|
||
| /*! | ||
| * @brief Address of the `KeepAlivePool`. | ||
| * | ||
| * Returns nullptr if the pool could not be created. | ||
| */ | ||
| void *keep_alive_pool_ptr() | ||
| { | ||
| try { | ||
| return static_cast<void *>( | ||
| &dpctl::detail::KeepAlivePool::local_instance()); | ||
| } catch (const std::exception &e) { | ||
| return nullptr; | ||
| } | ||
| } | ||
|
|
||
| /*! | ||
| * @brief Schedule DECREFs of `obj_array` for once `depERefs` have completed. | ||
| * | ||
| * Sets `*status` to 0 on success and 1 if scheduling threw. | ||
| */ | ||
| void async_dec_ref(PyObject **obj_array, | ||
| size_t obj_array_size, | ||
| DPCTLSyclEventRef *depERefs, | ||
| size_t nDepERefs, | ||
| int *status) | ||
| { | ||
| using dpctl::syclinterface::unwrap; | ||
|
|
||
| std::vector<PyObject *> obj_vec(obj_array, obj_array + obj_array_size); | ||
|
ndgrigorian marked this conversation as resolved.
|
||
|
|
||
| try { | ||
| std::vector<sycl::event> depends; | ||
| depends.reserve(nDepERefs); | ||
| for (size_t ev_id = 0; ev_id < nDepERefs; ++ev_id) { | ||
| depends.push_back(*(unwrap<sycl::event>(depERefs[ev_id]))); | ||
| } | ||
|
|
||
| dpctl::detail::KeepAlivePool::local_instance().submit( | ||
| std::move(depends), | ||
| [obj_array_size, obj_vec = std::move(obj_vec)]() { | ||
| #if PY_VERSION_HEX < 0x30d0000 | ||
| const bool finalizing = _Py_IsFinalizing(); | ||
| #else | ||
| const bool finalizing = Py_IsFinalizing(); | ||
| #endif | ||
| // if the main thread has not finalized the interpreter yet | ||
| if (!finalizing) { | ||
| PyGILState_STATE gstate; | ||
| gstate = PyGILState_Ensure(); | ||
| for (size_t i = 0; i < obj_array_size; ++i) { | ||
| Py_DECREF(obj_vec[i]); | ||
| } | ||
| PyGILState_Release(gstate); | ||
| } | ||
| }); | ||
|
|
||
| static constexpr int result_ok = 0; | ||
| *status = result_ok; | ||
| } catch (const std::exception &e) { | ||
| static constexpr int result_std_exception = 1; | ||
| *status = result_std_exception; | ||
| } | ||
| } | ||
|
|
||
| /*! | ||
| * @brief Event-returning form of `async_dec_ref`. | ||
| * | ||
| * Returns a default-constructed event. | ||
| * Returns nullptr on failure, with `*status` set. | ||
| */ | ||
| DPCTLSyclEventRef async_dec_ref_event(DPCTLSyclQueueRef QRef, | ||
| PyObject **obj_array, | ||
| size_t obj_array_size, | ||
| DPCTLSyclEventRef *depERefs, | ||
| size_t nDepERefs, | ||
| int *status) | ||
| { | ||
| using dpctl::syclinterface::wrap; | ||
|
|
||
| (void)QRef; | ||
|
|
||
| async_dec_ref(obj_array, obj_array_size, depERefs, nDepERefs, status); | ||
|
|
||
| if (*status != 0) { | ||
| return nullptr; | ||
| } | ||
|
|
||
| auto e_ptr = new sycl::event(); | ||
| return wrap<sycl::event>(e_ptr); | ||
| } | ||
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
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.