You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2020/03/27 23:03:41 UTC

[GitHub] [incubator-tvm] mehrdadhe opened a new pull request #5158: [Runtime][MISRA-C][Bundle] Bundle deployment with static linking

mehrdadhe opened a new pull request #5158: [Runtime][MISRA-C][Bundle] Bundle deployment with static linking
URL: https://github.com/apache/incubator-tvm/pull/5158
 
 
   Current implementation in MISRA-C bundle deployment depends on dynamic linker. This PR adds demo and test which does not rely on dynamic linking using dlopen function.
   

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

[GitHub] [incubator-tvm] tqchen commented on issue #5158: [Runtime][MISRA-C][Bundle] Bundle deployment with static linking

Posted by GitBox <gi...@apache.org>.
tqchen commented on issue #5158: [Runtime][MISRA-C][Bundle] Bundle deployment with static linking
URL: https://github.com/apache/incubator-tvm/pull/5158#issuecomment-605552316
 
 
   cc @liangfu 

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

[GitHub] [incubator-tvm] tmoreau89 commented on issue #5158: [Runtime][MISRA-C][Bundle] Bundle deployment with static linking

Posted by GitBox <gi...@apache.org>.
tmoreau89 commented on issue #5158: [Runtime][MISRA-C][Bundle] Bundle deployment with static linking
URL: https://github.com/apache/incubator-tvm/pull/5158#issuecomment-605350267
 
 
   @liangfu @siju-samuel 

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

[GitHub] [incubator-tvm] siju-samuel commented on a change in pull request #5158: [Runtime][MISRA-C][Bundle] Bundle deployment with static linking

Posted by GitBox <gi...@apache.org>.
siju-samuel 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_r399615836
 
 

 ##########
 File path: apps/bundle_deploy/bundle_static.c
 ##########
 @@ -0,0 +1,80 @@
