-
Notifications
You must be signed in to change notification settings - Fork 21
Add scheduler lookahead to elide buffer resizes #298
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,140 +1,91 @@ | ||
#pragma once | ||
|
||
#include <thread> | ||
#include <variant> | ||
|
||
#include "command_graph.h" | ||
#include "command_graph_generator.h" | ||
fknorr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#include "double_buffered_queue.h" | ||
#include "instruction_graph_generator.h" | ||
#include "ranges.h" | ||
#include "types.h" | ||
|
||
#include <cstddef> | ||
#include <functional> | ||
fknorr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#include <memory> | ||
#include <string> | ||
|
||
fknorr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
namespace celerity { | ||
namespace detail { | ||
|
||
class command_graph; | ||
class command_recorder; | ||
class instruction; | ||
class instruction_graph; | ||
class instruction_recorder; | ||
struct outbound_pilot; | ||
class task; | ||
|
||
// Abstract base class to allow different threading implementation in tests | ||
class abstract_scheduler { | ||
protected: | ||
friend struct scheduler_testspy; | ||
|
||
public: | ||
using delegate = instruction_graph_generator::delegate; | ||
|
||
struct policy_set { | ||
detail::command_graph_generator::policy_set command_graph_generator; | ||
detail::instruction_graph_generator::policy_set instruction_graph_generator; | ||
}; | ||
|
||
abstract_scheduler(size_t num_nodes, node_id local_node_id, const system_info& system_info, abstract_scheduler::delegate* delegate, | ||
command_recorder* crec, instruction_recorder* irec, const policy_set& policy = {}); | ||
|
||
abstract_scheduler(const abstract_scheduler&) = delete; | ||
abstract_scheduler(abstract_scheduler&&) = delete; | ||
abstract_scheduler& operator=(const abstract_scheduler&) = delete; | ||
abstract_scheduler& operator=(abstract_scheduler&&) = delete; | ||
|
||
virtual ~abstract_scheduler(); | ||
|
||
/** | ||
* @brief Notifies the scheduler that a new task has been created and is ready for scheduling. | ||
*/ | ||
void notify_task_created(const task* const tsk) { notify(event_task_available{tsk}); } | ||
|
||
void notify_buffer_created( | ||
const buffer_id bid, const range<3>& range, const size_t elem_size, const size_t elem_align, const allocation_id user_allocation_id) { | ||
notify(event_buffer_created{bid, range, elem_size, elem_align, user_allocation_id}); | ||
} | ||
|
||
void notify_buffer_debug_name_changed(const buffer_id bid, const std::string& name) { notify(event_buffer_debug_name_changed{bid, name}); } | ||
|
||
void notify_buffer_destroyed(const buffer_id bid) { notify(event_buffer_destroyed{bid}); } | ||
|
||
void notify_host_object_created(const host_object_id hoid, const bool owns_instance) { notify(event_host_object_created{hoid, owns_instance}); } | ||
|
||
void notify_host_object_destroyed(const host_object_id hoid) { notify(event_host_object_destroyed{hoid}); } | ||
|
||
void notify_epoch_reached(const task_id tid) { notify(event_epoch_reached{tid}); } | ||
|
||
protected: | ||
/** | ||
* This is called by the worker thread. | ||
*/ | ||
void schedule(); | ||
|
||
private: | ||
struct event_task_available { | ||
const task* tsk; | ||
}; | ||
struct event_buffer_created { | ||
buffer_id bid; | ||
celerity::range<3> range; | ||
size_t elem_size; | ||
size_t elem_align; | ||
allocation_id user_allocation_id; | ||
}; | ||
struct event_buffer_debug_name_changed { | ||
buffer_id bid; | ||
std::string debug_name; | ||
}; | ||
struct event_buffer_destroyed { | ||
buffer_id bid; | ||
}; | ||
struct event_host_object_created { | ||
host_object_id hoid; | ||
bool owns_instance; | ||
}; | ||
struct event_host_object_destroyed { | ||
host_object_id hoid; | ||
}; | ||
struct event_epoch_reached { | ||
task_id tid; | ||
}; | ||
struct event_test_inspect { // only used by scheduler_testspy | ||
std::function<void()> inspect; // executed inside scheduler thread, making it safe to access scheduler members | ||
}; | ||
using event = std::variant<event_task_available, event_buffer_created, event_buffer_debug_name_changed, event_buffer_destroyed, | ||
event_host_object_created, event_host_object_destroyed, event_epoch_reached, event_test_inspect>; | ||
|
||
std::unique_ptr<command_graph> m_cdag; | ||
command_recorder* m_crec; | ||
std::unique_ptr<command_graph_generator> m_cggen; | ||
std::unique_ptr<instruction_graph> m_idag; | ||
instruction_recorder* m_irec; | ||
std::unique_ptr<instruction_graph_generator> m_iggen; | ||
|
||
double_buffered_queue<event> m_event_queue; | ||
|
||
void notify(event&& evt); | ||
}; | ||
|
||
class scheduler final : public abstract_scheduler { | ||
friend struct scheduler_testspy; | ||
namespace celerity::detail::scheduler_detail { | ||
|
||
/// executed inside scheduler thread, making it safe to access scheduler members | ||
struct test_state { | ||
const command_graph* cdag = nullptr; | ||
const instruction_graph* idag = nullptr; | ||
experimental::lookahead lookahead = experimental::lookahead::automatic; | ||
}; | ||
using test_inspector = std::function<void(const test_state&)>; | ||
|
||
struct scheduler_impl; | ||
|
||
} // namespace celerity::detail::scheduler_detail | ||
|
||
public: | ||
scheduler(size_t num_nodes, node_id local_node_id, const system_info& system, scheduler::delegate* delegate, command_recorder* crec, | ||
instruction_recorder* irec, const policy_set& policy = {}); | ||
namespace celerity::detail { | ||
|
||
scheduler(const scheduler&) = delete; | ||
scheduler(scheduler&&) = delete; | ||
scheduler& operator=(const scheduler&) = delete; | ||
scheduler& operator=(scheduler&&) = delete; | ||
class command_recorder; | ||
class instruction_recorder; | ||
class task; | ||
|
||
~scheduler() override; | ||
// Abstract base class to allow different threading implementation in tests | ||
class scheduler { | ||
private: | ||
friend struct scheduler_testspy; | ||
|
||
private: | ||
std::thread m_thread; | ||
public: | ||
using delegate = instruction_graph_generator::delegate; | ||
|
||
void thread_main(); | ||
struct policy_set { | ||
detail::command_graph_generator::policy_set command_graph_generator; | ||
detail::instruction_graph_generator::policy_set instruction_graph_generator; | ||
}; | ||
|
||
} // namespace detail | ||
} // namespace celerity | ||
scheduler(size_t num_nodes, node_id local_node_id, const system_info& system_info, scheduler::delegate* delegate, command_recorder* crec, | ||
instruction_recorder* irec, const policy_set& policy = {}); | ||
|
||
scheduler(const scheduler&) = delete; | ||
scheduler(scheduler&&) = default; | ||
scheduler& operator=(const scheduler&) = delete; | ||
scheduler& operator=(scheduler&&) = default; | ||
|
||
~scheduler(); | ||
|
||
/** | ||
* @brief Notifies the scheduler that a new task has been created and is ready for scheduling. | ||
*/ | ||
void notify_task_created(const task* tsk); | ||
|
||
void notify_buffer_created(buffer_id bid, const range<3>& range, size_t elem_size, size_t elem_align, allocation_id user_allocation_id); | ||
|
||
void notify_buffer_debug_name_changed(buffer_id bid, const std::string& name); | ||
|
||
void notify_buffer_destroyed(buffer_id bid); | ||
|
||
void notify_host_object_created(host_object_id hoid, bool owns_instance); | ||
|
||
void notify_host_object_destroyed(host_object_id hoid); | ||
|
||
void notify_epoch_reached(task_id tid); | ||
|
||
void set_lookahead(experimental::lookahead lookahead); | ||
|
||
void flush_commands(); | ||
|
||
private: | ||
struct test_threadless_tag {}; | ||
|
||
std::unique_ptr<scheduler_detail::scheduler_impl> m_impl; | ||
|
||
// used in scheduler_testspy | ||
scheduler(test_threadless_tag, size_t num_nodes, node_id local_node_id, const system_info& system_info, scheduler::delegate* delegate, | ||
command_recorder* crec, instruction_recorder* irec, const policy_set& policy = {}); | ||
void test_scheduling_loop(); | ||
void test_inspect(scheduler_detail::test_inspector inspector); | ||
}; | ||
|
||
} // namespace celerity::detail |
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
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.