KEMBAR78
[AOTI] Support non auto-tuned triton kernels in aoti by oulgen · Pull Request #113090 · pytorch/pytorch · GitHub
Skip to content

Conversation

@pytorch-bot
Copy link

pytorch-bot bot commented Nov 6, 2023

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/113090

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 036cbc8 with merge base b7acd37 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

for arg_name in self.ordered_kwargs_for_cpp_kernel:
v = self.get_kwargs_value(arg_name)
kwargs.append(V.graph.wrapper_code.val_to_arg_str(v))
if isinstance(v, sympy.Expr):
Copy link
Contributor Author

@oulgen oulgen Nov 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this but not sure if there's a better solution..

@oulgen oulgen added ciflow/trunk Trigger trunk jobs on your pull request rocm This tag is for PRs from ROCm team ciflow/rocm Trigger "default" config CI on ROCm and removed rocm This tag is for PRs from ROCm team labels Nov 6, 2023
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler

[ghstack-poisoned]
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler

[ghstack-poisoned]
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler

[ghstack-poisoned]
oulgen added a commit that referenced this pull request Nov 7, 2023
ghstack-source-id: 0f7105a
Pull Request resolved: #113090
@jansel
Copy link
Contributor

jansel commented Nov 7, 2023

@desertfire @chenyang78 mind reviewing this one?

@jansel jansel removed their request for review November 7, 2023 04:20
Comment on lines 1024 to 1025
@requires_cuda()
@skipIfRocm
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we have if self.device != "cuda" check below, are these two redundant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

triton is not installed on all machines, so in the past, if i didn't include the both of these, i ran into some symbol problems. I can try deleting them and seeing if anything fails

if self.kwargs and not self.ordered_kwargs_for_cpp_kernel:
assert (
self.ordered_kwargs_for_cpp_kernel
), "ordered_kwargs_for_cpp_kernel is missing"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the assert condition is always False? Probably we could just thrown an exception here?

for arg_name in self.ordered_kwargs_for_cpp_kernel:
v = self.get_kwargs_value(arg_name)
kwargs.append(V.graph.wrapper_code.val_to_arg_str(v))
if isinstance(v, sympy.Expr):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a clause to handle sympy.Expr from CppWrapperCodeGen's val_to_arg_str so that we could make kwargs hold only strings.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I think the point here is to use sympy.Expr as kwarg to codegen it at a later stage? cc @oulgen.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if we converted to a string, then codegen will not be able to tell it was a sympy expr and emit it like a tensor. @chenyang78 The problem is codegen tries to figure out things based on their string representation but for sympy expr, it keeps them as is.. which is not great.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Thanks for the clarification. This is quite unfortunate...

self.grid = grid

kernel, _ = self.get_kernel_and_configs()
self.ordered_kwargs_for_cpp_kernel = kernel.arg_names
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be pretty hacky to rely on ordered_kwargs_for_cpp_kernel to generate kernel args indirectly. Wondering if we could implement a codegen_args method for UserDefinedTritonKernel, where we return arg strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not following. It is not possible to return all strings because then sympy expr can no longer be distinguished. Look at

def generate_args_decl(self, call_args):
dynamic_symbols = V.graph.sizevars.free_symbols()
# TODO: only works for constant now, need type info
new_args = []
for arg in call_args:
var_name = f"var_{next(self.arg_var_id)}"
if isinstance(
arg,
(
sympy.Integer,
sympy.Symbol,
SymbolicCallArg,
),
):
self.writeline(f"auto {var_name} = {arg};")
elif is_int(arg):
self.writeline(f"int {var_name} = {arg};")
elif is_float(arg):
self.writeline(f"float {var_name} = {arg};")
elif any(str(arg) == s.name for s in dynamic_symbols):
self.writeline(f"auto {var_name} = {arg};")
else:
if config.aot_inductor.abi_compatible:
self.writeline(f"CUdeviceptr {var_name};")
self.writeline(
f"AOTI_TORCH_ERROR_CODE_CHECK(aoti_torch_get_data_ptr({arg}, reinterpret_cast<void**>(&{var_name})));"
)
else:
self.writeline(
f"CUdeviceptr {var_name} = reinterpret_cast<CUdeviceptr>({arg}.data_ptr());"
)
new_args.append(f"&{var_name}")
return ", ".join(new_args)

arg,
(
sympy.Integer,
sympy.Expr,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we can simply use {arg} in the f-string below if the arg is sympy.Expr. From what I remember, in C++ codegen we need to use self.expr_printer for expressions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!

for arg_name in self.ordered_kwargs_for_cpp_kernel:
v = self.get_kwargs_value(arg_name)
kwargs.append(V.graph.wrapper_code.val_to_arg_str(v))
if isinstance(v, sympy.Expr):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I think the point here is to use sympy.Expr as kwarg to codegen it at a later stage? cc @oulgen.

Copy link
Contributor

@aakhundov aakhundov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with a few nits. Thanks!

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler

[ghstack-poisoned]
for arg_name in self.ordered_kwargs_for_cpp_kernel:
v = self.get_kwargs_value(arg_name)
kwargs.append(V.graph.wrapper_code.val_to_arg_str(v))
if isinstance(v, sympy.Expr):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Thanks for the clarification. This is quite unfortunate...

@oulgen
Copy link
Contributor Author

oulgen commented Nov 8, 2023

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot
Copy link
Collaborator

Merge failed

Reason: Command git -C /home/runner/work/pytorch/pytorch cherry-pick -x 8b2992137f78e28a48c9fa782d7124697a828436 returned non-zero exit code 1

Auto-merging test/inductor/test_aot_inductor.py
Auto-merging torch/_inductor/ir.py
CONFLICT (content): Merge conflict in torch/_inductor/ir.py
error: could not apply 8b2992137f7... [AOTI] Support non auto-tuned triton kernels in aoti
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
Details for Dev Infra team Raised by workflow job

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler

[ghstack-poisoned]
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler

[ghstack-poisoned]
@oulgen
Copy link
Contributor Author

oulgen commented Nov 8, 2023

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/rocm Trigger "default" config CI on ROCm ciflow/trunk Trigger trunk jobs on your pull request Merged module: inductor release notes: inductor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants