Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refactoring] extract reading leb numbers to a separate file, share t… #4

Open
wants to merge 50 commits into
base: main
Choose a base branch
from

Conversation

loganek
Copy link
Owner

@loganek loganek commented Aug 13, 2024

…he code between loader and mini loader

There's probably a number of other places where the bh_leb_read could be used (e.g. aot loader)
but I'm making the change as small as possible. Further refactoring can be done
later.

bianchui and others added 8 commits August 14, 2024 08:42
And enable merged os_mmap for aot data and text sections except on
platform nuttx and esp-idf.

Fix issue that aarch64 AOT module fails to load on android:
bytecodealliance#2274
…ween loader and mini loader (bytecodealliance#3701)

There's probably a number of other places where the bh_leb_read could be used (e.g. aot loader)
but I'm making the change as small as possible. Further refactoring can be done later.
…ealliance#3704)

As reported in bytecodealliance#3500, when debug interpreter is enabled, the classic interpreter
performs a lock operation to read `exec_env->current_status->signal_flag` and
do further handling before fetching next opcode, which makes the interpreter
run slower.

This PR atomic loads the `exec_env->current_status->signal_flag` without mutex
lock when 32-bit atomic load is supported, and only adding lock for further
handling when the signal_flag is WAMR_SIG_SINGSTEP, which improves the
performance.
Compilation warnings were reported on mac:
```
core/shared/mem-alloc/ems/ems_gc.c:454:22: warning: passing arguments to 'wasm_runtime_gc_prepare' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
    gct_vm_gc_prepare(NULL);
                     ^
core/shared/mem-alloc/ems/ems_gc.c:466:23: warning: passing arguments to 'wasm_runtime_gc_finalize' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
    gct_vm_gc_finished(NULL);
                      ^
2 warnings generated.
```
…ance#3717)

These symbols had been removed from NuttX in 2022, so it's time to
remove references to them.
@loganek loganek force-pushed the loganek/dyn-link-loading branch 3 times, most recently from 8f9a1ce to 4dd97a3 Compare August 15, 2024 12:29
Merge branch main into dev/dynamic_linking
@loganek loganek force-pushed the loganek/dyn-link-loading branch 3 times, most recently from d87d621 to 9bd2e16 Compare August 15, 2024 15:48
sjamesr and others added 6 commits August 16, 2024 06:56
…iance#3695)

Any use of a table index that isn't exactly a null byte (`0x00`) means that
the module makes use of the reference types proposal. This is important
to track because `aot_compiler.c` will blindly assume that all table indices
are a single byte long otherwise.

This fixes a crash in WAMR for modules that contain multi-byte encodings
of table indices in `call_indirect` but make no other use of reference types
features.
…ytecodealliance#3721)

If the value of a float constant is an NaN, the aot compiler creates an alloca,
stores the converted i32 const into it and then loads f32 from it again, which
may introduce a relocation in the AOT file and is not allowed for XIP mode.
no1wudi and others added 7 commits August 19, 2024 09:52
…ecodealliance#3726)

The table index in the call_indirect/return_call_indirect opcode should be
one byte 0x00 when ref-types/GC isn't enabled, and should be treated as
leb u32 when ref-types/GC is enabled.

And make aot compiler bail out if ref-types/GC is disabled by command line
argument while ref-types instructions are used.
…codealliance#3732)

For JIT, we naturally use mach-o on macOS, where the section name
we currently use is not valid and ends up with the errors like:

```
LLVM ERROR: Global variable '__orc_lcl.aot_stack_sizes.0' has an invalid section specifier '.aot_stack_sizes': mach-o section specifier requires a segment and section separated by a comma.
```

Because the dedicated section is not necessary for JIT,
this commit simply stops using it.

Fixes: bytecodealliance#3730
…iance#3734)

When AOT isn't enabled and the input is a wasm file, wasm_runtime_load doesn't
report error. Same when interpreter isn't enabled and the input is AOT file.

This PR makes wasm_runtime_load report error "magic header not detected" for
such situations.
wenyongh and others added 17 commits August 21, 2024 12:22
…ealliance#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.
…iance#3743)

Enable merged os_mmap for aot data sections first, and try enabling merged
os_mmap for them and aot text except on platform nuttx and esp-idf.

This fixes the issue that aarch64 AOT module fails to load on android:
bytecodealliance#2274

And also refine os_mmap related code.
Merge branch main into dev/dynamic_linking
Make wamrc normalize "arm64" to "aarch64v8". Previously the only way to
make the "arm64" target was to not specify a target on 64 bit arm-based
mac builds. Now arm64 and aarch64v8 are treated as the same.

Make aot_loader accept "aarch64v8" on arm-based apple (as well as
accepting legacy "arm64" based aot targets).

This also removes __APPLE__ and __MACH__ from the block that defaults
size_level to 1 since it doesn't seem to be supported for aarch64:
`LLVM ERROR: Only small, tiny and large code models are allowed on AArch64`
…3756)

