zhiics commented on a change in pull request #4934: [Relay][External Codegen]
Support data types for CSourceModuleCodegen args and output
URL: https://github.com/apache/incubator-tvm/pull/4934#discussion_r383543036
##########
File path: src/relay/backend/contrib/codegen_c/codegen_c.h
##########
@@ -232,24 +243,60 @@ class CodegenCBase {
}
// Copy output
- CHECK_EQ(out.size(), 1U) << "Internal error: only single output is
support.";
- this->PrintIndents();
- code_stream_ << "std::memcpy(out, " << out[0].first << ", 4 * " <<
out[0].second << ");\n";
-
- // Free buffers
- for (size_t i = 0; i < buf_decl.size(); i++) {
+ if (out[0].need_copy) {
this->PrintIndents();
- code_stream_ << "std::free(buf_" << i << ");\n";
+ code_stream_ << "std::memcpy(out, " << out[0].name << ", 4 * " <<
out[0].size << ");\n";
+
+ // Free buffers
+ for (size_t i = 0; i < buf_decl.size(); i++) {
+ this->PrintIndents();
+ code_stream_ << "std::free(buf_" << i << ");\n";
+ }
}
this->ExitScope();
code_stream_ << "}\n";
// Create the wrapper to call the ext_func
- this->GenerateBackendCFunc(ext_func_id, args.size() + 1 /* output */);
+ this->GenerateBackendCFunc(ext_func_id, args, out[0]);
return code_stream_.str();
}
+ /*!
+ * \brief Returns dtype string
+ *
+ * \param var Var to get the dtype of
+ *
+ * \return The dtype string.
+ */
+ std::string GetDtypeString(Var var) {
Review comment:
const Var&
----------------------------------------------------------------
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]
With regards,
Apache Git Services