+/*
+ * 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 "bundle.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "runtime.c"
+
+TVM_DLL void * tvm_runtime_create(const char * json_data,
+                                  const char * params_data,
+                                  const uint64_t params_size) {
+  int64_t device_type = kDLCPU;
+  int64_t device_id = 0;
+
+  TVMByteArray params;
+  params.data = params_data;
+  params.size = params_size;
+
+  TVMContext ctx;
+  ctx.device_type = (DLDeviceType)device_type;
+  ctx.device_id = device_id;
+
+  // declare pointers
+  void * (*SystemLibraryCreate)();
+  TVMGraphRuntime * (*TVMGraphRuntimeCreate)(const char *, const TVMModuleHandle, const TVMContext *);
+  int (*TVMGraphRuntime_LoadParams)(TVMModuleHandle, const char *, const uint32_t);
+
+  // get pointers
+  TVMFuncGetGlobal("runtime.SystemLib", (TVMFunctionHandle*)&SystemLibraryCreate);
+  TVMFuncGetGlobal("tvm.graph_runtime.create", (TVMFunctionHandle*)&TVMGraphRuntimeCreate);
+
+  // run modules
+  TVMModuleHandle mod_syslib = SystemLibraryCreate();
+  TVMModuleHandle mod = TVMGraphRuntimeCreate(json_data, mod_syslib, &ctx);
+  TVMModGetFunction(mod, "load_params", 0, (TVMFunctionHandle*)&TVMGraphRuntime_LoadParams);
+  TVMGraphRuntime_LoadParams(mod, params.data, params.size);
+  
+  return mod;
+}
+
+TVM_DLL void tvm_runtime_destroy(void * runtime) {
+  void (*TVMGraphRuntimeRelease)(TVMModuleHandle *);
+  TVMFuncGetGlobal("tvm.graph_runtime.release", (TVMFunctionHandle*)&TVMGraphRuntimeRelease);
+  TVMGraphRuntimeRelease(&runtime);
+}
+
+TVM_DLL void tvm_runtime_set_input(void * runtime, const char * name, DLTensor * tensor) {
+  void (*TVMGraphRuntime_SetInput)(TVMModuleHandle, const char *, DLTensor*);
+  TVMFuncGetGlobal("tvm.graph_runtime.set_input", (TVMFunctionHandle*)&TVMGraphRuntime_SetInput);
+  TVMGraphRuntime_SetInput(runtime, name, tensor);
+}
+
+TVM_DLL void tvm_runtime_run(void * runtime) {
+  void (*TVMGraphRuntime_Run)(TVMModuleHandle runtime);
+  TVMFuncGetGlobal("tvm.graph_runtime.run", (TVMFunctionHandle*)&TVMGraphRuntime_Run);
+  TVMGraphRuntime_Run(runtime);
+}
+
+TVM_DLL void tvm_runtime_get_output(void * runtime, int32_t index, DLTensor * tensor) {
+  int (*TVMGraphRuntime_GetOutput)(TVMModuleHandle, const int32_t, DLTensor *);
+  TVMFuncGetGlobal("tvm.graph_runtime.get_output", (TVMFunctionHandle*)&TVMGraphRuntime_GetOutput);
+  TVMGraphRuntime_GetOutput(runtime, index, tensor);
+}
+
 
 Review comment:
   Remove this extra line

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

[GitHub] [incubator-tvm] liangfu commented on a change in pull request #5158: [Runtime][MISRA-C][Bundle] Bundle deployment with static linking

Posted by GitBox <gi...@apache.org>.
liangfu 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_r399608373
 
 

 ##########
 File path: apps/bundle_deploy/Makefile
 ##########
 @@ -33,22 +33,36 @@ PKG_LDFLAGS = -pthread
 
 build_dir := build
 
-demo: $(build_dir)/demo $(build_dir)/bundle.so $(build_dir)/bundle_c.so $(build_dir)/cat.bin
-	TVM_NUM_THREADS=1 $(build_dir)/demo $(build_dir)/bundle.so $(build_dir)/cat.bin
-	TVM_NUM_THREADS=1 $(build_dir)/demo $(build_dir)/bundle_c.so $(build_dir)/cat.bin
+demo_dynamic: $(build_dir)/demo_dynamic $(build_dir)/bundle.so $(build_dir)/bundle_c.so $(build_dir)/cat.bin
 
 Review comment:
   update README.md to reflect this change.

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

[GitHub] [incubator-tvm] siju-samuel commented on a change in pull request #5158: [Runtime][MISRA-C][Bundle] Bundle deployment with static linking

Posted by GitBox <gi...@apache.org>.
siju-samuel 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_r399615789
 
 

 ##########
 File path: apps/bundle_deploy/bundle.h
 ##########
 @@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+
+#ifndef TVM_APPS_BUNDLE_H
+#define TVM_APPS_BUNDLE_H
+
+#include <tvm/runtime/c_runtime_api.h>
+
+TVM_DLL void * tvm_runtime_create(const char * json_data,
+                                  const char * params_data,
+                                  const uint64_t params_size);
+
+TVM_DLL void tvm_runtime_destroy(void * runtime);
+
+TVM_DLL void tvm_runtime_set_input(void * runtime,
+                                   const char * name, 
+                                   DLTensor * tensor);
+
+TVM_DLL void tvm_runtime_run(void * runtime);
+
+TVM_DLL void tvm_runtime_get_output(void * runtime,
+                                    int32_t index, 
+                                    DLTensor * tensor);
+
+#endif /* TVM_APPS_BUNDLE_H */
 
 Review comment:
   Add a CR at last line

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

[GitHub] [incubator-tvm] liangfu commented on a change in pull request #5158: [Runtime][MISRA-C][Bundle] Bundle deployment with static linking

Posted by GitBox <gi...@apache.org>.
liangfu 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_r399591983
 
 

 ##########
 File path: apps/bundle_deploy/bundle_static.c
 ##########
 @@ -0,0 +1,80 @@
+/*
+ * 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 "bundle.h"
+#include <stdio.h>
+#include <stdlib.h>
 
 Review comment:
   import order:
   
   ```c
   // tvm headers
   #include <tvm/..>
   //std headers
   #include <stdio.h>
   //local
   #include "runtime"
   ```

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

[GitHub] [incubator-tvm] tmoreau89 commented on a change in pull request #5158: [Runtime][MISRA-C][Bundle] Bundle deployment with static linking

Posted by GitBox <gi...@apache.org>.
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_r399576633
 
 

 ##########
 File path: apps/bundle_deploy/bundle_static.c
 ##########
 @@ -0,0 +1,94 @@
+/*
+ * 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 "bundle.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "runtime.c"
+
+
+// /*! \brief macro to do C API call */
 
 Review comment:
   Can we get those lines cleaned up?

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

