Skip to content

Commit d219aec

Browse files
authored
Add clang format (#148)
Add a CI action to check formatting and propose code modifications as patches or as comments.
1 parent b065245 commit d219aec

File tree

3 files changed

+126
-9
lines changed

3 files changed

+126
-9
lines changed

.github/workflows/cpp-linter.yml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: cpp-linter
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
cpp-linter:
8+
runs-on: ubuntu-latest
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
defaults:
13+
run:
14+
shell: bash -el {0}
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Install deps (APT)
18+
run: |
19+
sudo apt-get update
20+
sudo apt-get update
21+
sudo apt-get install -y \
22+
lsb-release \
23+
gnupg \
24+
software-properties-common \
25+
git \
26+
python3 \
27+
python3-pip \
28+
mariadb-server \
29+
mariadb-client \
30+
curl \
31+
rabbitmq-server \
32+
supervisor \
33+
python3-venv \
34+
nlohmann-json3-dev \
35+
build-essential \
36+
cmake \
37+
libopenmpi-dev \
38+
libmetis-dev \
39+
libhypre-dev \
40+
libblas-dev \
41+
liblapack-dev \
42+
libhdf5-dev \
43+
hdf5-tools
44+
- name: Install clang-llvm
45+
run: |
46+
wget https://apt.llvm.org/llvm.sh
47+
chmod +x llvm.sh
48+
sudo ./llvm.sh 18
49+
- name: Install AMQCPP
50+
run: |
51+
git clone --depth=1 https://github.com/CopernicaMarketingSoftware/AMQP-CPP.git
52+
cd AMQP-CPP/
53+
mkdir -p build/
54+
cd build/
55+
cmake -DCMAKE_CXX_FLAGS="-D_GLIBCXX_USE_CXX11_ABI=0" -DAMQP-CPP_LINUX_TCP=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DAMQP-CPP_BUILD_SHARED=On ..
56+
make && sudo make install
57+
- name: Install caliper
58+
run: |
59+
git clone --depth 1 https://github.com/LLNL/Caliper.git
60+
cd Caliper
61+
mkdir build && cd build
62+
cmake ..
63+
make && sudo make install
64+
- name: Install Torch and HDF5
65+
run: |
66+
pip3 install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
67+
pip3 install h5py
68+
- name: Install AMS
69+
run: |
70+
mkdir build
71+
cd build
72+
cmake -DWITH_RMQ=On \
73+
-DCMAKE_EXPORT_COMPILE_COMMANDS=on \
74+
-DTorch_DIR=$(python -c 'import torch; print(torch.__path__[0])')/share/cmake/Torch \
75+
-DBUILD_SHARED_LIBS=On \
76+
-DCMAKE_C_COMPILER=clang-18 \
77+
-DCMAKE_CXX_COMPILER=clang++-18 \
78+
-DWITH_CALIPER=On \
79+
-DWITH_HDF5=On \
80+
-DWITH_RMQ=On \
81+
-DWITH_TESTS=On \
82+
-DWITH_AMS_DEBUG=On \
83+
-DWITH_CUDA=Off \
84+
-DWITH_MPI=On ..
85+
- uses: cpp-linter/cpp-linter-action@v2
86+
id: linter
87+
continue-on-error: true
88+
env:
89+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
90+
with:
91+
version: 18
92+
ignore: .github | .gitlab | scripts | build | .git
93+
database: build
94+
extra-args: '-D__AMS_ENABLE_CALIPER__ -D__AMS_ENABLE_HDF5__ -D__AMS_ENABLE_MPI__ -D__AMS_ENABLE_RMQ__'
95+
style: file
96+
tidy-checks: ''
97+
lines-changed-only: true
98+
format-review: true
99+
tidy-review: false
100+
passive-reviews: true
101+
thread-comments: true
102+
- name: Check clang-format linter status
103+
if: steps.linter.outputs.clang-format-checks-failed != 0
104+
run: exit 1

src/AMSlib/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,12 @@ if (WITH_RMQ)
5151
target_link_libraries(AMS PUBLIC $<BUILD_INTERFACE:amqpcpp> PRIVATE $<INSTALL_INTERFACE:amqpcpp>)
5252

5353
if (OPENSSL_FOUND)
54-
target_link_libraries(AMS PUBLIC $<BUILD_INTERFACE:OpenSSL::SSL OpenSSL::Crypto> PRIVATE
55-
$<INSTALL_INTERFACE:OpenSSL::SSL OpenSSL::Crypto>)
54+
target_link_libraries(AMS PUBLIC
55+
$<BUILD_INTERFACE:OpenSSL::SSL>
56+
$<BUILD_INTERFACE:OpenSSL::Crypto>
57+
PRIVATE
58+
$<INSTALL_INTERFACE:OpenSSL::SSL>
59+
$<INSTALL_INTERFACE:OpenSSL::Crypto>)
5660
endif()
5761
# NOTE: We set here the event/event pthreads as public. As there is no easy way
5862
# to do a find package(libevent) and RMQ is not exposing that properly.

src/AMSlib/ml/surrogate.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ SurrogateModel::SurrogateModel(std::string& model_path, bool isDeltaUQ)
5656

5757
if (!std::experimental::filesystem::exists(Path, ec)) {
5858
FATAL(Surrogate,
59-
"Path to Surrogate Model (%s) Does not exist",
59+
"Path to Surrogate Model (%s) Does not "
60+
"exist",
6061
model_path.c_str())
6162
}
6263

@@ -69,7 +70,8 @@ SurrogateModel::SurrogateModel(std::string& model_path, bool isDeltaUQ)
6970
auto method_ptr = module.find_method("get_ams_info");
7071
if (!method_ptr) {
7172
FATAL(Surrogate,
72-
"The Surrogate %s is not a valid AMSModel",
73+
"The Surrogate %s is not a valid "
74+
"AMSModel",
7375
model_path.c_str());
7476
}
7577

@@ -121,7 +123,10 @@ std::tuple<AMSResourceType, torch::DeviceType> SurrogateModel::
121123
return std::make_tuple(AMS_DEVICE, c10::DeviceType::CUDA);
122124
}
123125
// If no parameters or buffers are found, default to unknown
124-
FATAL(Surrogate, "Cannot determine device type of model %s", value.c_str());
126+
FATAL(Surrogate,
127+
"Cannot determine device type of model "
128+
"%s",
129+
value.c_str());
125130
return std::make_tuple(AMS_UNKNOWN,
126131
c10::DeviceType::COMPILE_TIME_MAX_DEVICE_TYPES);
127132
}
@@ -184,7 +189,8 @@ std::tuple<torch::Tensor, torch::Tensor> SurrogateModel::_evaluate(
184189
{
185190
if (inputs.dtype() != torch_dtype) {
186191
throw std::runtime_error(
187-
"Received inputs of wrong dType. Model is expecting " +
192+
"Received inputs of wrong dType. Model "
193+
"is expecting " +
188194
getDTypeAsString(torch::typeMetaToScalarType(inputs.dtype())) +
189195
" and model is " + getDTypeAsString(torch_dtype));
190196
}
@@ -214,7 +220,8 @@ std::tuple<torch::Tensor, torch::Tensor> SurrogateModel::evaluate(
214220
{
215221
if (Inputs.size() == 0) {
216222
throw std::invalid_argument(
217-
"Input Vector should always contain at least one tensor");
223+
"Input Vector should always contain at "
224+
"least one tensor");
218225
}
219226

220227
torch::DeviceType InputDevice = Inputs[0].device().type();
@@ -225,12 +232,14 @@ std::tuple<torch::Tensor, torch::Tensor> SurrogateModel::evaluate(
225232
for (auto& In : Inputs) {
226233
if (InputDevice != In.device().type()) {
227234
throw std::invalid_argument(
228-
"Unsupported feature, application domain tensors are on different "
235+
"Unsupported feature, application "
236+
"domain tensors are on different "
229237
"devices\n");
230238
}
231239
if (InputDType != torch::typeMetaToScalarType(In.dtype())) {
232240
throw std::invalid_argument(
233-
"Unsupported feature, application domain tensors have different data "
241+
"Unsupported feature, application "
242+
"domain tensors have different data "
234243
"types\n");
235244
}
236245
}

0 commit comments

Comments
 (0)