kernel
Translation status: English reader-locale proof. Term names and code fences follow the en pack; supporting prose may still be English.
Sugar @ kernel fragment modifier marks a fragment-shader entry on the kernel surface.
Syntax: @ kernel fragment
Category#
kernel
Related#
- nucleum
- annotation-sugar
Examples#
radix/corpus/reference/annotation/nucleum/nucleum-fragment.fab (canonical · annotation)#
Sugar @ kernel fragment modifier marks a fragment-shader entry on the kernel surface.
# =============================================================================
# kernel — sugar @ kernel fragment modifier
# =============================================================================
#
# What this teaches:
# • Sugar modifier — `@ kernel fragment` on a function declaration marks
# it as the fragment-shader entry (NucleumRole::Fragment); the parser
# reads `fragment` as structured modifier data on the kernel annotation,
# never as an untyped name/argument pair
# • The la reader spelling — `kernel` is the la surface of the kernel
# annotation identity; the en twin is `@ kernel fragment`
# • A marked fragment function is a systems/shaders entry, not a host
# entry — the plain `main` driver below proves the module still
# checks and runs on the host lane
#
# Common mistakes:
# • writing `@ fragment` alone — the bare fragment name stays the graphics
# statement annotation, not the kernel modifier
# • expecting the marked function to be called from a host `main`
#
# See also: kernel, annotation-sugar
# =============================================================================
kernel umbra() fragment → void {
}
fn identitas(int x) → int {
return x
}
main {
print identitas(5)
}Expected output:
5
radix/corpus/reference/reject/nucleum/arg-exclusivity-reject-la.fab (supporting · reject)#
Nuclei argumentorum exklusivitas (la): omnis vocatio ubi argumentum scribendum (mut/penes) cum alio argumento cellam habet nominatim refutatur.
# =============================================================================
# kernel — kernel argument exclusivity rejects overlap (la)
# =============================================================================
#
# What this teaches:
# • A kernel's arguments stay live together for the whole launch, so a
# writable argument (`mut`, `penes`) may not overlap any other
# argument — whichever side of the call it is written on.
# • The whole tensor spelled twice, a `←` alias of it, and a view of the
# same storage are all the same overlap: one storage, two arguments.
# • Each refusal is named: `kernel_argument_overlap` for whole-tensor and
# alias overlap, `tensor_view_read_only` when a view is one side of the
# pair (a view is read-only and names its base).
# • To pass a value that must not overlap, bind an independent copy
# (`← exemplum t`) or call `materialize()` on a view first.
#
# Common mistakes:
# • relying on argument order — a read-only argument before the `mut` one
# overlaps exactly like one after it
# • passing two `penes` arguments that share storage — exclusive on both
# sides is still one storage
#
# See also: kernel, mutabilitas, tensor
# =============================================================================
@ kernel
@ public
fn axpy(mut tf32[3] y, tf32[3] x) → void {
y ⇇ x
}
@ kernel
@ public
fn scala(tf32[3] a, mut tf32[3] b) → void {
b ⇇ a
}
@ kernel
@ public
fn cap2(penes tf32[3] a, penes tf32[3] b) → void {
a ⇇ b
}
main {
mut tf32[3] t ← [1.0, 2.0, 3.0] ↦ tf32[3]
let tf32[3] u ← t
# 1. writable first, the same tensor after
axpy(mut t, t)
# 2. read-only first, writable second: the same overlap
scala(t, mut t)
# 3. a `←` alias names the same storage on either side
axpy(mut t, u)
scala(u, mut t)
# 4. a view of the writable argument's storage
axpy(mut t, t.forma([3]))
# 5. two `penes` arguments sharing one storage
cap2(penes t, penes u)
}Expected: compilation rejects this example.
radix/corpus/reference/reject/nucleum/arg-exclusivity-reject.fab (supporting · reject)#
Kernel argument exclusivity refuses every call where a writable (mut/own) argument overlaps another argument: the whole tensor spelled twice, a ← alias, a view of the same storage, or two own arguments sharing it.
# =============================================================================
# kernel — kernel argument exclusivity rejects overlap (K1)
# =============================================================================
#
# What this teaches:
# • A kernel's arguments stay live together for the whole launch, so a
# writable argument (`mut`, `own`) may not overlap any other argument —
# whichever side of the call it is written on.
# • The whole tensor spelled twice, a `←` alias of it, and a view of the
# same storage are all the same overlap: one storage, two arguments.
# • Each refusal is named: `kernel_argument_overlap` for whole-tensor and
# alias overlap, `tensor_view_read_only` when a view is one side of the
# pair (a view is read-only and names its base).
# • To pass a value that must not overlap, bind an independent copy
# (`← copy t`) or call `materialize()` on a view first.
#
# Common mistakes:
# • relying on argument order — a read-only argument before the `mut` one
# overlaps exactly like one after it
# • passing two `own` arguments that share storage — exclusive on both
# sides is still one storage
#
# See also: kernel, mutabilitas, tensor
# =============================================================================
@ kernel
@ public
fn axpy(mut tf32[3] y, tf32[3] x) → void {
y ⇇ x
}
@ kernel
@ public
fn scale(tf32[3] a, mut tf32[3] b) → void {
b ⇇ a
}
@ kernel
@ public
fn take2(own tf32[3] a, own tf32[3] b) → void {
a ⇇ b
}
main {
mut tf32[3] t ← [1.0, 2.0, 3.0] ↦ tf32[3]
let tf32[3] u ← t
# 1. writable first, the same tensor after
axpy(mut t, t)
# 2. read-only first, writable second: the same overlap
scale(t, mut t)
# 3. a `←` alias names the same storage on either side
axpy(mut t, u)
scale(u, mut t)
# 4. a view of the writable argument's storage
axpy(mut t, t.reshape([3]))
# 5. two `own` arguments sharing one storage
take2(own t, own u)
}Expected: compilation rejects this example.
radix/corpus/reference/reject/nucleum/legality-reject.fab (supporting · reject)#
Kernel legality at check time: host output, host-only types, calls to non-kernels, host calls to private kernels, and raw thread-id calls are named diagnostics.
# =============================================================================
# kernel — kernel legality is decided by `faber check`
# =============================================================================
#
# What this teaches:
# • A kernel body must not need the host runtime: no console output, no
# conversations, no async or generator forms, no heap-backed values
# (`list`, `map`, `set`, `string`, `json`, `value`), no local handlers.
# • A kernel may call another kernel or a built-in device operation, never
# an ordinary function.
# • Only a public kernel is launchable: host code may call a public kernel
# but not a private one.
# • A kernel never names its own lane: the thread-id builtins
# (`global_invocation_id()` and its siblings) are raw lane ids and are
# rejected in user code; the parallel pattern is an `for … at`
# loop over the tensor.
# • Each violation is a named diagnostic on the offending line, reported
# by `faber check` before any device lowering runs.
#
# Common mistakes:
# • printing from a kernel to debug it — run the kernel on the runner
# oracle instead.
# • passing a `list` to a kernel — use a tensor.
#
# See also: kernel, public
# =============================================================================
fn host_double(f32 x) → f32 {
return x * 2.0
}
# 1. host output
@ kernel
@ public
fn noisy(f32 x) → f32 {
print x
return x
}
# 2. call to an ordinary function
@ kernel
@ public
fn calls_host(f32 x) → f32 {
return host_double(x)
}
# 3. host-only parameter type
@ kernel
@ public
fn takes_list(list<f32> xs) → void {
}
# 4. host call to a private kernel
@ kernel
fn helper(f32 x) → f32 {
return x + 1.0
}
fn launches_private() → f32 {
return helper(1.0)
}
# 5. raw lane id
@ kernel
@ public
fn names_its_lane(f32 x) → f32 {
let vector<u32, size 3> gid ← global_invocation_id()
return x
}Expected: compilation rejects this example.
radix/corpus/reference/reject/nucleum/tier-duplicate-reject.fab (supporting · reject)#
A kernel names one tier: a second tier word is refused by name.
# =============================================================================
# kernel — A kernel names one tier: a second tier word is refused by name.
# =============================================================================
#
# What this teaches:
# • A kernel names one tier: a second tier word is refused by name.
#
# See also: kernel
# =============================================================================
@ kernel relaxed unsafe
fn k(f32 x) → f32 {
return x
}
main {
print 1
}Expected: compilation rejects this example.
radix/corpus/reference/reject/nucleum/tier-fragment-reject.fab (supporting · reject)#
A kernel fragment takes no tier: it uses the tier of the entry that composes it.
# =============================================================================
# kernel — A kernel fragment takes no tier: it uses the tier of the entry that composes it.
# =============================================================================
#
# What this teaches:
# • A kernel fragment takes no tier: it uses the tier of the entry that composes it.
#
# See also: kernel
# =============================================================================
@ kernel fragment relaxed
fn k(f32 x) → f32 {
return x
}
main {
print 1
}Expected: compilation rejects this example.
radix/corpus/reference/reject/nucleum/tier-non-kernel-reject.fab (supporting · reject)#
A kernel tier needs a kernel function: on any other declaration it is refused by name.
# =============================================================================
# kernel — A kernel tier needs a kernel function: on any other declaration it is refused by name.
# =============================================================================
#
# What this teaches:
# • A kernel tier needs a kernel function: on any other declaration it is refused by name.
#
# See also: kernel
# =============================================================================
@ kernel relaxed
class P {
let int a
}
main {
print 1
}Expected: compilation rejects this example.
radix/corpus/reference/reject/nucleum/tier-unknown-reject.fab (supporting · reject)#
A word after @ kernel that is no tier is refused by name.
# =============================================================================
# kernel — A word after @ kernel that is no tier is refused by name.
# =============================================================================
#
# What this teaches:
# • A word after @ kernel that is no tier is refused by name.
#
# See also: kernel
# =============================================================================
@ kernel fast
fn k(f32 x) → f32 {
return x
}
main {
print 1
}Expected: compilation rejects this example.