Skip to content

Commit 2bf9168

Browse files
authored
feat: enable sanitizer and clang-tidy build (#202)
* feat: enable sanitizer build (CPU-only) * chore: bump ViennaCore * chore: enable sanitizers in CI build * refactor: further slip specialization lib source files * feat: add clang-tidy build, fix: clang-tidy warnings * fix: update deps, add sanitizers correctly
1 parent 516d82c commit 2bf9168

14 files changed

Lines changed: 101 additions & 46 deletions

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
if (Test-Path build/_deps) { Remove-Item -Recurse -Force build/_deps }
6565
6666
- name: 🏗️ Compile
67-
run: cmake -DVIENNAPS_BUILD_TESTS=ON -B build && cmake --build build --config ${{ matrix.config }}
67+
run: cmake -DVIENNAPS_BUILD_TESTS=ON -DVIENNAPS_ENABLE_SANITIZER=ON -B build && cmake --build build --config ${{ matrix.config }}
6868

6969
- name: 🧪 Test
7070
run: ctest -E "Benchmark|Performance" -C ${{ matrix.config }} --test-dir build

CMakeLists.txt

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ endif()
2121

2222
option(VIENNAPS_PRECOMPILE_HEADERS "Enable precompiled headers" OFF)
2323
option(VIENNAPS_STATIC_BUILD "Build ViennaPS as static library" OFF)
24+
option(VIENNAPS_ENABLE_SANITIZER "Enable sanitizers" OFF)
25+
option(VIENNAPS_ENABLE_CLANG_TIDY "Run clang-tidy during build" OFF)
2426

2527
option(VIENNAPS_USE_GPU "Enable GPU support" OFF)
2628

@@ -68,7 +70,7 @@ if(VIENNAPS_BUILD_PYTHON)
6870
endif()
6971

7072
if(MSVC)
71-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -openmp:llvm /bigobj")
73+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /openmp:llvm /bigobj")
7274
endif()
7375

7476
# --------------------------------------------------------------------------------------------------------
@@ -105,7 +107,7 @@ include("cmake/cpm.cmake")
105107

106108
CPMAddPackage(
107109
NAME ViennaCore
108-
VERSION 1.9.4
110+
VERSION 1.9.5
109111
GIT_REPOSITORY "https://github.com/ViennaTools/ViennaCore"
110112
EXCLUDE_FROM_ALL ${VIENNAPS_BUILD_PYTHON}
111113
OPTIONS "VIENNACORE_USE_GPU ${VIENNAPS_USE_GPU}")
@@ -126,7 +128,8 @@ CPMAddPackage(
126128
NAME ViennaLS
127129
VERSION 5.5.0
128130
GIT_REPOSITORY "https://github.com/ViennaTools/ViennaLS"
129-
EXCLUDE_FROM_ALL ${VIENNAPS_BUILD_PYTHON})
131+
EXCLUDE_FROM_ALL ${VIENNAPS_BUILD_PYTHON}
132+
OPTIONS "VIENNALS_PRECOMPILE_HEADERS ${VIENNAPS_PRECOMPILE_HEADERS}")
130133

