Skip to content
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

How to execute string code with @triton.jit in python #5386

Open
starstream opened this issue Dec 10, 2024 · 1 comment
Open

How to execute string code with @triton.jit in python #5386

starstream opened this issue Dec 10, 2024 · 1 comment
Labels

Comments

@starstream
Copy link

starstream commented Dec 10, 2024

Describe the bug

source_code = """
@triton.jit
def add_kernel():
   ...
"""
exec(source_code)

size = 1024
x = torch.rand(size, device="cuda")
y = torch.rand(size, device="cuda")
add_kernel[grid](x, y, output, size, BLOCK_SIZE=1024)

Traceback (most recent call last):
File "", line 3, in
File "/opt/conda/lib/python3.10/site-packages/triton/runtime/jit.py", line 546, in jit
return decorator(fn)
File "/opt/conda/lib/python3.10/site-packages/triton/runtime/jit.py", line 537, in decorator
return JITFunction(
File "/opt/conda/lib/python3.10/site-packages/triton/runtime/jit.py", line 419, in init
self.starting_line_number = inspect.getsourcelines(fn)[1]
File "/opt/conda/lib/python3.10/inspect.py", line 1121, in getsourcelines
lines, lnum = findsource(object)
File "/opt/conda/lib/python3.10/inspect.py", line 958, in findsource
raise OSError('could not get source code')
OSError: could not get source code

Environment details

Triton 3.1.0
GPU NvidiaA100

@starstream starstream added the bug label Dec 10, 2024
@knwng
Copy link
Contributor

knwng commented Dec 15, 2024

Maybe you can take a look at patch_kernel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants