Skip to content

Commit

Permalink
fix compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
victoryang00 committed Oct 25, 2023
1 parent 105a518 commit 535a7d3
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- uses: actions/checkout@v2

- name: Install Dependency
run: brew install cxxopts fmt llvm@14
run: brew install cxxopts fmt llvm@14 google-benchmark

- name: Checkout
run: git submodule update --init
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- uses: actions/checkout@v2

- name: Install Dependency
run: sudo apt install libssl-dev gcc-13 g++-13 libprotobuf-c-dev libprotobuf-dev libgrpc-dev libfmt-dev llvm-14-dev libedit-dev libcxxopts-dev libpfm4-dev liblldb-dev
run: sudo apt install libssl-dev gcc-13 g++-13 libprotobuf-c-dev libprotobuf-dev libgrpc-dev libfmt-dev llvm-14-dev libedit-dev libcxxopts-dev libpfm4-dev liblldb-dev libgoogle-benchmark-dev

- name: Checkout
run: git submodule update --init
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
git clone https://github.com/microsoft/vcpkg
cd vcpkg
./bootstrap-vcpkg.bat
./vcpkg install fmt:x64-windows cxxopts:x64-windows
./vcpkg install fmt:x64-windows cxxopts:x64-windows google-benchmark:x64-windows
echo "C:/tools/msys64/usr/bin/" >> "$GITHUB_PATH"
C:/tools/msys64/usr/bin/pacman.exe --noconfirm -S gcc
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ build
.idea
cmake-*
.cache
.DS_Store
.DS_Store
foo
54 changes: 26 additions & 28 deletions bench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,30 @@ add_executable(mvvm_benchmark bench.cpp)
target_link_libraries(mvvm_benchmark benchmark)
include(ExternalProject)

# add_subdirectory(gapbs)
# add_subdirectory(clickhouse)
# ExternalProject_Add(gapbs
# SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/gapbs
# UPDATE_COMMAND ""
# PATCH_COMMAND ""
# CONFIGURE_COMMAND ${CMAKE_COMMAND}
# -DCMAKE_C_COMPILER_WORKS=1 -DCMAKE_CXX_COMPILER_WORKS=1
# -GNinja
# -DWASI_SDK_DIR=${WASI_SDK_DIR}
# -DCMAKE_TOOLCHAIN_FILE=${WASI_SDK_DIR}/share/cmake/wasi-sdk.cmake
# -DCMAKE_SYSROOT=${WASI_SDK_DIR}/share/wasi-sysroot
# ${CMAKE_CURRENT_SOURCE_DIR}/gapbs
# BUILD_COMMAND ${CMAKE_COMMAND} --build .
# )
ExternalProject_Add(gapbs
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/gapbs
UPDATE_COMMAND ""
PATCH_COMMAND ""
CONFIGURE_COMMAND ${CMAKE_COMMAND}
-DCMAKE_C_COMPILER_WORKS=1 -DCMAKE_CXX_COMPILER_WORKS=1
-GNinja
-DWASI_SDK_DIR=${WASI_SDK_DIR}
-DCMAKE_TOOLCHAIN_FILE=${WASI_SDK_DIR}/share/cmake/wasi-sdk.cmake
-DCMAKE_SYSROOT=${WASI_SDK_DIR}/share/wasi-sysroot
${CMAKE_CURRENT_SOURCE_DIR}/gapbs
BUILD_COMMAND ${CMAKE_COMMAND} --build .
)

