रेंडरिंगhi

कर्नेल

Translation status: हिन्दी reader-locale proof. Term names and code fences follow the hi pack; supporting prose may still be English.

Sugar @ कर्नेल fragment modifier marks a fragment-shader entry on the कर्नेल surface.

Syntax: @ कर्नेल खंड

Category#

lane

Examples#

radix/corpus/annotation-sugar/nucleum-fragment.fab (canonical · annotation)#

Sugar @ कर्नेल fragment modifier marks a fragment-shader entry on the कर्नेल surface.

# =============================================================================
# कर्नेल — sugar @ कर्नेल खंड modifier
# =============================================================================
#
# What this teaches:
#   • Sugar modifier — `@ कर्नेल खंड` on a function declaration marks
#     it as the fragment-shader entry (NucleumRole::Fragment); the parser
#     reads `खंड` as structured modifier data on the कर्नेल annotation,
#     never as an untyped name/argument pair
#   • The la reader spelling — `कर्नेल` is the la surface of the kernel
#     annotation identity; the en twin is `@ kernel खंड`
#   • A marked खंड function is a systems/shaders entry, not a host
#     entry — the plain `आरंभ` driver below proves the module still
#     checks and runs on the host लेन
#
# Common mistakes:
#   • writing `@ खंड` alone — the bare खंड name stays the graphics
#     statement annotation, not the कर्नेल modifier
#   • expecting the marked function to be called from a host `आरंभ`
#
# See also: कर्नेल, annotation-sugar
# =============================================================================

@ कर्नेल { खंड = सत्य }
फलन umbra() → रिक्त {
}

फलन identitas(संख्या x) → संख्या {
    लौटाओ x
}

आरंभ {
    दिखाओ identitas(5)
}

Expected output:

5

radix/corpus/kernel-closure/argument-escape.fab (supporting · reject)#

A kernel closure cannot be passed to an ordinary function argument.

# =============================================================================
# कर्नेल — reject ordinary-argument escape
# =============================================================================

fn apply(int value) → int {
    return value
}

fn take() → void {
    const _ kernel ← (int value) kernel ∴ value
    const int result ← apply(kernel)
}

Expected: compilation rejects this example.

radix/corpus/kernel-closure/bag-result.fab (supporting · reject)#

A kernel closure cannot return a host list/bag, including an append-built result.

# =============================================================================
# कर्नेल — reject list/bag result protocol
# =============================================================================
# A list is a host-managed bag/result carrier. The closure cannot return it,
# even when it is populated with append before the return.
# =============================================================================

fn take(int value) → void {
    const _ bad ← (int value) kernel → list<int> ∴ do {
        var list<int> items ← empty
        items.append(value)
        return items
    }
}

Expected: compilation rejects this example.

radix/corpus/kernel-closure/bare-body.fab (supporting · reject)#

A compact closure body cannot be a bare block; use do in the body joint.

# =============================================================================
# कर्नेल — reject bare compact brace body
# =============================================================================

main {
    const _ bad ← (int value) kernel ∴ {
        return value
    }
}

Expected: compilation rejects this example.

radix/corpus/kernel-closure/cape.fab (supporting · reject)#

A kernel closure cannot contain do/catch recovery.

# =============================================================================
# कर्नेल — reject पकड़ो/catch recovery in closure body
# =============================================================================

fn take(int value) → void {
    const _ bad ← (int value) kernel → int ∴ do {
        do {
            const int probe ← value
        } catch err {
            print err
        }
        return value
    }
}

Expected: compilation rejects this example.

radix/corpus/kernel-closure/capture.fab (supporting · reject)#

A kernel closure cannot capture an enclosing value local.

# =============================================================================
# कर्नेल — reject enclosing local capture
# =============================================================================

main {
    const int seed ← 2
    const _ bad ← (int value) kernel ∴ value + seed
}

Expected: compilation rejects this example.

radix/corpus/kernel-closure/dynamic-value.fab (supporting · reject)#

A kernel closure cannot produce a nested dynamic closure value.

# =============================================================================
# कर्नेल — reject dynamic closure value
# =============================================================================

fn take(int value) → void {
    const _ bad ← (int value) kernel ∴ (int inner) ∴ inner
}

Expected: compilation rejects this example.

radix/corpus/kernel-closure/error-channel.fab (supporting · reject)#

A kernel closure cannot declare an alternate-exit error channel.

# =============================================================================
# कर्नेल — reject closure error channel
# =============================================================================

