Repository navigation
fix(CuTeDSL): optimize positional-only functions with TVMFFIJitCompiledFunction to eliminate CPU overhead (#3527) - #3589
Ammar-Alnagar wants to merge 4 commits into
Conversation
…edFunction to eliminate CPU overhead (NVIDIA#3527) Functions defined with positional-only arguments (e.g., ) cannot be called with keyword arguments. Therefore, they do not require TVMFFIJitCompiledFunctionWithKwargs wrapper routing and can directly use TVMFFIJitCompiledFunction, bypassing Python execution and GIL overhead when called from C++ or Python.
|
Hey @kainzhong / @tqchen, Following up on the earlier discussion ([https://github.com//issues/3527]):
This PR addresses the routing issue so that pure positional-only functions ( Would appreciate a review when you have a chance — thanks! |
|
Hi @cyx-6 can you take a look at this PR? My opinion is
But I think that should be up to cutlass people to decide. What do you think? |
|
@kainzhong Thanks for contribution! This change looks good to me. And yes, I agree that some semantic changes should be discussed and decided by cutlass people. |
I can see where your point in the black box change and an input from one of the cutlass people would be much appreciated but i think the test cases don't hurt and are more of an assurance , but thats just my opinion and might not be the best flow for the project . |
|
Hi @Ammar-Alnagar unfortunately I'm not a cutlass developer. I think you probably should request their review instead since they are the ones who can approve it. |
no worries , thanks alot for the help and comments !!! |
|
@Junkai-Wu @brandon-yujie-sun @fengxie , can i get a review on this whenever you get a chance ? , thanks!!! |
brandon-yujie-sun
left a comment
There was a problem hiding this comment.
Thanks for contributing the change!
test Move keyword-only and positional-or-keyword flag checks after constexpr annotation filtering to avoid unnecessary computation for excluded parameters. Delete the C++ TVM FFI registry integration test which benchmarked GPU launch overhead via a custom C++ extension. The test required a CUDA toolkit and tvm_ffi at build time, making it fragile in CI environments. Move tvm_ffi import to top of kwargs wrapper spec test for consistency.
|
@Junkai-Wu for further processing |
1. What was the Issue? (#3527)
In CUTLASS v4.6, the routing condition in
python/CuTeDSL/cutlass/cutlass_dsl/cutlass.pywas updated to check:Because
kwargs_wrapper_spec.arg_namesincludes positional parameter names for every argument, any@cute.jitfunction taking 1 or more arguments evaluated toTrueand was routed toTVMFFIJitCompiledFunctionWithKwargs.TVMFFIJitCompiledFunctionWithKwargswraps invocation inkwargs_wrapper.make_kwargs_wrapper. When registered via TVM-FFI and called from C++, execution left C++ to enter Python (GIL + argument wrapper parsing), causing CPU overhead regression compared to direct C++ TVM-FFI function execution.2. What We Did
Positional-only parameters (
def func(a, b, c, /)) cannot be called with keyword arguments in Python grammar. Therefore, functions with strictly positional-only arguments do not require keyword-argument wrapping.python/CuTeDSL/cutlass/base_dsl/jit_executor.py:has_pos_or_kwtoKwargsWrapperSpec.get_kwargs_wrapper_specto track whether anyParameter.POSITIONAL_OR_KEYWORDparameter exists.python/CuTeDSL/cutlass/cutlass_dsl/cutlass.py:kwargs_wrapper_spec.arg_namescheck in_make_compiled_functokwargs_wrapper_spec.has_pos_or_kw.def func(a, b, c, /)without defaults or dataclasses now returnTVMFFIJitCompiledFunction(a direct subclass oftvm_ffi.Function).Unit Tests & Documentation:
test_tvm_ffi_kwargs_wrapper_spec.py.tvm_ffi_compilation.rst:64.3. Comparison & Verification of Fix
def func()()[]TVMFFIJitCompiledFunctiontvm_ffi.Function)def func(a, b, c, /)(Fix)()[]TVMFFIJitCompiledFunctiontvm_ffi.Function, bypasses GIL/wrapper)def func(a, b, c)()[]TVMFFIJitCompiledFunctionWithKwargsfunc(a=1, b=2))def func(a, b=1, /)(1,)[]TVMFFIJitCompiledFunctionWithKwargsdef func(a, /, *, k=1)()['k']TVMFFIJitCompiledFunctionWithKwargsVerification Summary
inspect.signatureacross positional-only, positional-or-keyword, and mixed argument patterns.def func(a, b, c, /)correctly evaluatescheck_routing()toFalse, bypassingTVMFFIJitCompiledFunctionWithKwargsand directly instantiatingTVMFFIJitCompiledFunction.