manupa-arm commented on a change in pull request #6917:
URL: https://github.com/apache/tvm/pull/6917#discussion_r530530023
##########
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) "
Review comment:
I still think void* should be enough here. void* would be less than 64
bits if the machine compiled for is less than 64bits. right? otherwise this
will make it store the pointer in 64bit space where the machine could have a
address space defined less than 64 bits, unless Im missing something here. In
this specific case, the array defined for the constant will have an address
depending the target machine it would be compiled for, hence my confusion.
Do we need to perform pointer arithmetic on this ? -- Im asking this because
uintptr_t cast is used. If so, using uintptr_t should be sufficient instead of
void*.
----------------------------------------------------------------
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]