-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[FFI] Allow IntImm arguments to PackedFunc with int parameter #15983
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 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
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 |
|---|---|---|
|
|
@@ -319,3 +319,62 @@ TEST(TypedPackedFunc, RValue) { | |
| tf(1, true); | ||
| } | ||
| } | ||
|
|
||
| TEST(TypedPackedFunc, IntImmWrapper) { | ||
| using namespace tvm::runtime; | ||
|
|
||
| TypedPackedFunc<void(int)> typed_func = [](int x) {}; | ||
| PackedFunc func = typed_func; | ||
|
|
||
| // Integer argument may be provided | ||
| func(5); | ||
|
|
||
| // IntImm argument may be provided, automatically unwrapped. | ||
| tvm::IntImm lvalue_intimm(DataType::Int(32), 10); | ||
| func(lvalue_intimm); | ||
|
|
||
| // Unwrapping of IntImm argument works for rvalues as well | ||
| func(tvm::IntImm(DataType::Int(32), 10)); | ||
| } | ||
|
|
||
| TEST(TypedPackedFunc, FloatImmWrapper) { | ||
| using namespace tvm::runtime; | ||
|
|
||
| TypedPackedFunc<void(double)> typed_func = [](double x) {}; | ||
| PackedFunc func = typed_func; | ||
|
|
||
| // Argument may be provided as a floating point. If provided as an | ||
|
Contributor
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. Trailing whitespace. |
||
| // integer, it will be converted to a float. | ||
| func(static_cast<double>(5.0)); | ||
| func(static_cast<int>(5)); | ||
|
|
||
| // IntImm and FloatImm arguments may be provided, and are | ||
| // automatically unwrapped. These arguments work correctly for | ||
| // either lvalue or rvalue arguments. | ||
|
|
||
| tvm::IntImm lvalue_intimm(DataType::Int(32), 10); | ||
| tvm::FloatImm lvalue_floatimm(DataType::Float(32), 10.5); | ||
|
|
||
| func(lvalue_intimm); | ||
| func(lvalue_floatimm); | ||
| func(tvm::IntImm(DataType::Int(32), 10)); | ||
| func(tvm::FloatImm(DataType::Float(32), 10.5)); | ||
| } | ||
|
|
||
| TEST(TypedPackedFunc, BoolWrapper) { | ||
| using namespace tvm::runtime; | ||
|
|
||
| TypedPackedFunc<void(bool)> typed_func = [](bool x) {}; | ||
| PackedFunc func = typed_func; | ||
|
|
||
| // Argument may be provided as an IntImm, or as its subclass Bool. | ||
| func(true); | ||
|
|
||
| tvm::IntImm lvalue_intimm(DataType::Int(32), 10); | ||
| func(lvalue_intimm); | ||
| func(tvm::IntImm(DataType::Int(32), 10)); | ||
|
|
||
| tvm::Bool lvalue_bool(false); | ||
| func(lvalue_bool); | ||
| func(tvm::Bool(true)); | ||
| } | ||
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.
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.
Trailing whitespace, also in lines 550, 552.
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.
Hmm, I'm not seeing the trailing whitespace in the commit, either using
git show --word-diff-regex="[ ]+|[^ ]+", setting my editor to show whitespace, or in the github diff.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.
Sorry, I used the wrong definition, there is a double space before "As"
Uh oh!
There was an error while loading. Please reload this page.
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.
Ah, I see. This is intentional, but is more of a stylistic difference than anything else. Traditionally, (accidental diversion into typography) a space after a sentence would use an em space (the same with as a capital M) after a sentence, wider than the spacing between words. This isn't possible in monospaced fonts, so typewriters would emulate the em space by using two spaces. Exactly which is better has since become the topic of a great many flame wars.
I was curious, and it looks like double-spacing after a sentence is about twice as common as single-spacing in the TVM repo, with the Apache copyright header being the most prominent example.