# ExternalProject_Add(clickhouse
# SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/clickhouse
# UPDATE_COMMAND ""
# PATCH_COMMAND ""
# CONFIGURE_COMMAND ${CMAKE_COMMAND}
# -DCMAKE_C_COMPILER_WORKS=1 -DCMAKE_CXX_COMPILER_WORKS=1
# -GNinja
# -DWASI_SDK_DIR=${WASI_SDK_DIR}
# -DCMAKE_TOOLCHAIN_FILE=${WASI_SDK_DIR}/share/cmake/wasi-sdk.cmake
# -DCMAKE_SYSROOT=${WASI_SDK_DIR}/share/wasi-sysroot
# ${CMAKE_CURRENT_SOURCE_DIR}/clickhouse
# BUILD_COMMAND ${CMAKE_COMMAND} --build .
# )
ExternalProject_Add(clickhouse
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/clickhouse
UPDATE_COMMAND ""
PATCH_COMMAND ""
CONFIGURE_COMMAND ${CMAKE_COMMAND}
-DCMAKE_C_COMPILER_WORKS=1 -DCMAKE_CXX_COMPILER_WORKS=1
-GNinja
-DWASI_SDK_DIR=${WASI_SDK_DIR}
-DCMAKE_TOOLCHAIN_FILE=${WASI_SDK_DIR}/share/cmake/wasi-sdk.cmake
-DCMAKE_SYSROOT=${WASI_SDK_DIR}/share/wasi-sysroot
${CMAKE_CURRENT_SOURCE_DIR}/clickhouse
BUILD_COMMAND ${CMAKE_COMMAND} --build .
)
24 changes: 12 additions & 12 deletions include/wamr_module_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ struct WAMRModuleInstance {
memories.push_back(local_mem);
}
global_data = std::vector<uint8>(env->global_data, env->global_data + env->global_data_size);
LOGV(DEBUG) << env->global_data_size;
for (int i = 0; i < env->global_data_size; i++) {
LOGV(DEBUG) << env->global_data[i];
}
// tables = std::vector<WASMTableInstance>(env->tables, env->tables + env->table_count);
LOGV(DEBUG) << env->global_data_size;
for (int i = 0; i < env->global_data_size; i++) {
LOGV(DEBUG) << env->global_data[i];
}
// tables = std::vector<WASMTableInstance>(env->tables, env->tables + env->table_count);
tables.reserve(env->table_count);
std::generate_n(
std::back_inserter(tables), env->table_count,
Expand All @@ -156,13 +156,13 @@ struct WAMRModuleInstance {
}
memcpy(env->global_data, global_data.data(), global_data.size());
env->global_data_size = global_data.size();
// env->global_data = global_data.data();
// env->global_data_size = global_data.size() - 1;
LOGV(DEBUG) << env->global_data_size;
LOGV(DEBUG) << env->global_data;
for (int i = 0; i < env->global_data_size; i++) {
LOGV(DEBUG) << env->global_data[i];
}
// env->global_data = global_data.data();
// env->global_data_size = global_data.size() - 1;
LOGV(DEBUG) << env->global_data_size;
LOGV(DEBUG) << env->global_data;
for (int i = 0; i < env->global_data_size; i++) {
LOGV(DEBUG) << env->global_data[i];
}
env->table_count = tables.size();
for (int i = 0; i < env->table_count; i++) {
*env->tables[i] = tables[i];
Expand Down
13 changes: 7 additions & 6 deletions include/wamr_module_instance_extra.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef MVVM_WAMR_MODULE_INSTANCE_EXTRA_H
#define MVVM_WAMR_MODULE_INSTANCE_EXTRA_H

#if WASM_ENABLE_WASI_NN!=0
#if WASM_ENABLE_WASI_NN != 0
#include "wamr_wasi_nn_context.h"
#endif
#include "wasm_runtime.h"
Expand Down Expand Up @@ -42,27 +42,28 @@ struct WAMRModuleInstanceExtra {
// WASMModuleInstance *next;
// #endif
//
#if WASM_ENABLE_WASI_NN!=0
#if WASM_ENABLE_WASI_NN != 0
WAMRWASINNContext wasi_nn_ctx{};
#endif
void dump_impl(WASMModuleInstanceExtra *env) {
global_count = env->global_count;
function_count = env->function_count;
#if WASM_ENABLE_WASI_NN!=0
#if WASM_ENABLE_WASI_NN != 0
dump(&wasi_nn_ctx, env->wasi_nn_ctx);
#endif
};
void restore_impl(WASMModuleInstanceExtra *env) const {
void restore_impl(WASMModuleInstanceExtra *env) {
env->global_count = global_count;
env->function_count = function_count;
#if WASM_ENABLE_WASI_NN!=0
#if WASM_ENABLE_WASI_NN != 0
restore(&wasi_nn_ctx, env->wasi_nn_ctx);
#endif
};
};

template <SerializerTrait<WASMModuleInstanceExtra *> T> void dump(T t, WASMModuleInstanceExtra *env) {
t->dump_impl(env); }
t->dump_impl(env);
}

template <SerializerTrait<WASMModuleInstanceExtra *> T> void restore(T t, WASMModuleInstanceExtra *env) {
t->restore_impl(env);
Expand Down
2 changes: 1 addition & 1 deletion include/wamr_wasi_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct SocketMetaData {
int domain{};
int type{};
int protocol{};
SocketAddrPool socketAddress;
SocketAddrPool socketAddress{};
};

struct WAMRWASIContext {
Expand Down
40 changes: 34 additions & 6 deletions include/wamr_wasi_nn_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,46 @@

#ifndef MVVM_WAMR_WASI_NN_CONTEXT_H
#define MVVM_WAMR_WASI_NN_CONTEXT_H
#include "wamr_serializer.h
#include "tensorflow/lite/interpreter.h"
#include "tensorflow/lite/model.h"
#include "wamr_serializer.h"
#include "wasi_nn.h"
#include "wasi_nn_private.h"
#include <memory>
#include <vector>
// https://github.com/WebAssembly/wasi-nn/blob/0f77c48ec195748990ff67928a4b3eef5f16c2de/wasi-nn.wit.md
/* Maximum number of graphs per WASM instance */
#define MAX_GRAPHS_PER_INST 10
/* Maximum number of graph execution context per WASM instance*/
#define MAX_GRAPH_EXEC_CONTEXTS_PER_INST 10

struct WAMRWASINNGraph {
std::vector<uint8_t> buffer;
};

struct WAMRWASINNInterpreter {
// std::unique_ptr<tflite::Interpreter> interpreter;
uint32_t a; //placeholder
};

struct WAMRWASINNModel {
// std::unique_ptr<tflite::FlatBufferModel> model;
execution_target target;
};

struct WAMRWASINNContext {
bool is_initialized;
graph_encoding current_encoding;
std::vector<WAMRWASINNGraph> graph; // TODO: support multiple graph
uint32_t current_models;
Model models[MAX_GRAPHS_PER_INST];
WAMRWASINNModel models[MAX_GRAPHS_PER_INST];
uint32_t current_interpreters;
Interpreter interpreters[MAX_GRAPH_EXEC_CONTEXTS_PER_INST];
};
WAMRWASINNInterpreter interpreters[MAX_GRAPH_EXEC_CONTEXTS_PER_INST];

template <SerializerTrait<WAMRWASINNContext *> T> void dump(T t, WASINNContext *env) { t->dump_impl(env); }
void dump_impl(WASINNContext *env);
void restore_impl(WASINNContext *env);
};

template <SerializerTrait<WAMRWASINNContext *> T> void restore(T t, WASINNContext *env) { t->restore_impl(env); }
template <SerializerTrait<WASINNContext *> T> void dump(T t, WASINNContext *env) { t->dump_impl(env); }
template <SerializerTrait<WASINNContext *> T> void restore(T t, WASINNContext *env) { t->restore_impl(env); }
#endif // MVVM_WAMR_WASI_NN_CONTEXT_H
52 changes: 26 additions & 26 deletions src/checkpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
WAMRInstance *wamr = nullptr;
std::ostringstream re{};
auto writer = FwriteStream("test.bin");
constinit std::vector<std::unique_ptr<WAMRExecEnv>> as;
constinit std::mutex as_mtx;
std::vector<std::unique_ptr<WAMRExecEnv>> as;
std::mutex as_mtx;
/**fopen, fseek*/
void insert_fd(int fd, const char *path, int flags, int offset) {
printf("\n #insert_fd(fd,filename,flags, offset) %d %s %d %d \n\n",fd, path,flags, offset);
printf("\n #insert_fd(fd,filename,flags, offset) %d %s %d %d \n\n", fd, path, flags, offset);

if (wamr->fd_map_.find(fd) != wamr->fd_map_.end()) {
LOGV(ERROR) << "fd already exist" << fd;
if(offset == 0) {
if (offset == 0) {
// fOpen call
std::string curPath;
int curFlags;
Expand All @@ -41,7 +41,7 @@ void insert_fd(int fd, const char *path, int flags, int offset) {
std::tie(curPath, curFlags, curOffset) = wamr->fd_map_[fd];
wamr->fd_map_[fd] = std::make_tuple(curPath, curFlags, offset);
}

} else
wamr->fd_map_.insert(std::make_pair(fd, std::make_tuple(std::string(path), flags, offset)));
}
Expand All @@ -51,18 +51,18 @@ void remove_fd(int fd) {
if (wamr->fd_map_.find(fd) != wamr->fd_map_.end())
wamr->fd_map_.erase(fd);
else
LOGV(ERROR)<< "fd not found" << fd;
LOGV(ERROR) << "fd not found" << fd;
}

/*
create fd-socketmetadata map and store the "domain", "type", "protocol" value
*/
void insert_socket(int fd, int domain, int type, int protocol){
printf("\n #insert_socket(fd, domain, type, protocol) %d %d %d %d \n\n",fd, domain, type, protocol);
void insert_socket(int fd, int domain, int type, int protocol) {
printf("\n #insert_socket(fd, domain, type, protocol) %d %d %d %d \n\n", fd, domain, type, protocol);

if (wamr->socket_fd_map_.find(fd) != wamr->socket_fd_map_.end()) {
LOGV(ERROR) << "socket_fd already exist" << fd;
} else{
} else {
SocketMetaData metaData{};
metaData.domain = domain;
metaData.type = type;
Expand All @@ -72,21 +72,21 @@ void insert_socket(int fd, int domain, int type, int protocol){
}

void update_socket_fd_address(int fd, SocketAddrPool *address) {
printf("\n #update_socket_fd_address(fd, address) %d \n\n",fd);
printf("\n #update_socket_fd_address(fd, address) %d \n\n", fd);

if (wamr->socket_fd_map_.find(fd) == wamr->socket_fd_map_.end()) {
// note: ? fd here is not same as insert_socket?
// set default value
insert_socket(fd, 0, 0, 0);
}
}

SocketMetaData metaData{};
metaData.domain = wamr->socket_fd_map_[fd].domain;
metaData.type = wamr->socket_fd_map_[fd].type;
metaData.protocol = wamr->socket_fd_map_[fd].protocol;

metaData.socketAddress.port = address->port;
if(address->is_4) {
if (address->is_4) {
metaData.socketAddress.is_4 = true;
metaData.socketAddress.ip4[0] = address->ip4[0];
metaData.socketAddress.ip4[1] = address->ip4[1];
Expand All @@ -104,23 +104,24 @@ void update_socket_fd_address(int fd, SocketAddrPool *address) {
metaData.socketAddress.ip6[7] = address->ip6[7];
}
wamr->socket_fd_map_[fd] = metaData;

}

void serialize_to_file(WASMExecEnv *instance) {
/** Sounds like AoT/JIT is in this?*/
// Note: insert fd
std::ifstream stdoutput; stdoutput.open("output.txt");
std:string current_str;
std::ifstream stdoutput;
stdoutput.open("output.txt");
std:
string current_str;
std::string fd_output;
std::string filename_output;
std::string flags_output;
if(stdoutput.is_open()) {
while(stdoutput.good()) {

if (stdoutput.is_open()) {
while (stdoutput.good()) {
stdoutput >> current_str;
if(current_str == "fopen_test(fd,filename,flags)") {
stdoutput >> fd_output;
if (current_str == "fopen_test(fd,filename,flags)") {
stdoutput >> fd_output;
stdoutput >> filename_output;
stdoutput >> flags_output;
insert_fd(std::stoi(fd_output), filename_output.c_str(), std::stoi(flags_output), 0);
Expand Down Expand Up @@ -203,8 +204,7 @@ int main(int argc, char *argv[]) {
options.add_options()("t,target", "The webassembly file to execute",
cxxopts::value<std::string>()->default_value("./test/counter.wasm"))(
"j,jit", "Whether the jit mode or interp mode", cxxopts::value<bool>()->default_value("false"))(
"d,dir", "The directory list exposed to WAMR",
cxxopts::value<std::vector<std::string>>()->default_value("./"))(
"d,dir", "The directory list exposed to WAMR", cxxopts::value<std::vector<std::string>>()->default_value("./"))(
"m,map_dir", "The mapped directory list exposed to WAMRe",
cxxopts::value<std::vector<std::string>>()->default_value(""))(
"e,env", "The environment list exposed to WAMR",
Expand All @@ -231,7 +231,7 @@ int main(int argc, char *argv[]) {
wamr = new WAMRInstance(target.c_str(), is_jit);
wamr->set_wasi_args(dir, map_dir, env, arg, addr, ns_pool);
wamr->instantiate();
freopen("output.txt","w",stdout);
freopen("output.txt", "w", stdout);

#ifndef MVVM_DEBUG
// Define the sigaction structure
Expand Down
1 change: 0 additions & 1 deletion src/wamr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ void WAMRInstance::set_wasi_args(const std::vector<std::string> &dir_list, const
wasm_runtime_set_wasi_addr_pool(module, addr_.data(), addr_.size());
wasm_runtime_set_wasi_ns_lookup_pool(module, ns_pool_.data(), ns_pool_.size());
}
void restart_execution(uint32 id) {}
void WAMRInstance::set_wasi_args(WAMRWASIContext &context) {
auto get_addr_from_context = [](const WAMRWASIContext &wasiContext) {
auto addr_pool = std::vector<std::string>(wasiContext.addr_pool.size());
Expand Down
Loading

0 comments on commit 535a7d3

Please sign in to comment.