Fix the compilation error of this CI:
https://github.com/bytecodealliance/wasm-micro-runtime/actions/runs/10575515238

```
/__w/wasm-micro-runtime/wasm-micro-runtime/bloaty/third_party/abseil-cpp/absl/debugging/failure_signal_handler.cc:139:32: error: no matching function for call to 'max(long int, int)'
  139 |   size_t stack_size = (std::max(SIGSTKSZ, 65536) + page_mask) & ~page_mask;
      |                        ~~~~~~~~^~~~~~~~~~~~~~~~~
```
…rge_aot_data_text

Merge branch dev/merge_aot_data_text into main to keep the commit history.
…ck is enabled (bytecodealliance#3754)

In the AOT compiler, allow the user to control stack boundary check when the boundary
check is enabled (e.g. `wamrc --bounds-checks=1`). Now the code logic is:

1. When `--stack-bounds-checks` is not set, it will be the same value as `--bounds-checks`.
2. When `--stack-bounds-checks` is set, it will be the option value no matter what the
    status of `--bounds-checks` is.
…64 or riscv64 (bytecodealliance#3755)

Mac on aarch64 uses posix_memmap.c os_mmap which doesn't do anything with
the flag MMAP_MAP_32BIT for that build so this condition ends up asserting unless
the mapping ends up in the first 4 gigs worth of addressable space.

Thsi PR changes to call os_mmap with MMAP_MAP_32BIT flag only when the target
is x86-64 or riscv64, and the macro __APPLE__ isn't enabled. The behavior is similar
to what the posix os_mmap does.
The specific commit has been deleted, I am pointing to the same commit in the main branch though.
- Only retry on EAGAIN, ENOMEM or EINTR.
- On EINTR, don't count it against the retry budget, just keep retrying.
  EINTR can happen in bursts.
- Log the errno on failure, and don't conditionalize that logging on
  BH_ENABLE_TRACE_MMAP. In other parts of the code, error logging is not
  conditional on that define, while turning on that tracing define makes
  things overly verbose.
…ce#3763)

Those parameters can be used to reduce the size of the AOT code.

There's going to be more changes related to AOT code size reduction,
this is just the initial step.

p.s. bytecodealliance#3758
…iance#3762)

Fixes to enable building iwasm_shared and iwasm_static libraries on win32.
@loganek loganek force-pushed the loganek/dyn-link-loading branch 3 times, most recently from 0bb5a01 to 8895f54 Compare September 9, 2024 10:46
no1wudi and others added 9 commits September 9, 2024 21:58
…ealliance#3709)

Minimum support:
- [x] accept (WasmEdge) customized model parameters. metadata.
- [x] Target [wasmedge-ggml examples](https://github.com/second-state/WasmEdge-WASINN-examples/tree/master/wasmedge-ggml)
  - [x] basic
  - [x] chatml
  - [x] gemma
  - [x] llama
  - [x] qwen

---

In the future, to support if required:
- [ ] Target [wasmedge-ggml examples](https://github.com/second-state/WasmEdge-WASINN-examples/tree/master/wasmedge-ggml)
  - [ ] command-r. (>70G memory requirement)
  - [ ] embedding. (embedding mode)
  - [ ] grammar. (use the grammar option to constrain the model to generate the JSON output)
  - [ ] llama-stream. (new APIS `compute_single`, `get_output_single`, `fini_single`)
  - [ ] llava. (image representation)
  - [ ] llava-base64-stream. (image representation)
  - [ ] multimodel. (image representation)
- [ ] Target [llamaedge](https://github.com/LlamaEdge/LlamaEdge)
- Implement TINY / STANDARD frame modes - tiny mode is only able to keep track on the IP
  and func idx, STANDARD mode provides more capabilities (parameters, stack pointer etc.).
- Implement FRAME_PER_FUNCTION / FRAME_PER_CALL modes - frame per function adds
  code at the beginning and at the end of each function for allocating / deallocating stack frame,
  whereas in per-call mode the frame is allocated before each call. The exception is call to
  the imported function, where frame-per-function mode also allocates the stack before the
  `call` instruction (as it can't instrument the imported function).

At the moment TINY + FRAME_PER_FUNCTION is automatically enabled in case GC and perf
profiling are disabled and `values` call stack feature is not requested. In all the other cases
STANDARD + FRAME_PER_CALL is used.

STANDARD + FRAME_PER_FUNCTION and TINY + FRAME_PER_CALL are currently not
implemented but possible, and might be enabled in the future.

ps. bytecodealliance#3758
Merge branch main into dev/dynamic_linking
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.