main {
    const _ bad ← (int value) kernel → int ⇥ string ∴ value
}

Expected: compilation rejects this example.

radix/corpus/kernel-closure/field-escape.fab (supporting · reject)#

A kernel closure cannot be stored in a field.

# =============================================================================
# कर्नेल — reject field escape
# =============================================================================

class Capsule {
    var int stored
}

fn take() → void {
    const _ kernel ← (int value) kernel ∴ value
    const Capsule boxed ← Capsule { stored = kernel }
}

Expected: compilation rejects this example.

radix/corpus/kernel-closure/host-effect.fab (supporting · reject)#

A kernel closure cannot perform host output.

# =============================================================================
# कर्नेल — reject host effect in closure body
# =============================================================================

fn take(int value) → void {
    const _ bad ← (int value) kernel → int ∴ do {
        print value
        return value
    }
}

Expected: compilation rejects this example.

radix/corpus/kernel-closure/list-escape.fab (supporting · reject)#

A kernel closure cannot be stored in a list.

# =============================================================================
# कर्नेल — reject list escape
# =============================================================================

fn take() → void {
    const _ kernel ← (int value) kernel ∴ value
    const list<int> items ← [kernel, kernel]
}

Expected: compilation rejects this example.

radix/corpus/kernel-closure/reject.fab (supporting · reject)#

A kernel closure cannot use a reject guard that throws.

# =============================================================================
# कर्नेल — reject reject guard in closure body
# =============================================================================

fn take(int value) → void {
    const _ bad ← (int value) kernel → int ∴ do {
        reject value > 10 throw value
        return value
    }
}

Expected: compilation rejects this example.

radix/corpus/kernel-closure/require.fab (supporting · reject)#

A kernel closure cannot use a require guard that throws.

# =============================================================================
# कर्नेल — reject require guard in closure body
# =============================================================================

fn take(int value) → void {
    const _ bad ← (int value) kernel → int ∴ do {
        require value < 10 throw value
        return value
    }
}

Expected: compilation rejects this example.

radix/corpus/kernel-closure/return-escape.fab (supporting · reject)#

A kernel closure cannot be returned as an outer function value.

# =============================================================================
# कर्नेल — reject return escape
# =============================================================================

fn take() → void {
    const _ kernel ← (int value) kernel ∴ value
    return kernel
}

Expected: compilation rejects this example.

radix/corpus/kernel-closure/source-callback.fab (supporting · reject)#

A kernel closure cannot capture a host source callback value.

# =============================================================================
# कर्नेल — reject source callback capture
# =============================================================================
# A source callback is an enclosing function value. Referencing it from a
# kernel closure is a capture and therefore cannot cross the device boundary.
# =============================================================================

fn take((string, int) → int source, int value) → void {
    const _ bad ← (int x) kernel → int ∴ source("weights", x)
}

Expected: compilation rejects this example.

radix/corpus/kernel-closure/stack-free-kernel.fab (supporting · reject)#

A closure cannot stack free and kernel modifiers.

# =============================================================================
# कर्नेल — reject stacked free then kernel modifiers
# =============================================================================

main {
    const _ bad ← (int value) free kernel ∴ value
}

Expected: compilation rejects this example.

radix/corpus/kernel-closure/stack-kernel-free.fab (supporting · reject)#

A closure cannot stack kernel and free modifiers.

# =============================================================================
# कर्नेल — reject stacked kernel then free modifiers
# =============================================================================

main {
    const _ bad ← (int value) kernel free ∴ value
}

Expected: compilation rejects this example.

radix/corpus/kernel-closure/throw.fab (supporting · reject)#

A kernel closure cannot throw an alternate-exit value.

# =============================================================================
# कर्नेल — reject throw in closure body
# =============================================================================

fn take(int value) → void {
    const _ bad ← (int value) kernel → int ∴ do {
        throw value
        return value
    }
}

Expected: compilation rejects this example.

radix/corpus/kernel/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 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 लेन: the thread-id builtins
#     (`global_invocation_id()` and its siblings) are raw लेन ids and are
#     rejected in user code; the parallel pattern is an `दोहराओ … पर`
#     loop over the टेंसर.
#   • 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 टेंसर.
#
# See also: कर्नेल, सार्वजनिक
# =============================================================================

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 लेन id
@ kernel
@ public
fn names_its_lane(f32 x) → f32 {
    const सदिश<u32, 3> gid ← global_invocation_id()
    return x
}

Expected: compilation rejects this example.