131134
CPMAddPackage(
132135
NAME ViennaCS
@@ -137,6 +140,29 @@ CPMAddPackage(
137140
target_link_libraries(${PROJECT_NAME} INTERFACE ViennaTools::ViennaCore ViennaTools::ViennaLS
138141
ViennaTools::ViennaRay ViennaTools::ViennaCS)
139142

143+
# --------------------------------------------------------------------------------------------------------
144+
# Setup Sanitizer or Clang-Tidy
145+
# --------------------------------------------------------------------------------------------------------
146+
147+
if(VIENNAPS_ENABLE_SANITIZER)
148+
if(VIENNAPS_USE_GPU)
149+
message(WARNING "[ViennaPS] Sanitizers cannot be used with GPU support enabled!")
150+
else()
151+
viennacore_enable_sanitizer()
152+
message(STATUS "[ViennaPS] Enabled Sanitizers")
153+
endif()
154+
endif()
155+
156+
if(VIENNAPS_ENABLE_CLANG_TIDY)
157+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
158+
find_program(CLANG_TIDY_EXE NAMES clang-tidy)
159+
if(NOT CLANG_TIDY_EXE)
160+
message(FATAL_ERROR "clang-tidy not found")
161+
endif()
162+
163+
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE}" "--quiet" "--warnings-as-errors=*")
164+
endif()
165+
140166
# --------------------------------------------------------------------------------------------------------
141167
# Setup Shared/Static Library
142168
# --------------------------------------------------------------------------------------------------------
@@ -155,8 +181,9 @@ if(VIENNAPS_PRECOMPILE_HEADERS)
155181
target_link_libraries(${LIB_NAME} PRIVATE ${PROJECT_NAME})
156182
target_compile_definitions(${LIB_NAME} PRIVATE VIENNAPS_USE_PRECOMPILED=1
157183
VIENNACORE_COMPILE_SHARED_LIB=1)
158-
target_sources(${LIB_NAME} PRIVATE "lib/specMain.cpp" "lib/specGeometries.cpp"
159-
"lib/specModels.cpp")
184+
target_sources(
185+
${LIB_NAME} PRIVATE "lib/specMain.cpp" "lib/specGeometries.cpp" "lib/specModelsEmulation.cpp"
186+
"lib/specModelsSimulation.cpp" "lib/specProcess.cpp")
160187

161188
set_target_properties(
162189
${LIB_NAME}

include/viennaps/models/psCF4O2Etching.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ class CF4O2Ion final
344344
const NumericType sqrt_E_th_ie_C;
345345
const NumericType sqrt_E_th_ie_Si;
346346

347-
NumericType E;
347+
NumericType E = 0.;
348348
};
349349

350350
template <typename NumericType, int D>

include/viennaps/models/psDirectionalProcess.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,6 @@ class DirectionalProcess : public ProcessModelCPU<NumericType, D> {
195195
// Default surface model
196196
auto surfModel = SmartPointer<SurfaceModel<NumericType>>::New();
197197

198-
// Velocity field with multiple rate sets
199-
auto velField =
200-
SmartPointer<impl::DirectionalVelocityField<NumericType, D>>::New(
201-
std::move(rateSets));
202-
203-
this->setSurfaceModel(surfModel);
204-
this->setVelocityField(velField);
205-
this->setProcessName("DirectionalProcess");
206-
207198
// Store process data
208199
processMetaData["DirectionalVelocity"] = std::vector<double>();
209200
processMetaData["IsotropicVelocity"] = std::vector<double>();
@@ -223,6 +214,15 @@ class DirectionalProcess : public ProcessModelCPU<NumericType, D> {
223214
processMetaData["Direction " + std::to_string(i++)] = std::vector<double>{
224215
rateSet.direction[0], rateSet.direction[1], rateSet.direction[2]};
225216
}
217+
218+
// Velocity field with multiple rate sets
219+
auto velField =
220+
SmartPointer<impl::DirectionalVelocityField<NumericType, D>>::New(
221+
std::move(rateSets));
222+
223+
this->setVelocityField(velField);
224+
this->setSurfaceModel(surfModel);
225+
this->setProcessName("DirectionalProcess");
226226
}
227227

228228
using ProcessModelCPU<NumericType, D>::processMetaData;

include/viennaps/models/psFluorocarbonEtching.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ class FluorocarbonIon
346346
const FluorocarbonParameters<NumericType> &p;
347347
const NumericType A;
348348
NumericType minEnergy = std::numeric_limits<NumericType>::max();
349-
NumericType E;
349+
NumericType E = 0.;
350350

351351
public:
352352
FluorocarbonIon(const FluorocarbonParameters<NumericType> &parameters)

include/viennaps/models/psPlasmaEtching.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ class PlasmaEtchingIon
327327
const NumericType sqrt_E_th_ie_P;
328328
const NumericType sqrt_E_th_ie_Sub;
329329

330-
NumericType E;
330+
NumericType E = 0.;
331331
};
332332

333333
template <typename NumericType, int D>

include/viennaps/process/psProcessModel.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ class ProcessModelCPU : public ProcessModelBase<NumericType, D> {
169169
}
170170
};
171171

172+
PS_PRECOMPILE_PRECISION_DIMENSION(ProcessModelCPU)
173+
172174
} // namespace viennaps
173175

174176
#ifdef VIENNACORE_COMPILE_GPU
@@ -239,5 +241,7 @@ class ProcessModelGPU : public ProcessModelBase<NumericType, D> {
239241
}
240242
};
241243

244+
PS_PRECOMPILE_PRECISION_DIMENSION(ProcessModelGPU)
245+
242246
} // namespace viennaps::gpu
243247
#endif

include/viennaps/psMaterials.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ class MaterialMap {
216216
}
217217

218218
static inline Material mapToMaterial(const int matId) {
219+
if (matId < 0 || matId > static_cast<int>(kMaterialMaxId)) {
220+
VIENNACORE_LOG_ERROR("Invalid material id " + std::to_string(matId));
221+
return Material::GAS;
222+
}
219223
return static_cast<Material>(matId);
220224
}
221225

include/viennaps/psReader.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "psDomain.hpp"
44
#include "psPreCompileMacros.hpp"
55

6+
#include <cstring>
67
#include <fstream>
78
#include <string>
89
#include <utility>
@@ -66,7 +67,7 @@ template <class NumericType, int D> class Reader {
6667
// Check identifier
6768
char identifier[8];
6869
fin.read(identifier, 8);
69-
if (std::string(identifier).compare(0, 8, "psDomain")) {
70+
if (std::memcmp(identifier, "psDomain", 8) != 0) {
7071
VIENNACORE_LOG_ERROR(
7172
"Reading domain from stream failed. Header could not be found.");
7273
return;

include/viennaps/psVTKRenderWindow.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ class Custom3DInteractorStyle : public vtkInteractorStyleTrackballCamera {
626626

627627
private:
628628
viennaps::VTKRenderWindow<double, 3> *Window = nullptr;
629-
}; // namespace viennaps
629+
};
630630

631631
// vtkStandardNewMacro(Custom3DInteractorStyle);
632632

@@ -651,7 +651,7 @@ class Custom2DInteractorStyle : public vtkInteractorStyleImage {
651651

652652
private:
653653
viennaps::VTKRenderWindow<double, 2> *Window = nullptr;
654-
}; // namespace viennaps
654+
};
655655

656656
// vtkStandardNewMacro(Custom2DInteractorStyle);
657657

0 commit comments

Comments
 (0)