Skip to content

Commit

Permalink
[Hexagon] -Build Hexagon runtime components using the Hexagon SDK (Cl…
Browse files Browse the repository at this point in the history
…one of #7671) (#7741)

* Add CMakeLists.txt to build the hexagon_remote runtime.

* Print an error message if libhalide_hexagon_host.so is not found.

* Fix case mismatch in hexagon_remote/CMakeLists.txt

* Remove some code that had been commented out in hexagon_remote/CMakeLists.txt

* Remove unused argument in macro in hexagon_remote/CMakeLists.txt

* add find module for Hexagon

* move more variables to find module

* Build binary modules with ExternalProject

* group platform-speicifc sources into subdirectories

* Pass HEXAGON_TOOLS_ROOT, too

* Use the desired layout for the build-tree artifacts

* Use SYSTEM for Hexagon SDK include dirs

* trigger buildbots

* Ignore code in src/runtime/hexagon_remote/bin/src for clang-tidy

* Just skip hexagon_remote entirely for Halide_CLANG_TIDY_BUILD

* Add an option to enable the building of the hexagon remote runtime

---------

Co-authored-by: Alex Reinking <quic_areinkin@quicinc.com>
Co-authored-by: Steven Johnson <srj@google.com>
  • Loading branch information
3 people committed Aug 21, 2023
1 parent 708d41b commit fcc1c3b
Show file tree
Hide file tree
Showing 19 changed files with 261 additions and 3 deletions.
92 changes: 92 additions & 0 deletions cmake/FindHexagonSDK.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
include(FindPackageHandleStandardArgs)

##
# Find the Hexagon SDK root

# We use the presense of the hexagon toolchain file to determine the SDK
# root. Other files have names that are too generic (like readme.txt) or
# are platform-specific (like setup_sdk_env.source) to and so can't be
# used to autodetect the path. Plus, we need to find this file anyway.

find_path(
HEXAGON_SDK_ROOT build/cmake/hexagon_toolchain.cmake
HINTS ENV HEXAGON_SDK_ROOT
)

##
# Detect the installed Hexagon tools version

if (NOT DEFINED HEXAGON_TOOLS_VER AND DEFINED ENV{HEXAGON_TOOLS_VER})
set(HEXAGON_TOOLS_VER "$ENV{HEXAGON_TOOLS_VER}")
endif ()

if (NOT DEFINED HEXAGON_TOOLS_VER)
# No other way to list a directory; no need for CONFIGURE_DEPENDS here
# since this is just used to initialize a cache variable.
file(
GLOB tools_versions
RELATIVE "${HEXAGON_SDK_ROOT}/tools/HEXAGON_Tools"
"${HEXAGON_SDK_ROOT}/tools/HEXAGON_Tools/*"
)
if (NOT tools_versions STREQUAL "")
list(GET tools_versions 0 HEXAGON_TOOLS_VER)
endif ()
endif ()

set(HEXAGON_TOOLS_VER "${HEXAGON_TOOLS_VER}"
CACHE STRING "Version of the Hexagon tools to use")

set(HEXAGON_TOOLS_ROOT "${HEXAGON_SDK_ROOT}/tools/HEXAGON_Tools/${HEXAGON_TOOLS_VER}")

##
# Set known paths

set(HEXAGON_TOOLCHAIN ${HEXAGON_SDK_ROOT}/build/cmake/hexagon_toolchain.cmake)
set(HEXAGON_QAIC ${HEXAGON_SDK_ROOT}/ipc/fastrpc/qaic/Ubuntu16/qaic)

set(ANDROID_NDK_ROOT ${HEXAGON_SDK_ROOT}/tools/android-ndk-r19c)
set(ANDROID_NDK_TOOLCHAIN ${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake)

##
# Find ISS wrapper library and headers

find_library(
HEXAGON_ISS_WRAPPER_LIBRARY
NAMES wrapper
HINTS "${HEXAGON_TOOLS_ROOT}"
PATH_SUFFIXES Tools/lib/iss lib/iss iss
)

find_path(
HEXAGON_ISS_WRAPPER_INCLUDE_DIRECTORY
NAMES HexagonWrapper.h
HINTS "${HEXAGON_TOOLS_ROOT}"
PATH_SUFFIXES Tools/include/iss include/iss iss
)

##
# Validate we found everything correctly

find_package_handle_standard_args(
HexagonSDK
REQUIRED_VARS
HEXAGON_SDK_ROOT
HEXAGON_TOOLS_ROOT
HEXAGON_TOOLCHAIN
HEXAGON_ISS_WRAPPER_LIBRARY
HEXAGON_ISS_WRAPPER_INCLUDE_DIRECTORY
HANDLE_COMPONENTS
)

##
# Create imported targets

if (HexagonSDK_FOUND AND NOT TARGET HexagonSDK::wrapper)
add_library(HexagonSDK::wrapper UNKNOWN IMPORTED)
set_target_properties(
HexagonSDK::wrapper
PROPERTIES
IMPORTED_LOCATION "${HEXAGON_ISS_WRAPPER_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${HEXAGON_ISS_WRAPPER_INCLUDE_DIRECTORY}"
)
endif ()
4 changes: 4 additions & 0 deletions src/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,8 @@ add_library(Halide_Runtime INTERFACE)
add_library(Halide::Runtime ALIAS Halide_Runtime)
target_include_directories(Halide_Runtime INTERFACE $<BUILD_INTERFACE:${Halide_BINARY_DIR}/include>)
set_target_properties(Halide_Runtime PROPERTIES EXPORT_NAME Runtime)
option(Halide_BUILD_HEXAGON_REMOTE_RUNTIME "Build the hexagon remote runtime for offloading to Hexagon (HVX)" OFF)

if (Halide_BUILD_HEXAGON_REMOTE_RUNTIME AND NOT Halide_CLANG_TIDY_BUILD)
add_subdirectory(hexagon_remote)
endif ()
6 changes: 5 additions & 1 deletion src/runtime/hexagon_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ WEAK int init_hexagon_runtime(void *user_context) {
if (!host_lib) {
host_lib = halide_load_library("libhalide_hexagon_host.dll");
}

if (!host_lib) {
// This will now cause a more specific error 'halide_error_code_symbol_not_found' down the line.
// So, just print this message and continue on instead of returning a generic error here.
error(user_context) << "Hexagon: unable to load libhalide_hexagon_host.so";
}
debug(user_context) << "Hexagon: init_hexagon_runtime (user_context: " << user_context << ")\n";

// Get the symbols we need from the library.
Expand Down
74 changes: 74 additions & 0 deletions src/runtime/hexagon_remote/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
include(ExternalProject)

find_package(HexagonSDK REQUIRED)

add_custom_command(
OUTPUT
halide_hexagon_remote.h
halide_hexagon_remote_skel.c
halide_hexagon_remote_stub.c
COMMAND ${HEXAGON_QAIC} -I ${HEXAGON_SDK_ROOT}/incs/stddef ${CMAKE_CURRENT_SOURCE_DIR}/halide_hexagon_remote.idl
DEPENDS halide_hexagon_remote.idl
VERBATIM
)

add_custom_target(
halide_hexagon_remote_idl
DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/halide_hexagon_remote.h
${CMAKE_CURRENT_BINARY_DIR}/halide_hexagon_remote_skel.c
${CMAKE_CURRENT_BINARY_DIR}/halide_hexagon_remote_stub.c
)

set(common_cache_args
"-DHALIDE_HEXAGON_REMOTE_IDL:PATH=${CMAKE_CURRENT_BINARY_DIR}"
"-DHEXAGON_SDK_ROOT:PATH=${HEXAGON_SDK_ROOT}"
"-DHEXAGON_TOOLS_ROOT:PATH=${HEXAGON_TOOLS_ROOT}"
"-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>"
)

if (CMAKE_BUILD_TYPE)
list(APPEND common_cache_args "-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}")
endif ()

ExternalProject_Add(
hexagon_remote-qurt
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/qurt"
CMAKE_CACHE_ARGS
"-DCMAKE_TOOLCHAIN_FILE:FILEPATH=${HEXAGON_TOOLCHAIN}"
${common_cache_args}
PREFIX hexagon
DEPENDS halide_hexagon_remote_idl
CONFIGURE_HANDLED_BY_BUILD ON
)

set(arm_abis armeabi-v7a arm64-v8a)
set(arm_bits 32 64)
foreach (abi bits IN ZIP_LISTS arm_abis arm_bits)
ExternalProject_Add(
halide_hexagon_host-${abi}
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android"
CMAKE_CACHE_ARGS
"-DCMAKE_TOOLCHAIN_FILE:FILEPATH=${ANDROID_NDK_TOOLCHAIN}"
"-DANDROID_ABI:STRING=${abi}"
"-DANDROID_PLATFORM:STRING=21"
${common_cache_args}
PREFIX arm-${bits}-android
DEPENDS halide_hexagon_remote_idl
CONFIGURE_HANDLED_BY_BUILD ON
)
endforeach ()

add_library(halide_hexagon_host SHARED sim_host.cpp sim_protocol.h)
target_compile_features(halide_hexagon_host PRIVATE cxx_std_17)
target_include_directories(halide_hexagon_host PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/..)
target_link_libraries(halide_hexagon_host PRIVATE HexagonSDK::wrapper)

add_custom_target(hexagon_remote)
add_dependencies(
hexagon_remote
hexagon_remote-qurt
halide_hexagon_host
halide_hexagon_host-armeabi-v7a
halide_hexagon_host-arm64-v8a
)
41 changes: 41 additions & 0 deletions src/runtime/hexagon_remote/android/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
cmake_minimum_required(VERSION 3.22)
project(halide-hexagon_remote-android)

set(_aarch64 "")
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
set(_aarch64 "_aarch64")
endif ()

add_library(fastrpc::cdsprpc SHARED IMPORTED)
set_target_properties(
fastrpc::cdsprpc
PROPERTIES
IMPORTED_LOCATION "${HEXAGON_SDK_ROOT}/ipc/fastrpc/remote/ship/android${_aarch64}/libcdsprpc.so"
)

add_library(
halide_hexagon_host
MODULE
${HALIDE_HEXAGON_REMOTE_IDL}/halide_hexagon_remote_stub.c
host_malloc.cpp
host_shim.cpp
libadsprpc_shim.cpp
)
target_include_directories(
halide_hexagon_host
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../..
)
target_include_directories(
halide_hexagon_host
SYSTEM PRIVATE
${HALIDE_HEXAGON_REMOTE_IDL}
${HEXAGON_SDK_ROOT}/incs
${HEXAGON_SDK_ROOT}/incs/stddef
)
target_link_libraries(halide_hexagon_host PRIVATE fastrpc::cdsprpc log)

install(
TARGETS halide_hexagon_host
DESTINATION bin
)
File renamed without changes.
File renamed without changes.
43 changes: 43 additions & 0 deletions src/runtime/hexagon_remote/qurt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
cmake_minimum_required(VERSION 3.22)

# The Hexagon toolchain is broken
set(ENV{HEXAGON_SDK_ROOT} "${HEXAGON_SDK_ROOT}")
set(ENV{HEXAGON_TOOLS_ROOT} "${HEXAGON_TOOLS_ROOT}")

project(halide-hexagon_remote-qurt)

add_library(sim_qurt STATIC sim_qurt.cpp sim_qurt_vtcm.cpp)
target_include_directories(sim_qurt SYSTEM PRIVATE ${HALIDE_HEXAGON_REMOTE_IDL})

add_executable(
hexagon_sim_remote
known_symbols.cpp
sim_remote.cpp
$<TARGET_OBJECTS:sim_qurt>
)
target_include_directories(
hexagon_sim_remote
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/..
${CMAKE_CURRENT_SOURCE_DIR}/../..
)
target_include_directories(hexagon_sim_remote SYSTEM PRIVATE ${HALIDE_HEXAGON_REMOTE_IDL})
target_link_libraries(hexagon_sim_remote PRIVATE ${CMAKE_DL_LIBS})

add_library(
halide_hexagon_remote_skel
MODULE
c11_stubs.cpp
halide_remote.cpp
known_symbols.cpp
log.cpp
nearbyint.cpp
${HALIDE_HEXAGON_REMOTE_IDL}/halide_hexagon_remote_skel.c
)
target_include_directories(halide_hexagon_remote_skel PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../..)
target_include_directories(halide_hexagon_remote_skel SYSTEM PRIVATE ${HALIDE_HEXAGON_REMOTE_IDL})

install(
TARGETS sim_qurt hexagon_sim_remote halide_hexagon_remote_skel
DESTINATION bin
)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ extern "C" {
#include "known_symbols.h"
#include "log.h"

const int stack_alignment = 128;
const int stack_size = 1024 * 1024;
// const int stack_alignment = 128;
// const int stack_size = 1024 * 1024;

typedef halide_hexagon_remote_handle_t handle_t;
typedef halide_hexagon_remote_buffer buffer;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit fcc1c3b

Please sign in to comment.