Repository navigation
fix(CuTeDSL): optimize positional-only functions with TVMFFIJitCompiledFunction to eliminate CPU overhead (#3527) #3589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Ammar-Alnagar
wants to merge
4
commits into
NVIDIA:main
Choose a base branch
from
Ammar-Alnagar:fix/tvm-ffi-posonly-overhead
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
02b1231
fix(CuTeDSL): optimize positional-only functions with TVMFFIJitCompil…
Ammar-Alnagar fc67310
Document TVM FFI positional-only fast path and add tests
Ammar-Alnagar cdebd81
Add test for CuTe DSL TVM FFI C++ registry integration
Ammar-Alnagar 8675019
Refactor parameter inspection order and remove C++ registry benchmark
Ammar-Alnagar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
test/python/CuTeDSL/test_tvm_ffi_kwargs_wrapper_spec.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| # Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
| import inspect | ||
| import pytest | ||
|
|
||
| pytest.importorskip("tvm_ffi") | ||
|
|
||
| import cutlass.cute as cute | ||
| from cutlass import Int32 | ||
| from cutlass.base_dsl.jit_executor import ExecutionArgs | ||
| from cutlass.cutlass_dsl.tvm_ffi_provider import ( | ||
| TVMFFIJitCompiledFunction, | ||
| TVMFFIJitCompiledFunctionWithKwargs, | ||
| ) | ||
|
|
||
|
|
||
| @cute.jit | ||
| def _positional_only(a: Int32, b: Int32, /): | ||
| pass | ||
|
|
||
|
|
||
| @cute.jit | ||
| def _positional_or_keyword(a: Int32, b: Int32): | ||
| pass | ||
|
|
||
|
|
||
| @cute.jit | ||
| def _positional_default(a: Int32, b: Int32 = Int32(2), /): | ||
| pass | ||
|
|
||
|
|
||
| @cute.jit | ||
| def _keyword_only(a: Int32, /, *, k: Int32 = Int32(2)): | ||
| pass | ||
|
|
||
|
|
||
| def _compile(func, *args): | ||
| return cute.compile(func, *args, options="--enable-tvm-ffi") | ||
|
|
||
|
|
||
| def test_tvm_ffi_routes_positional_only_signature_to_native_function(): | ||
| compiled = _compile(_positional_only, Int32(1), Int32(2)) | ||
|
|
||
| assert isinstance(compiled, TVMFFIJitCompiledFunction) | ||
| compiled(1, 2) | ||
|
|
||
|
|
||
| def test_tvm_ffi_routes_positional_or_keyword_signature_to_kwargs_wrapper(): | ||
| compiled = _compile(_positional_or_keyword, Int32(1), Int32(2)) | ||
|
|
||
| assert isinstance(compiled, TVMFFIJitCompiledFunctionWithKwargs) | ||
| compiled(a=1, b=2) | ||
|
|
||
|
|
||
| def test_tvm_ffi_routes_positional_default_signature_to_kwargs_wrapper(): | ||
| compiled = _compile(_positional_default, Int32(1)) | ||
|
|
||
| assert isinstance(compiled, TVMFFIJitCompiledFunctionWithKwargs) | ||
| compiled(1) | ||
|
|
||
|
|
||
| def test_tvm_ffi_routes_keyword_only_signature_to_kwargs_wrapper(): | ||
| compiled = _compile(_keyword_only, Int32(1)) | ||
|
|
||
| assert isinstance(compiled, TVMFFIJitCompiledFunctionWithKwargs) | ||
| compiled(1, k=2) | ||
|
|
||
|
|
||
| def test_kwargs_wrapper_spec_positional_only(): | ||
| def func_posonly(a, b, c, /): | ||
| pass | ||
|
|
||
| sig = inspect.signature(func_posonly) | ||
| exec_args = ExecutionArgs(sig, "func_posonly") | ||
| spec = exec_args.get_kwargs_wrapper_spec() | ||
|
|
||
| assert spec.arg_names == ["a", "b", "c"] | ||
| assert spec.arg_defaults == () | ||
| assert spec.kwonly_names == [] | ||
| assert spec.kwonly_defaults == {} | ||
| assert spec.has_pos_or_kw is False | ||
|
|
||
|
|
||
| def test_kwargs_wrapper_spec_positional_or_keyword(): | ||
| def func_pos_or_kw(a, b, c): | ||
| pass | ||
|
|
||
| sig = inspect.signature(func_pos_or_kw) | ||
| exec_args = ExecutionArgs(sig, "func_pos_or_kw") | ||
| spec = exec_args.get_kwargs_wrapper_spec() | ||
|
|
||
| assert spec.arg_names == ["a", "b", "c"] | ||
| assert spec.has_pos_or_kw is True | ||
|
|
||
|
|
||
| def test_kwargs_wrapper_spec_mixed_posonly_and_pos_or_kw(): | ||
| def func_mixed(a, /, b): | ||
| pass | ||
|
|
||
| sig = inspect.signature(func_mixed) | ||
| exec_args = ExecutionArgs(sig, "func_mixed") | ||
| spec = exec_args.get_kwargs_wrapper_spec() | ||
|
|
||
| assert spec.arg_names == ["a", "b"] | ||
| assert spec.has_pos_or_kw is True | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.