Skip to content

Commit 337795f

Browse files
Reject ndarray fields inside template-annotated struct params
Passing structs containing ndarrays through qd.template() bypasses argument pruning — every ndarray field gets registered regardless of whether the kernel uses it — and inflates the cached launch context, causing a measured 42% launch overhead on real workloads. Raise a clear QuadrantsCompilationError guiding users to use a concrete dataclass type annotation instead. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent da5e8e0 commit 337795f

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

python/quadrants/lang/ast/ast_transformers/function_def_transformer.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
ASTTransformerFuncContext,
2828
)
2929
from quadrants.lang.exception import (
30+
QuadrantsCompilationError,
3031
QuadrantsSyntaxError,
3132
)
3233
from quadrants.lang.matrix import MatrixType
@@ -220,6 +221,16 @@ def _walk_obj(obj, arg_idx, path):
220221
_register_ndarray(attr_val, arg_idx, (*path, attr_name))
221222

222223
def _register_ndarray(nd, arg_idx, attr_chain):
224+
param_name = ctx.func.arg_metas[arg_idx].name
225+
attr_path = ".".join(attr_chain)
226+
raise QuadrantsCompilationError(
227+
f"Kernel parameter '{param_name}' is annotated as qd.template(), but "
228+
f"'{param_name}.{attr_path}' is a qd.ndarray. Passing ndarrays through "
229+
f"template structs is not supported because it bypasses argument pruning "
230+
f"and degrades launch performance. Use a concrete struct annotation "
231+
f"(e.g. a @dataclass type hint) instead of qd.template() for struct "
232+
f"parameters that contain ndarrays."
233+
)
223234
key = id(nd)
224235
if key in cache:
225236
return

0 commit comments

Comments
 (0)