[GitHub] [incubator-tvm] liangfu commented on issue #5158: [Runtime][MISRA-C][Bundle] Bundle deployment with static linking

Posted by GitBox <gi...@apache.org>.
liangfu commented on issue #5158: [Runtime][MISRA-C][Bundle] Bundle deployment with static linking
URL: https://github.com/apache/incubator-tvm/pull/5158#issuecomment-605554589
 
 
   LGTM
   
   > On Mar 29, 2020, at 11:21, Tianqi Chen <no...@github.com> wrote:
   > 
   > 
   > cc @liangfu
   > 
   > —
   > You are receiving this because you were mentioned.
   > Reply to this email directly, view it on GitHub, or unsubscribe.
   

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

[GitHub] [incubator-tvm] tmoreau89 merged pull request #5158: [Runtime][MISRA-C][Bundle] Bundle deployment with static linking

Posted by GitBox <gi...@apache.org>.
tmoreau89 merged pull request #5158: [Runtime][MISRA-C][Bundle] Bundle deployment with static linking
URL: https://github.com/apache/incubator-tvm/pull/5158
 
 
   

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

[GitHub] [incubator-tvm] mehrdadhe commented on issue #5158: [Runtime][MISRA-C][Bundle] Bundle deployment with static linking

Posted by GitBox <gi...@apache.org>.
mehrdadhe commented on issue #5158: [Runtime][MISRA-C][Bundle] Bundle deployment with static linking
URL: https://github.com/apache/incubator-tvm/pull/5158#issuecomment-605745880
 
 
   @tmoreau89  I have pushed a commit.

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

[GitHub] [incubator-tvm] mehrdadhe commented on a change in pull request #5158: [Runtime][MISRA-C][Bundle] Bundle deployment with static linking

Posted by GitBox <gi...@apache.org>.
mehrdadhe 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_r399577994
 
 

 ##########
 File path: apps/bundle_deploy/bundle_static.c
 ##########
 @@ -0,0 +1,94 @@
+/*
+ * 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 "bundle.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "runtime.c"
+
+
+// /*! \brief macro to do C API call */
 
 Review comment:
   Done!

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

[GitHub] [incubator-tvm] mehrdadhe commented on a change in pull request #5158: [Runtime][MISRA-C][Bundle] Bundle deployment with static linking

Posted by GitBox <gi...@apache.org>.
mehrdadhe 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_r399742635
 
 

 ##########
 File path: apps/bundle_deploy/Makefile
 ##########
 @@ -33,22 +33,36 @@ PKG_LDFLAGS = -pthread
 
 build_dir := build
 
-demo: $(build_dir)/demo $(build_dir)/bundle.so $(build_dir)/bundle_c.so $(build_dir)/cat.bin
-	TVM_NUM_THREADS=1 $(build_dir)/demo $(build_dir)/bundle.so $(build_dir)/cat.bin
-	TVM_NUM_THREADS=1 $(build_dir)/demo $(build_dir)/bundle_c.so $(build_dir)/cat.bin
+demo_dynamic: $(build_dir)/demo_dynamic $(build_dir)/bundle.so $(build_dir)/bundle_c.so $(build_dir)/cat.bin
 
 Review comment:
   Added!

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

[GitHub] [incubator-tvm] siju-samuel commented on a change in pull request #5158: [Runtime][MISRA-C][Bundle] Bundle deployment with static linking

Posted by GitBox <gi...@apache.org>.
siju-samuel 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_r399616351
 
 

 ##########
 File path: apps/bundle_deploy/Makefile
 ##########
 @@ -33,22 +33,36 @@ PKG_LDFLAGS = -pthread
 
 build_dir := build
 
