liangfu commented on a change in pull request #3934: [Runtime] MISRA-C 
compliant TVM runtime
URL: https://github.com/apache/incubator-tvm/pull/3934#discussion_r384315312
 
 

 ##########
 File path: src/runtime/crt/graph_runtime.h
 ##########
 @@ -0,0 +1,517 @@
+/*
+ * 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.
+ */
+
+/*!
+ * \file graph_runtime.h
+ * \brief Tiny graph runtime that can run graph containing only tvm PackedFunc.
+ */
+#ifndef TVM_RUNTIME_CRT_GRAPH_RUNTIME_H_
+#define TVM_RUNTIME_CRT_GRAPH_RUNTIME_H_
+
+#include <dlpack/dlpack.h>
+
+#include "load_json.h"
+#include "ndarray.h"
+#include "packed_func.h"
+#include "module.h"
+
+/*! \brief macro to do C API call */
+#define TVM_CCALL(func)                                            \
+  {                                                                \
+    int ret = (func);                                              \
+    CHECK_EQ(ret, 0)                                               \
+        << TVMGetLastError();                                      \
+  }
+
+/*! \brief operator attributes about tvm op */
+typedef struct tvm_op_param_t {
+  char func_name[120];
+  uint32_t num_inputs;
+  uint32_t num_outputs;
+  uint32_t flatten_data;
+} TVMOpParam;
+
+// Memory pool entry.
+typedef struct graph_runtime_pool_entry_t {
+  size_t size;
+  int device_type;
+} PoolEntry;
+
+// Node entry
+typedef struct graph_runtime_node_entry_t {
+  uint32_t node_id;
+  uint32_t index;
+  uint32_t version;
+  // JSON Loader
+  void (*Load)(JSONReader *reader);
+} NodeEntry;
+
+static inline int NodeEntry_Load(NodeEntry * entry, JSONReader * reader) {
+  int status = 0;
+  reader->BeginArray(reader);
+  if (!(reader->NextArrayItem(reader))) {
+    fprintf(stderr, "invalid json format: failed to parse `node_id`\n");
+  }
+  reader->ReadUnsignedInteger(reader, &(entry->node_id));
+  if (!(reader->NextArrayItem(reader))) {
+    fprintf(stderr, "invalid json format: failed to parse `index`\n");
+  }
+  reader->ReadUnsignedInteger(reader, &(entry->index));
+  if (reader->NextArrayItem(reader)) {
+    reader->ReadUnsignedInteger(reader, &(entry->version));
+    if (reader->NextArrayItem(reader)) {
+      fprintf(stderr, "invalid json format: failed to parse `version`\n");
+    }
+  } else {
+    entry->version = 0;
+  }
+  return status;
+}
+
+// Node
+typedef struct graph_runtime_node_t {
 
 Review comment:
   fixed

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