Skip to content

Commit

Permalink
[SSVM] Upgrade to 0.7.3
Browse files Browse the repository at this point in the history
  • Loading branch information
hydai committed Apr 28, 2021
1 parent a8aed2a commit e7273ab
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 29 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/external-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ jobs:
with:
submodules: recursive

- name: Set Rust to required version
run: rustup override set 1.50.0

- name: Build and install SSVM-napi
uses: './ssvm-napi/.github/actions/build-from-source'

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ jobs:
with:
submodules: recursive

- name: Set Rust to required version
run: rustup override set 1.50.0

- name: Build SSVM-napi with ${{ matrix.cc }}
uses: './ssvm-napi/.github/actions/build-from-source'
with:
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
[submodule "ssvm-tensorflow"]
path = ssvm-tensorflow
url = https://github.com/second-state/ssvm-tensorflow.git
[submodule "ssvm-image"]
path = ssvm-image
url = git@github.com:second-state/ssvm-image.git
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ For the tensorflow extensions:
* libtensorflow.so
* Please refer to the TensorFlow website for more details
```base
RUN wget https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-2.4.0.tar.gz \
wget https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-2.4.0.tar.gz \
&& tar -C /usr/local -xzf libtensorflow-cpu-linux-x86_64-2.4.0.tar.gz \
&& ldconfig
```
Expand Down Expand Up @@ -92,17 +92,19 @@ Please refer to [Tutorial: A standalone wasm32-wasi application](./Tutorial_Wasm
### Constructor: `ssvm.VM(wasm, ssvm_options) -> vm_instance`
* Create a ssvm instance by given wasm file and options.
* Arguments:
* `wasm`: Input wasm file, can be the following three formats:
* `wasm`: Input wasm file, can be the following two formats:
1. Wasm file path (String, e.g. `/tmp/hello.wasm`)
2. Wasm bytecode format which is the content of a wasm binary file (Uint8Array)
* `options`: An options object for setup the SSVM execution environment.
* `options` <JS Object>
* `args` <JS Array>: An array of strings that Wasm application will get as function arguments. Default: `[]`
* `env` <JS Object>: An object like `process.env` that Wasm application will get as its environment variables. Default: `{}`
* `preopens` <JS Object>: An object which maps '<guest_path>:<host_path>'. E.g. `{'/sandbox': '/some/real/path/that/wasm/can/access'}` Default: `{}`
* `EnableWasiStartFunction`: This option will disable wasm-bindgen mode and prepare the working environment for standalone wasm program. If you want to run an appliation with `main()`, you should set this to `true`. Default: `false`.
* `EnableAOT`: This option will enable ssvm aot mode. Default: `false`.
* `EnableMeasurement`: This option will enable measurement but decrease its performance. Default: `false`.
* `args` <JS Array>: An array of strings that Wasm application will get as function arguments. Default: `[]`.
* `env` <JS Object>: An object like `process.env` that Wasm application will get as its environment variables. Default: `{}`.
* `preopens` <JS Object>: An object which maps '<guest_path>:<host_path>'. E.g. `{'/sandbox': '/some/real/path/that/wasm/can/access'}` Default: `{}`.
* `EnableWasiStartFunction` <Boolean>: This option will disable wasm-bindgen mode and prepare the working environment for standalone wasm program. If you want to run an appliation with `main()`, you should set this to `true`. Default: `false`.
* `EnableAOT` <Boolean>: This option will enable ssvm aot mode. Default: `false`.
* `EnableMeasurement` <Boolean>: This option will enable measurement but decrease its performance. Default: `false`.
* `AllowCommands` <JS Array>: An array of strings that indicate what commands are allowed to execute in the SSVM Process Module. Default `[]`.
* `AllowAllCommands` <Boolean>: Allow users to call any command in the SSVM Process Module. This option will overwrite the `AllowCommands`. Default: `false`.
* Return value:
* `vm_instance`: A ssvm instance.

Expand Down Expand Up @@ -218,6 +220,7 @@ vm.RunXXX("Func", args);
* `InstructionCount` -> <Integer>: The number of executed instructions in this execution.
* `TotalGasCost` -> <Integer>: The cost of this execution.
* `InstructionPerSecond` -> <Float>: The instructions per second of this execution.

```javascript
let result = RunInt("Add", 1, 2);
// result should be 3
Expand Down
17 changes: 11 additions & 6 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
},
"sources": [
"ssvmaddon.cc",
"ssvm-napi/addon.cc",
"ssvm-napi/bytecode.cc",
"ssvm-napi/options.cc",
"ssvm-napi/utils.cc",
"ssvm-napi/src/addon.cc",
"ssvm-napi/src/bytecode.cc",
"ssvm-napi/src/options.cc",
"ssvm-napi/src/utils.cc",
"ssvm-napi/ssvm-core/lib/aot/compiler.cpp",
"ssvm-napi/ssvm-core/lib/ast/description.cpp",
"ssvm-napi/ssvm-core/lib/ast/expression.cpp",
Expand All @@ -61,6 +61,7 @@
"ssvm-napi/ssvm-core/lib/interpreter/engine/control.cpp",
"ssvm-napi/ssvm-core/lib/interpreter/engine/engine.cpp",
"ssvm-napi/ssvm-core/lib/interpreter/engine/memory.cpp",
"ssvm-napi/ssvm-core/lib/interpreter/engine/proxy.cpp",
"ssvm-napi/ssvm-core/lib/interpreter/engine/table.cpp",
"ssvm-napi/ssvm-core/lib/interpreter/engine/variable.cpp",
"ssvm-napi/ssvm-core/lib/interpreter/instantiate/data.cpp",
Expand All @@ -72,18 +73,20 @@
"ssvm-napi/ssvm-core/lib/interpreter/instantiate/memory.cpp",
"ssvm-napi/ssvm-core/lib/interpreter/instantiate/module.cpp",
"ssvm-napi/ssvm-core/lib/interpreter/instantiate/table.cpp",
"ssvm-napi/ssvm-core/lib/interpreter/helper.cpp",
"ssvm-napi/ssvm-core/lib/interpreter/interpreter.cpp",
"ssvm-napi/ssvm-core/lib/loader/filemgr.cpp",
"ssvm-napi/ssvm-core/lib/loader/ldmgr.cpp",
"ssvm-napi/ssvm-core/lib/loader/loader.cpp",
"ssvm-napi/ssvm-core/lib/loader/shared_library.cpp",
"ssvm-napi/ssvm-core/lib/validator/formchecker.cpp",
"ssvm-napi/ssvm-core/lib/validator/validator.cpp",
"ssvm-napi/ssvm-core/lib/vm/vm.cpp",
"ssvm-napi/ssvm-core/thirdparty/easyloggingpp/easylogging++.cc",
"ssvm-image/lib/image_func.cpp",
"ssvm-image/lib/image_module.cpp",
"ssvm-storage/lib/storage_func.cpp",
"ssvm-storage/lib/storage_module.cpp",
"ssvm-tensorflow/lib/image_func.cpp",
"ssvm-tensorflow/lib/image_module.cpp",
"ssvm-tensorflow/lib/tensorflow_func.cpp",
"ssvm-tensorflow/lib/tensorflow_module.cpp",
"ssvm-tensorflow/lib/tensorflowlite_func.cpp",
Expand All @@ -92,9 +95,11 @@
"include_dirs": [
"<!@(node -p \"require('node-addon-api').include\")",
"ssvm-napi",
"ssvm-napi/src",
"ssvm-napi/ssvm-core/include",
"ssvm-napi/ssvm-core/thirdparty",
"ssvm-napi/ssvm-core/thirdparty/googletest/include",
"ssvm-image/include",
"ssvm-storage/include",
"ssvm-tensorflow/include",
"ssvm-tensorflow/utils/ssvm-tensorflow-deps",
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var binary = require('node-pre-gyp');
var binary = require('@mapbox/node-pre-gyp');
var path = require('path')
var binding_path =
binary.find(path.resolve(path.join(__dirname, './package.json')));
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ssvm-extensions",
"version": "0.7.2",
"version": "0.7.3",
"description": "Second State WebAssembly VM for Node.js Addon with all extensions",
"keywords": [
"wasm",
Expand All @@ -24,13 +24,13 @@
},
"dependencies": {
"node-addon-api": "^3.0.0",
"node-pre-gyp": "^0.14.0",
"npm": "^6.14.5"
"@mapbox/node-pre-gyp": "^1.0.0",
"npm": "^7.11.1"
},
"devDependencies": {
"mocha": "^8.1.3",
"node-gyp-cache": "^0.2.1",
"ssvmup": "^0.1.17"
"ssvmup": "^0.1.21"
},
"scripts": {
"preinstall": "./scripts/preinstall.sh",
Expand Down
1 change: 1 addition & 0 deletions ssvm-image
Submodule ssvm-image added at 74c470
2 changes: 1 addition & 1 deletion ssvm-storage
2 changes: 1 addition & 1 deletion ssvm-tensorflow
23 changes: 17 additions & 6 deletions ssvmaddon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "common/log.h"
#include "common/span.h"
#include "loader/loader.h"
#include "host/ssvm_process/processmodule.h"
#include "host/wasi/wasimodule.h"
#include "utils.h"

#include <limits>
Expand Down Expand Up @@ -64,8 +66,8 @@ inline uint64_t castFromU32ToU64(uint32_t L, uint32_t H) {

inline bool endsWith(const std::string &S, const std::string &Suffix) {
return S.length() >= Suffix.length() &&
S.compare(S.length() - Suffix.length(), std::string::npos,
Suffix) == 0;
S.compare(S.length() - Suffix.length(), std::string::npos, Suffix) ==
0;
}

} // namespace
Expand Down Expand Up @@ -146,6 +148,17 @@ void SSVMAddon::InitVM(const Napi::CallbackInfo &Info) {

SSVM::Log::setErrorLoggingLevel();

SSVM::Host::SSVMProcessModule *ProcMod =
dynamic_cast<SSVM::Host::SSVMProcessModule *>(
VM->getImportModule(SSVM::VM::Configure::VMType::SSVM_Process));

if (Options.isAllowedCmdsAll()) {
ProcMod->getEnv().AllowedAll = true;
}
for (auto &Cmd : Options.getAllowedCmds()) {
ProcMod->getEnv().AllowedCmd.insert(Cmd);
}

Inited = true;
}

Expand Down Expand Up @@ -173,8 +186,7 @@ void SSVMAddon::InitWasi(const Napi::CallbackInfo &Info,
if (Options.isAOTMode()) {
if (BC.isFile() && endsWith(BC.getPath(), ".so")) {
// BC is already the compiled filename, do nothing
}
else if (!BC.isCompiled()) {
} else if (!BC.isCompiled()) {
Compile();
}
/// After Compile(), {Bytecode, FilePath} -> {FilePath}
Expand Down Expand Up @@ -432,8 +444,7 @@ void SSVMAddon::Run(const Napi::CallbackInfo &Info) {
FiniVM();
}

Napi::Value SSVMAddon::RunCompile(const Napi::CallbackInfo &Info)
{
Napi::Value SSVMAddon::RunCompile(const Napi::CallbackInfo &Info) {
std::string FileName;
if (Info.Length() > 0) {
FileName = Info[0].As<Napi::String>().Utf8Value();
Expand Down
5 changes: 4 additions & 1 deletion utils/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ RUN wget https://github.com/second-state/ssvm-tensorflow-deps/releases/download/
&& ldconfig

RUN npm install -y -g --unsafe-perm \
node-pre-gyp \
@mapbox/node-pre-gyp \
ssvmup \
wabt

Expand All @@ -40,5 +40,8 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
mtcnn \
mobilenet_v2

RUN rustup override set 1.50.0


RUN rm -rf /var/lib/apt/lists/* ${TENSORFLOW_TARBALL}
WORKDIR /root

0 comments on commit e7273ab

Please sign in to comment.