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

feature: Add make style target and refactor RAJA with clang-format #1731

Closed
wants to merge 12 commits into from

Conversation

johnbowen42
Copy link
Contributor

@johnbowen42 johnbowen42 commented Sep 4, 2024

This PR refactors the entire RAJA codebase using a new make style code target. The style target is configured in cmake using the raja_add_code_checks macro, which uses much of the same logic as axom_add_code_checks macro in axom.

To apply the formatting specified by this PR, simply call make style from the build directory, and specify a valid clang-format 14 version via CLANGFORMAT_EXECUTABLE

update 10/1: I removed examples and exercises from this PR, with the intention of reformatting them once I create a script for excluding compound template types from clang formatting. The plan is to
(1) merge this PR once everyone is satisfied with the formatting rules
(2) Add a pipeline that formats and enforces style
(3) Add a script that excludes nested typedefs automatically in a follow-up

>
>
>(make_tuple(RangeSegment{0,25}, RangeSegment{0,25}),
kernel_param<KernelPolicy<statement::Tile<
Copy link
Member

Choose a reason for hiding this comment

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

This is an example of making nested templates hard to read. I think the original format is much easier to read. @artv3 do you agree?

Copy link
Member

Choose a reason for hiding this comment

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

Agree

Copy link
Member

@artv3 artv3 left a comment

Choose a reason for hiding this comment

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

Some of the kernels look wonky due to the formatter, perhaps there are some parameters we can play with to adjust the formatting in RAJA kernels.

examples/launch_flatten.cpp Outdated Show resolved Hide resolved
examples/launch_flatten.cpp Outdated Show resolved Hide resolved
examples/kernel-dynamic-tile.cpp Outdated Show resolved Hide resolved
@rhornung67
Copy link
Member

@johnbowen42 About this PR...As we merge other PRs, we need to merge develop into this PR branch. So please post instructions for rerunning the formatting (which clang version, etc.) in the top description of this PR. Thank you.

@rhornung67
Copy link
Member

Also, @johnbowen42 I noticed that some header file inclusion orders were changed in this PR. I haven't dug in, but that may be the cause of the CI failures.

@johnbowen42
Copy link
Contributor Author

Also, @johnbowen42 I noticed that some header file inclusion orders were changed in this PR. I haven't dug in, but that may be the cause of the CI failures.

Should be fixed:

SortIncludes: false

@johnbowen42
Copy link
Contributor Author

@LLNL/raja-core please drop this PR a review

Copy link
Member

@adrienbernede adrienbernede left a comment

Choose a reason for hiding this comment

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

I can only recommend developers to setup a pre-commit git hook that will check format before each commit.

include/RAJA/index/IndexSetUtils.hpp Show resolved Hide resolved
RAJA_INLINE bool compareSegmentById(
size_t segid,
const TypedIndexSet<P0, PREST...> &other) const
RAJA_INLINE bool
Copy link
Member

Choose a reason for hiding this comment

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

Why does it put a line break here between the return type and method name, but not below at line 189?

}
);
forall<ExecPolicy<seq_segit, seq_exec>>(
iset, [&](typename CONTAINER_T::value_type idx) { tcon.push_back(idx); });
Copy link
Member

Choose a reason for hiding this comment

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

I think it's better to start lambda expressions on a new line. Also, why did it not format the curly braces on new lines like other code sections?

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 have it set to allow single line lambdas

tcon.push_back(idx);
}
);
forall<seq_exec>(seg, [&](typename CONTAINER_T::value_type idx)
Copy link
Member

Choose a reason for hiding this comment

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

The formatting choices, like this one, are inconsistent with others.

}
);
forall<ExecPolicy<seq_segit, seq_exec>>(
iset,
Copy link
Member

Choose a reason for hiding this comment

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

why is it indenting 4 spaces here and 2 spaces in other places?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's applying an argument alignment rule instead of an indentation rule

);
forall<ExecPolicy<seq_segit, seq_exec>>(
iset,
[&](typename CONTAINER_T::value_type idx)
Copy link
Member

Choose a reason for hiding this comment

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

This is what I would expect in my comments above. It appears that it is formatting lambda expressions in multiple inconsistent ways.....grrrfff.

struct StripIndexTypeT {
using type = FROM;
namespace internal
{
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice if it inserted a blank line between namespace declarations and the contents inside.

};
} // namespace internal
} // namespace internal
Copy link
Member

Choose a reason for hiding this comment

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

Adding to an earlier comment, adding a blank line before the closing curly brace of a namespace would be preferred.

struct StripIndexTypeT<FROM, typename std::enable_if<std::is_base_of<IndexValueBase, FROM>::value>::type>
template <typename FROM>
struct StripIndexTypeT<
FROM,
Copy link
Member

Choose a reason for hiding this comment

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

This template parameter formatting is strange.

using IndexValueType = TYPE; \
RAJA_HOST_DEVICE RAJA_INLINE TYPE() : parent::IndexValue() {} \
RAJA_HOST_DEVICE RAJA_INLINE explicit TYPE(::RAJA::Index_type v) \
: parent::IndexValue(v) \
Copy link
Member

Choose a reason for hiding this comment

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

4 space indentation?

public: \
RAJA_HOST_DEVICE RAJA_INLINE TYPE() \
: RAJA::IndexValue<TYPE, IDXT>::IndexValue() \
{} \
Copy link
Member

Choose a reason for hiding this comment

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

Is there a way to make it add an empty line between methods?

Copy link
Member

@rhornung67 rhornung67 left a comment

Choose a reason for hiding this comment

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

Some changes I like. But, the inconsistent formatting introduced is painful to look at. This will be good to discuss with the team at next week's meeting.

@johnbowen42
Copy link
Contributor Author

please see this pull request for a simplified version #1767

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.

4 participants