Skip to content

Commit

Permalink
add library
Browse files Browse the repository at this point in the history
  • Loading branch information
victoryang00 committed Feb 5, 2024
1 parent c3177b5 commit f6211b4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 71 deletions.
37 changes: 4 additions & 33 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ set(CMAKE_CXX_STANDARD 23)

find_package(fmt REQUIRED)
# find_package(LLVM REQUIRED)
find_package(benchmark REQUIRED)
find_package(cxxopts REQUIRED)
# find_package(benchmark REQUIRED)
# find_package(cxxopts REQUIRED)
include(CTest)
if (WIN32)
set(WASI_SDK_DIR D:/wasi-sdk/)
Expand All @@ -19,40 +19,20 @@ if (APPLE)
set(WAMR_BUILD_LIB_WASI_THREADS 1)
set(WAMR_BUILD_THREAD_MGR 1)
set(WAMR_BUILD_PLATFORM "darwin")
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)")
set(BLAS_LIBRARIES /opt/homebrew/opt/openblas/lib/libopenblas.0.dylib)
else ()
set(BLAS_LIBRARIES /usr/local/opt/openblas/lib/libopenblas.0.dylib)
endif ()
find_path(BLAS_INCLUDE_DIRS cblas.h
/opt/homebrew/opt/openblas/include
/usr/local/opt/openblas/include
$ENV{BLAS_HOME}/include)
message(${BLAS_INCLUDE_DIRS})
elseif (LINUX)
set(WAMR_BUILD_PLATFORM "linux")
set(WAMR_BUILD_LIB_PTHREAD 1)
set(WAMR_BUILD_LIB_PTHREAD_SEMAPHORE 1)
set(WAMR_BUILD_LIB_WASI_THREADS 1)
set(WAMR_BUILD_THREAD_MGR 1)
set(BLAS_LIBRARIES -lopenblas)
find_path(BLAS_INCLUDE_DIRS cblas.h
/usr/include
/usr/local/include
/opt/OpenBLAS/include/
$ENV{BLAS_HOME}/include)
message(${BLAS_INCLUDE_DIRS})
else ()
set(WAMR_BUILD_PLATFORM "windows")
set(WAMR_BUILD_LIBC_UVWASI 1)
set(CMAKE_MSVC_RUNTIME_LIBRARY "")
set(CMAKE_GENERATOR_PLATFORM "")
set(CMAKE_CXX_FLAGS "/MD")
set(WIN_EXTRA_LIBS uvwasi_a uv_a ws2_32)
if(MVVM_BUILD_TEST)
set(BLAS_LIBRARIES "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.1/lib/x64/cublas.lib" "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.1/lib/x64/cudart.lib")
set(BLAS_INCLUDE_DIRS "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.1/include/")
endif()
endif ()

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
Expand Down Expand Up @@ -109,7 +89,7 @@ include(${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE})

