Skip to content

Commit

Permalink
[RUNTIME] Hexagon driver for offloading kernels to simulator (apache#…
Browse files Browse the repository at this point in the history
…5492)

* [RUNTIME] Hexagon driver for offloading kernels to simulator

* Add sim_dev as external project when building with Hexagon/sim support

* Change target CPU for sim_dev to v60
  • Loading branch information
Krzysztof Parzyszek authored and Trevor Morris committed Jun 8, 2020
1 parent 8e21d89 commit 76a3069
Show file tree
Hide file tree
Showing 8 changed files with 1,112 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmake/modules/Hexagon.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# specific language governing permissions and limitations
# under the License.

include(ExternalProject)

set(PICK_SIM "sim")
set(PICK_HW "target")
set(PICK_NONE "OFF")
Expand Down Expand Up @@ -77,6 +79,13 @@ if(USE_HEXAGON_DEVICE STREQUAL "${PICK_SIM}")
include_directories("${HEXAGON_TOOLCHAIN}/include/iss")
link_directories("${HEXAGON_TOOLCHAIN}/lib/iss")
list(APPEND TVM_RUNTIME_LINKER_LIBS "-lwrapper")
ExternalProject_Add(sim_dev
SOURCE_DIR "${CMAKE_SOURCE_DIR}/src/runtime/hexagon/sim/driver"
CMAKE_ARGS
"-DCMAKE_C_COMPILER=${HEXAGON_TOOLCHAIN}/bin/hexagon-clang"
"-DCMAKE_CXX_COMPILER=${HEXAGON_TOOLCHAIN}/bin/hexagon-clang++"
INSTALL_COMMAND "true"
)
elseif(USE_HEXAGON_DEVICE STREQUAL "${PICK_HW}")
find_hexagon_sdk_root()
find_hexagon_toolchain()
Expand Down
62 changes: 62 additions & 0 deletions src/runtime/hexagon/sim/driver/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# 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.

project(SIM_DEV C CXX)
cmake_minimum_required(VERSION 3.0.2)

set(CMAKE_SYSTEM_NAME "Linux")

if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/config.cmake)
include(${CMAKE_CURRENT_BINARY_DIR}/config.cmake)
endif()

set(EXTRA_CXX_FLAGS
"-O2"
"-Wno-format"
"-mhvx -mhvx-length=128b"
"-mv60"
"-stdlib=libc++"
)

set(EXTRA_LINK_FLAGS
"-stdlib=libc++"
"-G0"
"-Wl,--force-dynamic"
"-Wl,--export-dynamic"
"-Wl,--whole-archive" # This should link entire libc, libc++ and libc+abi.
"-Wl,--defsym=HEAP_SIZE=0x40000000"
)

string(REGEX REPLACE ";" " " EXTRA_CXX_FLAGS_STR "${EXTRA_CXX_FLAGS}")
string(REGEX REPLACE ";" " " EXTRA_LINK_FLAGS_STR "${EXTRA_LINK_FLAGS}")

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${EXTRA_CXX_FLAGS_STR} ${CMAKE_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${EXTRA_LINK_FLAGS_STR} ${CMAKE_EXE_LINKER_FLAGS}")

# Set project properties.

file(GLOB SOURCE_FILES "*.cc")
add_executable(sim_dev ${SOURCE_FILES})
target_include_directories(sim_dev
PUBLIC "."
PUBLIC ".."
PUBLIC "../../../../../include"
PUBLIC "../../../../../3rdparty/dlpack/include"
)

target_link_libraries(sim_dev "-ldl")
38 changes: 38 additions & 0 deletions src/runtime/hexagon/sim/driver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!--- 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. -->

# Hexagon simulator driver

The driver (`sim_dev` executable) is the process running on the Hexagon simulator that handles the Hexagon-side communication with the TVM runtime running on x86. The location of `sim_dev` should be added to `PATH` before running any python code that uses Hexagon. The `sim_dev` executable is not intended to be run by users, it is automatically loaded by the simulator control code (in `hexagon_device_sim.cc`).

### Prerequisites

1. Hexagon C/C++ toolchain (such as the one in Hexagon SDK version 3.5.0 or later).

Hexagon SDK is available at //developer.qualcomm.com/software/hexagon-dsp-sdk.

### Configuring

Set
```
CMAKE_C_COMPILER=hexagon-clang
CMAKE_CXX_COMPILER=hexagon-clang++
```

### Building

There are no special options required for `make` (or the tool selected with `cmake`). The location of the resulting binary `sim_dev` should be added to `PATH`.
Loading

0 comments on commit 76a3069

Please sign in to comment.