alanmacd commented on code in PR #13690:
URL: https://github.com/apache/tvm/pull/13690#discussion_r1062816744


##########
3rdparty/mlperftiny/api/internally_implemented.cpp:
##########
@@ -0,0 +1,325 @@
+/*
+Copyright 2020 EEMBC and The MLPerf Authors. All Rights Reserved.
+Licensed 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.
+This file is a modified version of the original EEMBC implementation of ee_lib.
+The file name has been changed and some functions removed. Malloc has been
+replaced by a fixed-size array.
+==============================================================================*/
+/// \file
+/// \brief Internally-implemented methods required to perform inference.
+
+#include "internally_implemented.h"
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <string.h>
+
+#include "submitter_implemented.h"
+
+// Command buffer (incoming commands from host)
+char volatile g_cmd_buf[EE_CMD_SIZE + 1];
+size_t volatile g_cmd_pos = 0u;
+
+// Generic buffer to db input.
+uint8_t gp_buff[MAX_DB_INPUT_SIZE];
+size_t g_buff_size = 0u;
+size_t g_buff_pos = 0u;
+
+/**
+ * Since the serial port ISR may be connected before the loop is ready, this
+ * flag turns off the parser until the main routine is ready.
+ */
+bool g_state_parser_enabled = false;
+
+/**
+ * This function assembles a command string from the UART. It should be called
+ * from the UART ISR for each new character received. When the parser sees the
+ * termination character, the user-defined th_command_ready() command is 
called.
+ * It is up to the application to then dispatch this command outside the ISR
+ * as soon as possible by calling ee_serial_command_parser_callback(), below.
+ */
+void ee_serial_callback(char c) {
+  if (c == EE_CMD_TERMINATOR) {
+    g_cmd_buf[g_cmd_pos] = (char)0;
+    th_command_ready(g_cmd_buf);
+    g_cmd_pos = 0;
+  } else {
+    g_cmd_buf[g_cmd_pos] = c;
+    g_cmd_pos = g_cmd_pos >= EE_CMD_SIZE ? EE_CMD_SIZE : g_cmd_pos + 1;
+  }
+}
+
+/**
+ * This is the minimal parser required to test the monitor; profile-specific
+ * commands are handled by whatever profile is compiled into the firmware.
+ *
+ * The most basic commands are:
+ *
+ * name             Print m-name-NAME, where NAME defines the intent of the f/w
+ * timestamp        Generate a signal used for timestamping by the framework
+ */
+/*@-mustfreefresh*/
+/*@-nullpass*/
+void ee_serial_command_parser_callback(char *p_command) {
+  char *tok;
+
+  if (g_state_parser_enabled != true) {
+    return;
+  }
+
+  tok = strtok(p_command, EE_CMD_DELIMITER);
+
+  if (strncmp(tok, EE_CMD_NAME, EE_CMD_SIZE) == 0) {
+    th_printf(EE_MSG_NAME, EE_DEVICE_NAME, TH_VENDOR_NAME_STRING);
+  } else if (strncmp(tok, EE_CMD_TIMESTAMP, EE_CMD_SIZE) == 0) {
+    th_timestamp();
+  } else if (ee_profile_parse(tok) == EE_ARG_CLAIMED) {
+  } else {
+    th_printf(EE_ERR_CMD, tok);
+  }
+
+  th_printf(EE_MSG_READY);
+}
+
+/**
+ * Perform the basic setup.
+ */
+void ee_benchmark_initialize(void) {
+  th_serialport_initialize();
+  th_timestamp_initialize();
+  th_final_initialize();
+  th_printf(EE_MSG_INIT_DONE);
+  // Enable the command parser here (the callback is connected)
+  g_state_parser_enabled = true;
+  // At this point, the serial monitor should be up and running,
+  th_printf(EE_MSG_READY);
+}
+
+arg_claimed_t ee_profile_parse(char *command) {
+  char *p_next; /* strtok already primed from ee_main.c */
+
+  if (strncmp(command, "profile", EE_CMD_SIZE) == 0) {
+    th_printf("m-profile-[%s]\r\n", EE_FW_VERSION);
+    th_printf("m-model-[%s]\r\n", TH_MODEL_VERSION);
+  } else if (strncmp(command, "help", EE_CMD_SIZE) == 0) {
+    th_printf("%s\r\n", EE_FW_VERSION);
+    th_printf("\r\n");
+    /* These are the three common functions for all IoTConnect f/w. */
+    th_printf("help         : Print this information\r\n");
+    th_printf("name         : Print the name of the device\r\n");
+    th_printf("timestsamp   : Generate a timetsamp\r\n");
+    /* These are profile-specific commands. */
+    th_printf("db SUBCMD    : Manipulate a generic byte buffer\r\n");
+    th_printf("  load N     : Allocate N bytes and set load counter\r\n");
+    th_printf("  db HH[HH]* : Load 8-bit hex byte(s) until N bytes\r\n");
+    th_printf("  print [N=16] [offset=0]\r\n");
+    th_printf("             : Print N bytes at offset as hex\r\n");
+    th_printf(
+        "infer N [W=0]: Load input, execute N inferences after W warmup "
+        "loops\r\n");
+    th_printf("results      : Return the result fp32 vector\r\n");
+  } else if (ee_buffer_parse(command) == EE_ARG_CLAIMED) {
+  } else if (strncmp(command, "infer", EE_CMD_SIZE) == 0) {
+    size_t n = 1;
+    size_t w = 10;
+    int i;
+
+    /* Check for inference iterations */
+    p_next = strtok(NULL, EE_CMD_DELIMITER);
+    if (p_next) {
+      i = atoi(p_next);
+      if (i <= 0) {
+        th_printf("e-[Inference iterations must be >0]\r\n");
+        return EE_ARG_CLAIMED;
+      }
+      n = (size_t)i;
+      /* Check for warmup iterations */
+      p_next = strtok(NULL, EE_CMD_DELIMITER);
+      if (p_next) {
+        i = atoi(p_next);
+        if (i < 0) {
+          th_printf("e-[Inference warmup must be >=0]\r\n");
+          return EE_ARG_CLAIMED;
+        }
+        w = (size_t)i;
+      }
+    }
+
+    ee_infer(n, w);
+  } else if (strncmp(command, "results", EE_CMD_SIZE) == 0) {
+    th_results();
+  } else {
+    return EE_ARG_UNCLAIMED;
+  }
+  return EE_ARG_CLAIMED;
+}
+
+/**
+ * Inference without feature engineering. The inpput tensor is expected to

Review Comment:
   I guess that needs to be fixed upstream.



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to