include(${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/lib/wasm-micro-runtime/core/iwasm/aot ${CMAKE_CURRENT_SOURCE_DIR}/lib/yalantinglibs/include ${LLVM_INCLUDE_DIRS} ${BLAS_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/lib/libcrafter/libcrafter/)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/lib/wasm-micro-runtime/core/iwasm/aot ${CMAKE_CURRENT_SOURCE_DIR}/lib/yalantinglibs/include ${LLVM_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/lib/libcrafter/libcrafter/)

if (MVVM_BUILD_BENCH)
add_subdirectory(bench)
Expand All @@ -127,14 +107,5 @@ endif ()

file(GLOB_RECURSE SOURCE_FILES src/logging.cpp src/wamr*.cpp)
add_library(MVVM_export ${SOURCE_FILES} ${UNCOMMON_SHARED_SOURCE})
add_executable(MVVM_restore src/restore.cpp ${UNCOMMON_SHARED_SOURCE})
add_executable(MVVM_checkpoint src/checkpoint.cpp ${UNCOMMON_SHARED_SOURCE})

target_link_libraries(MVVM_export fmt::fmt -lm -ldl -lpthread ${BLAS_LIBRARIES})
target_link_libraries(MVVM_restore fmt::fmt cxxopts::cxxopts -lm -ldl -lpthread ${BLAS_LIBRARIES} MVVM_export vmlib ${WIN_EXTRA_LIBS})
target_link_libraries(MVVM_checkpoint fmt::fmt cxxopts::cxxopts -lm -ldl -lpthread ${BLAS_LIBRARIES} MVVM_export vmlib ${WIN_EXTRA_LIBS})
if (MVVM_BUILD_MPI)
add_executable(MVVM_mpi_test test/mpi.cpp ${UNCOMMON_SHARED_SOURCE})
target_link_libraries(MVVM_mpi_test fmt::fmt cxxopts::cxxopts -lm -ldl -lpthread ${BLAS_LIBRARIES} MVVM_export vmlib ${WIN_EXTRA_LIBS})
endif()
add_definitions(-DCXXOPTS_NO_RTTI=1)
target_link_libraries(MVVM_export fmt::fmt -lm -ldl -lpthread ${BLAS_LIBRARIES})
33 changes: 14 additions & 19 deletions include/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
#include <algorithm>
#include <cstdlib>
#include <filesystem>
#include <fmt/color.h>
#include <fmt/format.h>
#include <fmt/os.h>
#include <fmt/ostream.h>
#include <fmt/printf.h>
#include <fstream>
#include <iostream>
#include <list>
Expand All @@ -29,21 +25,21 @@
#else
#include <winsock2.h>
#endif
#ifndef __APPLE__
// #ifndef __APPLE__
/** Barry's work*/
struct Enumerate : std::ranges::range_adaptor_closure<Enumerate> {
template <std::ranges::viewable_range R> constexpr auto operator()(R &&r) const {
return std::views::zip(std::views::iota(0), (R &&)r);
}
};
#else
struct Enumerate : std::__range_adaptor_closure<Enumerate> {
template <std::ranges::viewable_range R> constexpr auto operator()(R &&r) const {
return std::views::zip(std::views::iota(0), (R &&)r);
}
};
#endif
inline constexpr Enumerate enumerate;
// struct Enumerate : std::ranges::range_adaptor_closure<Enumerate> {
// template <std::ranges::viewable_range R> constexpr auto operator()(R &&r) const {
// return std::views::zip(std::views::iota(0), (R &&)r);
// }
// };
// #else
// struct Enumerate : std::__range_adaptor_closure<Enumerate> {
// template <std::ranges::viewable_range R> constexpr auto operator()(R &&r) const {
// return std::views::zip(std::views::iota(0), (R &&)r);
// }
// };
// #endif
// inline constexpr Enumerate enumerate;
using std::list;
using std::string;
struct LocationInfo {
Expand Down Expand Up @@ -104,7 +100,6 @@ class LogStream {
};

string level2string(LogLevel level);
fmt::color level2color(LogLevel level);

#define MVVM_SOCK_ADDR "172.17.0.1"
#define MVVM_SOCK_ADDR6 "fe80::42:aeff:fe1f:b579"
Expand Down
20 changes: 2 additions & 18 deletions src/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ void LogWriter::operator<(const LogStream &stream) {

void LogWriter::output_log(const std::ostringstream &msg) {
if (log_level_ >= env_log_level)
std::cout << fmt::format(fmt::emphasis::bold | fg(level2color(log_level_)), "[{}] ({}:{} L {}) ",
std::cout << fmt::format( "[{}] ({}:{} L {}) ",
level2string(log_level_), location_.file_, location_.line_, location_.func_)
<< fmt::format(fg(level2color(log_level_)), "{}", msg.str()) << std::endl;
<< fmt::format("{}", msg.str()) << std::endl;
}
std::string level2string(LogLevel level) {
switch (level) {
Expand All @@ -32,22 +32,6 @@ std::string level2string(LogLevel level) {
return "";
}
}
fmt::color level2color(LogLevel level) {
switch (level) {
case BH_LOG_LEVEL_DEBUG:
return fmt::color::alice_blue;
case BH_LOG_LEVEL_VERBOSE:
return fmt::color::magenta;
case BH_LOG_LEVEL_FATAL:
return fmt::color::rebecca_purple;
case BH_LOG_LEVEL_WARNING:
return fmt::color::yellow;
case BH_LOG_LEVEL_ERROR:
return fmt::color::red;
default:
return fmt::color::white;
}
}

bool is_ip_in_cidr(const char *base_ip, int subnet_mask_len, uint32_t ip) {
uint32_t base_ip_bin, subnet_mask, network_addr, broadcast_addr;
Expand Down
4 changes: 3 additions & 1 deletion src/wamr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,8 @@ void WAMRInstance::recover(std::vector<std::unique_ptr<WAMRExecEnv>> *e_) {
void WAMRInstance::spawn_child(WASMExecEnv *cur_env) {
#if !defined(_WIN32)
this->as_mtx.lock();
for (auto [idx, exec_] : execEnv | enumerate) {
int idx = 0;
for (auto &exec_ : execEnv) {
if (idx + 1 == execEnv.size()) {
// the last one should be the main thread
break;
Expand Down Expand Up @@ -757,6 +758,7 @@ void WAMRInstance::spawn_child(WASMExecEnv *cur_env) {
this->as_mtx.unlock();
thread_init.acquire();
}
idx++;
}
#endif
}
Expand Down

0 comments on commit f6211b4

Please sign in to comment.