Skip to content

[CI] Add bare-metal RISCV 64 sample and QEMU smoke test - #24844

Open
phemashekar wants to merge 3 commits into
iree-org:mainfrom
phemashekar:riscv-bare-metal-ci-test
Open

[CI] Add bare-metal RISCV 64 sample and QEMU smoke test#24844
phemashekar wants to merge 3 commits into
iree-org:mainfrom
phemashekar:riscv-bare-metal-ci-test

Conversation

@phemashekar

Copy link
Copy Markdown
Contributor

Adds samples/baremetal_riscv64, a single-op inference runner for bare-metal RISCV 64 under qemu-system-riscv64 (-machine virt, no OS, semihosted I/O), together with a pkgci smoke test.

The sample covers two execution paths:

  • llvm-cpu using inline-dynamic and the embedded-ELF loader.
  • vmvx-inline using inline-static.

The runner uses the inline HAL instead of the full-HAL implementation following samples/simple_embedding, because HAL device creation currently requires a proactor that IREE_PLATFORM_GENERIC does not provide.

The runtime is compiled and linked using an xPack GCC/newlib sysroot. Its newlib is built with -mcmodel=medany required for QEMUs RAM base and provides semihost.specs for semihosted I/O and exit handling.

No HAL device drivers are enabled; the embedded-ELF loader is enabled explicitly for the LLVMCPU runner. The sample is EXCLUDE_FROM_ALL and CI builds only samples/baremetal_riscv64/all, so it does not affect other Generic RISCV builds.

Also fixes 4 <ctype.h> calls to pass unsigned char, as required by the API and exposed by the GCC/newlib build.

Assisted-by: Claude Code

@phemashekar
phemashekar force-pushed the riscv-bare-metal-ci-test branch 2 times, most recently from ea30560 to d33cd2f Compare August 24, 2026 16:20
@phemashekar phemashekar changed the title Add bare-metal RISCV 64 sample and QEMU CI smoke test [CI] Add bare-metal RISCV 64 sample and QEMU smoke test Aug 24, 2026
The HAL_Loader and HAL_Inline dialects registered no
DialectInlinerInterface, so CombineInitializers could not inline any
util.initializer containing their ops into the combined initializer:
- hal_loader: the multi-block executable-loading initializer broke all
  inline-dynamic compilation.
- hal_inline: the buffer-allocating initializer of mutable globals broke
  stateful programs under both inline-dynamic and inline-static.
Both dialects now register the same permissive inliner interface used by
the HAL dialect.

The hal_loader dispatch runtime shim used sizeof(iree_vm_abi_rIiii_t)
(which may include trailing struct padding) as the offset of the
variadic segment, but the VM writes that segment immediately after the
last fixed field with no trailing padding; every dispatch failed with an
argument/result signature mismatch. The shim now sizes the fixed prefix
through its final field.

Assisted-by: Claude Code
Signed-off-by: Pooja Hemashekar <hemashekar@roofline.ai>
iree_vm_buffer_destroy assumed every non-module-owned buffer was
co-allocated with its data by iree_vm_buffer_create, and therefore
freed the handle with iree_allocator_free_aligned. This is invalid for
buffers initialized in-place over caller-owned storage, such as the
inline HAL storage buffer wrapper, and caused the wrapper to leak in the
inline execution model end-to-end test.

Hence, tag buffers created/cloned with
IREE_VM_BUFFER_ACCESS_COALLOCATED and only use the aligned free path
for those. Other buffers pass the handle directly to their allocator.

Also initialize the inline storage buffer's host_allocator and
hal_buffer fields. Without this, destroying the wrapper would use a
null allocator and fail to release the retained HAL buffer.

Assisted-by: Claude Code
Signed-off-by: Pooja Hemashekar <hemashekar@roofline.ai>
@phemashekar
phemashekar force-pushed the riscv-bare-metal-ci-test branch 3 times, most recently from 656d212 to df1fc14 Compare August 25, 2026 14:16
Adds samples/baremetal_riscv64: a single-op inference runner for bare-metal
riscv64 (IREE_PLATFORM_GENERIC, inline HAL) executed on qemu-system-riscv64
(-machine virt, no OS, semihosted I/O), and a pkgci job that builds it and
runs it for both the llvm-cpu (inline-dynamic, embedded-ELF loader) and
vmvx-inline (inline-static) backends.

Design notes:
- samples/simple_embedding's CMake pattern (iree_cc_binary +
  iree_bytecode_module) is the model for the sample, but not its full-HAL
  runtime code: iree_hal_sync_device_create is currently unusable on
  IREE_PLATFORM_GENERIC (device creation eagerly acquires a proactor and no
  generic proactor implementation exists), so the runner uses the inline
  HAL (hal_inline + hal_loader) instead.
- One toolchain/sysroot end to end: xPack riscv-none-elf-gcc, whose newlib
  is built -mcmodel=medany (QEMU virt RAM starts at 0x80000000, outside
  medlow range) and ships semihost.specs. The riscv-collab LLVM toolchain
  was rejected because its newlib is medlow-built, which would have forced
  linking against a second toolchain's newlib -- not a stable ABI boundary.
- The sample is added with EXCLUDE_FROM_ALL and guarded on a GNU toolchain:
  its link options rely on GCC spec files, so it must not enter the default
  all build of other Generic riscv64 configurations (e.g.
  generic_riscv64.cmake with clang). CI builds it explicitly via
  --target samples/baremetal_riscv64/all.
- The toolchain download is pinned by sha256.
- Four ctype-macro call sites (string_view.c, regex lexer.c) now cast to
  unsigned char: newlib's ctype macros index a table with the argument and
  GCC's -Werror=char-subscripts rejects plain char there.

Assisted-by: Claude Code
Signed-off-by: Pooja Hemashekar <hemashekar@roofline.ai>
@phemashekar
phemashekar force-pushed the riscv-bare-metal-ci-test branch from df1fc14 to 3913720 Compare August 25, 2026 16:07
@phemashekar

Copy link
Copy Markdown
Contributor Author

Please review only the last commit in this PR since this is based off of #24827

@phemashekar
phemashekar marked this pull request as ready for review August 25, 2026 16:36
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.

1 participant