Skip to content
Closed
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
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ tvm_option(USE_OPENMP "Build with OpenMP thread pool implementation" OFF)
tvm_option(USE_RELAY_DEBUG "Building Relay in debug mode..." OFF)
tvm_option(USE_RTTI "Build with RTTI" ON)
tvm_option(USE_MSVC_MT "Build with MT" OFF)
tvm_option(USE_MICRO "Build with Micro TVM support" OFF)
tvm_option(INSTALL_DEV "Install compiler infrastructure" OFF)
tvm_option(HIDE_PRIVATE_SYMBOLS "Compile with -fvisibility=hidden." OFF)
tvm_option(USE_TF_TVMDSOOP "Build with TensorFlow TVMDSOOp" OFF)
Expand Down Expand Up @@ -115,6 +114,12 @@ tvm_option(USE_CLML "Build with CLML Codegen support" OFF)
tvm_option(USE_CLML_GRAPH_EXECUTOR "Build with CLML graph runtime" OFF)
tvm_option(USE_UMA "Build with UMA support" OFF)

if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "iOS")
set(USE_MICRO true)
else()
set(USE_MICRO false)
endif()

# include directories
include_directories(${CMAKE_INCLUDE_PATH})
include_directories("include")
Expand Down
3 changes: 3 additions & 0 deletions apps/hexagon_api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ ExternalProject_Add(x86_tvm_runtime_rpc
"-DUSE_HEXAGON_RPC=ON"
"-DBUILD_STATIC_RUNTIME=ON"
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
"-DUSE_MICRO=OFF"
INSTALL_COMMAND ""
BUILD_ALWAYS ON
)
Expand Down Expand Up @@ -88,6 +89,7 @@ ExternalProject_Add(android_tvm_runtime_rpc
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
"-DUSE_ALTERNATIVE_LINKER=OFF"
"-DUSE_RANDOM=ON"
"-DUSE_MICRO=OFF"
INSTALL_COMMAND ""
BUILD_ALWAYS ON
)
Expand Down Expand Up @@ -136,6 +138,7 @@ ExternalProject_Add(hexagon_tvm_runtime_rpc
"-DUSE_HEXAGON_QHL=ON"
"-DUSE_RANDOM=ON"
"${GTEST_FLAG}"
"-DUSE_MICRO=OFF"
INSTALL_COMMAND ""
BUILD_ALWAYS ON
)
Expand Down
3 changes: 0 additions & 3 deletions cmake/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ set(USE_SPIRV_KHR_INTEGER_DOT_PRODUCT OFF)
# Whether enable OpenGL runtime
set(USE_OPENGL OFF)

# Whether enable MicroTVM runtime
set(USE_MICRO OFF)

# Whether enable RPC runtime
set(USE_RPC ON)

Expand Down
1 change: 1 addition & 0 deletions cmake/modules/StandaloneCrt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ if(USE_MICRO)
"include/tvm/runtime c_*_api.h -> include/tvm/runtime"
"include/tvm/runtime metadata_types.h -> include/tvm/runtime"
"include/tvm/runtime/crt *.h -> include/tvm/runtime/crt"
"include/tvm/support ssize.h -> include/tvm/support"
"src/runtime/crt Makefile -> ."
"src/runtime/crt/include *.h -> include"
"src/runtime/crt/aot_executor *.c -> src/runtime/crt/aot_executor"
Expand Down
3 changes: 2 additions & 1 deletion include/tvm/runtime/crt/rpc_common/framing.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <stddef.h>
#include <tvm/runtime/crt/error_codes.h>
#include <tvm/runtime/crt/rpc_common/write_stream.h>
#include <tvm/support/ssize.h>

