triton-lang / triton

Development repository for the Triton language and compiler
https://triton-lang.org/
MIT License
13.28k stars 1.63k forks source link

Proposal to use a template engine for code generation #1990

Open youkaichao opened 1 year ago

youkaichao commented 1 year ago

Currently, the code generation in triton uses python f-string, which has to deal with all the escaping for special characters like { and }.

Is it possible to use some template engine like Jinja to make the code generation more maintainable?

I come up with this issue when I tried to understand the generated source code. Copying cpp code in https://github.com/openai/triton/blob/main/python/triton/compiler/make_launcher.py leads to headache. I have to carefully back-escape the code.

If it is acceptable, I can take this PR to do the refactor.

@ptillet

Jokeren commented 1 year ago

I think it's a good proposal

youkaichao commented 1 year ago

Using template engine would separate the code string and the variables, which is not as intuitive as it is now. In addition, I have to deal with the various design of how to place the template files. The granularity is also a problem: there are some one-line f-strings, as well as several lines, together with f-strings with dozens of lines. I don't know how to control the granularity of when to use template engines.

Finally, I gave it up. Using a template engine does not bring much benefit.

The next time when I want to write the code myself, there are not many steps actually:

@Jokeren