-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial Implementation of TIRToRuntime Target hook (#9190)
* Initial Implementation of TIRToRuntime Target hook This is the initial implementation which wires in a test case for TIRToRuntime, in order to get this working I re-used `CodegenCHost` as it implements all of the `Op`s required from the lowered `PrimFunc`. Currently, the `IRModule` is non-unified but in future work it should definitely do so, I wanted to implement the basics here to get the infra in place. * Fix heterogeneous compute with multiple kDLCPU targets * Remove rogue te_compiler.h include
- Loading branch information
Showing
9 changed files
with
199 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
/* | ||
* 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 <tvm/relay/transform.h> | ||
#include <tvm/target/target.h> | ||
|
||
namespace tvm { | ||
|
||
namespace relay { | ||
namespace contrib { | ||
namespace example_target_hooks { | ||
tvm::transform::Pass RelayToTIR(); | ||
runtime::Module TIRToRuntime(IRModule mod, Target target); | ||
} // namespace example_target_hooks | ||
} // namespace contrib | ||
} // namespace relay | ||
|
||
TVM_REGISTER_TARGET_KIND("example_target_hook", kDLCPU) | ||
.set_attr<FTVMRelayToTIR>("RelayToTIR", relay::contrib::example_target_hooks::RelayToTIR()) | ||
.set_attr<FTVMTIRToRuntime>("TIRToRuntime", relay::contrib::example_target_hooks::TIRToRuntime); | ||
|
||
} // namespace tvm |
64 changes: 64 additions & 0 deletions
64
src/relay/backend/contrib/example_target_hooks/tir_to_runtime.cc
This file contains 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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* 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 <sstream> | ||
#include <string> | ||
|
||
#include "../../../../target/source/codegen_c_host.h" | ||
|
||
namespace tvm { | ||
namespace relay { | ||
namespace contrib { | ||
namespace example_target_hooks { | ||
|
||
using namespace tir; | ||
|
||
class CodeGenExampleTargetHook : public codegen::CodeGenCHost { | ||
public: | ||
/*! | ||
* \brief Emit code that changes adds to multiplies for testing | ||
*/ | ||
void VisitExpr_(const SubNode* op, std::ostream& os) final { | ||
os << '('; | ||
PrintExpr(op->a, os); | ||
os << " * "; | ||
PrintExpr(op->b, os); | ||
os << ')'; | ||
} | ||
}; | ||
|
||
runtime::Module TIRToRuntime(IRModule mod, Target target) { | ||
bool output_ssa = false; | ||
bool emit_asserts = false; | ||
CodeGenExampleTargetHook codegen; | ||
Array<String> function_names; | ||
codegen.Init(output_ssa, emit_asserts, target->str()); | ||
for (auto kv : mod->functions) { | ||
auto prim_func = Downcast<PrimFunc>(kv.second); | ||
auto global_symbol = prim_func->GetAttr<String>(tvm::attr::kGlobalSymbol); | ||
function_names.push_back(global_symbol.value()); | ||
codegen.AddFunction(prim_func); | ||
} | ||
std::string code = codegen.Finish(); | ||
return codegen::CSourceModuleCreate(code, "c", function_names); | ||
} | ||
|
||
} // namespace example_target_hooks | ||
} // namespace contrib | ||
} // namespace relay | ||
} // namespace tvm |
This file contains 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 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 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