Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions cmake/modules/Hexagon.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ endif()
if(USE_HEXAGON_DEVICE STREQUAL "${PICK_SIM}")
find_hexagon_toolchain()
message(STATUS "Hexagon toolchain: ${HEXAGON_TOOLCHAIN}")
file(GLOB RUNTIME_HEXAGON_SIM_SRCS src/runtime/hexagon/sim/*.cc)
file(GLOB RUNTIME_HEXAGON_SIM_SRCS src/runtime/hexagon/android/sim/*.cc)
include_directories(SYSTEM "${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"
SOURCE_DIR "${CMAKE_SOURCE_DIR}/src/runtime/hexagon/android/sim/driver"
CMAKE_ARGS
"-DCMAKE_C_COMPILER=${HEXAGON_TOOLCHAIN}/bin/hexagon-clang"
"-DCMAKE_CXX_COMPILER=${HEXAGON_TOOLCHAIN}/bin/hexagon-clang++"
Expand All @@ -88,7 +88,7 @@ if(USE_HEXAGON_DEVICE STREQUAL "${PICK_SIM}")
elseif(USE_HEXAGON_DEVICE STREQUAL "${PICK_HW}")
find_hexagon_sdk_root("${USE_HEXAGON_SDK}" "${USE_HEXAGON_ARCH}")
find_hexagon_toolchain()
file(GLOB RUNTIME_HEXAGON_DEVICE_SRCS src/runtime/hexagon/target/*.cc)
file(GLOB RUNTIME_HEXAGON_DEVICE_SRCS src/runtime/hexagon/android/target/*.cc)

include_directories(SYSTEM
${HEXAGON_SDK_INCLUDES}
Expand All @@ -102,7 +102,10 @@ elseif(USE_HEXAGON_DEVICE STREQUAL "${PICK_HW}")
endif()
endif()

file(GLOB RUNTIME_HEXAGON_SRCS src/runtime/hexagon/*.cc)
if(BUILD_FOR_HEXAGON AND USE_HEXAGON_DEVICE STREQUAL "${PICK_NONE}")
file(GLOB RUNTIME_HEXAGON_SRCS src/runtime/hexagon/hexagon/*.cc)
else()
file(GLOB RUNTIME_HEXAGON_SRCS src/runtime/hexagon/android/*.cc)
endif()
list(APPEND RUNTIME_SRCS ${RUNTIME_HEXAGON_SRCS} ${RUNTIME_HEXAGON_SIM_SRCS}
${RUNTIME_HEXAGON_DEVICE_SRCS})

135 changes: 135 additions & 0 deletions src/runtime/hexagon/android/hexagon_device.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* 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.
*/

#ifndef TVM_RUNTIME_HEXAGON_ANDROID_HEXAGON_DEVICE_H_
#define TVM_RUNTIME_HEXAGON_ANDROID_HEXAGON_DEVICE_H_

#include <tvm/runtime/logging.h>
#include <tvm/runtime/module.h>

#include <memory>
#include <string>

#include "../../meta_data.h"

namespace tvm {
namespace runtime {
namespace hexagon {

/*!
* \brief Low-level interface for communicating with Hexagon devices.
*/
class Device {
public:
/*!
* \brief Allocate memory on device.
* \param size Requested size.
* \param align Requested alignment.
* \return Pointer (local to the device) of the allocated memory,
* or nullptr if allocation failed.
*/
virtual void* Alloc(unsigned size, unsigned align) = 0;
/*!
* \brief Release allocated memory on device.
* \param ptr Pointer to memory previously allocated by \ref Alloc.
*/
virtual void Free(void* ptr) = 0;
/*!
* \brief Allocate VTCM memory on device.
* \param size Requested size.
* \param align Requested alignment.
* \return Pointer (local to the device) of the allocated memory,
* or nullptr if allocation failed.
*/
virtual void* AllocVtcm(unsigned size, unsigned align) = 0;
/*!
* \brief Release allocated VTCM memory on device.
* \param ptr Pointer to memory previously allocated by \ref AllocVtcm.
*/
virtual void FreeVtcm(void* ptr) = 0;
/*!
* \brief Copy a block of data on device to another location on the device.
* \param dst Pointer (local to device) to the destination buffer.
* \param src Pointer (local to device) of the source buffer.
* \param len Number of bytes to copy.
*/
virtual void CopyDeviceToDevice(void* dst, const void* src, unsigned len) = 0;
/*!
* \brief Copy a block of data from device to host.
* \param host_dst Pointer (local to host) to the destination buffer.
* \param src Pointer (local to device) to the source buffer.
* \param len Number of bytes to copy.
*/
virtual void CopyDeviceToHost(void* host_dst, const void* src, unsigned len) = 0;
/*!
* \brief Copy a block of data from host to device.
* \param dst Pointer (local to device) to the destination buffer.
* \param host_src Pointer (local to host) to the source buffer.
* \param len Number of bytes to copy.
*/
virtual void CopyHostToDevice(void* dst, const void* host_src, unsigned len) = 0;
/*!
* \brief Load a module (typically a shared library) into device.
* \param data Name of the shared library.
* \param fmt Format of the library (currently ignored).
* \return Pointer to the loaded module.
* \note Currently only one module can be loaded at any given time.
*/
virtual void* Load(const std::string& data, const std::string& fmt) = 0;
/*!
* \brief Unload a module from device.
* \param mod Pointer to a loaded module returned by \ref Load.
*/
virtual void Unload(void* mod) = 0;
/*!
* \brief Find the address of an object in the currently loaded module.
* \param sym Name of the object.
* \return Address of the located object, or nullptr if object was
* not found.
*/
virtual void* Resolve(const std::string& sym) = 0;
/*!
* \brief Invoke a function on device with given arguments.
* \param func Address (local to device) of the function to call.
* \param scalar Pointer to an array of 32-bit values that will be
* passed via consecutive registers: r0..r5. This array
* includes dummy values for skipped registers.
* \param sc_num Number of values in the "scalar" array.
* \param stack Pointer to an array of 32-bit values that will be
* passed on the stack. This array includes dummy values
* for padding.
* \param st_num Number of values in the "stack" array.
*/
virtual void Call(void* func, uint32_t* scalar, unsigned sc_num, uint32_t* stack,
unsigned st_num) = 0;

virtual ~Device() = 0;

static std::shared_ptr<Device> Global();
static bool ValidateDeviceId(decltype(DLDevice::device_id) device_id) {
// Only supporting a single device for now.
return device_id == 0;
}
};

} // namespace hexagon

} // namespace runtime
} // namespace tvm
#endif // TVM_RUNTIME_HEXAGON_ANDROID_HEXAGON_DEVICE_H_
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <algorithm>
#include <cstring>

#include "hexagon_module.h"
#include "hexagon_device.h"

namespace tvm {
namespace runtime {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

#include "hexagon_module.h"
#include "../hexagon_module.h"

#ifdef __ANDROID__
#include <android/log.h>
Expand All @@ -31,8 +31,8 @@
#include <unordered_map>
#include <vector>

#include "../file_utils.h"
#include "../meta_data.h"
#include "../../file_utils.h"
#include "hexagon_device.h"

namespace tvm {
namespace runtime {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ add_executable(sim_dev ${SOURCE_FILES})
target_include_directories(sim_dev
PUBLIC "."
PUBLIC ".."
PUBLIC "../../../../../include"
PUBLIC "../../../../../../include"
)
target_include_directories(sim_dev SYSTEM
PUBLIC "../../../../../3rdparty/dlpack/include"
PUBLIC "../../../../../../3rdparty/dlpack/include"
)

target_link_libraries(sim_dev "-ldl")
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* under the License.
*/

#ifndef TVM_RUNTIME_HEXAGON_SIM_DRIVER_PTHREAD_H_
#define TVM_RUNTIME_HEXAGON_SIM_DRIVER_PTHREAD_H_
#ifndef TVM_RUNTIME_HEXAGON_ANDROID_SIM_DRIVER_PTHREAD_H_
#define TVM_RUNTIME_HEXAGON_ANDROID_SIM_DRIVER_PTHREAD_H_

#define _PROVIDE_POSIX_TIME_DECLS 1
#include <time.h>
Expand Down Expand Up @@ -89,4 +89,4 @@ pthread_t pthread_self(void);
}
#endif

#endif // TVM_RUNTIME_HEXAGON_SIM_DRIVER_PTHREAD_H_
#endif // TVM_RUNTIME_HEXAGON_ANDROID_SIM_DRIVER_PTHREAD_H_
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* under the License.
*/

#ifndef TVM_RUNTIME_HEXAGON_SIM_DRIVER_SCHED_H_
#define TVM_RUNTIME_HEXAGON_SIM_DRIVER_SCHED_H_
#ifndef TVM_RUNTIME_HEXAGON_ANDROID_SIM_DRIVER_SCHED_H_
#define TVM_RUNTIME_HEXAGON_ANDROID_SIM_DRIVER_SCHED_H_

#ifdef __cplusplus
extern "C" {
Expand All @@ -28,4 +28,4 @@ int sched_yield(void);
}
#endif

#endif // TVM_RUNTIME_HEXAGON_SIM_DRIVER_SCHED_H_
#endif // TVM_RUNTIME_HEXAGON_ANDROID_SIM_DRIVER_SCHED_H_
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include <utility>
#include <vector>

#include "../hexagon_module.h"
#include "../hexagon_device.h"
#include "HexagonWrapper.h"
#include "hexagon_sim_proto.h"

Expand Down Expand Up @@ -121,7 +121,7 @@ struct non_const_str {
ICHECK_EQ(pointers_.size(), 1);
return pointers_[0];
}
operator char* *() { return pointers_.data(); }
operator char**() { return pointers_.data(); }

private:
std::vector<char*> pointers_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* under the License.
*/

#ifndef TVM_RUNTIME_HEXAGON_SIM_HEXAGON_SIM_PROTO_H_
#define TVM_RUNTIME_HEXAGON_SIM_HEXAGON_SIM_PROTO_H_
#ifndef TVM_RUNTIME_HEXAGON_ANDROID_SIM_HEXAGON_SIM_PROTO_H_
#define TVM_RUNTIME_HEXAGON_ANDROID_SIM_HEXAGON_SIM_PROTO_H_

// Protocol:

Expand Down Expand Up @@ -70,4 +70,4 @@ struct MsgCall {
uint32_t data[]; // 12
} __attribute__((packed));

#endif // TVM_RUNTIME_HEXAGON_SIM_HEXAGON_SIM_PROTO_H_
#endif // TVM_RUNTIME_HEXAGON_ANDROID_SIM_HEXAGON_SIM_PROTO_H_
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* under the License.
*/

#ifndef TVM_RUNTIME_HEXAGON_TARGET_FASTRPC_SRC_TVM_HVX_H_
#define TVM_RUNTIME_HEXAGON_TARGET_FASTRPC_SRC_TVM_HVX_H_
#ifndef TVM_RUNTIME_HEXAGON_ANDROID_TARGET_FASTRPC_SRC_TVM_HVX_H_
#define TVM_RUNTIME_HEXAGON_ANDROID_TARGET_FASTRPC_SRC_TVM_HVX_H_

// Utility providing functions for accessing the Hexagon Vector Extensions
// (HVX) hardware.
Expand Down Expand Up @@ -150,4 +150,4 @@ int cleanup_mt_job(const config_t* hvx_config);

} // namespace hvx

#endif // TVM_RUNTIME_HEXAGON_TARGET_FASTRPC_SRC_TVM_HVX_H_
#endif // TVM_RUNTIME_HEXAGON_ANDROID_TARGET_FASTRPC_SRC_TVM_HVX_H_
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <string>
#include <utility>

#include "../hexagon_module.h"
#include "../hexagon_device.h"
#include "AEEStdErr.h"
#include "fastrpc/include/tvm_remote.h"
#include "hexagon_dsprpcapi.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* under the License.
*/

#ifndef TVM_RUNTIME_HEXAGON_TARGET_HEXAGON_DSPRPCAPI_H_
#define TVM_RUNTIME_HEXAGON_TARGET_HEXAGON_DSPRPCAPI_H_
#ifndef TVM_RUNTIME_HEXAGON_ANDROID_TARGET_HEXAGON_DSPRPCAPI_H_
#define TVM_RUNTIME_HEXAGON_ANDROID_TARGET_HEXAGON_DSPRPCAPI_H_

#ifdef __ANDROID__
#include <stdint.h>
Expand Down Expand Up @@ -189,4 +189,4 @@ class DspRpcAPI {
} // namespace tvm

#endif // __ANDROID__
#endif // TVM_RUNTIME_HEXAGON_TARGET_HEXAGON_DSPRPCAPI_H_
#endif // TVM_RUNTIME_HEXAGON_ANDROID_TARGET_HEXAGON_DSPRPCAPI_H_
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* under the License.
*/

#ifndef TVM_RUNTIME_HEXAGON_TARGET_HEXAGON_STUBAPI_H_
#define TVM_RUNTIME_HEXAGON_TARGET_HEXAGON_STUBAPI_H_
#ifndef TVM_RUNTIME_HEXAGON_ANDROID_TARGET_HEXAGON_STUBAPI_H_
#define TVM_RUNTIME_HEXAGON_ANDROID_TARGET_HEXAGON_STUBAPI_H_

#ifdef __ANDROID__
#include <AEEStdErr.h>
Expand Down Expand Up @@ -312,4 +312,4 @@ class StubAPI {
} // namespace tvm

#endif // __ANDROID__
#endif // TVM_RUNTIME_HEXAGON_TARGET_HEXAGON_STUBAPI_H_
#endif // TVM_RUNTIME_HEXAGON_ANDROID_TARGET_HEXAGON_STUBAPI_H_
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* under the License.
*/

#ifndef TVM_RUNTIME_HEXAGON_TARGET_HEXAGON_TARGET_LOG_H_
#define TVM_RUNTIME_HEXAGON_TARGET_HEXAGON_TARGET_LOG_H_
#ifndef TVM_RUNTIME_HEXAGON_ANDROID_TARGET_HEXAGON_TARGET_LOG_H_
#define TVM_RUNTIME_HEXAGON_ANDROID_TARGET_HEXAGON_TARGET_LOG_H_
#ifdef __ANDROID__

#include <android/log.h>
Expand All @@ -31,4 +31,4 @@
#define TVM_LOGF(...) __android_log_print(ANDROID_LOG_FATAL, "TVM", ##__VA_ARGS__)

#endif // __ANDROID__
#endif // TVM_RUNTIME_HEXAGON_TARGET_HEXAGON_TARGET_LOG_H_
#endif // TVM_RUNTIME_HEXAGON_ANDROID_TARGET_HEXAGON_TARGET_LOG_H_
Loading