Add support for multi-memory proposal in classic interpreter (#3742)

Implement multi-memory for classic-interpreter. Support core spec (and bulk memory) opcodes now,
and will support atomic opcodes, and add multi-memory export APIs in the future. 

PS: Multi-memory spec test patched a lot for linking test to adapt for multi-module implementation.
This commit is contained in:
Wenyong Huang
2024-08-21 12:22:23 +08:00
committed by GitHub
parent f4383a9e62
commit 1329e1d3e1
22 changed files with 1658 additions and 262 deletions

View File

@ -14,7 +14,7 @@ import time
"""
The script itself has to be put under the same directory with the "spec".
To run a single non-GC and non-memory64 case with interpreter mode:
To run a single non-GC case with interpreter mode:
cd workspace
python3 runtest.py --wast2wasm wabt/bin/wat2wasm --interpreter iwasm \
spec/test/core/xxx.wast
@ -22,7 +22,7 @@ To run a single non-GC case with aot mode:
cd workspace
python3 runtest.py --aot --wast2wasm wabt/bin/wat2wasm --interpreter iwasm \
--aot-compiler wamrc spec/test/core/xxx.wast
To run a single GC case or single memory64 case:
To run a single GC case case:
cd workspace
python3 runtest.py --wast2wasm spec/interpreter/wasm --interpreter iwasm \
--aot-compiler wamrc --gc spec/test/core/xxx.wast
@ -79,6 +79,7 @@ def ignore_the_case(
simd_flag=False,
gc_flag=False,
memory64_flag=False,
multi_memory_flag=False,
xip_flag=False,
eh_flag=False,
qemu_flag=False,
@ -165,6 +166,7 @@ def test_case(
verbose_flag=True,
gc_flag=False,
memory64_flag=False,
multi_memory_flag=False,
qemu_flag=False,
qemu_firmware="",
log="",
@ -223,6 +225,9 @@ def test_case(
if memory64_flag:
CMD.append("--memory64")
if multi_memory_flag:
CMD.append("--multi-memory")
if log != "":
CMD.append("--log-dir")
CMD.append(log)
@ -291,6 +296,7 @@ def test_suite(
verbose_flag=True,
gc_flag=False,
memory64_flag=False,
multi_memory_flag=False,
parl_flag=False,
qemu_flag=False,
qemu_firmware="",
@ -316,6 +322,10 @@ def test_suite(
eh_case_list_include = [test for test in eh_case_list if test.stem in ["throw", "tag", "try_catch", "rethrow", "try_delegate"]]
case_list.extend(eh_case_list_include)
if multi_memory_flag:
multi_memory_list = sorted(suite_path.glob("multi-memory/*.wast"))
case_list.extend(multi_memory_list)
# ignore based on command line options
filtered_case_list = []
for case_path in case_list:
@ -330,6 +340,7 @@ def test_suite(
simd_flag,
gc_flag,
memory64_flag,
multi_memory_flag,
xip_flag,
eh_flag,
qemu_flag,
@ -366,6 +377,7 @@ def test_suite(
verbose_flag,
gc_flag,
memory64_flag,
multi_memory_flag,
qemu_flag,
qemu_firmware,
log,
@ -408,6 +420,7 @@ def test_suite(
verbose_flag,
gc_flag,
memory64_flag,
multi_memory_flag,
qemu_flag,
qemu_firmware,
log,
@ -546,6 +559,13 @@ def main():
dest="memory64_flag",
help="Running with memory64 feature",
)
parser.add_argument(
"--multi-memory",
action="store_true",
default=False,
dest="multi_memory_flag",
help="Running with multi-memory feature",
)
parser.add_argument(
"cases",
metavar="path_to__case",
@ -591,6 +611,7 @@ def main():
options.verbose_flag,
options.gc_flag,
options.memory64_flag,
options.multi_memory_flag,
options.parl_flag,
options.qemu_flag,
options.qemu_firmware,
@ -619,6 +640,7 @@ def main():
options.verbose_flag,
options.gc_flag,
options.memory64_flag,
options.multi_memory_flag,
options.qemu_flag,
options.qemu_firmware,
options.log,

File diff suppressed because it is too large Load Diff

View File

@ -327,6 +327,9 @@ parser.add_argument('--gc', default=False, action='store_true',
parser.add_argument('--memory64', default=False, action='store_true',
help='Test with Memory64')
parser.add_argument('--multi-memory', default=False, action='store_true',
help='Test with multi-memory(with multi-module auto enabled)')
parser.add_argument('--qemu', default=False, action='store_true',
help="Enable QEMU")
@ -1097,6 +1100,8 @@ def compile_wast_to_wasm(form, wast_tempfile, wasm_tempfile, opts):
cmd = [opts.wast2wasm, "--enable-threads", "--no-check", "--enable-exceptions", "--enable-tail-call", wast_tempfile, "-o", wasm_tempfile ]
elif opts.memory64:
cmd = [opts.wast2wasm, "--enable-memory64", "--no-check", wast_tempfile, "-o", wasm_tempfile ]
elif opts.multi_memory:
cmd = [opts.wast2wasm, "--enable-multi-memory", "--no-check", wast_tempfile, "-o", wasm_tempfile ]
else:
cmd = [opts.wast2wasm, "--enable-threads", "--no-check",
wast_tempfile, "-o", wasm_tempfile ]

View File

@ -25,6 +25,7 @@ function help()
echo "-S enable SIMD feature"
echo "-G enable GC feature"
echo "-W enable memory64 feature"
echo "-E enable multi memory feature"
echo "-X enable XIP feature"
echo "-e enable exception handling"
echo "-x test SGX"
@ -59,6 +60,7 @@ COLLECT_CODE_COVERAGE=0
ENABLE_SIMD=0
ENABLE_GC=0
ENABLE_MEMORY64=0
ENABLE_MULTI_MEMORY=0
ENABLE_XIP=0
ENABLE_EH=0
ENABLE_DEBUG_VERSION=0
@ -85,7 +87,7 @@ REQUIREMENT_NAME=""
# Initialize an empty array for subrequirement IDs
SUBREQUIREMENT_IDS=()
while getopts ":s:cabgvt:m:MCpSXexwWPGQF:j:T:r:A:" opt
while getopts ":s:cabgvt:m:MCpSXexwWEPGQF:j:T:r:A:" opt
do
OPT_PARSED="TRUE"
case $opt in
@ -148,6 +150,11 @@ do
echo "enable wasm64(memory64) feature"
ENABLE_MEMORY64=1
;;
E)
echo "enable multi memory feature(auto enable multi module)"
ENABLE_MULTI_MEMORY=1
ENABLE_MULTI_MODULE=1
;;
C)
echo "enable code coverage"
COLLECT_CODE_COVERAGE=1
@ -496,6 +503,20 @@ function spec_test()
git reset --hard 48e69f394869c55b7bbe14ac963c09f4605490b6
git checkout 044d0d2e77bdcbe891f7e0b9dd2ac01d56435f0b -- test/core/elem.wast test/core/data.wast
git apply ../../spec-test-script/memory64_ignore_cases.patch || exit 1
elif [[ ${ENABLE_MULTI_MEMORY} == 1 ]]; then
echo "checkout spec for multi memory proposal"
# check spec test cases for multi memory
git clone -b main --single-branch https://github.com/WebAssembly/multi-memory.git spec
pushd spec
# Reset to commit: "Merge pull request #48 from backes/specify-memcpy-immediate-order"
git reset --hard 48e69f394869c55b7bbe14ac963c09f4605490b6
git checkout 044d0d2e77bdcbe891f7e0b9dd2ac01d56435f0b -- test/core/elem.wast
git apply ../../spec-test-script/multi_memory_ignore_cases.patch || exit 1
if [[ ${RUNNING_MODE} == "aot" ]]; then
git apply ../../spec-test-script/multi_module_aot_ignore_cases.patch || exit 1
fi
else
echo "checkout spec for default proposal"
@ -572,6 +593,13 @@ function spec_test()
ARGS_FOR_SPEC_TEST+="--memory64 "
fi
# multi memory is only enabled in interp and aot mode
if [[ 1 == ${ENABLE_MULTI_MEMORY} ]]; then
if [[ $1 == 'classic-interp' || $1 == 'aot' ]]; then
ARGS_FOR_SPEC_TEST+="--multi-memory "
fi
fi
if [[ ${ENABLE_QEMU} == 1 ]]; then
ARGS_FOR_SPEC_TEST+="--qemu "
ARGS_FOR_SPEC_TEST+="--qemu-firmware ${QEMU_FIRMWARE} "
@ -852,6 +880,14 @@ function do_execute_in_running_mode()
{
local RUNNING_MODE="$1"
if [[ ${ENABLE_MULTI_MEMORY} -eq 1 ]]; then
if [[ "${RUNNING_MODE}" != "classic-interp" \
&& "${RUNNING_MODE}" != "aot" ]]; then
echo "support multi-memory in classic-interp mode and aot mode"
return 0
fi
fi
if [[ ${ENABLE_MEMORY64} -eq 1 ]]; then
if [[ "${RUNNING_MODE}" != "classic-interp" \
&& "${RUNNING_MODE}" != "aot" ]]; then
@ -941,6 +977,12 @@ function trigger()
EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_MEMORY64=0"
fi
if [[ ${ENABLE_MULTI_MEMORY} == 1 ]];then
EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_MULTI_MEMORY=1"
else
EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_MULTI_MEMORY=0"
fi
if [[ ${ENABLE_MULTI_THREAD} == 1 ]];then
EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_LIB_PTHREAD=1"
fi