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

Disable whitespace disrupting CUDA chevrons #162

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JamieJQuinn
Copy link

@JamieJQuinn JamieJQuinn commented Feb 8, 2024

Previously, fprettify did not understand CUDA fortran's triple-chevron syntax for calling kernel functions, e.g.

call example_kernel<<<1, 1>>>(args)

As a result, each symbol in the chevrons <<< would have whitespace added, resulting in the incorrect syntax:

call example_kernel <  <  < 1, 1 >  >  > (args)

This problem only occurs when adding whitespace around relational operators is enabled.

This commit adds an escape hatch to the function that handles whitespace around operators add_whitespace_context which disables the whitespace handling for any line that matches the REGEX "<<<.*>>>":

CUDA_CHEVRONS_RE = re.compile(r"<<<.*>>>", RE_FLAGS)

...

if not ( ... or CUDA_CHEVRONS_RE.search(line) ):

This change should not break any Fortran syntax, however any relational operator that appears in a line that also features a triple-chevron will not be formatted, e.g.

call example_kernel<<<1, 1>>>(3< 4, var1 ==var2)

This fixes #124.

Previously, fprettify did not understand CUDA fortran's triple-chevron syntax
for calling kernel functions, e.g.
```fortran
call example_kernel<<<1, 1>>>(args)
```
As a result, each symbol in the chevrons `<<<` would have whitespace added, resulting
in the incorrect syntax:
```fortran
call example_kernel <  <  < 1, 1 >  >  > (args)
```

This problem only occurs when adding whitespace around relational operators
is enabled.

This commit adds an escape hatch to the function that handles whitespace
around operators `add_whitespace_context` which disables the whitespace
handling for any line that matches the REGEX "<<<.*>>>":

```python
CUDA_CHEVRONS_RE = re.compile(r"<<<.*>>>", RE_FLAGS)

...

if not ( ... or CUDA_CHEVRONS_RE.search(line) ):
```

This change should not break any Fortran syntax, however any relational
operator that appears in a line that *also* features a triple-chevron
will not be formatted, e.g.

```fortran
call example_kernel<<<1, 1>>>(3< 4, var1 ==var2)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature request: prevent fprettify from separating <<<,>>>
1 participant