-
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
[Metal] Add codegen/runtime support for print() #1310
Conversation
def test_print_matrix(): | ||
x = ti.Matrix(2, 3, dt=ti.f32, shape=()) | ||
y = ti.Vector(3, dt=ti.f32, shape=3) | ||
|
||
@ti.kernel | ||
def func(k: ti.f32): | ||
x[None][0, 0] = -1.0 |
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.
Without this, x
and y
are just all zero.
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, we may able to assert the print result after #1303?
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.
Yep, good point. I think we can compare pop_python_print_buffer
with expected strs.
Codecov Report
@@ Coverage Diff @@
## master #1310 +/- ##
=========================================
Coverage ? 66.40%
=========================================
Files ? 37
Lines ? 5155
Branches ? 939
=========================================
Hits ? 3423
Misses ? 1568
Partials ? 164 Continue to review full report at Codecov.
|
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.
Thanks, didn't read all yet.
@@ -1043,6 +1086,11 @@ class KernelCodegen : public IRVisitor { | |||
return kernel_name + "_func"; | |||
} | |||
|
|||
void mark_print_used() { | |||
TI_ASSERT(current_kernel_attribs_ != nullptr); | |||
current_kernel_attribs_->uses_print = true; |
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.
nit: Use a UsedFeatures
structure like OpenGL does.
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.
Good point.. This is a sloppy design in Metal. I don't have a data structure that records the attributes of a taichi kernel. All i have is a vector of Metal kernels', see
const std::vector<KernelAttributes> &kernels_attribs, |
I'd like to take this opportunity to clean up this flaw in another PR. Once I have a TaichiKernelAttributes
, i can also add a UsedFeatures
there. Then we don't even need to iterate over all the metal kernels to figure out if we need to flush the print buffers or not. (I tried adding something, but feel like it's too noisy for this one.) WDYT?
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.
Yes, ff2 do it iapr, you may also implement a operator|=(UsedFeatures, UsedFeatures)
for recording all used feature among kernels :)
def test_print_matrix(): | ||
x = ti.Matrix(2, 3, dt=ti.f32, shape=()) | ||
y = ti.Vector(3, dt=ti.f32, shape=3) | ||
|
||
@ti.kernel | ||
def func(k: ti.f32): | ||
x[None][0, 0] = -1.0 |
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, we may able to assert the print result after #1303?
Note that code format presubmit failed, which is intentional. I guess the clang formatter is never gonna play well with these
|
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.
Thank you so much! This will help a lot of Metal users to debug their programs. The changes LGTM.
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.
LGTM! Verified locally with LLVM 10.0.0, Xcode 11.5
Merging so that i can further address #1310 (comment) |
This PR completes the support for
print()
on Metal. Again, it's similar to OpenGL's implementation. I added a new Metal buffer to holdPrintMsg
. We will need a sync whenprint
is used.Related issue = #1281
[Click here for the format server]