Skip to content

Commit

Permalink
Enable WAMR optimized interpreter
Browse files Browse the repository at this point in the history
Signed-off-by: Marcela Melara <[email protected]>
  • Loading branch information
marcelamelara authored and masomel committed Mar 31, 2020
1 parent 6d48df4 commit bf671a0
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 19 deletions.
9 changes: 6 additions & 3 deletions build/common-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ var_set() {

env_val[WASM_MODE]="${WASM_MODE:-INTERP}"
env_desc[WASM_MODE]="
WASM_MODE indicates the mode of the wasm runtime. If the
variable is set to 'INTERP', the runtime will be built to
run intepreted wasm bytecode contracts. If the variable is
WASM_MODE indicates the execution mode of the wasm runtime.
If the variable is set to 'INTERP', the runtime will be
built to run intepreted wasm bytecode contracts. If the
variable is set to 'INTERP_OPT', the runtime will be
built to run the optimized interpreter for wasm bytecode
contracts. If the variable is
set to 'AOT', the runtime will be built to run AoT-compiled
native wasm contracts.
"
Expand Down
16 changes: 11 additions & 5 deletions common/interpreter/wawaka_wasm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ IF (NOT DEFINED ENV{WASM_MODE})
ENDIF()

SET(WASM_SRC "$ENV{WASM_SRC}")
SET(WASM_MODE "INTERP")
SET(WASM_MODE "$ENV{WASM_MODE}")

# Reset default linker flags
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
Expand All @@ -63,14 +63,20 @@ IF (WASM_MODE STREQUAL "AOT")
# Disable Interpreter for AoT mode
set (WAMR_BUILD_INTERP 0)
set (WAMR_BUILD_FAST_INTERP 0)
ELSE()
message(STATUS "Building wawaka in AOT mode")
message(FATAL_ERROR "AoT mode is not currently implemented")
ELSE ()
# Disable AoT by default
set (WAMR_BUILD_AOT 0)
set (WAMR_BUILD_INTERP 1)
if (NOT DEFINED WAMR_BUILD_FAST_INTERP)
# Disable fast interpreter by default
if (WASM_MODE STREQUAL "INTERP_OPT")
set (WAMR_BUILD_FAST_INTERP 1)
message(STATUS "Building wawaka in optimized INTERP mode")
else()
# Disable optimized interpreter by default
set (WAMR_BUILD_FAST_INTERP 0)
endif ()
message(STATUS "Building wawaka in INTERP mode")
endif()
ENDIF()

# Disable JIT by default for all runtime modes.
Expand Down
18 changes: 14 additions & 4 deletions common/interpreter/wawaka_wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,37 @@ source ./emsdk_env.sh
If wawaka is configured as the contract interpreter, the libraries implementing the WASM interpreter
will be built for use with Intel SGX. The source for the WAMR interpreter is
included as a submodule in the interpreters/ folder, and will
always point to the latest tagged commit that we have validated: `WAMR-03-19-2020`.
always point to the latest tagged commit that we have validated: `WAMR-03-30-2020`.
If the PDO parent repo was not cloned with the `--recurse-submodules` flag,
you will have to explictly pull the submodule source.

```
cd ${PDO_SOURCE_ROOT}/interpreters/wasm-micro-runtime
git submodule update --init
git checkout WAMR-03-19-2020 # optional
git checkout WAMR-03-30-2020 # optional
```

The WAMR API is built during the Wawaka build, so no additional
build steps are required to set up WAMR.

### Set the environment variables ###

By default, PDO will be built with the Gipsy Scheme contract interpreter. To use the experimental wawaka interpreter, set the environment variables `WASM_SRC` (default is the submodule directory with the WAMR source) and `PDO_INTERPRETER` (the name of the contract interpreter to use.
By default, PDO will be built with the Gipsy Scheme contract interpreter. To use the experimental wawaka interpreter, set the environment variables `WASM_SRC` (default is the submodule directory with the WAMR source), `PDO_INTERPRETER` (the name of the contract interpreter to use), and `WASM_MODE` (the
execution mode of the wawaka WASM runtime).

```bash
export WASM_SRC=${PDO_SOURCE_ROOT}/interpreters/wasm-micro-runtime
export PDO_INTERPRETER=wawaka
export WASM_MODE=INTERP
```

PDO supports two WAMR interpreter modes: classic
interpreter and optimized interpreter (more details at
[WAMR documentation](https://github.com/bytecodealliance/wasm-micro-runtime/blob/master/doc/build_wamr.md#configure-interpreter)).
By default, PDO builds the classic interpreter. To enable the
optimized interpreter, set the `WASM_MODE` environment variable
to `INTERP_OPT`.

### Build PDO ###

Note that any change to the contract interpreter requires PDO to be completely rebuilt.
Expand All @@ -94,7 +103,8 @@ pdo-test-contract --no-ledger --interpreter wawaka --contract mock-contract \

### Setup

By default, wawaka will be built for interpreted wasm contracts. If you would like to enable
By default, wawaka will be built for interpreted wasm contracts.
If you would like to enable
ahead-of-time (AoT) compiled wasm contracts, set the environment variable `WASM_MODE` (default: `INTERP`):

```bash
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile.pdo-build
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# - pdo repo branch to use: PDO_REPO_BRANCH (default: master)
# - build in debug mode: PDO_DEBUG_BUILD (default: 0)
# - contract interpreter (gipsy or wawaka): PDO_INTERPRETER (default: gipsy)
# - wamr version: WAMR (default: WAMR-03-19-2020)
# - wamr version: WAMR (default: WAMR-03-30-2020)

# Build:
# $ docker build -f docker/Dockerfile.pdo-build -t pdo-build docker
Expand Down Expand Up @@ -104,7 +104,7 @@ ENV PDO_INTERPRETER=${PDO_INTERPRETER}

# - web-assembly/wasm/wawaka
# - Configure WAMR source
ARG WAMR=WAMR-03-19-2020
ARG WAMR=WAMR-03-30-2020
RUN cd /project/pdo/src/private-data-objects/interpreters/wasm-micro-runtime \
&& git checkout ${WAMR}\
&& echo "export WASM_SRC=$(pwd)" >> /etc/profile.d/pdo.sh
Expand Down
20 changes: 16 additions & 4 deletions docs/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,24 @@ the contract enclave.

<!-- -------------------------------------------------- -->
### `WASM_SRC`
(default: `${PDO_SOURCE_ROOT}/wasm`)
(default: `${PDO_SOURCE_ROOT}/interpreters/wasm-micro-runtime`)

`WASM_SRC` points to the installation of the micro-wasm source. This
`WASM_SRC` points to the installation of the wasm-micro-runtime. This
is used to build the WASM interpreter for the wawaka contract interpreter.
Clone branch/tag 'tag-11-28-2019' of the micro-wasm source from
https://github.com/intel/wasm-micro-runtime
The git submodule points to the latest tagged commit of [WAMR](https://github.com/bytecodealliance/wasm-micro-runtime) we have validated:
`WAMR-03-30-2020`.

<!-- -------------------------------------------------- -->
### `WASM_MODE`
(default: `INTERP`)

`WASM_MODE` indicates the execution mode of the wasm runtime.
If the variable is set to `INTERP`, the runtime will be
built to run intepreted wasm bytecode contracts. If the
variable is set to `INTERP_OPT`, the runtime will be
built to run the optimized interpreter for wasm bytecode
contracts. If the variable is set to `AOT`, the runtime will
be built to run AoT-compiled native wasm contracts.

<!-- -------------------------------------------------- -->
<!-- -------------------------------------------------- -->
Expand Down
2 changes: 1 addition & 1 deletion interpreters/wasm-micro-runtime

0 comments on commit bf671a0

Please sign in to comment.