Skip to content

Embedded c target - #13

Merged
amasat01 merged 18 commits into
mainfrom
embedded-c-target
Oct 23, 2026
Merged

amasat01 merged 18 commits into
mainfrom
embedded-c-target

Conversation

@tyrrellgit

Copy link
Copy Markdown
Collaborator

Created a 'dialect' construct to allow hawk to emit either the c-core added to aether (PR link) or the original aether cpp dialect.

This allows for C-code emission alongside the usual CPU/GPU aether code.

In order to separate the embedded C code generation, an "embedded" module has been added also. Later this might be better generalised by a dedicated dialect handler but for now this is the minimal diff change required to emit embedded code.

rory3va and others added 11 commits October 20, 2026 13:02
Every piece of target text the body renderer produces now goes through a
Dialect passed at construction (hawk/emit/dialect.py); today's C++ spelling
moves, unchanged, into AetherDialect (dialect_aether.py). The traversal and
policy stay in the renderer. Host and cuda output is byte-identical (checked
over 488 translation units), with one deliberate exception: a lookup or
wide-input plane read twice, and a rank>=1 lookup plane read at all, no
longer emit a dead load at the sample index. Dialect.exit_if spells the if
that opens a head/middle break so a C dialect can avoid redundant parentheses.

Signed-off-by: Rory <Rory@3va.studio>
A kernel now carries the sha256 of its source (None when it cannot be read),
carried through hawk.steps. Nothing consumes it yet; the embedded target
records it in the header and report.  Useful for auditing in embedded generation.

Signed-off-by: Rory <Rory@3va.studio>
hawk.embedded.render / check / export emit a kernel as <name>.c, <name>.h and
<name>.embedded.json: serial, a plain structure-of-arrays ABI, a
status-returning entry, no eagle or aether header. A verify pass over the IR
refuses unsupported features by name, records budgets, index sites, the
floating-point domain and the interface contract; a text audit, strict cc
(c99 and c11) and cppcheck's MISRA addon check the result. The arithmetic
comes from aether_dsc.c_core, so hawk now requires aether-dsc>=0.2.4. Also
adds the lazy hawk.embedded submodule door, the cppcheck CI install, and the
two_fin fixture. Tests include a ctypes bit-identity harness against the host
build.

Signed-off-by: Rory <Rory@3va.studio>
c joins host and cuda as a build target. A c-only build writes the three C
files and no manifest or sidecar; host+c keeps exec_targets host-only. The
profile, each kernel's source digest and the aether core version are terms of
the unit key (tag unit-key/6). hawk.load and hawk.artifact.plugins refuse a
c-only build with an error naming the c target.

Signed-off-by: Rory <Rory@3va.studio>
Reference page (docs/content/embedded.md), a runnable example notebook, index
and pointer edits, contributing note, the Unreleased changelog entry, and
docs/superpowers excluded from the Sphinx tree.

Signed-off-by: Rory <Rory@3va.studio>
cppcheck does not read system headers in the MISRA run, and older releases
(2.13, the Ubuntu 24.04 package CI installs) then report every INT64_C(...)
and UINT32_C(...) as a call to an undeclared function (Rule 17.3). run_checks
now writes a small cppcheck library declaring those macros as glibc defines
them and passes it with --library. Nothing is suppressed and the emitted C is
unchanged.

With the macros visible, 2.13 also reports a real Rule 2.2 finding: a
runtime-count loop header scaled by a step of magnitude 1, `(12 - cnt) * 1`.
The C dialect now omits the multiply when the step is 1. verify.py's imports
are re-sorted (lint only).

Signed-off-by: Rory <rorytyrrell2@gmail.com>
The double-promotion row planted `(float)sqrt((float)x)`: Clang refuses a float
passed to sqrt's double parameter under -Wdouble-promotion, GCC does not, so
on CI's GCC the check raised nothing. The planted unit now promotes a float to
meet a double operand, which both compilers refuse, and the row asserts the
flag's name rather than Clang's wording. A bare sqrt in a float32 unit stays
pinned by the float32 render rows.

Signed-off-by: Rory <rorytyrrell2@gmail.com>
@tyrrellgit
tyrrellgit requested a review from amasat01 as a code owner October 21, 2026 15:57
amasat01
amasat01 previously approved these changes Oct 22, 2026

@amasat01 amasat01 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

All good - let's talk and discuss a permanent setup for multi-backend language support!
Like for aether, make sure you bump the release versions and that conflicts are resolved (other than all green in CI)

@tyrrellgit

Copy link
Copy Markdown
Collaborator Author

macOS tests failing on missing pipit package for aether 0.2.7 which should be released soon.

amasat01
amasat01 previously approved these changes Oct 23, 2026
@amasat01
amasat01 merged commit 40dda0e into main Oct 23, 2026
48 checks passed
@amasat01
amasat01 deleted the embedded-c-target branch October 25, 2026 16:18
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