Skip to content

Commit

Permalink
[Hexagon] Add support for v75
Browse files Browse the repository at this point in the history
Add support for executing v75 (Snapdragon 8 gen 3). This PR just adds
the support, but to build and execute for v75, the Hexagon SDK used
should be 5.4+.
  • Loading branch information
quic-sanirudh committed Jun 29, 2024
1 parent 4a5e22e commit 26cf77c
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 19 deletions.
16 changes: 8 additions & 8 deletions apps/hexagon_launcher/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ Create a subdirectory for the build files, and run `cmake` with the
following variables set:

```
cmake -DCMAKE_C_COMPILER=/path/to/hexagon-clang \
-DCMAKE_CXX_COMPILER=/path/to/hexagon-clang++ \
-DUSE_HEXAGON_ARCH=v65|v66|v68|v69|v73 \
-DUSE_HEXAGON_SDK=/path/to/hexagon/SDK \
cmake -DCMAKE_C_COMPILER=/path/to/hexagon-clang \
-DCMAKE_CXX_COMPILER=/path/to/hexagon-clang++ \
-DUSE_HEXAGON_ARCH=v65|v66|v68|v69|v73|v75 \
-DUSE_HEXAGON_SDK=/path/to/hexagon/SDK \
/path/to/apps/hexagon_launcher/cmake/hexagon
```

Expand All @@ -60,10 +60,10 @@ the TVM runtime for Hexagon will be built as a part of the process.

```
cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/android-ndk/build/cmake/android.toolchain.cmake \
-DANDROID_ABI=arm64-v8a \
-DANDROID_PLATFORM=android-28 \
-DUSE_HEXAGON_SDK=/p/Hexagon_SDK/4.3.0.0 \
-DUSE_HEXAGON_ARCH=v65|v66|v68|v69|v73 \
-DANDROID_ABI=arm64-v8a \
-DANDROID_PLATFORM=android-28 \
-DUSE_HEXAGON_SDK=/p/Hexagon_SDK/4.3.0.0 \
-DUSE_HEXAGON_ARCH=v65|v66|v68|v69|v73|v75 \
/path/to/apps/hexagon_launcher/cmake/android
```

Expand Down
2 changes: 1 addition & 1 deletion cmake/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ set(USE_HEXAGON_RPC OFF)
# compiling _by_ TVM). This applies to components like the TVM runtime, but is
# also used to select correct include/library paths from the Hexagon SDK when
# building runtime for Android.
# Valid values are v65, v66, v68, v69, v73.
# Valid values are v65, v66, v68, v69, v73, v75.
set(USE_HEXAGON_ARCH "v68")

