-
Notifications
You must be signed in to change notification settings - Fork 98
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
Remove CommandQueue redirecting usages straight to HWCQ #17219
Changes from 4 commits
7b93564
51ed99a
a05f98e
47dc587
baffafd
b6ce1b3
9acc448
52e8f1a
e9f0be6
c9f5d94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,20 +22,18 @@ | |
#include "worker_config_buffer.hpp" | ||
#include "program_impl.hpp" | ||
#include "trace_buffer.hpp" | ||
#include "hardware_command_queue.hpp" | ||
|
||
namespace tt::tt_metal { | ||
inline namespace v0 { | ||
|
||
class CommandQueue; | ||
class BufferRegion; | ||
class Event; | ||
class Trace; | ||
using RuntimeArgs = std::vector<std::variant<Buffer*, uint32_t>>; | ||
|
||
} // namespace v0 | ||
|
||
class HWCommandQueue; | ||
|
||
// Only contains the types of commands which are enqueued onto the device | ||
enum class EnqueueCommandType { | ||
ENQUEUE_READ_BUFFER, | ||
|
@@ -228,98 +226,6 @@ struct CommandInterface { | |
tt::stl::Span<const SubDeviceId> sub_device_ids; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we please remove this while we're at it? This was used for deprecated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do |
||
}; | ||
|
||
inline namespace v0 { | ||
|
||
class CommandQueue { | ||
friend class Trace; | ||
|
||
public: | ||
enum class CommandQueueMode { | ||
PASSTHROUGH = 0, | ||
ASYNC = 1, | ||
TRACE = 2, | ||
}; | ||
enum class CommandQueueState { | ||
IDLE = 0, | ||
RUNNING = 1, | ||
TERMINATE = 2, | ||
}; | ||
|
||
CommandQueue() = delete; | ||
|
||
CommandQueue(IDevice* device, uint32_t id, CommandQueueMode mode = CommandQueue::default_mode()); | ||
~CommandQueue(); | ||
|
||
// Trace queue constructor | ||
CommandQueue(Trace& trace); | ||
|
||
// Getters for private members | ||
IDevice* device() const { return this->device_ptr; } | ||
uint32_t id() const { return this->cq_id; } | ||
|
||
// Blocking method to wait for all commands to drain from the queue | ||
// Optional if used in passthrough mode (async_mode = false) | ||
void wait_until_empty(); | ||
|
||
// Schedule a command to be run on the device | ||
// Blocking if in passthrough mode. Non-blocking if in async mode | ||
void run_command(CommandInterface&& command); | ||
|
||
// API for setting/getting the mode of the command queue | ||
// TODO: disallow changing the mode of the queue. This is error prone, because changing mode requires | ||
// accordingly updating the higher-level abstractions. | ||
void set_mode(const CommandQueueMode& mode); | ||
CommandQueueMode get_mode() const { return this->mode; } | ||
|
||
// Reference to the underlying hardware command queue, non-const because side-effects are allowed | ||
HWCommandQueue& hw_command_queue(); | ||
|
||
// The empty state of the worker queue | ||
bool empty() const { return this->worker_queue.empty(); } | ||
|
||
// Dump methods for name and pending commands in the queue | ||
void dump(); | ||
std::string name(); | ||
|
||
static CommandQueueMode default_mode() { | ||
// Envvar is used for bringup and debug only. Will be removed in the future and should not be relied on in | ||
// production. | ||
static int value = | ||
parse_env<int>("TT_METAL_CQ_ASYNC_MODE", /*default_value=*/static_cast<int>(CommandQueueMode::PASSTHROUGH)); | ||
return static_cast<CommandQueue::CommandQueueMode>(value); | ||
} | ||
// Determine if any CQ is using Async mode | ||
static bool async_mode_set() { return num_async_cqs > 0; } | ||
|
||
private: | ||
// Initialize Command Queue Mode based on the env-var. This will be default, unless the user excplictly sets the | ||
// mode using set_mode. | ||
CommandQueueMode mode; | ||
CommandQueueState worker_state; | ||
std::unique_ptr<std::thread> worker_thread; | ||
WorkerQueue worker_queue; | ||
uint32_t cq_id = 0; | ||
IDevice* device_ptr = nullptr; | ||
Trace* trace_ptr = nullptr; | ||
|
||
void start_worker(); | ||
void stop_worker(); | ||
void run_worker(); | ||
void run_command_impl(const CommandInterface& command); | ||
|
||
bool async_mode() { return this->mode == CommandQueueMode::ASYNC; } | ||
bool trace_mode() { return this->mode == CommandQueueMode::TRACE; } | ||
bool passthrough_mode() { return this->mode == CommandQueueMode::PASSTHROUGH; } | ||
|
||
std::atomic<std::size_t> worker_thread_id = -1; | ||
std::atomic<std::size_t> parent_thread_id = -1; | ||
// Track the number of CQs using async vs pt mode | ||
inline static uint32_t num_async_cqs = 0; | ||
inline static uint32_t num_passthrough_cqs = 0; | ||
}; | ||
|
||
} // namespace v0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for removing this class and cleaning things up. We have a bunch of command structs defined in this file, ex: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree. Want to make this in the PR after this is merged together with file names. |
||
|
||
// Primitives used to place host only operations on the SW Command Queue. | ||
// These are used in functions exposed through tt_metal.hpp or host_api.hpp | ||
void EnqueueGetBufferAddr(CommandQueue& cq, uint32_t* dst_buf_addr, const Buffer* buffer, bool blocking); | ||
|
@@ -337,5 +243,4 @@ void EnqueueAddBufferToProgram( | |
|
||
} // namespace tt::tt_metal | ||
|
||
std::ostream& operator<<(std::ostream& os, tt::tt_metal::EnqueueCommandType const& type); | ||
std::ostream& operator<<(std::ostream& os, tt::tt_metal::CommandQueue::CommandQueueMode const& type); | ||
std::ostream& operator<<(std::ostream& os, const tt::tt_metal::EnqueueCommandType& type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Want to fix file names and includes in a separate PR