comaniac commented on a change in pull request #4482: [Relay] External codegen
URL: https://github.com/apache/incubator-tvm/pull/4482#discussion_r358119567
 
 

 ##########
 File path: src/relay/backend/contrib/codegen_c/codegen.cc
 ##########
 @@ -0,0 +1,227 @@
+/*
+ * 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/expr_functor.h>
+#include <tvm/relay/transform.h>
+#include <tvm/relay/type.h>
+#include <tvm/runtime/module.h>
+#include <tvm/runtime/object.h>
+
+#include <fstream>
+#include <sstream>
+
+#include "codegen_c.h"
+
+namespace tvm {
+namespace relay {
+namespace contrib {
+
+/*!
+ * \brief An example codegen that is only used for quick prototyping and 
testing
+ * purpose. Only several binary options are covered. Users
+ * may need to extend them to cover more operators.
+ */
+class CodegenC : public ExprVisitor, public CodgenCBase {
+ public:
+  explicit CodegenC(const std::string& id) { this->ext_func_id_ = id; }
+
+  void VisitExpr_(const VarNode* node) {
+    ext_func_args_.push_back(node->name_hint());
+    out_.clear();
+    out_.push_back({node->name_hint(), 0});
+  }
+
+  void VisitExpr_(const CallNode* call) final {
+    std::ostringstream macro_stream;
+    std::ostringstream decl_stream;
+    std::ostringstream buf_stream;
+
+    auto op_node = call->op.as<OpNode>();
+    std::string func_name = ext_func_id_ + "_" + std::to_string(func_idx++);
+
+    // Make function declaration
+    macro_stream << "CSOURCE_BINARY_OP_" << call->args.size() << "D(" << 
func_name << ", ";
+
+    if (GetRef<Op>(op_node) == Op::Get("add")) {
 
 Review comment:
   That's a fair concern. As we put the comment, there must be some other 
utilities like these two and we should summarize them to a place for 
developers' convenience, but they would be clearer over time. 
   
   In addition, adding utilities to a larger scope requires more discussions. 
In this PR, we hope to focus on the interface and class structure design, so I 
think what utilities should be unified (including names and functionalities) 
and where to put them can be decided in the future.

----------------------------------------------------------------
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

Reply via email to