This is an automated email from the ASF dual-hosted git repository.

zhaowu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/main by this push:
     new 7b43db1  [Hexagon] Reenable compilation of TVM runtime for Hexagon 
(#7784)
7b43db1 is described below

commit 7b43db1bb83855d53bb8588be1df0fcbdc0a610a
Author: Krzysztof Parzyszek <kparz...@quicinc.com>
AuthorDate: Thu Apr 1 21:47:19 2021 -0500

    [Hexagon] Reenable compilation of TVM runtime for Hexagon (#7784)
    
    - Add support for Hexagon SDK 4.x (different directory structure)
    - Conditionally disable functions not present on Hexagon (popen, etc.)
    - Bump sim_dev architecture target to v65 (older versions can still be
      used with older compilers).
    
    Co-authored-by: Ravishankar Kolachana <quic_rkola...@quicinc.com>
    
    Co-authored-by: Ravishankar Kolachana <quic_rkola...@quicinc.com>
---
 CMakeLists.txt                                |  6 ----
 cmake/modules/Hexagon.cmake                   | 48 ++++++++++++++++++++++++---
 src/runtime/hexagon/sim/driver/CMakeLists.txt |  2 +-
 src/support/utils.h                           | 14 +++++++-
 4 files changed, 58 insertions(+), 12 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 277fe4a..8279687 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -449,12 +449,6 @@ if(BUILD_FOR_HEXAGON)
   # Wrap pthread_create to allow setting custom stack size.
   set_property(TARGET tvm_runtime APPEND PROPERTY LINK_FLAGS
                         "-Wl,--wrap=pthread_create")
-
-  target_include_directories(tvm_runtime SYSTEM
-    PUBLIC "${USE_HEXAGON_SDK}/libs/common/qurt/ADSPv62MP/include/posix"
-    PUBLIC "${USE_HEXAGON_SDK}/libs/common/qurt/ADSPv62MP/include/qurt"
-    PUBLIC "${USE_HEXAGON_SDK}/incs"
-    PUBLIC "${USE_HEXAGON_SDK}/incs/stddef")
 endif()
 
 if(USE_THREADS AND NOT BUILD_FOR_HEXAGON)
diff --git a/cmake/modules/Hexagon.cmake b/cmake/modules/Hexagon.cmake
index 9fc806c..80df76b 100644
--- a/cmake/modules/Hexagon.cmake
+++ b/cmake/modules/Hexagon.cmake
@@ -21,8 +21,14 @@ set(PICK_SIM  "sim")
 set(PICK_HW   "target")
 set(PICK_NONE "OFF")
 
+set(FOUND_HEXAGON_SDK_ROOT  FALSE)
+set(FOUND_HEXAGON_TOOLCHAIN FALSE)
+
 function(find_hexagon_toolchain)
-  if (NOT "${USE_HEXAGON_TOOLCHAIN}" STREQUAL "")
+  if(FOUND_HEXAGON_TOOLCHAIN)
+    return()
+  endif()
+  if(NOT "${USE_HEXAGON_TOOLCHAIN}" STREQUAL "")
     set(TRY_PATH "${USE_HEXAGON_TOOLCHAIN}")
   else()
     set(TRY_PATH "${USE_HEXAGON_SDK}")
@@ -35,12 +41,16 @@ function(find_hexagon_toolchain)
     get_filename_component(HEXAGON_TMP1 "${HEXAGON_TMP0}" DIRECTORY)
     set(HEXAGON_TOOLCHAIN "${HEXAGON_TMP1}" CACHE PATH
         "Path to the Hexagon toolchain")
+    set(FOUND_HEXAGON_TOOLCHAIN TRUE)
   else(HEXAGON_CLANG)
     message(SEND_ERROR "Cannot find Hexagon toolchain in ${TRY_PATH}")
   endif()
 endfunction()
 
 function(find_hexagon_sdk_root)
+  if(FOUND_HEXAGON_SDK_ROOT)
+    return()
+  endif()
   message(STATUS "Checking Hexagon SDK root: ${USE_HEXAGON_SDK}")
   file(GLOB_RECURSE HEXAGON_AEESTDDEF "${USE_HEXAGON_SDK}/*/AEEStdDef.h")
   if(HEXAGON_AEESTDDEF)
@@ -50,11 +60,30 @@ function(find_hexagon_sdk_root)
     get_filename_component(HEXAGON_TMP2 "${HEXAGON_TMP1}" DIRECTORY)
     set(HEXAGON_SDK_ROOT "${HEXAGON_TMP2}" CACHE PATH
         "Root directory of Hexagon SDK")
+    set(FOUND_HEXAGON_SDK_ROOT TRUE)
   else(HEXAGON_AEESTDDEF)
     message(SEND_ERROR "Cannot validate Hexagon SDK in ${USE_HEXAGON_SDK}")
   endif()
 endfunction()
 
+if(BUILD_FOR_HEXAGON)
+  find_hexagon_sdk_root()
+  if(HEXAGON_SDK_ROOT MATCHES "3.5.1")
+    message(SEND_ERROR "Hexagon SDK 3.5.1 is not supported")
+  elseif(HEXAGON_SDK_ROOT MATCHES "3\.[0-9]+\.[0-9]+")
+    include_directories(
+      SYSTEM "${USE_HEXAGON_SDK}/libs/common/qurt/ADSPv62MP/include/posix"
+      SYSTEM "${USE_HEXAGON_SDK}/libs/common/qurt/ADSPv62MP/include/qurt")
+  else()
+    include_directories(
+      SYSTEM "${HEXAGON_SDK_ROOT}/rtos/qurt/computev65/include/posix"
+      SYSTEM "${HEXAGON_SDK_ROOT}/rtos/qurt/computev65/include/qurt")
+  endif()
+  include_directories(
+    SYSTEM "${HEXAGON_SDK_ROOT}/incs"
+    SYSTEM "${HEXAGON_SDK_ROOT}/incs/stddef")
+endif()
+
 if(USE_HEXAGON_DEVICE STREQUAL "OFF")
   list(APPEND COMPILER_SRCS src/target/opt/build_hexagon_off.cc)
   return()
@@ -67,7 +96,7 @@ elseif(NOT USE_HEXAGON_DEVICE STREQUAL "${PICK_SIM}" AND
 endif()
 # If USE_HEXAGON_DEVICE is set to a valid value, make sure that USE_HEXAGON_SDK
 # is defined.
-if (NOT USE_HEXAGON_SDK)
+if(NOT USE_HEXAGON_SDK)
   message(SEND_ERROR "Please set USE_HEXAGON_SDK to the Hexagon SDK root")
   return()
 endif()
@@ -90,11 +119,22 @@ elseif(USE_HEXAGON_DEVICE STREQUAL "${PICK_HW}")
   find_hexagon_sdk_root()
   find_hexagon_toolchain()
   message(STATUS "Hexagon SDK: ${HEXAGON_SDK_ROOT}")
+  if(HEXAGON_SDK_ROOT MATCHES "3.5.1")
+    message(SEND_ERROR "Hexagon SDK 3.5.1 is not supported")
+  elseif(HEXAGON_SDK_ROOT MATCHES "3\.[0-9]+\.[0-9]+")
+      set(RPCMEM_DIR "libs/common/rpcmem")
+      set(REMOTE_DIR "libs/common/remote/ship/android_Release_aarch64")
+  else()
+      set(RPCMEM_DIR "ipc/fastrpc/rpcmem")
+      set(REMOTE_DIR "ipc/fastrpc/remote/ship/android_aarch64")
+  endif()
   file(GLOB RUNTIME_HEXAGON_DEVICE_SRCS src/runtime/hexagon/target/*.cc)
   include_directories(SYSTEM "${HEXAGON_SDK_ROOT}/incs/stddef")
-  include_directories(SYSTEM "${HEXAGON_SDK_ROOT}/libs/common/rpcmem/inc")
+  include_directories(SYSTEM "${HEXAGON_SDK_ROOT}/${RPCMEM_DIR}/inc")
+  include_directories(
+      SYSTEM "${HEXAGON_SDK_ROOT}/incs")
   include_directories(
-      SYSTEM 
"${HEXAGON_SDK_ROOT}/libs/common/remote/ship/android_Release_aarch64")
+      SYSTEM "${HEXAGON_SDK_ROOT}/${REMOTE_DIR}")
   include_directories(SYSTEM "${HEXAGON_TOOLCHAIN}/include/iss")
   list(APPEND TVM_RUNTIME_LINKER_LIBS "dl")
   if(BUILD_FOR_ANDROID)
diff --git a/src/runtime/hexagon/sim/driver/CMakeLists.txt 
b/src/runtime/hexagon/sim/driver/CMakeLists.txt
index a98cfe0..bed23c1 100644
--- a/src/runtime/hexagon/sim/driver/CMakeLists.txt
+++ b/src/runtime/hexagon/sim/driver/CMakeLists.txt
@@ -28,7 +28,7 @@ set(EXTRA_CXX_FLAGS
   "-O2"
   "-Wno-format"
   "-mhvx -mhvx-length=128b"
-  "-mv60"
+  "-mv65"
   "-stdlib=libc++"
 )
 
diff --git a/src/support/utils.h b/src/support/utils.h
index c51b7b9..91b9c13 100644
--- a/src/support/utils.h
+++ b/src/support/utils.h
@@ -27,8 +27,10 @@
 #include <stdio.h>
 #ifndef _WIN32
 #include <sys/types.h>
+#ifndef __hexagon__
 #include <sys/wait.h>
-#endif
+#endif  // __hexagon__
+#endif  // _WIN32
 #include <algorithm>
 #include <array>
 #include <cctype>
@@ -45,6 +47,7 @@ namespace support {
  * \param type "r" is for reading or "w" for writing.
  * \return normal standard stream
  */
+#ifndef __hexagon__
 inline FILE* TVMPOpen(const char* command, const char* type) {
 #if defined(_WIN32)
   return _popen(command, type);
@@ -52,12 +55,14 @@ inline FILE* TVMPOpen(const char* command, const char* 
type) {
   return popen(command, type);
 #endif
 }
+#endif  // __hexagon__
 
 /*!
  * \brief TVMPClose wrapper of pclose between windows / linux
  * \param stream the stream needed to be close.
  * \return exit status
  */
+#ifndef __hexagon__
 inline int TVMPClose(FILE* stream) {
 #if defined(_WIN32)
   return _pclose(stream);
@@ -65,12 +70,14 @@ inline int TVMPClose(FILE* stream) {
   return pclose(stream);
 #endif
 }
+#endif  // __hexagon__
 
 /*!
  * \brief TVMWifexited wrapper of WIFEXITED between windows / linux
  * \param status The status field that was filled in by the wait or waitpid 
function
  * \return the exit code of the child process
  */
+#ifndef __hexagon__
 inline int TVMWifexited(int status) {
 #if defined(_WIN32)
   return (status != 3);
@@ -78,12 +85,14 @@ inline int TVMWifexited(int status) {
   return WIFEXITED(status);
 #endif
 }
+#endif  // __hexagon__
 
 /*!
  * \brief TVMWexitstatus wrapper of WEXITSTATUS between windows / linux
  * \param status The status field that was filled in by the wait or waitpid 
function.
  * \return the child process exited normally or not
  */
+#ifndef __hexagon__
 inline int TVMWexitstatus(int status) {
 #if defined(_WIN32)
   return status;
@@ -91,6 +100,7 @@ inline int TVMWexitstatus(int status) {
   return WEXITSTATUS(status);
 #endif
 }
+#endif  // __hexagon__
 
 /*!
  * \brief IsNumber check whether string is a number.
@@ -137,6 +147,7 @@ inline bool EndsWith(std::string const& value, std::string 
const& end) {
  * \param err_msg The error message if we have
  * \return executed output status
  */
+#ifndef __hexagon__
 inline int Execute(std::string cmd, std::string* err_msg) {
   std::array<char, 128> buffer;
   std::string result;
@@ -151,6 +162,7 @@ inline int Execute(std::string cmd, std::string* err_msg) {
   }
   return 255;
 }
+#endif  // __hexagon__
 
 /*!
  * \brief Combine two hash values into a single one.

Reply via email to