Skip to content

Add Spatz task compilation and embedding support for MAGIA-SDK#3

Open
callme-sam wants to merge 67 commits intopulp-platform:mainfrom
FondazioneChipsIT:sc/magia_v2/spatz_on_magia
Open

Add Spatz task compilation and embedding support for MAGIA-SDK#3
callme-sam wants to merge 67 commits intopulp-platform:mainfrom
FondazioneChipsIT:sc/magia_v2/spatz_on_magia

Conversation

@callme-sam
Copy link

@callme-sam callme-sam commented Feb 18, 2026

Description

This PR introduces the support for compiling Spatz tasks and embedding them into the CV32 binary, porting the workflow originally developed by @luca24balboni in the MAGIA repository.

Key Changes

  • CMake Translation & Workflow: Translated the compilation and embedding logic from Makefile to CMake. The new flow:

    • Compiles the Spatz task.
    • Generates Spatzt binary from ELF.
    • Generate header with binary array and extracted symbols.
    • Includes the generated header during the CV32 compilation.
    • Also generates disassembly and stimuli
  • Bootrom Integration: Added conditional compilation for the Bootrom, which is now built only when a Spatz task is included in the compilation process.

  • Utilities Merge: Merged necessary hardware/utility headers from the original MAGIA project with the existing magia-v2 headers, resolving naming conflicts and ensuring compatibility.

  • Test Suite: Ported two existing tests and added new tests in tests/spatz_on_magia to verify the end-to-end flow.

  • Root Makefile Update: Added a new configuration option spatz_tests (enabled by default). It allows users to disable the compilation of Spatz-specific tests by setting it to 0.

@callme-sam callme-sam marked this pull request as ready for review February 18, 2026 12:23
@callme-sam
Copy link
Author

CC: @Dequino @luca24balboni - Ready for review

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain me what are the effects of this change? Have you tried it on RTL? If it is the case, once the PR will be succesfully merged on magia-sdk, we need to update also the Makefile in MAGIA's main repo. If you did not tested yet on RTL, I can try it on the MAGIA's main repo changing directly the ISA extension?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The switch of the ISA extension to xgap9 was necessary to add float16 support, which is not supported by xpulpv2. This follows a discussion on the Mattermost MAGIA Deployment channel between Francesco, Alberto, and Giuseppe. To quote Giuseppe: "Using xgap9 on that compiler basically amounts to using xpulpv2 plus FP support."

I admit I haven't tested it on RTL yet, my bad. I'll do it as soon as I have a moment; I also need to build the MAGIA RTL from scratch (never tried). That said, I believe you can test it on the MAGIA main branch simply by changing the ISA extension. Let me know if you have the time and opportunity to do so, thanks a lot!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I have tested it also on RTL and it seems there aren't problems, so it's okay from my side

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I have tested it also on RTL and it seems there aren't problems, so it's okay from my side

@luca24balboni
Copy link

When the PR will be merged I will update my branch lb/magia-spatz to be aligned with this changes.

@callme-sam callme-sam marked this pull request as draft February 20, 2026 11:38
@Dequino
Copy link
Member

Dequino commented Feb 23, 2026

Some comments and action items to do:
a - SPATZ_LLVM_PATH is set as an absolute path
b - No workflow for installing the llvm toolchain. My suggestion would be to do something like this:

mkdir -p llvm
cd llvm && git clone git@github.com:pulp-platform/llvm-project.git
cd llvm/llvm-project &&                  \
	git checkout b494f2d8dde88723026db8ec16ac6c7ee1e140ca && \
	git submodule update --init --recursive --jobs=8 .
mkdir -p $(LLVM_INSTALL_DIR)
cd llvm/llvm-project && mkdir -p build && cd build &&\
$(CMAKE) \
		-DCMAKE_INSTALL_PREFIX=$(LLVM_INSTALL_DIR) \
		-DCMAKE_CXX_COMPILER=${CXX} \
		-DCMAKE_C_COMPILER=${CC} \
		-DLLVM_OPTIMIZED_TABLEGEN=True \
		-DLLVM_ENABLE_PROJECTS="clang;lld" \
		-DLLVM_TARGETS_TO_BUILD="RISCV" \
		-DLLVM_DEFAULT_TARGET_TRIPLE=riscv32-unknown-elf \
		-DLLVM_ENABLE_LLD=False \
		-DLLVM_APPEND_VC_REV=ON \
		-DCMAKE_BUILD_TYPE=Release \
                ../llvm && \
make -j8 all && \
make install

And add it as a new option for the make workflow
c - Update the readme to inform the user about the new option available (spatz_tests), what happens when it's set on 1, when it's on 0, and which one is the default value. I also suggest the default value to be 0 to speed up the compilation process.

I'll now try to locally run the tests to see if any issue rises

@callme-sam callme-sam force-pushed the sc/magia_v2/spatz_on_magia branch from f21f2e3 to 57e730b Compare February 27, 2026 13:11
@callme-sam
Copy link
Author

Hi,

The PR is finalized. Since the last reviews, the following changes have been introduced:

  • Makefile

    • Added a custom rule to run simulations for binaries using Spatz.

      • For gvsoc, a specialized command is required as the bootrom must be specified in the parameters.

      • For RTL, it simply call the existing rule.

    • Added a rule to clone and install llvm-spatz.

    • Added an option to specify the LLVM path in case it is already installed elsewhere.

  • Refactored Compilation Flow

    • Stimuli are now generated only at runtime (consistent with mesh tests), significantly speeding up compilation.
  • Updated README

    • Added descriptions of the compilation flow and how to use the CMake functions. For implementation details, I have linked to the README written by Luca.

I’m keeping this as a Draft for now just to be safe. I am waiting for Lorenzo to implement the latest RTL changes (introduced by Luca to fix the Spatz boot race condition) into the gvsoc model for a final test.

After that, if there are no further requests (which are always welcome), it’s ready to be merged.

Thanks everyone!

@callme-sam
Copy link
Author

Ok, I've also tested it with an updated version of gvsoc, and everything looks fine. I'm taking it out of draft mode. If there are no further requests, this is ready to merge for me

@callme-sam callme-sam marked this pull request as ready for review February 27, 2026 15:04
Copy link
Member

@Dequino Dequino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 - The Makefile changed the MAGIA_DIR to ../MAGIA which breaks the other commands if you install magia-sdk under MAGIA like suggested in the README.
2 - The README file referred in "Spatz integration in MAGIA" of the README refers to a file that kind of repeats itself 3 times and has some little inaccuracies due to the fact it refers to baremetal and not the SDK directly, maybe put a warning on it.
3 - The new path for the modelsim.ini copy instruction is also broken (that command is not run from the sdk folder, but from the build folder, so the relative path breaks)

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.

3 participants