Skip to content

Commit

Permalink
Switch to clang-format (#1051)
Browse files Browse the repository at this point in the history
* style - switch to clang-format

* ci - use newer libxsmm

* action - update format action

* format - consistent use of {} for multi-line if/for

* make - remove stray newline

* make - simpler 'make format' target

* ci - use newer libxsmm

* doc - minor release note claification

* minor - minor fix

* minor - minor fix

* minor - minor fix

* minor - minor fix

* make format

* format - less aggressive alignment rules

* tidy - check for argument name mismatches

* fix newline

* format - mirror Ratel update to .clang-format

* fix merge error

* fix merge conflict

* fix merge error

* drop style in .phony list

* Update .clang-format

Co-authored-by: Jed Brown <[email protected]>

* apply updated format

Co-authored-by: Jed Brown <[email protected]>
  • Loading branch information
jeremylt and jedbrown authored Nov 17, 2022
1 parent 6929379 commit 2b730f8
Show file tree
Hide file tree
Showing 534 changed files with 43,734 additions and 53,472 deletions.
12 changes: 0 additions & 12 deletions .astylerc

This file was deleted.

14 changes: 14 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
BasedOnStyle: "Google"

AlignAfterOpenBracket: Align
AlignArrayOfStructures: Left
AlignConsecutiveAssignments: Consecutive
AlignConsecutiveDeclarations: Consecutive
AlignEscapedNewlines: true
AlignOperands: Align
AlignTrailingComments: true
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
ColumnLimit: 150
CommentPragmas: 'TESTARGS'
TabWidth: 4
UseTab: Never
2 changes: 2 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Checks: "clang-diagnostic-*,clang-analyzer-*,readability-inconsistent-declaration-parameter-name"
HeaderFilterRegex: .*
6 changes: 3 additions & 3 deletions .github/workflows/c-fortran-test-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:
steps:
- name: Environment setup
uses: actions/checkout@v3
- name: Install astyle
run: sudo apt-get install astyle
- name: Install clang-format
run: sudo apt install clang-format-14
- name: C style
env:
CC: ${{ matrix.compiler }}
FC: gfortran-11
run: |
make info
make style-c -j2 && git diff --exit-code
make format-c -j2 && git diff --exit-code
2 changes: 1 addition & 1 deletion .github/workflows/python-test-with-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ jobs:
CC: ${{ matrix.compiler }}
FC: gfortran-11
run: |
make style-py && git diff --exit-code
make format-py && git diff --exit-code
31 changes: 19 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ install : $(libceed) $(OBJDIR)/ceed.pc
$(INSTALL_DATA) $(wildcard include/ceed/jit-source/hip/*.h) "$(DESTDIR)$(includedir)/ceed/jit-source/hip/"
$(INSTALL_DATA) $(wildcard include/ceed/jit-source/gallery/*.h) "$(DESTDIR)$(includedir)/ceed/jit-source/gallery/"

.PHONY : all cln clean doxygen doc lib install par print test tst prove prv prove-all junit examples style style-c style-py tidy iwyu info info-backends info-backends-all
.PHONY : all cln clean doxygen doc format lib install par print test tst prove prv prove-all junit examples tidy iwyu info info-backends info-backends-all

cln clean :
$(RM) -r $(OBJDIR) $(LIBDIR) dist *egg* .pytest_cache *cffi*
Expand All @@ -687,6 +687,7 @@ cln clean :
distclean : clean
$(RM) -r doc/html doc/sphinx/build $(CONFIG)

# Documentation
DOXYGEN ?= doxygen
doxygen :
$(DOXYGEN) -q Doxyfile
Expand All @@ -696,19 +697,24 @@ doc-html doc-latexpdf doc-epub doc-livehtml : doc-% : doxygen

doc : doc-html

style-c :
@astyle --options=.astylerc \
$(filter-out include/ceedf.h $(wildcard tests/t*-f.h), \
$(wildcard include/*.h interface/*.[ch] tests/*.[ch] backends/*/*.[ch] \
examples/*/*/*.[ch] examples/*/*.[ch] examples/*/*.[ch]pp gallery/*/*.[ch]))
# Style/Format
CLANG_FORMAT ?= clang-format

FORMAT_OPTS += -style=file -i

format.ch := $(filter-out include/ceedf.h $(wildcard tests/t*-f.h), $(shell git ls-files *.[ch]pp *.[ch]))

format-c :
$(CLANG_FORMAT) $(FORMAT_OPTS) $(format.ch)

AUTOPEP8 = autopep8
style-py : AUTOPEP8_ARGS = --in-place --aggressive
style-py :
format-py : AUTOPEP8_ARGS = --in-place --aggressive
format-py :
@$(AUTOPEP8) $(AUTOPEP8_ARGS) $(wildcard *.py python**/*.py python/tests/*.py examples**/*.py doc/sphinx/source**/*.py benchmarks/*.py)

style : style-c style-py
format : format-c format-py

# Tidy
CLANG_TIDY ?= clang-tidy

%.c.tidy : %.c
Expand All @@ -717,16 +723,17 @@ CLANG_TIDY ?= clang-tidy
%.cpp.tidy : %.cpp
$(CLANG_TIDY) $(TIDY_OPTS) $^ -- $(CPPFLAGS) --std=c++11 -I$(CUDA_DIR)/include -I$(OCCA_DIR)/include -I$(HIP_DIR)/include

tidy_c : $(libceed.c:%=%.tidy)
tidy_cpp : $(libceed.cpp:%=%.tidy)
tidy-c : $(libceed.c:%=%.tidy)
tidy-cpp : $(libceed.cpp:%=%.tidy)

tidy : tidy_c tidy_cpp
tidy : tidy-c tidy-cpp

ifneq ($(wildcard ../iwyu/*),)
IWYU_DIR ?= ../iwyu
IWYU_CC ?= $(IWYU_DIR)/build/bin/include-what-you-use
endif

# IWYU
iwyu : CC=$(IWYU_CC)
iwyu : lib

Expand Down
31 changes: 12 additions & 19 deletions backends/avx/ceed-avx-blocked.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,34 @@
//
// This file is part of CEED: http://github.com/ceed

#include <ceed/ceed.h>
#include <ceed/backend.h>
#include <ceed/ceed.h>
#include <stdbool.h>
#include <string.h>

#include "ceed-avx.h"

//------------------------------------------------------------------------------
// Backend Init
//------------------------------------------------------------------------------
static int CeedInit_Avx(const char *resource, Ceed ceed) {
int ierr;
if (strcmp(resource, "/cpu/self") && strcmp(resource, "/cpu/self/avx") &&
strcmp(resource, "/cpu/self/avx/blocked"))
if (strcmp(resource, "/cpu/self") && strcmp(resource, "/cpu/self/avx") && strcmp(resource, "/cpu/self/avx/blocked")) {
// LCOV_EXCL_START
return CeedError(ceed, CEED_ERROR_BACKEND,
"AVX backend cannot use resource: %s", resource);
// LCOV_EXCL_STOP
ierr = CeedSetDeterministic(ceed, true); CeedChkBackend(ierr);
return CeedError(ceed, CEED_ERROR_BACKEND, "AVX backend cannot use resource: %s", resource);
// LCOV_EXCL_STOP
}
CeedCallBackend(CeedSetDeterministic(ceed, true));

// Create reference CEED that implementation will be dispatched
// through unless overridden
Ceed ceed_ref;
CeedInit("/cpu/self/opt/blocked", &ceed_ref);
ierr = CeedSetDelegate(ceed, ceed_ref); CeedChkBackend(ierr);
CeedCallBackend(CeedInit("/cpu/self/opt/blocked", &ceed_ref));
CeedCallBackend(CeedSetDelegate(ceed, ceed_ref));

if (CEED_SCALAR_TYPE == CEED_SCALAR_FP64) {
ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "TensorContractCreate",
CeedTensorContractCreate_f64_Avx);
CeedChkBackend(ierr);
CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "TensorContractCreate", CeedTensorContractCreate_f64_Avx));
} else {
ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "TensorContractCreate",
CeedTensorContractCreate_f32_Avx);
CeedChkBackend(ierr);
CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "TensorContractCreate", CeedTensorContractCreate_f32_Avx));
}

return CEED_ERROR_SUCCESS;
Expand All @@ -46,7 +41,5 @@ static int CeedInit_Avx(const char *resource, Ceed ceed) {
//------------------------------------------------------------------------------
// Backend Register
//------------------------------------------------------------------------------
CEED_INTERN int CeedRegister_Avx_Blocked(void) {
return CeedRegister("/cpu/self/avx/blocked", CeedInit_Avx, 30);
}
CEED_INTERN int CeedRegister_Avx_Blocked(void) { return CeedRegister("/cpu/self/avx/blocked", CeedInit_Avx, 30); }
//------------------------------------------------------------------------------
31 changes: 12 additions & 19 deletions backends/avx/ceed-avx-serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,34 @@
//
// This file is part of CEED: http://github.com/ceed

#include <ceed/ceed.h>
#include <ceed/backend.h>
#include <ceed/ceed.h>
#include <stdbool.h>
#include <string.h>

#include "ceed-avx.h"

//------------------------------------------------------------------------------
// Backend Init
//------------------------------------------------------------------------------
static int CeedInit_Avx(const char *resource, Ceed ceed) {
int ierr;
if (strcmp(resource, "/cpu/self")
&& strcmp(resource, "/cpu/self/avx/serial"))
if (strcmp(resource, "/cpu/self") && strcmp(resource, "/cpu/self/avx/serial")) {
// LCOV_EXCL_START
return CeedError(ceed, CEED_ERROR_BACKEND,
"AVX backend cannot use resource: %s", resource);
// LCOV_EXCL_STOP
ierr = CeedSetDeterministic(ceed, true); CeedChkBackend(ierr);
return CeedError(ceed, CEED_ERROR_BACKEND, "AVX backend cannot use resource: %s", resource);
// LCOV_EXCL_STOP
}
CeedCallBackend(CeedSetDeterministic(ceed, true));

// Create reference CEED that implementation will be dispatched
// through unless overridden
Ceed ceed_ref;
CeedInit("/cpu/self/opt/serial", &ceed_ref);
ierr = CeedSetDelegate(ceed, ceed_ref); CeedChkBackend(ierr);
CeedCallBackend(CeedInit("/cpu/self/opt/serial", &ceed_ref));
CeedCallBackend(CeedSetDelegate(ceed, ceed_ref));

if (CEED_SCALAR_TYPE == CEED_SCALAR_FP64) {
ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "TensorContractCreate",
CeedTensorContractCreate_f64_Avx);
CeedChkBackend(ierr);
CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "TensorContractCreate", CeedTensorContractCreate_f64_Avx));
} else {
ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "TensorContractCreate",
CeedTensorContractCreate_f32_Avx);
CeedChkBackend(ierr);
CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "TensorContractCreate", CeedTensorContractCreate_f32_Avx));
}

return CEED_ERROR_SUCCESS;
Expand All @@ -46,7 +41,5 @@ static int CeedInit_Avx(const char *resource, Ceed ceed) {
//------------------------------------------------------------------------------
// Backend Register
//------------------------------------------------------------------------------
CEED_INTERN int CeedRegister_Avx_Serial(void) {
return CeedRegister("/cpu/self/avx/serial", CeedInit_Avx, 35);
}
CEED_INTERN int CeedRegister_Avx_Serial(void) { return CeedRegister("/cpu/self/avx/serial", CeedInit_Avx, 35); }
//------------------------------------------------------------------------------
Loading

0 comments on commit 2b730f8

Please sign in to comment.