-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Add order to functions in C Codegen #10590
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
Changes from 2 commits
24f793d
795237a
3d11372
d0e33a2
60de0b7
f97c405
25ae939
fea6594
a95e147
ddbe737
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 |
|---|---|---|
|
|
@@ -105,7 +105,7 @@ PackedFunc Executable::GetFunction(const std::string& name, const ObjectPtr<Obje | |
| }); | ||
| } else { | ||
| LOG(FATAL) << "Unknown packed function: " << name; | ||
| return PackedFunc(nullptr); | ||
| return PackedFunc(); | ||
|
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. i think this change is equivalent
Member
Author
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. yeah, |
||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ | |
|
|
||
| #include <string> | ||
| #include <unordered_map> | ||
| #include <utility> | ||
| #include <vector> | ||
|
|
||
| #include "codegen_c.h" | ||
|
|
@@ -42,7 +43,12 @@ class CodeGenCHost : public CodeGenC { | |
|
|
||
| void InitGlobalContext(); | ||
| void AddFunction(const PrimFunc& f); | ||
|
|
||
| /*! | ||
| * \brief Add functions from the (unordered) range to the current module in a deterministic order. | ||
|
||
| * | ||
| * \param functions A vector of unordered range of current module. | ||
| */ | ||
| void AddFunctionsOrdered(std::vector<std::pair<tvm::GlobalVar, tvm::BaseFunc>> functions); | ||
| void DefineModuleName(); | ||
|
|
||
| void PrintType(DataType t, std::ostream& os) final; // NOLINT(*) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| #include <gmock/gmock.h> | ||
| #include <gtest/gtest.h> | ||
| #include <tvm/driver/driver_api.h> | ||
| #include <tvm/ir/type.h> | ||
| #include <tvm/node/reflection.h> | ||
| #include <tvm/runtime/metadata.h> | ||
| #include <tvm/runtime/module.h> | ||
| #include <tvm/target/target.h> | ||
| #include <tvm/te/operation.h> | ||
|
|
||
| TEST(CCodegen, FunctionOrder) { | ||
| using namespace tvm; | ||
| using namespace tvm::te; | ||
|
|
||
| std::string tvm_module_main = std::string(runtime::symbol::tvm_module_main); | ||
|
|
||
| tvm::Target target_c = tvm::Target("c -keys=cpu -link-params=0"); | ||
|
|
||
| const int n = 4; | ||
| Array<PrimExpr> shape{n}; | ||
|
|
||
| auto A = placeholder(shape, DataType::Float(32), "A"); | ||
| auto B = placeholder(shape, DataType::Float(32), "B"); | ||
|
|
||
| auto elemwise_add = compute( | ||
| A->shape, [&A, &B](PrimExpr i) { return A[i] + B[i]; }, "elemwise_add"); | ||
|
|
||
| auto fcreate = [=]() { | ||
| With<Target> llvm_scope(target_c); | ||
| return create_schedule({elemwise_add->op}); | ||
| }; | ||
|
|
||
| auto args = Array<Tensor>({A, B, elemwise_add}); | ||
|
|
||
| std::unordered_map<Tensor, Buffer> binds; | ||
| auto lowered = LowerSchedule(fcreate(), args, "elemwise_add", binds); | ||
| Map<tvm::Target, IRModule> inputs = {{target_c, lowered}}; | ||
| runtime::Module module = build(inputs, Target()); | ||
| Array<String> functions = module->GetFunction("get_func_names", false)(); | ||
|
|
||
| ICHECK(functions.back().compare(tvm_module_main) == 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.
for this one, i think
return PackedFunc()is still abiding by theGetFunctionconvention, so it might be a bit superfluous to emit a log line here.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.
I'm looking for a way to show some output message to developers that they are using the wrong function name for this module. Specially since we have multiple version of this runtime.Module it would be very useful to have some messaging. What is your suggestion?
Also is LOG(DEBUG) better in this case?
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.
does this work? or are you saying from c++?
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.
yeah from C++. I would overwrite << operator in runtime::Module to provide more info on this. Cause that way we can get module type in C++.