tqchen commented on a change in pull request #4274: [µTVM] Enable AutoTVM for 
ARM STM32F746XX Boards
URL: https://github.com/apache/incubator-tvm/pull/4274#discussion_r346651119
 
 

 ##########
 File path: src/runtime/micro/micro_session.cc
 ##########
 @@ -76,79 +214,122 @@ MicroSession::~MicroSession() {
   low_level_device_ = nullptr;
 }
 
-void MicroSession::CreateSession(const std::string& device_type,
-                                 const std::string& binary_path,
-                                 const std::string& toolchain_prefix,
-                                 std::uintptr_t base_addr,
-                                 const std::string& server_addr,
-                                 int port) {
-  // TODO(weberlo): make device type enum
-  toolchain_prefix_ = toolchain_prefix;
-  if (device_type == "host") {
-    low_level_device_ = HostLowLevelDeviceCreate(memory_size_);
-  } else if (device_type == "openocd") {
-    // TODO(weberlo): We need a better way of configuring devices.
-    low_level_device_ = OpenOCDLowLevelDeviceCreate(base_addr, server_addr, 
port);
-  } else {
-    LOG(FATAL) << "unsupported micro low-level device";
+double MicroSession::PushToExecQueue(DevPtr func_ptr, const TVMArgs& args) {
+  if (thumb_mode_) {
+    func_ptr += 1;
   }
-
-  SetRuntimeBinaryPath(binary_path);
-  CHECK(!runtime_binary_path_.empty()) << "uTVM runtime not initialized";
-  runtime_bin_info_ = LoadBinary(runtime_binary_path_, /* patch_dylib_pointers 
*/ false);
-  utvm_main_symbol_ = 
low_level_device()->ToDevOffset(runtime_symbol_map()["UTVMMain"]);
-  utvm_done_symbol_ = 
low_level_device()->ToDevOffset(runtime_symbol_map()["UTVMDone"]);
-
-  if (device_type == "openocd") {
-    // Set OpenOCD device's stack pointer.
-    auto stack_section = GetAllocator(SectionKind::kStack);
-    low_level_device_->SetStackTop(stack_section->max_end_offset());
-  }
-
-  // Patch workspace pointers to the start of the workspace section.
-  DevBaseOffset workspace_start_offset = 
GetAllocator(SectionKind::kWorkspace)->start_offset();
-  DevBaseOffset workspace_end_offset = 
GetAllocator(SectionKind::kWorkspace)->max_end_offset();
-  void* workspace_start_addr =
-      low_level_device_->ToDevPtr(workspace_start_offset).cast_to<void*>();
-  void* workspace_end_addr =
-      low_level_device_->ToDevPtr(workspace_end_offset).cast_to<void*>();
-  DevSymbolWrite(runtime_symbol_map(), "utvm_workspace_begin", 
workspace_start_addr);
-  DevSymbolWrite(runtime_symbol_map(), "utvm_workspace_end", 
workspace_end_addr);
-}
-
-void MicroSession::PushToExecQueue(DevBaseOffset func, const TVMArgs& args) {
   int32_t (*func_dev_addr)(void*, void*, int32_t) =
-      reinterpret_cast<int32_t (*)(void*, void*, int32_t)>(
-          low_level_device()->ToDevPtr(func).value());
+      reinterpret_cast<int32_t (*)(void*, void*, int32_t)>(func_ptr.value());
 
   // Create an allocator stream for the memory region after the most recent
   // allocation in the args section.
-  DevPtr args_addr =
-      
low_level_device()->ToDevPtr(GetAllocator(SectionKind::kArgs)->curr_end_offset());
-  TargetDataLayoutEncoder encoder(args_addr);
+  DevPtr args_addr = GetAllocator(SectionKind::kArgs)->curr_end_addr();
+  TargetDataLayoutEncoder encoder(args_addr, word_size_);
 
   std::tuple<DevPtr, DevPtr> arg_field_addrs = EncoderAppend(&encoder, args);
+
   // Flush `stream` to device memory.
-  DevBaseOffset stream_dev_offset =
+  DevPtr stream_dev_addr =
       GetAllocator(SectionKind::kArgs)->Allocate(encoder.buf_size());
-  low_level_device()->Write(stream_dev_offset,
+  low_level_device()->Write(stream_dev_addr,
                             reinterpret_cast<void*>(encoder.data()),
                             encoder.buf_size());
 
-  UTVMTask task = {
-      .func = func_dev_addr,
-      .arg_values = std::get<0>(arg_field_addrs).cast_to<TVMValue*>(),
-      .arg_type_codes = std::get<1>(arg_field_addrs).cast_to<int*>(),
+  if (word_size_ == 4) {
+    TVMValue* arg_values_dev_addr = 
std::get<0>(arg_field_addrs).cast_to<TVMValue*>();
+    int* arg_type_codes_dev_addr = 
std::get<1>(arg_field_addrs).cast_to<int*>();
+    UTVMTask32 task = {
+      .func = *((uint32_t*) &func_dev_addr),  // NOLINT(*)
+      .arg_values = *((uint32_t*) &arg_values_dev_addr),  // NOLINT(*)
+      .arg_type_codes = *((uint32_t*) &arg_type_codes_dev_addr),  // NOLINT(*)
       .num_args = args.num_args,
-  };
-  // Write the task.
-  DevSymbolWrite(runtime_symbol_map(), "task", task);
+    };
+    // Write the task.
+    DevSymbolWrite(runtime_symbol_map_, "utvm_task", task);
+  } else if (word_size_ == 8) {
+    TVMValue* arg_values_dev_addr = 
std::get<0>(arg_field_addrs).cast_to<TVMValue*>();
+    int* arg_type_codes_dev_addr = 
std::get<1>(arg_field_addrs).cast_to<int*>();
+    UTVMTask64 task = {
+      .func = *((uint64_t*) &func_dev_addr),  // NOLINT(*)
 
 Review comment:
   Consider use a union to do the cast, instead of the aliasing approach

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