-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[RUNTIME] FastRPC interface for Hexagon runtime #5353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| # 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. | ||
|
|
||
| cmake_minimum_required(VERSION 3.2) | ||
| project(HexagonIDL C CXX) | ||
|
|
||
| if(NOT "${FASTRPC_LIBS}" STREQUAL "SKEL" AND | ||
| NOT "${FASTRPC_LIBS}" STREQUAL "STUB") | ||
| message(SEND_ERROR "Please set FASTRPC_LIBS to either SKEL or STUB") | ||
| endif() | ||
|
|
||
|
|
||
| set(FASTRPC_SRC "${CMAKE_CURRENT_SOURCE_DIR}") | ||
|
|
||
| include_directories(include) | ||
| include_directories(${HEXAGON_SDK_ROOT}/incs) | ||
| include_directories(${HEXAGON_SDK_ROOT}/incs/stddef) | ||
| include_directories( | ||
| ${HEXAGON_SDK_ROOT}/libs/common/remote/ship/android_Release_aarch64) | ||
|
|
||
| set(QAIC_EXE "${HEXAGON_SDK_ROOT}/tools/qaic/Ubuntu16/qaic") | ||
| set(QAIC_FLAGS | ||
| "-I${HEXAGON_SDK_ROOT}/incs/stddef" | ||
| "-I${HEXAGON_SDK_ROOT}/libs/common/remote/ship/android_Release_aarch64" | ||
| "-I${HEXAGON_SDK_ROOT}/libs/common/rpcmem/inc" | ||
| ) | ||
|
|
||
| set(CMAKE_SKIP_RPATH TRUE) | ||
|
|
||
| # Qaic for the non-domain header. | ||
| # | ||
| # Don't add paths to these filenames, or otherwise cmake may spontaneously | ||
| # add -o option to the qaic invocation (with an undesirable path). | ||
| set(TVM_REMOTE_ND_IDL "tvm_remote_nd.idl") | ||
| set(TVM_REMOTE_ND_H "tvm_remote_nd.h") | ||
| set(TVM_REMOTE_ND_SKEL_C "tvm_remote_nd_skel.c") | ||
| set(TVM_REMOTE_ND_STUB_C "tvm_remote_nd_stub.c") | ||
|
|
||
| add_custom_command( | ||
| OUTPUT ${TVM_REMOTE_ND_SKEL_C} ${TVM_REMOTE_ND_STUB_C} | ||
| "${FASTRPC_SRC}/include/${TVM_REMOTE_ND_H}" | ||
| COMMAND ${QAIC_EXE} ${QAIC_FLAGS} | ||
| "${FASTRPC_SRC}/include/${TVM_REMOTE_ND_IDL}" | ||
| COMMAND ${CMAKE_COMMAND} -E rename "${TVM_REMOTE_ND_H}" | ||
| "${FASTRPC_SRC}/include/${TVM_REMOTE_ND_H}" | ||
| MAIN_DEPENDENCY "${FASTRPC_SRC}/include/${TVM_REMOTE_ND_IDL}" | ||
| ) | ||
|
|
||
| # Qaic for the domain header. | ||
| # | ||
| # Don't add paths to these filenames, or otherwise cmake may spontaneously | ||
| # add -o option to the qaic invocation (with an undesirable path). | ||
| set(TVM_REMOTE_D_IDL "tvm_remote.idl") | ||
| set(TVM_REMOTE_D_H "tvm_remote.h") | ||
| set(TVM_REMOTE_D_SKEL_C "tvm_remote_skel.c") | ||
| set(TVM_REMOTE_D_STUB_C "tvm_remote_stub.c") | ||
|
|
||
| add_custom_command( | ||
| OUTPUT ${TVM_REMOTE_D_SKEL_C} ${TVM_REMOTE_D_STUB_C} | ||
| "${FASTRPC_SRC}/include/${TVM_REMOTE_D_H}" | ||
| COMMAND ${QAIC_EXE} ${QAIC_FLAGS} | ||
| "${FASTRPC_SRC}/include/${TVM_REMOTE_D_IDL}" | ||
| COMMAND ${CMAKE_COMMAND} -E rename "${TVM_REMOTE_D_H}" | ||
| "${FASTRPC_SRC}/include/${TVM_REMOTE_D_H}" | ||
| MAIN_DEPENDENCY "${FASTRPC_SRC}/include/${TVM_REMOTE_D_IDL}" | ||
| ) | ||
|
|
||
|
|
||
| if("${FASTRPC_LIBS}" STREQUAL "SKEL") | ||
| # Skel libraries. | ||
| # | ||
| set(HEXARCH_DIR_v60 "ADSPv60MP") | ||
| set(HEXARCH_DIR_v62 "ADSPv62MP") | ||
| set(HEXARCH_DIR_v65 "computev65") | ||
| set(HEXARCH_DIR_v66 "computev66") | ||
| set(HEXARCH_DIR_STR "HEXARCH_DIR_${HEXAGON_ARCH}") | ||
| set(HEXARCH_DIR ${${HEXARCH_DIR_STR}}) | ||
|
|
||
| if(NOT HEXARCH_DIR) | ||
| message(SEND_ERROR | ||
| "Please set HEXAGON_ARCH to one of v60, v62, v65, v66") | ||
| endif() | ||
|
|
||
| include_directories( | ||
| ${HEXAGON_SDK_ROOT}/libs/common/qurt/${HEXARCH_DIR}/include/qurt) | ||
| include_directories( | ||
| ${HEXAGON_SDK_ROOT}/libs/common/qurt/${HEXARCH_DIR}/include/posix) | ||
|
|
||
| # Extra compile flags (both C and C++). | ||
| set(EXTRA_COMP_FLAGS | ||
| "-O3" | ||
| "-m${HEXAGON_ARCH}" | ||
| ) | ||
| string(REGEX REPLACE ";" " " EXTRA_COMP_FLAGS_STR "${EXTRA_COMP_FLAGS}") | ||
| message(STATUS "EXTRA_COMP_FLAGS_STR: ${EXTRA_COMP_FLAGS_STR}") | ||
| set(CMAKE_C_FLAGS "${EXTRA_COMP_FLAGS_STR} ${CMAKE_C_FLAGS}") | ||
| set(CMAKE_CXX_FLAGS "${EXTRA_COMP_FLAGS_STR} ${CMAKE_CXX_FLAGS}") | ||
|
|
||
| set(EXTRA_LINK_FLAGS | ||
| "-Wl,--no-threads" | ||
| "-Wl,--wrap=malloc" | ||
| "-Wl,--wrap=calloc" | ||
| "-Wl,--wrap=free" | ||
| "-Wl,--wrap=realloc" | ||
| "-Wl,--wrap=memalign" | ||
| "-Wl,--wrap=posix_memalign" | ||
| "-Wl,--wrap=__stack_chk_fail" | ||
| ) | ||
| string(REGEX REPLACE ";" " " EXTRA_LINK_FLAGS_STR "${EXTRA_LINK_FLAGS}") | ||
|
|
||
| # Extra linker flags for linking shared libraries. | ||
| set(CMAKE_SHARED_LINKER_FLAGS | ||
| "${EXTRA_LINK_FLAGS_STR} ${CMAKE_SHARED_LINKER_FLAGS}") | ||
|
|
||
| set(SKEL_ND_SRCS | ||
| "src/tvm_hvx.cc" | ||
| "src/tvm_remote_nd_imp.cc" | ||
| ) | ||
| add_library(tvm_remote_nd_skel SHARED | ||
| "${FASTRPC_SRC}/include/${TVM_REMOTE_ND_H}" | ||
| ${TVM_REMOTE_ND_SKEL_C} | ||
| ${SKEL_ND_SRCS} | ||
| ) | ||
|
|
||
| set(SKEL_D_SRCS | ||
| # Also includes src/tvm_remote_nd_imp.cc | ||
| ${SKEL_ND_SRCS} | ||
| "src/tvm_remote_imp.cc" | ||
| ) | ||
| add_library(tvm_remote_skel SHARED | ||
| "${FASTRPC_SRC}/include/${TVM_REMOTE_D_H}" | ||
| ${TVM_REMOTE_D_SKEL_C} | ||
| ${SKEL_D_SRCS} | ||
| ) | ||
|
|
||
| # Separate shared library with __wrap_pthread_create. | ||
| # It is necessary to have it as a separate library because it defines | ||
| # a function that libtvm_runtime.so will call. Because of that, this | ||
| # function needs to be in the global dynamic symbol table, but the | ||
| # skel libraries are loaded as private by FastRPC. | ||
| set(WRAP_PTHREAD_SRCS "src/tvm_wrap_pthread.cc") | ||
| add_library(tvm_wrap_pthread SHARED ${WRAP_PTHREAD_SRCS}) | ||
|
|
||
| else() | ||
| # Stub libraries. | ||
| # | ||
| include_directories(${HEXAGON_SDK_ROOT}/incs/a1std) | ||
| include_directories(${HEXAGON_SDK_ROOT}/incs/qlist) | ||
| include_directories(${HEXAGON_SDK_ROOT}/libs/common/rpcmem/inc) | ||
| link_directories( | ||
| ${HEXAGON_SDK_ROOT}/libs/common/remote/ship/android_Release_aarch64) | ||
|
|
||
| add_library(tvm_remote_nd_stub SHARED | ||
| "${FASTRPC_SRC}/include/${TVM_REMOTE_ND_H}" | ||
| "${HEXAGON_SDK_ROOT}/libs/common/rpcmem/src/rpcmem_android.c" | ||
| "${TVM_REMOTE_ND_STUB_C}" | ||
| ) | ||
| add_library(tvm_remote_stub SHARED | ||
| "${FASTRPC_SRC}/include/${TVM_REMOTE_D_H}" | ||
| "${HEXAGON_SDK_ROOT}/libs/common/rpcmem/src/rpcmem_android.c" | ||
| "${TVM_REMOTE_D_STUB_C}" | ||
| ) | ||
| target_link_libraries(tvm_remote_nd_stub adsprpc) | ||
| target_link_libraries(tvm_remote_stub adsprpc) | ||
| endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| <!--- 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 IDL libraries | ||
|
|
||
| This directory hosts IDL files and their implementations to offload TVM kernels to Hexagon via FastRPC. The implementations can be used to generate stub and skel libraries. | ||
|
|
||
| ### Prerequisites | ||
|
|
||
| 1. Android NDK version r19c or later. | ||
| 2. Hexagon SDK version 3.5.0 or later. | ||
|
|
||
| Android NDK can be downloaded from https://developer.android.com/ndk. | ||
| Hexagon SDK is available at //developer.qualcomm.com/software/hexagon-dsp-sdk. | ||
|
|
||
| ### Configuring | ||
|
|
||
| Skel and stub libraries need to be configured and built separately. Please use different subdirectories for each. Otherwise the cmake cache from one configuration can interfere with the next. | ||
|
|
||
| For skel libraries, set | ||
| ``` | ||
| FASTRPC_LIBS=SKEL | ||
| HEXAGON_SDK_ROOT=/path/to/sdk | ||
| CMAKE_C_COMPILER=hexagon-clang | ||
| CMAKE_CXX_COMPILER=hexagon-clang++ | ||
| HEXAGON_ARCH= one of v60, v62, v65, v66 | ||
| ``` | ||
|
|
||
| Please note that support for older versions of the Hexagon processor may be removed from the future versions of the Hexagon toolchain. | ||
|
|
||
|
|
||
| For stub libraries, set | ||
| ``` | ||
| FASTRPC_LIBS=STUB | ||
| HEXAGON_SDK_ROOT=/path/to/sdk | ||
| CMAKE_C_COMPILER=aarch64-linux-android28-clang # or later | ||
| CMAKE_CXX_COMPILER=aarch64-linux-android28-clang++ # or later | ||
| ``` | ||
|
|
||
| ### Building | ||
|
|
||
| In each instance, simple `make` command will create header files `fastrpc/include/tvm_remote.h` and `fastrpc/include/tvm_remote_nd.h`. These headers are needed to compile the TVM runtime for Android (and the stub/skel libraries themselves). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| /* | ||
| * IDL to offload TVM kernels to Hexagon from APPS for multi-domains. | ||
| */ | ||
| #include "remote.idl" | ||
| #include "AEEStdDef.idl" | ||
|
|
||
| interface tvm_remote : remote_handle64 { | ||
| typedef sequence<octet> buffer; | ||
| typedef unsigned long handle_t; | ||
|
|
||
| long load_library(in sequence<char> soname, | ||
| rout handle_t mod_ptr); | ||
| long get_symbol(in handle_t mod, | ||
| in sequence<char> name, | ||
| rout handle_t sym_ptr); | ||
| long kernel(in handle_t mod, | ||
| in handle_t symbol, | ||
| inrout sequence <long> scalar, | ||
| inrout sequence <long> stack, | ||
| in sequence<buffer> scalar_in_octet, | ||
| rout sequence<buffer> scalar_out_octet, | ||
| in sequence<buffer> stack_in_octet, | ||
| rout sequence<buffer> stack_out_octet, | ||
| rout unsigned long long pcycles, | ||
| rout unsigned long long time_usec); | ||
| long release_library(in handle_t mod); | ||
| long alloc_vtcm(in unsigned long size, | ||
| in unsigned long align, | ||
| rout unsigned long dsp_va); | ||
| long free_vtcm(in unsigned long dsp_va); | ||
| long call_mmap64(); | ||
| }; | ||
49 changes: 49 additions & 0 deletions
49
src/runtime/hexagon/target/fastrpc/include/tvm_remote_nd.idl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| /* | ||
| * IDL to offload TVM kernels to Hexagon from APPS for non-domains. | ||
| */ | ||
| #include "remote.idl" | ||
| #include "AEEStdDef.idl" | ||
|
|
||
| interface tvm_remote_nd { | ||
| typedef sequence<octet> buffer; | ||
| typedef unsigned long handle_t; | ||
|
|
||
| long open(); | ||
| long close(); | ||
| long load_library(in sequence<char> soname, | ||
| rout handle_t mod_ptr); | ||
| long get_symbol(in handle_t mod, | ||
| in sequence<char> name, | ||
| rout handle_t sym_ptr); | ||
| long kernel(in handle_t mod, | ||
| in handle_t symbol, | ||
| inrout sequence <long> scalar, | ||
| inrout sequence <long> stack, | ||
| in sequence<buffer> scalar_in_octet, | ||
| rout sequence<buffer> scalar_out_octet, | ||
| in sequence<buffer> stack_in_octet, | ||
| rout sequence<buffer> stack_out_octet, | ||
| rout unsigned long long pcycles, | ||
| rout unsigned long long time_usec); | ||
| long release_library(in handle_t mod); | ||
| long call_mmap64(); | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to
routto pass the value back to CPU? I assume we only needinhere. The generated type will be changed fromint*toconst int*.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps. The stub/skel code generated from IDL will do different things for
in,rout, andinroutparameters. This has to do with cache/memory synchronization that happens under the covers. It may work with justin, but we have never tried it. I'm somewhat reluctant to changing it without more testing.