Skip to content

Commit

Permalink
Refactor: separate sim and device runtimes into their own directories
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzysztof Parzyszek committed May 13, 2019
1 parent 89c7a7c commit 02253e7
Show file tree
Hide file tree
Showing 13 changed files with 250 additions and 339 deletions.
5 changes: 4 additions & 1 deletion cmake/modules/Hexagon.cmake
Expand Up @@ -71,18 +71,21 @@ if(USE_HEXAGON STREQUAL "sim")
find_hexagon_toolchain()
message(STATUS "Hexagon toolchain: ${HEXAGON_TOOLCHAIN}")
add_definitions("-DHEXAGON_TOOLCHAIN=\"${HEXAGON_TOOLCHAIN}\"")
file(GLOB RUNTIME_HEXAGON_SIM_SRCS src/runtime/hexagon/sim/*.cc)
include_directories("${HEXAGON_TOOLCHAIN}/include/iss")
elseif(USE_HEXAGON STREQUAL "device")
find_hexagon_sdk_root()
find_hexagon_toolchain()
message(STATUS "Hexagon SDK: ${HEXAGON_SDK_ROOT}")
add_definitions("-DHEXAGON_TOOLCHAIN=\"${HEXAGON_TOOLCHAIN}\"")
file(GLOB RUNTIME_HEXAGON_DEVICE_SRCS src/runtime/hexagon/device/*.cc)
include_directories("${HEXAGON_SDK_ROOT}/incs/stddef")
include_directories("${HEXAGON_SDK_ROOT}/libs/common/rpcmem/inc")
include_directories("${HEXAGON_SDK_ROOT}/libs/common/remote/ship")
include_directories("${HEXAGON_TOOLCHAIN}/include/iss")
endif()

file(GLOB RUNTIME_HEXAGON_SRCS src/runtime/hexagon/*.cc)
list(APPEND RUNTIME_SRCS ${RUNTIME_HEXAGON_SRCS})
list(APPEND RUNTIME_SRCS ${RUNTIME_HEXAGON_SRCS} ${RUNTIME_HEXAGON_SIM_SRCS}
${RUNTIME_HEXAGON_DEVICE_SRCS})
list(APPEND TVM_RUNTIME_LINKER_LIBS "-ldl")
Expand Up @@ -25,8 +25,8 @@
* permitted use with any of the "vta" and "verilog" subdirectories in the TVM
* repo.
*/
#ifndef TVM_RUNTIME_HEXAGON_FASTRPC_TVM_HEXAGON_REMOTE_H_
#define TVM_RUNTIME_HEXAGON_FASTRPC_TVM_HEXAGON_REMOTE_H_
#ifndef TVM_RUNTIME_HEXAGON_DEVICE_FASTRPC_TVM_HEXAGON_REMOTE_H_
#define TVM_RUNTIME_HEXAGON_DEVICE_FASTRPC_TVM_HEXAGON_REMOTE_H_
/// @file tvm_hexagon_remote.idl
///
// qidl copyright
Expand Down Expand Up @@ -107,8 +107,8 @@ __QAIC_HEADER_EXPORT int __QAIC_HEADER(tvm_hexagon_remote_unmap_buffer_to_dsp)(
remote_handle64 _h, uint64 dsp_va,
tvm_hexagon_remote_handle_t bufferLen) __QAIC_HEADER_ATTRIBUTE;
__QAIC_HEADER_EXPORT int __QAIC_HEADER(tvm_hexagon_remote_load_library)(
remote_handle64 _h, const char* soname, int sonameLen,
const char* code, int codeLen,
remote_handle64 _h, const char* soname, int sonameLen, const char* code,
int codeLen,
tvm_hexagon_remote_handle_t* module_ptr) __QAIC_HEADER_ATTRIBUTE;
__QAIC_HEADER_EXPORT int __QAIC_HEADER(tvm_hexagon_remote_get_symbol)(
remote_handle64 _h, tvm_hexagon_remote_handle_t module_ptr,
Expand All @@ -135,4 +135,4 @@ __QAIC_HEADER_EXPORT int __QAIC_HEADER(tvm_hexagon_remote_release_library)(
#ifdef __cplusplus
}
#endif
#endif // TVM_RUNTIME_HEXAGON_FASTRPC_TVM_HEXAGON_REMOTE_H_
#endif // TVM_RUNTIME_HEXAGON_DEVICE_FASTRPC_TVM_HEXAGON_REMOTE_H_
File renamed without changes.
Expand Up @@ -26,21 +26,67 @@
* repo.
*/
#ifdef __ANDROID__
#include "hexagon_device_target.h"

#include <tvm/runtime/device_api.h>
#include <tvm/runtime/registry.h>
#include <android/log.h>
#include <llvm/ADT/STLExtras.h>
#include <unistd.h>

#include <map>
#include <memory>
#include <string>
#include <utility>

#include "../hexagon_module.h"
#include "AEEStdErr.h"
#include "fastrpc/tvm_hexagon_remote.h"
#include "rpcmem.h"

#pragma weak remote_session_control

#define RPCMEM_HEAP 25
#define LOG_TVM __android_log_print

namespace tvm {
namespace runtime {
namespace hexagon {

class HexagonTarget : public tvm::runtime::hexagon::Device {
public:
HexagonTarget() {}
~HexagonTarget() final {}
void* Alloc(unsigned size, unsigned align) final;
void Free(void* ptr) final;
void Copy(void* dst, const void* src, unsigned len) final;
void CopyFrom(void* host_dst, const void* src, unsigned len) final;
void CopyTo(void* dst, const void* host_src, unsigned len) final;
void* Load(const std::string& data, const std::string& fmt) final;
void Unload(void* mod) final;
void* Resolve(const std::string& sym) final;
void Call(void* func, uint32_t* scalar, unsigned sc_num, uint32_t* stack,
unsigned st_num) final;
int CdspSsrHandler(void* func, uint32_t* scalar, unsigned sc_num,
uint32_t* stack, unsigned st_num,
tvm_hexagon_remote_buffer* scalar_octet, int scalar_num,
tvm_hexagon_remote_buffer* stack_octet, int stack_num,
uint64* pcycles, uint64* execution_time_usec);

private:
std::map<uint64_t, uint64_t> dsp_address_mapping_;
std::map<uint64_t, uint64_t> dsp_size_mapping_;
remote_handle64 domain_channel_handle_ = AEE_EUNKNOWN;
tvm_hexagon_remote_handle_t module_pointer_ = AEE_EUNKNOWN;
tvm_hexagon_remote_handle_t pf_ = AEE_EUNKNOWN;
uint64_t count_channel_open_ = 0;
std::string lib_name_;
std::string symbol_name_;
std::string format_;
};

std::unique_ptr<Device> CreateHexagonTarget() {
// C++11 does not have std::make_unique.
return llvm::make_unique<HexagonTarget>();
}

void* HexagonTarget::Alloc(unsigned size, unsigned align) {
if (domain_channel_handle_ == AEE_EUNKNOWN) {
if (remote_session_control) {
Expand Down
172 changes: 0 additions & 172 deletions src/runtime/hexagon/hexagon_device_sim.h

This file was deleted.

82 changes: 0 additions & 82 deletions src/runtime/hexagon/hexagon_device_target.h

This file was deleted.

0 comments on commit 02253e7

Please sign in to comment.