This is an automated email from the ASF dual-hosted git repository.
masahi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/main by this push:
new af5a6c48e3 [CodegenC] Updated unit test for sorted CodegenC output
(#14949)
af5a6c48e3 is described below
commit af5a6c48e3172cda8ca53507221f32c7863c1e83
Author: Eric Lunderberg <[email protected]>
AuthorDate: Fri Jun 2 16:43:15 2023 -0500
[CodegenC] Updated unit test for sorted CodegenC output (#14949)
* [Bugfix][TIR][VTA] Update host-side target, even without device func
This resolves an issue introduced by the combination of
https://github.com/apache/tvm/pull/14918 and
https://github.com/apache/tvm/pull/14945. The bug occurred for
targets that do not require device-side codegen, but do require a
`device_type` other than `kDLCPU`. It wasn't caught by CI, as the
issue only occurred with the combination of both PRs.
1. #14918 updated `SplitHostDevice` to only modify the `"target"`
attribute when a device-side function has been extracted.
2. For VTA, there is no device-side function, as everything is done
through host-side API calls.
3. From (1) and (2), the VTA examples kept the target
`T.target("ext_dev", host="llvm")` after the `SplitHostDevice`
pass, instead of being updated to `T.target("llvm")`.
4. #14945 restricted CombineContextCall to only apply to host-side
passes.
5. From (4) and (5), the `CombineContextCall` pass was no longer
applied to the VTA context calls.
This PR fixes `SplitHostDevice`, updating the target from
`T.target("ext_dev", host="llvm")` to `T.target("llvm")`, even if no
device sections have been extracted from the function.
* [CodegenC] Updated unit test for sorted CodegenC output
Previously, this unit test generated a `Map<tvm::Target, IRModule>`
whose default iteration order was not sorted by function name, built
the `Map` of modules, then validated whether the resulting C code was
a sorted list of 4 elements. However, this condition was stricter
than necessary, as it depended on the number of items added to the
`Map` until it was unsorted.
This commit updates the test to instead validate that `std::is_sorted`
returns true.
* Ignore __tvm_main__ in unit test
---
tests/cpp/c_codegen_test.cc | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/tests/cpp/c_codegen_test.cc b/tests/cpp/c_codegen_test.cc
index e764d21505..a01921239a 100644
--- a/tests/cpp/c_codegen_test.cc
+++ b/tests/cpp/c_codegen_test.cc
@@ -121,5 +121,11 @@ TEST(CCodegen, FunctionOrder) {
auto module = build(inputs, Target());
Array<String> func_array = module->GetFunction("get_func_names", false)();
std::vector<std::string> functions{func_array.begin(), func_array.end()};
- EXPECT_THAT(functions, ElementsAre(StrEq("op_1"), _, StrEq("op_2"), _));
+ // The entry point is handled separately from the other functions.
+ functions.erase(std::remove_if(functions.begin(), functions.end(),
+ [](const std::string& name) {
+ return name ==
tvm::runtime::symbol::tvm_module_main;
+ }),
+ functions.end());
+ EXPECT_TRUE(std::is_sorted(functions.begin(), functions.end()));
}