-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring: introduce a single source of truth for thread names
- also deduplicate thread body boilerplate
- Loading branch information
Showing
23 changed files
with
247 additions
and
207 deletions.
There are no files selected for viewing
This file contains 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 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 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,14 +1,33 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <string> | ||
#include <thread> | ||
|
||
namespace celerity::detail { | ||
namespace celerity::detail::named_threads { | ||
|
||
std::thread::native_handle_type get_current_thread_handle(); | ||
constexpr uint32_t thread_type_step = 10000; | ||
|
||
void set_thread_name(const std::thread::native_handle_type thread_handle, const std::string& name); | ||
// The threads Celerity interacts with ("application") and creates (everything else), identified for the purpose of naming and pinning. | ||
enum class thread_type : uint32_t { | ||
application = 0 * thread_type_step, // pinned | ||
scheduler = 1 * thread_type_step, // pinned | ||
executor = 2 * thread_type_step, // pinned | ||
alloc = 3 * thread_type_step, // | ||
first_device_submitter = 4 * thread_type_step, // pinned | ||
first_host_queue = 5 * thread_type_step, // | ||
first_test = 6 * thread_type_step, // | ||
max = 7 * thread_type_step, // | ||
}; | ||
// Builds the n-th thread types of various kinds | ||
thread_type tt_device_submitter(const uint32_t n); | ||
thread_type tt_host_queue(const uint32_t n); | ||
thread_type tt_test(const uint32_t n); | ||
|
||
std::string get_thread_name(const std::thread::native_handle_type thread_handle); | ||
// Converts a thread type to a canoncial string representation | ||
std::string thread_type_to_string(const thread_type t_type); | ||
|
||
} // namespace celerity::detail | ||
// Performs naming, pinning and tracy ordering (if enabled for this thread) of the invoking thread | ||
// This should be the first thing called in any thread that is part of the Celerity runtime | ||
void name_and_pin_and_order_this_thread(const named_threads::thread_type t_type); | ||
|
||
} // namespace celerity::detail::named_threads |
This file contains 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 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 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 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 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 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 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,55 @@ | ||
#include "named_threads.h" | ||
|
||
#include <cassert> | ||
|
||
#include <fmt/format.h> | ||
|
||
#include "affinity.h" | ||
#include "tracy.h" | ||
|
||
namespace celerity::detail::named_threads { | ||
|
||
thread_type tt_device_submitter(const uint32_t n) { | ||
assert(n < thread_type_step); | ||
return thread_type(static_cast<uint32_t>(thread_type::first_device_submitter) + n); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) | ||
} | ||
thread_type tt_host_queue(const uint32_t n) { | ||
assert(n < thread_type_step); | ||
return thread_type(static_cast<uint32_t>(thread_type::first_host_queue) + n); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) | ||
} | ||
thread_type tt_test(const uint32_t n) { | ||
assert(n < thread_type_step); | ||
return thread_type(static_cast<uint32_t>(thread_type::first_test) + n); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) | ||
} | ||
|
||
std::string thread_type_to_string(const thread_type t_type) { | ||
switch(t_type) { | ||
case thread_type::application: return "cy-application"; | ||
case thread_type::scheduler: return "cy-scheduler"; | ||
case thread_type::executor: return "cy-executor"; | ||
case thread_type::alloc: return "cy-alloc"; | ||
default: break; | ||
} | ||
if(t_type >= thread_type::first_device_submitter && t_type < thread_type::first_host_queue) { // | ||
return fmt::format("cy-dev-sub-{}", static_cast<uint32_t>(t_type) - static_cast<uint32_t>(thread_type::first_device_submitter)); | ||
} | ||
if(t_type >= thread_type::first_host_queue && t_type < thread_type::first_test) { // | ||
return fmt::format("cy-host-{}", static_cast<uint32_t>(t_type) - static_cast<uint32_t>(thread_type::first_host_queue)); | ||
} | ||
if(t_type >= thread_type::first_test && t_type <= thread_type::max) { // | ||
return fmt::format("cy-test-{}", static_cast<uint32_t>(t_type) - static_cast<uint32_t>(thread_type::first_test)); | ||
} | ||
return fmt::format("unknown({})", static_cast<uint32_t>(t_type)); | ||
} | ||
|
||
// Sets the name for the invoking thread to its canonical string representation using OS-specific functions, if available | ||
// Has a per-platform implementation in the platform-specific files | ||
void set_current_thread_name(const thread_type t_type); | ||
|
||
void name_and_pin_and_order_this_thread(const named_threads::thread_type t_type) { | ||
set_current_thread_name(t_type); | ||
thread_pinning::pin_this_thread(t_type); | ||
CELERITY_DETAIL_TRACY_SET_THREAD_NAME_AND_ORDER(t_type); | ||
} | ||
|
||
} // namespace celerity::detail::named_threads |
Oops, something went wrong.