# Whether use MRVL codegen
Expand Down
6 changes: 5 additions & 1 deletion cmake/modules/HexagonSDK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,12 @@ function(_get_hexagon_sdk_property_impl
set(_hexarch_dir_v68 "computev68")
set(_hexarch_dir_v69 "computev69")
set(_hexarch_dir_v73 "computev73")
set(_hexarch_dir_v75 "computev75")
set(_hexarch_dir_str "_hexarch_dir_${_hexagon_arch}")
set(_hexarch_dir "${${_hexarch_dir_str}}")

if(NOT _hexarch_dir)
message(SEND_ERROR "Please set Hexagon architecture to one of v65, v66, v68, v69, v73")
message(SEND_ERROR "Please set Hexagon architecture to one of v65, v66, v68, v69, v73, v75")
endif()

if(_property STREQUAL "VERSION")
Expand Down Expand Up @@ -160,6 +161,9 @@ function(_get_hexagon_sdk_property_impl
elseif(_property STREQUAL "QURT_INCLUDE")
# Set the Hexagon arch directory for runtime linker.
set(_rtld_dir "hexagon_toolv84_${_hexagon_arch}")
if(_hexagon_arch STREQUAL "v75")
set(_rtld_dir "hexagon_toolv87_v75") # Use hexagon_toolv87_v75 for v75
endif()
if(_hexagon_arch STREQUAL "v69")
set(_rtld_dir "hexagon_toolv84_v68") # Use hexagon_toolv84_v68 for v69
endif()
Expand Down
15 changes: 10 additions & 5 deletions python/tvm/contrib/hexagon/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,9 @@ def get_graph_debug_executor(
graph_json, graph_debug_mod, self.device, dump_root=str(dump_root)
)

def get_executor_from_factory(self, module: Union[ExecutorFactoryModule, relax.Executable]):
def get_executor_from_factory(
self, module: Union[ExecutorFactoryModule, relax.Executable], hexagon_arch: str = "v68"
):
"""Create a local GraphModule which consumes a remote libmod.
Parameters
Expand All @@ -296,13 +298,15 @@ def get_executor_from_factory(self, module: Union[ExecutorFactoryModule, relax.E
The module to upload to the remote
session and load.
hexagon_arch : str
The hexagon arch to be used
"""
if isinstance(module, AOTExecutorFactoryModule):
return self._aot_executor_from_factory(module)
if isinstance(module, GraphExecutorFactoryModule):
return self._graph_executor_from_factory(module)
if isinstance(module, relax.Executable):
return self._relax_vm_executable_executor(module)
return self._relax_vm_executable_executor(module, hexagon_arch=hexagon_arch)

raise TypeError(f"Unsupported executor type: {type(module)}")

Expand Down Expand Up @@ -354,7 +358,7 @@ def _graph_executor_from_factory(
"""
return self.get_graph_executor(module.get_graph_json(), module.get_lib())

def _relax_vm_executable_executor(self, vm_exec: relax.Executable):
def _relax_vm_executable_executor(self, vm_exec: relax.Executable, hexagon_arch: str):
"""Create a local TVM module which consumes a remote vm executable.
Paramters
Expand All @@ -363,7 +367,8 @@ def _relax_vm_executable_executor(self, vm_exec: relax.Executable):
vm_exec : relax.Executable
The Relax VM Executable to upload to the remote and load. This will typically be the
output of `relax.build`.
hexagon_arch : str
The hexagon arch to be used
Returns
-------
TVMModule :
Expand All @@ -377,7 +382,7 @@ def _relax_vm_executable_executor(self, vm_exec: relax.Executable):
vm_exec.mod.export_library(
path_exec,
fcompile=hexagon.create_aot_shared,
hexagon_arch="v68",
hexagon_arch=hexagon_arch,
)

path = self.upload(path_exec, "exec.so")
Expand Down
3 changes: 2 additions & 1 deletion python/tvm/target/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ def get_arch_version(cpu_ver):
return int(m.group(1))

# Check for valid codegen cpu
valid_hex = ["v65", "v66", "v67", "v67t", "v68", "v69", "v71", "v73"]
valid_hex = ["v65", "v66", "v67", "v67t", "v68", "v69", "v71", "v73", "v75"]
try:
cpu_ver = cpu_ver[cpu_ver.index("v") :].lower()
assert cpu_ver in valid_hex
Expand All @@ -731,6 +731,7 @@ def get_vtcm_capacity(cpu_ver):
"v68": 4 * one_mb,
"v69": 8 * one_mb,
"v73": 8 * one_mb,
"v75": 8 * one_mb,
}
return default_vtcm_sizes.get(cpu_ver, 0)

Expand Down
4 changes: 2 additions & 2 deletions src/runtime/hexagon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ ANDROID_ABI=aarch64-v8a
ANDROID_PLATFORM=android-28
CMAKE_TOOLCHAIN_FILE=/path/to/android-ndk/build/cmake/android.toolchain.cmake
USE_HEXAGON=ON
USE_HEXAGON_ARCH=v65|v66|v68|v69|v73
USE_HEXAGON_ARCH=v65|v66|v68|v69|v73|v75
USE_HEXAGON_SDK=/path/to/sdk
```

Expand All @@ -63,7 +63,7 @@ Building for Hexagon requires setting the C/C++ compiler to `hexagon-clang/++`:
CMAKE_C_COMPILER=hexagon-clang
CMAKE_CXX_COMPILER=hexagon-clang++
USE_HEXAGON=ON
USE_HEXAGON_ARCH=v65|v66|v68|v69|v73
USE_HEXAGON_ARCH=v65|v66|v68|v69|v73|v75
USE_HEXAGON_SDK=/path/to/sdk
USE_RPC=OFF
USE_LIBBACKTRACE=OFF
Expand Down
7 changes: 7 additions & 0 deletions src/runtime/hexagon/rpc/simulator/session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,10 @@ std::string SimulatorRPCChannel::Cpu_::str() const {
#ifdef HEX_CPU_ID_V73NA_1
case HEX_CPU_V73:
return "v73";
#endif
#ifdef HEX_CPU_ID_V75NA_1
case HEX_CPU_V75:
return "v75";
#endif
default:
break;
Expand Down Expand Up @@ -574,6 +578,9 @@ std::optional<HEXAPI_Cpu> SimulatorRPCChannel::GetCPU(const detail::MaybeString&
#endif
#ifdef HEX_CPU_ID_V73NA_1
.Case("v73", HEX_CPU_V73)
#endif
#ifdef HEX_CPU_ID_V75NA_1
.Case("v75", HEX_CPU_V75)
#endif
.Default(std::nullopt);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/python/contrib/test_hexagon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ cd build
cmake -DANDROID_ABI=arm64-v8a \
-DANDROID_PLATFORM=android-28 \
-DUSE_ANDROID_TOOLCHAIN="path to `android-ndk/build/cmake/android.toolchain.cmake` file" \
-DUSE_HEXAGON_ARCH=v65|v66|v68|v69|v73 \
-DUSE_HEXAGON_ARCH=v65|v66|v68|v69|v73|v75 \
-DUSE_HEXAGON_SDK="path to Hexagon SDK" \
-DUSE_HEXAGON_TOOLCHAIN="path to Hexagon toolchain `Tools` sub-directory which explained above" \
-DUSE_OUTPUT_BINARY_DIR="path to `build/hexagon_api_output` which is a sub-directory of `tvm`" ..
Expand Down

0 comments on commit 26cf77c

Please sign in to comment.