-demo: $(build_dir)/demo $(build_dir)/bundle.so $(build_dir)/bundle_c.so $(build_dir)/cat.bin
-	TVM_NUM_THREADS=1 $(build_dir)/demo $(build_dir)/bundle.so $(build_dir)/cat.bin
-	TVM_NUM_THREADS=1 $(build_dir)/demo $(build_dir)/bundle_c.so $(build_dir)/cat.bin
+demo_dynamic: $(build_dir)/demo_dynamic $(build_dir)/bundle.so $(build_dir)/bundle_c.so $(build_dir)/cat.bin
 
 Review comment:
   apps/bundle_deploy/README.md needs to be updated?

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

[GitHub] [incubator-tvm] tmoreau89 commented on issue #5158: [Runtime][MISRA-C][Bundle] Bundle deployment with static linking

Posted by GitBox <gi...@apache.org>.
tmoreau89 commented on issue #5158: [Runtime][MISRA-C][Bundle] Bundle deployment with static linking
URL: https://github.com/apache/incubator-tvm/pull/5158#issuecomment-606074463
 
 
   Thank you @mehrdadhe @siju-samuel @liangfu! The PR has been merged!

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

[GitHub] [incubator-tvm] mehrdadhe commented on a change in pull request #5158: [Runtime][MISRA-C][Bundle] Bundle deployment with static linking

Posted by GitBox <gi...@apache.org>.
mehrdadhe 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_r399735066
 
 

 ##########
 File path: apps/bundle_deploy/demo_static.c
 ##########
 @@ -0,0 +1,106 @@