namespace tvm {
namespace runtime {
Expand Down Expand Up @@ -143,7 +144,7 @@ class Unframer {

class Framer {
public:
typedef ssize_t (*WriteFunc)(const uint8_t* data, size_t data_size_bytes);
typedef tvm_ssize_t (*WriteFunc)(const uint8_t* data, size_t data_size_bytes);

explicit Framer(WriteStream* stream)
: stream_{stream}, state_{State::kReset}, num_payload_bytes_remaining_{0} {}
Expand Down
11 changes: 10 additions & 1 deletion include/tvm/runtime/crt/rpc_common/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <tvm/runtime/crt/rpc_common/frame_buffer.h>
#include <tvm/runtime/crt/rpc_common/framing.h>
#include <tvm/runtime/crt/rpc_common/write_stream.h>
#include <tvm/support/ssize.h>

namespace tvm {
namespace runtime {
Expand All @@ -43,10 +44,18 @@ enum class MessageType : uint8_t {
kNormal = 0x10,
};

#if defined(_MSC_VER)
#pragma pack(4)
typedef struct SessionHeader {
uint16_t session_id;
MessageType message_type;
} SessionHeader;
#else
typedef struct SessionHeader {
uint16_t session_id;
MessageType message_type;
} __attribute__((packed)) SessionHeader;
#endif

/*!
* \brief CRT communication session management class.
Expand Down Expand Up @@ -187,7 +196,7 @@ class Session {
explicit SessionReceiver(Session* session) : session_{session} {}
virtual ~SessionReceiver() {}

ssize_t Write(const uint8_t* data, size_t data_size_bytes) override;
tvm_ssize_t Write(const uint8_t* data, size_t data_size_bytes) override;
void PacketDone(bool is_valid) override;

private:
Expand Down
3 changes: 2 additions & 1 deletion include/tvm/runtime/crt/rpc_common/write_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <stddef.h>
#include <sys/types.h>
#include <tvm/runtime/crt/error_codes.h>
#include <tvm/support/ssize.h>

namespace tvm {
namespace runtime {
Expand All @@ -37,7 +38,7 @@ namespace micro_rpc {
class WriteStream {
public:
virtual ~WriteStream();
virtual ssize_t Write(const uint8_t* data, size_t data_size_bytes) = 0;
virtual tvm_ssize_t Write(const uint8_t* data, size_t data_size_bytes) = 0;
virtual void PacketDone(bool is_valid) = 0;

tvm_crt_error_t WriteAll(uint8_t* data, size_t data_size_bytes, size_t* bytes_consumed);
Expand Down
12 changes: 8 additions & 4 deletions src/support/ssize.h → include/tvm/support/ssize.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@

/*!
* \file ssize.h
* \brief this file aims to define ssize_t for Windows platform
* \brief this file aims to define tvm_ssize_t.
*/

#ifndef TVM_SUPPORT_SSIZE_H_
#define TVM_SUPPORT_SSIZE_H_

#include <sys/types.h>

#if defined(_MSC_VER)
#if defined(_WIN32)
using ssize_t = int32_t;
#if defined(_WIN64)
typedef int64_t tvm_ssize_t;
#else
using ssize_t = int64_t;
typedef int32_t tvm_ssize_t;
#endif
#else
typedef ssize_t tvm_ssize_t;
#endif

#endif // TVM_SUPPORT_SSIZE_H_
2 changes: 1 addition & 1 deletion src/runtime/crt/microtvm_rpc_common/write_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ tvm_crt_error_t WriteStream::WriteAll(uint8_t* data, size_t data_size_bytes,
size_t* bytes_consumed) {
*bytes_consumed = 0;
while (data_size_bytes > 0) {
ssize_t to_return = Write(data, data_size_bytes);
tvm_ssize_t to_return = Write(data, data_size_bytes);
if (to_return == 0) {
return kTvmErrorWriteStreamShortWrite;
} else if (to_return < 0) {
Expand Down
9 changes: 7 additions & 2 deletions src/runtime/micro/micro_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <tvm/runtime/crt/rpc_common/session.h>
#include <tvm/runtime/logging.h>
#include <tvm/runtime/registry.h>
#include <tvm/support/ssize.h>

#include <algorithm>
#include <chrono>
Expand All @@ -52,7 +53,7 @@ class CallbackWriteStream : public WriteStream {
explicit CallbackWriteStream(PackedFunc fsend, ::std::chrono::microseconds write_timeout)
: fsend_{fsend}, write_timeout_{write_timeout} {}

ssize_t Write(const uint8_t* data, size_t data_size_bytes) override {
tvm_ssize_t Write(const uint8_t* data, size_t data_size_bytes) override {
TVMByteArray bytes;
bytes.data = (const char*)data;
bytes.size = data_size_bytes;
Expand All @@ -62,7 +63,7 @@ class CallbackWriteStream : public WriteStream {
fsend_(bytes, write_timeout_.count());
}

return static_cast<ssize_t>(data_size_bytes);
return static_cast<tvm_ssize_t>(data_size_bytes);
}

void PacketDone(bool is_valid) override {}
Expand Down Expand Up @@ -180,7 +181,11 @@ class MicroTransportChannel : public RPCChannel {
}
uint8_t initial_nonce = 0;
for (int i = 0; i < kNumRandRetries && initial_nonce == 0; ++i) {
#if defined(_MSC_VER)
initial_nonce = rand();
#else
initial_nonce = rand_r(&seed);
#endif
}
random_seed.store(seed);
ICHECK_NE(initial_nonce, 0) << "rand() does not seem to be producing random values";
Expand Down
7 changes: 4 additions & 3 deletions src/runtime/minrpc/minrpc_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include <string.h>
#include <tvm/runtime/c_runtime_api.h>
#include <tvm/support/ssize.h>

#include <memory>
#include <utility>
Expand Down Expand Up @@ -150,7 +151,7 @@ class MinRPCReturns : public MinRPCReturnInterface {
const uint8_t* buf = static_cast<const uint8_t*>(data);
size_t ndone = 0;
while (ndone < size) {
ssize_t ret = io_->PosixWrite(buf, size - ndone);
tvm_ssize_t ret = io_->PosixWrite(buf, size - ndone);
if (ret <= 0) {
this->ThrowError(RPCServerStatus::kWriteError);
}
Expand Down Expand Up @@ -526,7 +527,7 @@ class MinRPCExecute : public MinRPCExecInterface {
uint8_t* buf = static_cast<uint8_t*>(data);
size_t ndone = 0;
while (ndone < size) {
ssize_t ret = io_->PosixRead(buf, size - ndone);
tvm_ssize_t ret = io_->PosixRead(buf, size - ndone);
if (ret <= 0) return ret;
ndone += ret;
buf += ret;
Expand Down Expand Up @@ -757,7 +758,7 @@ class MinRPCServer {
uint8_t* buf = static_cast<uint8_t*>(data);
size_t ndone = 0;
while (ndone < size) {
ssize_t ret = io_->PosixRead(buf, size - ndone);
tvm_ssize_t ret = io_->PosixRead(buf, size - ndone);
if (ret == 0) {
if (allow_clean_shutdown_) {
Shutdown();
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/minrpc/minrpc_server_logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class MinRPCSniffer {
uint8_t* buf = reinterpret_cast<uint8_t*>(data);
size_t ndone = 0;
while (ndone < size) {
ssize_t ret = io_->PosixRead(buf, size - ndone);
tvm_ssize_t ret = io_->PosixRead(buf, size - ndone);
if (ret <= 0) {
this->ThrowError(RPCServerStatus::kReadError);
return false;
Expand Down
6 changes: 3 additions & 3 deletions src/runtime/rpc/rpc_channel_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
#define TVM_RUNTIME_RPC_RPC_CHANNEL_LOGGER_H_

#include <tvm/runtime/c_runtime_api.h>
#include <tvm/support/ssize.h>

#include <memory>
#include <utility>

#include "../../support/ssize.h"
#include "../minrpc/minrpc_server_logging.h"
#include "rpc_channel.h"

Expand Down Expand Up @@ -99,11 +99,11 @@ class SnifferIOHandler {

void MessageStart(size_t message_size_bytes) {}

ssize_t PosixWrite(const uint8_t* buf, size_t buf_size_bytes) { return 0; }
tvm_ssize_t PosixWrite(const uint8_t* buf, size_t buf_size_bytes) { return 0; }

void MessageDone() {}

ssize_t PosixRead(uint8_t* buf, size_t buf_size_bytes) {
tvm_ssize_t PosixRead(uint8_t* buf, size_t buf_size_bytes) {
return receive_buffer_->Read(buf, buf_size_bytes);
}

Expand Down
4 changes: 2 additions & 2 deletions src/runtime/rpc/rpc_socket_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ class SockChannel final : public RPCChannel {
}
}
size_t Send(const void* data, size_t size) final {
ssize_t n = sock_.Send(data, size);
tvm_ssize_t n = sock_.Send(data, size);
if (n == -1) {
support::Socket::Error("SockChannel::Send");
}
return static_cast<size_t>(n);
}
size_t Recv(void* data, size_t size) final {
ssize_t n = sock_.Recv(data, size);
tvm_ssize_t n = sock_.Recv(data, size);
if (n == -1) {
support::Socket::Error("SockChannel::Recv");
}
Expand Down
16 changes: 8 additions & 8 deletions src/support/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@
#endif
#include <tvm/runtime/logging.h>
#include <tvm/runtime/registry.h>
#include <tvm/support/ssize.h>

#include <cstring>
#include <string>
#include <unordered_map>
#include <vector>

#include "../support/ssize.h"
#include "../support/utils.h"

#if defined(_WIN32)
Expand Down Expand Up @@ -378,8 +378,8 @@ class Socket {
* \return The return code returned by function f or error_value on retry failure.
*/
template <typename FuncType>
ssize_t RetryCallOnEINTR(FuncType func) {
ssize_t ret = func();
tvm_ssize_t RetryCallOnEINTR(FuncType func) {
tvm_ssize_t ret = func();
// common path
if (ret != -1) return ret;
// less common path
Expand Down Expand Up @@ -497,7 +497,7 @@ class TCPSocket : public Socket {
* \return size of data actually sent
* return -1 if error occurs
*/
ssize_t Send(const void* buf_, size_t len, int flag = 0) {
tvm_ssize_t Send(const void* buf_, size_t len, int flag = 0) {
const char* buf = reinterpret_cast<const char*>(buf_);
return RetryCallOnEINTR(
[&]() { return send(sockfd, buf, static_cast<sock_size_t>(len), flag); });
Expand All @@ -510,7 +510,7 @@ class TCPSocket : public Socket {
* \return size of data actually received
* return -1 if error occurs
*/
ssize_t Recv(void* buf_, size_t len, int flags = 0) {
tvm_ssize_t Recv(void* buf_, size_t len, int flags = 0) {
char* buf = reinterpret_cast<char*>(buf_);
return RetryCallOnEINTR(
[&]() { return recv(sockfd, buf, static_cast<sock_size_t>(len), flags); });
Expand All @@ -526,8 +526,8 @@ class TCPSocket : public Socket {
const char* buf = reinterpret_cast<const char*>(buf_);
size_t ndone = 0;
while (ndone < len) {
ssize_t ret = RetryCallOnEINTR(
[&]() { return send(sockfd, buf, static_cast<ssize_t>(len - ndone), 0); });
tvm_ssize_t ret = RetryCallOnEINTR(
[&]() { return send(sockfd, buf, static_cast<tvm_ssize_t>(len - ndone), 0); });
if (ret == -1) {
if (LastErrorWouldBlock()) return ndone;
Socket::Error("SendAll");
Expand All @@ -548,7 +548,7 @@ class TCPSocket : public Socket {
char* buf = reinterpret_cast<char*>(buf_);
size_t ndone = 0;
while (ndone < len) {
ssize_t ret = RetryCallOnEINTR(
tvm_ssize_t ret = RetryCallOnEINTR(
[&]() { return recv(sockfd, buf, static_cast<sock_size_t>(len - ndone), MSG_WAITALL); });
if (ret == -1) {
if (LastErrorWouldBlock()) {
Expand Down
1 change: 0 additions & 1 deletion tests/scripts/task_config_build_arm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ cp ../cmake/config.cmake .

echo set\(USE_SORT ON\) >> config.cmake
echo set\(USE_RPC ON\) >> config.cmake
echo set\(USE_MICRO ON\) >> config.cmake
echo set\(USE_MICRO_STANDALONE_RUNTIME ON\) >> config.cmake
echo set\(USE_PROFILER ON\) >> config.cmake
echo set\(USE_LLVM llvm-config-8\) >> config.cmake
Expand Down
1 change: 0 additions & 1 deletion tests/scripts/task_config_build_cortexm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ cd "$BUILD_DIR"
cp ../cmake/config.cmake .

echo set\(USE_SORT ON\) >> config.cmake
echo set\(USE_MICRO ON\) >> config.cmake
echo set\(USE_CMSISNN ON\) >> config.cmake
echo set\(USE_ETHOSU ON\) >> config.cmake
echo set\(USE_UMA ON\) >> config.cmake
Expand Down
1 change: 0 additions & 1 deletion tests/scripts/task_config_build_cpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ cd "$BUILD_DIR"
cp ../cmake/config.cmake .

echo set\(USE_SORT ON\) >> config.cmake
echo set\(USE_MICRO ON\) >> config.cmake
echo set\(USE_MICRO_STANDALONE_RUNTIME ON\) >> config.cmake
echo set\(USE_PROFILER ON\) >> config.cmake
echo set\(USE_DNNL ON\) >> config.cmake
Expand Down
1 change: 0 additions & 1 deletion tests/scripts/task_config_build_gpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ echo set\(USE_CUDA ON\) >> config.cmake
echo set\(USE_VULKAN ON\) >> config.cmake
echo set\(USE_OPENGL ON\) >> config.cmake
echo set\(USE_OPENCL ON\) >> config.cmake
echo set\(USE_MICRO ON\) >> config.cmake
echo set\(USE_MICRO_STANDALONE_RUNTIME ON\) >> config.cmake
echo set\(USE_LLVM \"/usr/bin/llvm-config-9 --link-static\"\) >> config.cmake
echo set\(USE_NNPACK ON\) >> config.cmake
Expand Down
1 change: 0 additions & 1 deletion tests/scripts/task_config_build_gpu_other.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ cp ../cmake/config.cmake .

echo set\(USE_OPENCL ON\) >> config.cmake
echo set\(USE_ROCM ON\) >> config.cmake
echo set\(USE_MICRO ON\) >> config.cmake
echo set\(USE_PROFILER ON\) >> config.cmake
echo set\(USE_LIBBACKTRACE OFF\) >> config.cmake
echo set\(CMAKE_CXX_FLAGS -Werror\) >> config.cmake
Expand Down
Loading