-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[async] Compute offloaded IR hash once and cache it #1608
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,12 +110,15 @@ class KernelLaunchRecord { | |
Context context; | ||
Kernel *kernel; // TODO: remove this | ||
OffloadedStmt *stmt; | ||
std::unique_ptr<IRNode> stmt_holder; | ||
uint64 h; | ||
uint64 h; // hash of |stmt| | ||
|
||
KernelLaunchRecord(Context contxet, | ||
KernelLaunchRecord(Context context, | ||
Kernel *kernel, | ||
std::unique_ptr<IRNode> &&stmt); | ||
std::unique_ptr<IRNode> &&stmt, | ||
uint64 h); | ||
|
||
private: | ||
std::unique_ptr<IRNode> stmt_holder_; | ||
}; | ||
|
||
// In charge of (parallel) compilation to binary and (serial) kernel launching | ||
|
@@ -154,13 +157,6 @@ class AsyncEngine { | |
public: | ||
// TODO: state machine | ||
|
||
struct TaskMeta { | ||
std::unordered_set<SNode *> input_snodes, output_snodes; | ||
std::unordered_set<SNode *> activation_snodes; | ||
}; | ||
|
||
std::unordered_map<std::uint64_t, TaskMeta> metas; | ||
|
||
ExecutionQueue queue; | ||
|
||
std::deque<KernelLaunchRecord> task_queue; | ||
|
@@ -183,11 +179,26 @@ class AsyncEngine { | |
void synchronize(); | ||
|
||
private: | ||
struct KernelMeta { | ||
std::unique_ptr<Block> dummy_root; | ||
std::vector<uint64> offloaded_hashes; | ||
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. This is a bit confusing to me: Why do offload hashes belong to the kernel meta? Is the same offload's hash different when the kernel is different? 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.
Each offloaded task in a kernel will generate a hash. What I'm trying to avoid is the re-computation of the hashes for the offloads inside a kernel...
I don't think so. From what I can tell, the However, this identical relationship is kind of shaky. The current impl of |
||
|
||
inline bool initialized() const { | ||
return dummy_root != nullptr; | ||
} | ||
}; | ||
|
||
struct TaskMeta { | ||
std::unordered_set<SNode *> input_snodes, output_snodes; | ||
std::unordered_set<SNode *> activation_snodes; | ||
}; | ||
|
||
// In async mode, the root of an AST is an OffloadedStmt instead of a Block. | ||
// This map provides a dummy Block root for these OffloadedStmt, so that | ||
// get_kernel() could still work correctly. | ||
std::unordered_map<const Kernel *, std::unique_ptr<Block>> | ||
kernel_to_dummy_roots_; | ||
std::unordered_map<const Kernel *, KernelMeta> kernel_metas_; | ||
|
||
std::unordered_map<std::uint64_t, TaskMeta> offloaded_metas_; | ||
}; | ||
|
||
TLANG_NAMESPACE_END |
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.
What if we have two same offloads in a kernel? And does it prevent two different offloads in two different kernels having the same hash?
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.
BTW if the hash really crashes, I think it should be an error rather than an assertion.
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.
Note that
offloaded_hashes
is astd::vector
. It maps to an offloaded task by its position in that kernel... The assertion is checking for position (i.e. the hash of this offloaded task isn't computed yet), not hash collision.I actually think it's fine for the same offloads (regardless of whether they are in the same kernel or not) to have the same hashes. If two offloads are indeed the same, then they should have the same
TaskMeta
s (i.e. input/output snodes, activation snodes)?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.
Oh I see. I thought
offloaded_hashes
was anstd::unordered_map
, which would cause an assertion failure when there are two same offloads...I agree.