[{"data":1,"prerenderedAt":35},["ShallowReactive",2],{"chapter:kernels\u002Freference\u002Fcompile-errors.json":3},{"project":4,"route":5,"title":6,"titleHtml":6,"navTitle":6,"part":7,"sourcePath":8,"editUrl":9,"html":10,"toc":11,"hasMermaid":28,"prev":29,"next":32},"kernels","\u002Fkernels\u002Freference\u002Fcompile-errors","Common Compile Errors","Reference","reference\u002Fcompile-errors.md","https:\u002F\u002Fgithub.com\u002Fteenygrad\u002Fteenygrad\u002Fedit\u002Fmain\u002Fbooks\u002Fkernels\u002Fsrc\u002Freference\u002Fcompile-errors.md","\u003Cp>Errors you will actually hit, with the real text and the fix. Grouped by which\ncompiler produced them, because that tells you where to look.\u003C\u002Fp>\n\u003Ch2 id=\"from-the-kernel-macro\">From the \u003Ccode>#[kernel]\u003C\u002Fcode> macro\u003C\u002Fh2>\n\u003Cp>These come from the proc macro, at ordinary \u003Ccode>cargo build\u003C\u002Fcode> time.\u003C\u002Fp>\n\u003Chr>\n\u003Cpre class=\"code-panel\" data-lang=\"text\">\u003Ccode>#[kernel] requires a type parameter with a `Triton` bound\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>\u003Cstrong>Cause.\u003C\u002Fstrong> The macro finds the GPU by looking for the type parameter bounded by\n\u003Ccode>Triton\u003C\u002Fcode>. Yours has none.\u003C\u002Fp>\n\u003Cp>\u003Cstrong>Fix.\u003C\u002Fstrong> Add it. Every kernel starts:\u003C\u002Fp>\n\u003Cpre data-lang=\"rust\" class=\"shiki teeny-datasheet\" style=\"background-color:#16181a;color:#e6e8e3\" tabindex=\"0\">\u003Ccode>\u003Cspan class=\"line\">\u003Cspan style=\"color:#FF5F9E\">pub\u003C\u002Fspan>\u003Cspan style=\"color:#FF5F9E\"> fn\u003C\u002Fspan>\u003Cspan style=\"color:#7FB6D9\"> my_kernel\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">&#x3C;\u003C\u002Fspan>\u003Cspan style=\"color:#6FBF98\">T\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">:\u003C\u002Fspan>\u003Cspan style=\"color:#6FBF98\"> Triton\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">,\u003C\u002Fspan>\u003Cspan style=\"color:#6FBF98\"> D\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">:\u003C\u002Fspan>\u003Cspan style=\"color:#6FBF98\"> Num\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">,\u003C\u002Fspan>\u003Cspan style=\"color:#FF5F9E\"> const\u003C\u002Fspan>\u003Cspan style=\"color:#B79AD4\"> BLOCK_SIZE\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">:\u003C\u002Fspan>\u003Cspan style=\"color:#6FBF98\"> i32\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">>(...)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>This is also what you get if you wrote \u003Ccode>Triton\u003C\u002Fcode> but did not import it.\u003C\u002Fp>\n\u003Chr>\n\u003Cpre class=\"code-panel\" data-lang=\"text\">\u003Ccode>`dtypes` must be a list, e.g. `dtypes = [f32, f64]`\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>\u003Cstrong>Cause.\u003C\u002Fstrong> \u003Ccode>#[kernel(dtypes = f32)]\u003C\u002Fcode> — a bare name where a list belongs.\u003C\u002Fp>\n\u003Cp>\u003Cstrong>Fix.\u003C\u002Fstrong> Brackets: \u003Ccode>#[kernel(dtypes = [f32])]\u003C\u002Fcode>.\u003C\u002Fp>\n\u003Chr>\n\u003Cpre class=\"code-panel\" data-lang=\"text\">\u003Ccode>`f16` is not a known scalar dtype\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>Or any other name. \u003Cstrong>Cause.\u003C\u002Fstrong> The dtype list only accepts scalar dtype\nidentifiers: \u003Ccode>bool\u003C\u002Fcode>, \u003Ccode>i8\u003C\u002Fcode>…\u003Ccode>i64\u003C\u002Fcode>, \u003Ccode>u8\u003C\u002Fcode>…\u003Ccode>u64\u003C\u002Fcode>, \u003Ccode>f16\u003C\u002Fcode>, \u003Ccode>bf16\u003C\u002Fcode>, \u003Ccode>f32\u003C\u002Fcode>, \u003Ccode>f64\u003C\u002Fcode>.\u003C\u002Fp>\n\u003Cp>\u003Cstrong>Fix.\u003C\u002Fstrong> Use one of those. Note that \u003Ccode>f16\u003C\u002Fcode> and \u003Ccode>bf16\u003C\u002Fcode> \u003Cem>parse\u003C\u002Fem> but cannot be\nmonomorphized — see Chapter 15 and \u003Ccode>KNOWN-GAPS.md\u003C\u002Fcode> item 4.\u003C\u002Fp>\n\u003Chr>\n\u003Cpre class=\"code-panel\" data-lang=\"text\">\u003Ccode>duplicate dtype `f32` in `dtypes`\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>\u003Cstrong>Fix.\u003C\u002Fstrong> Remove the repeat.\u003C\u002Fp>\n\u003Chr>\n\u003Cpre class=\"code-panel\" data-lang=\"text\">\u003Ccode>unknown `#[kernel]` argument `dtype` (expected `dtypes` or `backward`)\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>\u003Cstrong>Cause.\u003C\u002Fstrong> A typo. There are exactly two arguments.\u003C\u002Fp>\n\u003Chr>\n\u003Cpre class=\"code-panel\" data-lang=\"text\">\u003Ccode>cannot infer supported dtypes: a `#[kernel]` that opts into dispatch without an\nexplicit `dtypes = [..]` must have a dtype type parameter bound by one of\nDtype\u002FNum\u002FInt\u002FFloat\u002FBool\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>\u003Cstrong>Cause.\u003C\u002Fstrong> You used \u003Ccode>#[kernel(backward = ...)]\u003C\u002Fcode>, which opts into dispatch, but\nyour dtype parameter is bounded by something the macro cannot expand into a\ndtype set.\u003C\u002Fp>\n\u003Cp>\u003Cstrong>Fix.\u003C\u002Fstrong> Either bound it by one of the five, or list the dtypes explicitly.\nChapter 15 has the table.\u003C\u002Fp>\n\u003Ch2 id=\"from-rustc-about-kernel-bodies\">From rustc, about kernel bodies\u003C\u002Fh2>\n\u003Chr>\n\u003Cpre class=\"code-panel\" data-lang=\"text\">\u003Ccode>the trait bound `&lt;T as Triton&gt;::Pointer&lt;D&gt;: AddOffsets&lt;...&gt;` is not satisfied\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>\u003Cstrong>Cause.\u003C\u002Fstrong> A missing \u003Ccode>where\u003C\u002Fcode> clause. This is the most common error in a first\nkernel, and it means you called \u003Ccode>add_offsets\u003C\u002Fcode> without declaring that you would.\u003C\u002Fp>\n\u003Cp>\u003Cstrong>Fix.\u003C\u002Fstrong> The three clauses every kernel carries:\u003C\u002Fp>\n\u003Cpre data-lang=\"rust\" class=\"shiki teeny-datasheet\" style=\"background-color:#16181a;color:#e6e8e3\" tabindex=\"0\">\u003Ccode>\u003Cspan class=\"line\">\u003Cspan style=\"color:#FF5F9E\">where\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#6FBF98\">    T\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">::\u003C\u002Fspan>\u003Cspan style=\"color:#6FBF98\">I32Tensor\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">:\u003C\u002Fspan>\u003Cspan style=\"color:#6FBF98\"> types\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">::\u003C\u002Fspan>\u003Cspan style=\"color:#6FBF98\">Tensor\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">&#x3C;\u003C\u002Fspan>\u003Cspan style=\"color:#6FBF98\">i32\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">,\u003C\u002Fspan>\u003Cspan style=\"color:#E6E8E3\"> 1\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">>,\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#6FBF98\">    T\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">::\u003C\u002Fspan>\u003Cspan style=\"color:#6FBF98\">I32Tensor\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">:\u003C\u002Fspan>\u003Cspan style=\"color:#6FBF98\"> Comparison\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">&#x3C;\u003C\u002Fspan>\u003Cspan style=\"color:#6FBF98\">i32\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">,\u003C\u002Fspan>\u003Cspan style=\"color:#6FBF98\"> BoolTensor\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\"> =\u003C\u002Fspan>\u003Cspan style=\"color:#6FBF98\"> T\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">::\u003C\u002Fspan>\u003Cspan style=\"color:#6FBF98\">BoolTensor\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">>,\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#6FBF98\">    T\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">::\u003C\u002Fspan>\u003Cspan style=\"color:#6FBF98\">Pointer\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">&#x3C;\u003C\u002Fspan>\u003Cspan style=\"color:#6FBF98\">D\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">>:\u003C\u002Fspan>\u003Cspan style=\"color:#6FBF98\"> AddOffsets\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">&#x3C;\u003C\u002Fspan>\u003Cspan style=\"color:#6FBF98\">i32\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">,\u003C\u002Fspan>\u003Cspan style=\"color:#E6E8E3\"> 1\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">,\u003C\u002Fspan>\u003Cspan style=\"color:#6FBF98\"> T\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">::\u003C\u002Fspan>\u003Cspan style=\"color:#6FBF98\">I32Tensor\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">,\u003C\u002Fspan>\u003Cspan style=\"color:#6FBF98\"> Output\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\"> =\u003C\u002Fspan>\u003Cspan style=\"color:#6FBF98\"> T\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">::\u003C\u002Fspan>\u003Cspan style=\"color:#6FBF98\">Tensor\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">&#x3C;\u003C\u002Fspan>\u003Cspan style=\"color:#6FBF98\">T\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">::\u003C\u002Fspan>\u003Cspan style=\"color:#6FBF98\">Pointer\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">&#x3C;\u003C\u002Fspan>\u003Cspan style=\"color:#6FBF98\">D\u003C\u002Fspan>\u003Cspan style=\"color:#8A9088\">>>>,\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>Copy them verbatim. They are identical in every kernel in this tree, which is\nthe first item in \u003Ccode>API-FRICTION.md\u003C\u002Fcode>.\u003C\u002Fp>\n\u003Chr>\n\u003Cpre class=\"code-panel\" data-lang=\"text\">\u003Ccode>expected fn pointer `fn(...) -&gt; ...`\n   found closure `[closure@src\u002Fkernels\u002Fmine.rs:42:30]`\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>\u003Cstrong>Cause.\u003C\u002Fstrong> A closure passed to \u003Ccode>T::reduce\u003C\u002Fcode> or \u003Ccode>T::associative_scan\u003C\u002Fcode>.\u003C\u002Fp>\n\u003Cp>\u003Cstrong>Fix.\u003C\u002Fstrong> Make it a named function. The combine function is compiled from\ncaptured source text, so it must be statically known — Chapter 13. The error\ndoes not mention kernels at all, which is why it belongs on this list.\u003C\u002Fp>\n\u003Chr>\n\u003Cpre class=\"code-panel\" data-lang=\"text\">\u003Ccode>no method named `lt` found for associated type `&lt;T as Triton&gt;::I32Tensor`\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>\u003Cstrong>Cause.\u003C\u002Fstrong> The \u003Ccode>Comparison\u003C\u002Fcode> trait is not in scope, or its \u003Ccode>where\u003C\u002Fcode> clause is\nmissing.\u003C\u002Fp>\n\u003Cp>\u003Cstrong>Fix.\u003C\u002Fstrong> \u003Ccode>use teeny_triton::triton::types::Comparison;\u003C\u002Fcode> — usually already\ncovered by the glob import every kernel starts with.\u003C\u002Fp>\n\u003Chr>\n\u003Cpre class=\"code-panel\" data-lang=\"text\">\u003Ccode>mismatched types\n   expected `Option&lt;&lt;T as Triton&gt;::BoolTensor&gt;`\n      found `Option&lt;&lt;T as Triton&gt;::I32Tensor&gt;`\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>\u003Cstrong>Cause.\u003C\u002Fstrong> An integer tensor used as a mask. A mask must come from a\ncomparison.\u003C\u002Fp>\n\u003Cp>\u003Cstrong>Fix.\u003C\u002Fstrong> \u003Ccode>Some(offsets.lt(n))\u003C\u002Fcode>, not \u003Ccode>Some(offsets)\u003C\u002Fcode>.\u003C\u002Fp>\n\u003Ch2 id=\"from-teenyc\">From \u003Ccode>teenyc\u003C\u002Fcode>\u003C\u002Fh2>\n\u003Cp>These appear when \u003Ccode>compile_kernel\u003C\u002Fcode> runs, which is at \u003Cem>run\u003C\u002Fem> time — Chapter 3.\u003C\u002Fp>\n\u003Chr>\n\u003Cpre class=\"code-panel\" data-lang=\"text\">\u003Ccode>no teenyc rustup toolchain found; set TEENYC_PATH to the teenyc binary, or\ninstall one with `cargo teeny install-toolchain` (see cargo-teeny)\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>\u003Cstrong>Fix.\u003C\u002Fstrong> Either install it, or set \u003Ccode>TEENYC_PATH\u003C\u002Fcode>. Chapter 4. There is\ndeliberately no fallback to a bare \u003Ccode>teenyc\u003C\u002Fcode> on \u003Ccode>$PATH\u003C\u002Fcode>.\u003C\u002Fp>\n\u003Chr>\n\u003Cpre class=\"code-panel\" data-lang=\"text\">\u003Ccode>multiple teenyc rustup toolchains found (a, b); set TEENYC_PATH to disambiguate\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>\u003Cstrong>Fix.\u003C\u002Fstrong> Set \u003Ccode>TEENYC_PATH\u003C\u002Fcode> to the one you want.\u003C\u002Fp>\n\u003Chr>\n\u003Cp>\u003Cstrong>A \u003Ccode>teenyc\u003C\u002Fcode> failure mentioning names you did not use.\u003C\u002Fstrong> The kernel body is\ncompiled against a small generated environment, not your crate. \u003Ccode>println!\u003C\u002Fcode>, your\nown helper functions, and most of \u003Ccode>std\u003C\u002Fcode> are not there.\u003C\u002Fp>\n\u003Cp>\u003Cstrong>Fix.\u003C\u002Fstrong> Use only the \u003Ccode>Triton\u003C\u002Fcode> trait and plain arithmetic in a kernel body. For\nprinting, \u003Ccode>T::device_print\u003C\u002Fcode>.\u003C\u002Fp>\n\u003Ch2 id=\"from-the-cuda-driver\">From the CUDA driver\u003C\u002Fh2>\n\u003Cp>At load time, when the PTX becomes machine code.\u003C\u002Fp>\n\u003Chr>\n\u003Cpre class=\"code-panel\" data-lang=\"text\">\u003Ccode>PTX .version 8.6 does not support .target sm_120a\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>\u003Cstrong>Cause.\u003C\u002Fstrong> \u003Ccode>teenyc\u003C\u002Fcode>’s default PTX version is newer than your driver accepts.\nSeen on Blackwell.\u003C\u002Fp>\n\u003Cp>\u003Cstrong>Fix.\u003C\u002Fstrong> \u003Ccode>TEENYC_PTX_VERSION=87\u003C\u002Fcode>. A \u003Ccode>teenyc\u003C\u002Fcode>-side default; the SDK cannot work\naround it.\u003C\u002Fp>\n\u003Chr>\n\u003Cpre class=\"code-panel\" data-lang=\"text\">\u003Ccode>wrapper.h:17:10: fatal error: 'cuda.h' file not found\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>\u003Cstrong>Cause.\u003C\u002Fstrong> Not a kernel error at all — \u003Ccode>teeny-cuda\u003C\u002Fcode>’s build.rs generating\nbindings, with no CUDA toolkit installed. A driver alone is not enough.\u003C\u002Fp>\n\u003Cp>\u003Cstrong>Fix.\u003C\u002Fstrong> Install the toolkit, or build without the \u003Ccode>cuda\u003C\u002Fcode> feature. Chapter 4.\u003C\u002Fp>\n\u003Chr>\n\u003Cpre class=\"code-panel\" data-lang=\"text\">\u003Ccode>custom op 'my.op' is not handled — implement CustomOp::lower()\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>\u003Cstrong>Cause.\u003C\u002Fstrong> A \u003Ccode>CustomOp\u003C\u002Fcode> whose \u003Ccode>lower\u003C\u002Fcode> still returns the default \u003Ccode>None\u003C\u002Fcode>.\u003C\u002Fp>\n\u003Cp>\u003Cstrong>Fix.\u003C\u002Fstrong> Implement it. Chapter 20.\u003C\u002Fp>\n\u003Ch2 id=\"things-that-do-not-error\">Things that do not error\u003C\u002Fh2>\n\u003Cp>The worst list, because there is nothing to search for.\u003C\u002Fp>\n\u003Ctable>\n\u003Cthead>\n\u003Ctr>\n\u003Cth>Symptom\u003C\u002Fth>\n\u003Cth>Likely cause\u003C\u002Fth>\n\u003C\u002Ftr>\n\u003C\u002Fthead>\n\u003Ctbody>\n\u003Ctr>\n\u003Ctd>Wrong numbers, no crash\u003C\u002Ftd>\n\u003Ctd>Argument order in \u003Ccode>pack_args\u003C\u002Fcode> or the launch tuple. Nothing checks it\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>Wrong numbers only at the end of a buffer\u003C\u002Ftd>\n\u003Ctd>Missing mask. Chapter 7\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>Wrong reduction results\u003C\u002Ftd>\n\u003Ctd>Masked lanes not filled with the identity. Chapter 10\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>Gradients all zero\u003C\u002Ftd>\n\u003Ctd>\u003Ccode>has_backward\u003C\u002Fcode> not overridden, or \u003Ccode>backward_grid\u003C\u002Fcode> left at its \u003Ccode>[0,0,0]\u003C\u002Fcode> default. Chapter 22\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>Results differ run to run\u003C\u002Ftd>\n\u003Ctd>Atomics. Expected; compare with a tolerance. Chapter 14\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>Correct but slow after a port\u003C\u002Ftd>\n\u003Ctd>Block size tuned for a different card. Chapter 24\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003Ctr>\n\u003Ctd>Kernel silently does nothing\u003C\u002Ftd>\n\u003Ctd>Calling the \u003Ccode>#[kernel]\u003C\u002Fcode> function directly. It is not the kernel; the struct is\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003C\u002Ftbody>\n\u003C\u002Ftable>\n\u003Cp>For any of these, the first move is Chapter 9: read the MLIR. Count the loads\nand stores, check the constants, and look for the mask operand.\u003C\u002Fp>\n",[12,16,19,22,25],{"id":13,"text":14,"level":15},"from-the-kernel-macro","From the #[kernel] macro",2,{"id":17,"text":18,"level":15},"from-rustc-about-kernel-bodies","From rustc, about kernel bodies",{"id":20,"text":21,"level":15},"from-teenyc","From teenyc",{"id":23,"text":24,"level":15},"from-the-cuda-driver","From the CUDA driver",{"id":26,"text":27,"level":15},"things-that-do-not-error","Things that do not error",false,{"title":30,"titleHtml":30,"route":31},"Python Triton to Rust","\u002Fkernels\u002Freference\u002Ftranslation-table",{"title":33,"titleHtml":33,"route":34},"Glossary","\u002Fkernels\u002Freference\u002Fglossary",1786271830144]