areusch commented on a change in pull request #6917:
URL: https://github.com/apache/tvm/pull/6917#discussion_r529659051
##########
File path: src/target/source/codegen_c_host.cc
##########
@@ -57,6 +60,48 @@ void CodeGenCHost::AddFunction(const PrimFunc& f) {
CodeGenC::AddFunction(f);
}
+void CodeGenCHost::LinkParameters(Map<String, LinkedParam> params) {
+ PrintFuncPrefix();
+ stream << " " << tvm::runtime::symbol::tvm_lookup_linked_param
+ << "(void* args, int* arg_type_ids, int num_args, void*
out_ret_value, "
+ << "int* out_ret_tcode, void* resource_handle) {\n";
+ ICHECK_EQ(GetUniqueName(tvm::runtime::symbol::tvm_lookup_linked_param),
+ tvm::runtime::symbol::tvm_lookup_linked_param)
+ << "builtin PackedFunc name already taken: " <<
tvm::runtime::symbol::tvm_lookup_linked_param;
+ stream << " switch (((int64_t*) args)[0]) {\n"
+ << " default:\n"
+ << " out_ret_tcode[0] = " << kTVMNullptr << ";\n"
+ << " return 0;\n";
+
+ function_names_.emplace_back(tvm::runtime::symbol::tvm_lookup_linked_param);
+ for (auto kv : params) {
+ decl_stream << "\n"
+ << "#ifdef __cplusplus\n"
+ << "extern \"C\" {\n"
+ << "#endif\n"
+ << "static const ";
+ int64_t num_elements = 1;
+ for (int64_t dim : kv.second->param.Shape()) {
+ num_elements *= dim;
+ }
+ PrintType(kv.second->param.DataType(), decl_stream);
+ decl_stream << " " << ::tvm::runtime::symbol::tvm_param_prefix << kv.first
<< "["
+ << num_elements << "] = {\n";
+ NDArrayDataToC(kv.second->param, 4, decl_stream);
+ decl_stream << "};\n"
+ << "#ifdef __cplusplus\n"
+ << "} // extern \"C\"\n"
+ << "#endif\n";
+ stream << " case " << kv.second->id << ":\n"
+ << " ((uint64_t*)out_ret_value)[0] = (uint64_t) (uintptr_t) "
+ << ::tvm::runtime::symbol::tvm_param_prefix << kv.first << ";\n"
+ << " out_ret_tcode[0] = " << kTVMOpaqueHandle << ";\n"
+ << " return 0;\n";
Review comment:
it would be nice to return a specific error code here (this was my
original implementation), but unfortunately it's not easy to catch on the other
side. we need to do a bit more legwork to be able to catch specific function
return values in c++/python. as it stands, returning nullptr from this function
is specific enough, and has the benefit that an exception flow isn't triggered
by default for non-parameters.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]