+/*
+ * 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 <float.h>
+
+#include "bundle.h"
+#include "build/graph.json.c"
+#include "build/params.bin.c"
+
+
+int main(int argc, char **argv) {
+  assert(argc == 2 && "Usage: demo_static <cat.bin>");
+
+  char * json_data = (char *)(build_graph_json);
+  char * params_data = (char *)(build_params_bin);
+  uint64_t params_size = build_params_bin_len;
+
+  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[1 * 3 * 224 * 224];
+  FILE * fp = fopen(argv[1], "rb");
+  fread(input_storage, 3 * 224 * 224, 4, fp);
+  fclose(fp);
+
+  DLTensor input;
+  input.data = input_storage;
+  DLContext ctx = {kDLCPU, 0};
+  input.ctx = ctx;
+  input.ndim = 4;
+  DLDataType dtype = {kDLFloat, 32, 1};
+  input.dtype = dtype;
+  int64_t shape [4] = {1, 3, 224, 224};
+  input.shape = &shape;
+  input.strides = NULL;
+  input.byte_offset = 0;
+
+  tvm_runtime_set_input(handle, "data", &input);
+  gettimeofday(&t2, 0);
+
+  tvm_runtime_run(handle);
+  gettimeofday(&t3, 0);
+
+  float output_storage[1000];
+  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] = {1, 1000};
+  output.shape = &out_shape;
+  output.strides = NULL;
+  output.byte_offset = 0;
+
+  tvm_runtime_get_output(handle, 0, &output);
+  gettimeofday(&t4, 0);
+
+  float max_iter = -FLT_MAX;
+  int32_t max_index = -1;
+  for (auto i = 0; i < 1000; ++i) {
 
 Review comment:
   Added, thanks for suggestion.

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

[GitHub] [incubator-tvm] mehrdadhe commented on a change in pull request #5158: [Runtime][MISRA-C][Bundle] Bundle deployment with static linking

Posted by GitBox <gi...@apache.org>.
mehrdadhe 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_r399742635
 
 

 ##########
 File path: apps/bundle_deploy/Makefile
 ##########
 @@ -33,22 +33,36 @@ PKG_LDFLAGS = -pthread
 
 build_dir := build
 
-demo: $(build_dir)/demo $(build_dir)/bundle.so $(build_dir)/bundle_c.so $(build_dir)/cat.bin
-	TVM_NUM_THREADS=1 $(build_dir)/demo $(build_dir)/bundle.so $(build_dir)/cat.bin
-	TVM_NUM_THREADS=1 $(build_dir)/demo $(build_dir)/bundle_c.so $(build_dir)/cat.bin
+demo_dynamic: $(build_dir)/demo_dynamic $(build_dir)/bundle.so $(build_dir)/bundle_c.so $(build_dir)/cat.bin
 
 Review comment:
   Done!

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

[GitHub] [incubator-tvm] siju-samuel commented on a change in pull request #5158: [Runtime][MISRA-C][Bundle] Bundle deployment with static linking

Posted by GitBox <gi...@apache.org>.
siju-samuel 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_r399616880
 
 

 ##########
 File path: apps/bundle_deploy/bundle.h
 ##########
 @@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+
+#ifndef TVM_APPS_BUNDLE_H
 
 Review comment:
   #ifndef TVM_APPS_BUNDLE_DEPLOY_BUNDLE_H_

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

[GitHub] [incubator-tvm] mehrdadhe commented on a change in pull request #5158: [Runtime][MISRA-C][Bundle] Bundle deployment with static linking

Posted by GitBox <gi...@apache.org>.
mehrdadhe 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_r399578021
 
 

 ##########
 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:
   Done!

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

[GitHub] [incubator-tvm] mehrdadhe commented on a change in pull request #5158: [Runtime][MISRA-C][Bundle] Bundle deployment with static linking

Posted by GitBox <gi...@apache.org>.
mehrdadhe 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_r399735957
 
 

 ##########
 File path: apps/bundle_deploy/Makefile
 ##########
 @@ -33,22 +33,36 @@ PKG_LDFLAGS = -pthread
 
 build_dir := build
 
-demo: $(build_dir)/demo $(build_dir)/bundle.so $(build_dir)/bundle_c.so $(build_dir)/cat.bin
-	TVM_NUM_THREADS=1 $(build_dir)/demo $(build_dir)/bundle.so $(build_dir)/cat.bin
-	TVM_NUM_THREADS=1 $(build_dir)/demo $(build_dir)/bundle_c.so $(build_dir)/cat.bin
+demo_dynamic: $(build_dir)/demo_dynamic $(build_dir)/bundle.so $(build_dir)/bundle_c.so $(build_dir)/cat.bin
 
 Review comment:
   I updated the README file. Please let me know if you have any suggestions.

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

[GitHub] [incubator-tvm] siju-samuel commented on a change in pull request #5158: [Runtime][MISRA-C][Bundle] Bundle deployment with static linking

Posted by GitBox <gi...@apache.org>.
siju-samuel 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_r399617118
 
 

 ##########
 File path: apps/bundle_deploy/demo_static.c
 ##########
 @@ -0,0 +1,106 @@
+/*
+ * 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 <float.h>
+
+#include "bundle.h"
+#include "build/graph.json.c"
+#include "build/params.bin.c"
+
+
+int main(int argc, char **argv) {
+  assert(argc == 2 && "Usage: demo_static <cat.bin>");
+
+  char * json_data = (char *)(build_graph_json);
+  char * params_data = (char *)(build_params_bin);
+  uint64_t params_size = build_params_bin_len;
+
+  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[1 * 3 * 224 * 224];
+  FILE * fp = fopen(argv[1], "rb");
+  fread(input_storage, 3 * 224 * 224, 4, fp);
+  fclose(fp);
+
+  DLTensor input;
+  input.data = input_storage;
+  DLContext ctx = {kDLCPU, 0};
+  input.ctx = ctx;
+  input.ndim = 4;
+  DLDataType dtype = {kDLFloat, 32, 1};
+  input.dtype = dtype;
+  int64_t shape [4] = {1, 3, 224, 224};
+  input.shape = &shape;
+  input.strides = NULL;
+  input.byte_offset = 0;
+
+  tvm_runtime_set_input(handle, "data", &input);
+  gettimeofday(&t2, 0);
+
+  tvm_runtime_run(handle);
+  gettimeofday(&t3, 0);
+
+  float output_storage[1000];
+  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] = {1, 1000};
+  output.shape = &out_shape;
+  output.strides = NULL;
+  output.byte_offset = 0;
+
+  tvm_runtime_get_output(handle, 0, &output);
+  gettimeofday(&t4, 0);
+
+  float max_iter = -FLT_MAX;
+  int32_t max_index = -1;
+  for (auto i = 0; i < 1000; ++i) {
 
 Review comment:
   Suggest to use a macro for output_storage len 1000,  3 places its used

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

[GitHub] [incubator-tvm] tmoreau89 commented on a change in pull request #5158: [Runtime][MISRA-C][Bundle] Bundle deployment with static linking

Posted by GitBox <gi...@apache.org>.
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