tvm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-tvm] tmoreau89 commented on a change in pull request #5158: [Runtime][MISRA-C][Bundle] Bundle deployment with static linking
Date Fri, 27 Mar 2020 23:09:35 GMT
tmoreau89 commented on a change in pull request #5158: [Runtime][MISRA-C][Bundle] Bundle deployment
with static linking
URL: https://github.com/apache/incubator-tvm/pull/5158#discussion_r399577296
 
 

 ##########
 File path: apps/bundle_deploy/test_static.c
 ##########
 @@ -0,0 +1,122 @@
+/*
+ * 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/runtime/c_runtime_api.h>
+#include <assert.h>
+#include <stdio.h>
+#include <sys/time.h>
+#include <sys/stat.h>
+#include "bundle.h"
+
+
+int main(int argc, char **argv) {
+  assert(argc == 5 && "Usage: test_static <data.bin> <output.bin> <graph.json>
<params.bin>");
+
+  struct stat st;
+  char * json_data;
+  char * params_data;
+  uint64_t params_size;
+
+  FILE * fp = fopen(argv[3], "rb");
+  stat(argv[3], &st);
+  json_data = (char*)malloc(st.st_size);
+  fread(json_data, st.st_size, 1, fp);
+  fclose(fp);
+
+  fp = fopen(argv[4], "rb");
+  stat(argv[4], &st);
+  params_data = (char*)malloc(st.st_size);
+  fread(params_data, st.st_size, 1, fp);
+  params_size = st.st_size;
+  fclose(fp);
+
+  struct timeval t0, t1, t2, t3, t4, t5;
+  gettimeofday(&t0, 0);
+
+  auto *handle = tvm_runtime_create(json_data, params_data, params_size);
+  gettimeofday(&t1, 0);
+
+  float input_storage[10 * 5];
+  fp = fopen(argv[1], "rb");
+  fread(input_storage, 10 * 5, 4, fp);
+  fclose(fp);
+
+  float result_storage[10 * 5];
+  fp = fopen(argv[2], "rb");
+  fread(result_storage, 10 * 5, 4, fp);
+  fclose(fp);
+
+  DLTensor input;
+  input.data = input_storage;
+  DLContext ctx = {kDLCPU, 0};
+  input.ctx = ctx;
+  input.ndim = 2;
+  DLDataType dtype = {kDLFloat, 32, 1};
+  input.dtype = dtype;
+  int64_t shape [2] = {10, 5};
+  input.shape = &shape;
+  input.strides = NULL;
+  input.byte_offset = 0;
+
+  tvm_runtime_set_input(handle, "x", &input);
+  gettimeofday(&t2, 0);
+
+  tvm_runtime_run(handle);
+  gettimeofday(&t3, 0);
+
+  float output_storage[10 * 5];
+  DLTensor output;
+  output.data = output_storage;
+  DLContext out_ctx = {kDLCPU, 0};
+  output.ctx = out_ctx;
+  output.ndim = 2;
+  DLDataType out_dtype = {kDLFloat, 32, 1};
+  output.dtype = out_dtype;
+  int64_t out_shape [2] = {10, 5};
+  output.shape = &out_shape;
+  output.strides = NULL;
+  output.byte_offset = 0;
+  
+  tvm_runtime_get_output(handle, 0, &output);
+  gettimeofday(&t4, 0);
+
+  for (auto i = 0; i < 10 * 5; ++i) {
+    assert(fabs(output_storage[i] - result_storage[i]) < 1e-5f);
+    if (fabs(output_storage[i] - result_storage[i]) >= 1e-5f) {
+      printf("got %f, expected %f\n", output_storage[i], result_storage[i]);
+    }
+    // printf("out: %f, exp: %f\n", output_storage[i], result_storage[i]);
 
 Review comment:
   cleanup here too

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message