docs: clarify user-defined NFloat and InterlockedAddF16Emulated in autodiff tutorial 2 - #201
docs: clarify user-defined NFloat and InterlockedAddF16Emulated in autodiff tutorial 2#201nv-slang-bot[bot] wants to merge 3 commits into
Conversation
…diff tutorial 2
Adds a "Conventions Used in the Code Listings" subsection at the start
of section 3 that declares `NFloat` (typealias for `half`) and stubs
`InterlockedAddF16Emulated`, both of which are used pervasively in the
tutorial code blocks but were never defined in the doc, leaving readers
unable to tell them apart from Slang built-ins.
The choice of `half` for `NFloat` is consistent with the rest of the
tutorial:
- the explanatory note at line 83 ("we are using half type ... 16-bit
floating-point type for better throughput and to reduce memory usage")
- `MLVec<N>` storing `half data[N]` and returning `NFloat[N]` from it
- `Optimizer::learningRate = 0.01h` (half-precision literal)
- the "F16Emulated" naming on the atomic-add helper
Fixes #196
|
@nv-slang-bot Can you please update this branch from the main one? Also, is this PR still consistent with the current state of things, or has the documentation and/or samples being referenced been updated since? |
|
@jhelferty-nv Done — both parts below. 1. Branch updated from main ✅I merged the latest 2. Consistency re-verify — still consistent for the doc; one caveat on the linked sampleThe doc change itself is still correct and correctly placed:
Caveat worth flagging (pre-existing, non-blocking): the PR justifies
Since the doc's new stubs are self-contained and explicitly say to "treat them as if declared once at file scope," the PR still stands on its own as a readability fix for #196. The only thing I'd surface for your call: the sentence claims the identifiers' "full implementations live in the companion example repository," and for I have not marked this ready-for-review or merged — that stays with you. 🤖 Generated by an automated Slang coworker — may be inaccurate. A human maintainer should verify. |
…companion sample The linked mlp-training sample uses `typealias NFloat = float` and `Atomic<NFloat>.add()`, and does not define `InterlockedAddF16Emulated`, so the "full implementations live in the companion repository" clause was inaccurate. Frame the two identifiers as helpers the reader supplies, matching the stub-based intent of #196. The companion repo remains linked later in the tutorial for the complete runnable example.
|
@nv-slang-bot Would the sample code in this documentation still compile. or has the API changed sufficiently that it no longer would with, e.g., slangpy 0.43.1? |
|
@nv-slang-bot see my earlier reply |
|
@jhelferty-nv Good question — I checked this concretely rather than by eye. Short answer: yes, it still compiles; no relevant API/language drift affecting this tutorial. First, a framing note: every code listing in this tutorial is Slang shader code ( What I verified (with slangc 2026.12, the compiler in 0.43.1):
One honest caveat about the listings themselves: the in-page snippets are elided teaching excerpts — several bodies are shown as Bottom line: the complete linked sample compiles unchanged with slangpy 0.43.1 / Slang 2026.12, and the exact Slang constructs shown in the tutorial remain accepted — I hit no identifier or signature incompatibility in either the full sample or the targeted reproducer. No API change affects this tutorial. 🤖 Generated by an automated Slang coworker — may be inaccurate. A human maintainer should verify. |
Summary
In
docs/auto-diff-tutorial-2.md, the identifiersNFloatandInterlockedAddF16Emulatedare used throughout the code listings but never declared. A reader can plausibly mistakeNFloatfor a built-in scalar type alongsidefloat/half, andInterlockedAddF16Emulatedlooks like an HLSLInterlocked*intrinsic.This PR adds a brief "Conventions Used in the Code Listings" subsection at the start of section 3, just before the first place these identifiers appear. It declares
NFloatas a typealias forhalfand provides a one-line signature stub forInterlockedAddF16Emulated, with comments explaining why each exists.The fix shape is intentionally different from the empty-struct stubs in #195 —
NFloatis a typedef-like alias and the right form istypealias NFloat = half;, not an empty struct.Why
halfforNFloatConsistent with how the tutorial already uses these types:
halftype, which is 16-bit floating-point type for better throughput and to reduce memory usage".MLVec<N>storeshalf data[N]andtoArray()returnsNFloat[N]directly fromdata(only valid ifNFloat = half).Optimizer::learningRate = 0.01h— thehsuffix is a half-precision literal.InterlockedAddF16Emulated.Test plan
NFloatandInterlockedAddF16Emulatedhave a definition the reader can trace back to without leaving the page.Fixes #196