- Notifications
You must be signed in to change notification settings - Fork261
How to format code
Adam Dickin edited this pageJun 13, 2025 ·9 revisions
There are now two make commands in the repo that can help with formatting.
make check_format
: this will check your format and output an error if something is incorrectly formatted.Does not make changesmake format
: this will format any files that are incorrectly formatted automatically.Makes Changes
Run this script from the root of MIOpen tree (where the.clang-format file resides) prior committing your edits to avoid formatting failures:
CLANG_FORMAT='clang-format-12'if!command -v$CLANG_FORMAT2>&1 /dev/nullthenecho"${CLANG_FORMAT} is not installed or in your path"exit 1fifind. -iname'*.h' \ -o -iname'*.hpp' \ -o -iname'*.cpp' \ -o -iname'*.h.in' \ -o -iname'*.hpp.in' \ -o -iname'*.cpp.in' \ -o -iname'*.cl' \| grep -v -E'(build/)|(install/)' \| xargs -n 1 -P$(nproc) -I{} -t${CLANG_FORMAT} -style=file {} -i2>/dev/null
The script reformats source files, when necessary. Please do not forget to commit reformatted source files after that.
Note:| grep -v -E '(build/)|(install/)'
is used to avoid formatting within./build/
and./install/
; please fix this line according to your needs.