Skip to content

Commit 98529b6

Browse files
committed
feat: CPU scaling benchmark
1 parent c2a390b commit 98529b6

8 files changed

Lines changed: 738 additions & 7 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ CPMAddPackage(
124124
CPMAddPackage(
125125
NAME ViennaRay
126126
VERSION 4.3.1
127+
GIT_TAG benchmark
127128
GIT_REPOSITORY "https://github.com/ViennaTools/ViennaRay"
128129
EXCLUDE_FROM_ALL ${VIENNAPS_BUILD_PYTHON}
129130
OPTIONS "VIENNARAY_USE_GPU ${VIENNAPS_USE_GPU}")

gpu/benchmark/Benchmark.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
#include <rayParticle.hpp>
99

1010
#define MAKE_GEO Trench
11-
#define DEFAULT_GRID_DELTA 0.1
11+
#define DEFAULT_GRID_DELTA 0.25
1212
#define DEFAULT_STICKING 0.1
1313
#define DIM 3
14-
#define FIXED_RAYS true
14+
#define FIXED_RAYS false
1515

1616
using TranslatorType = std::unordered_map<unsigned long, unsigned long>;
1717
using namespace viennaps;

gpu/benchmark/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ target_link_libraries(CPU_Benchmark PRIVATE ViennaPS)
1212
add_dependencies(CPU_Benchmark ${VIENNAPS_GPU_DEPENDENCIES})
1313
add_dependencies(ViennaPS-GPU_Benchmark CPU_Benchmark)
1414

15+
add_executable(CPU_Scaling ${CMAKE_CURRENT_SOURCE_DIR}/CPU_Scaling.cpp)
16+
target_link_libraries(CPU_Scaling PRIVATE ViennaPS)
17+
add_dependencies(CPU_Scaling ${VIENNAPS_GPU_DEPENDENCIES})
18+
add_dependencies(ViennaPS-GPU_Benchmark CPU_Scaling)
19+
1520
add_executable(holeComparison ${CMAKE_CURRENT_SOURCE_DIR}/holeCompare.cpp)
1621
target_link_libraries(holeComparison PRIVATE ViennaPS)
1722
add_dependencies(holeComparison ${VIENNAPS_GPU_DEPENDENCIES})

gpu/benchmark/CPU_Benchmark.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ int main() {
1212
constexpr int D = DIM;
1313

1414
auto particle = makeCPUParticle<NumericType, D>();
15-
std::vector<std::unique_ptr<viennaray::AbstractParticle<NumericType>>>
16-
particles;
17-
particles.push_back(particle->clone());
1815
std::string fluxLabel = particleType == 0 ? "flux" : "ionFlux";
1916

2017
if constexpr (runDisk) { // Disk

gpu/benchmark/CPU_Scaling.cpp

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
#include <lsToDiskMesh.hpp>
2+
#include <process/psTranslationField.hpp>
3+
#include <psElementToPointData.hpp>
4+
#include <rayTraceDisk.hpp>
5+
#include <rayTraceTriangle.hpp>
6+
7+
#include "Benchmark.hpp"
8+
9+
int main() {
10+
using NumericType = float;
11+
constexpr int D = DIM;
12+
13+
const std::vector<int> numThreadsList = {1, 2, 4, 8, 16};
14+
std::string fluxLabel = particleType == 0 ? "flux" : "ionFlux";
15+
auto particle = makeCPUParticle<NumericType, D>();
16+
17+
if constexpr (runDisk) { // Disk
18+
std::ofstream file(std::string("CPU_Scaling_Disk_") +
19+
std::to_string(particleType) + ".txt");
20+
file << "Meshing;Tracing;Postprocessing;RayTraced;NumThreads\n";
21+
22+
viennaray::TraceDisk<NumericType, D> tracer;
23+
tracer.setNumberOfRaysPerPoint(raysPerPoint);
24+
if (FIXED_RAYS)
25+
tracer.setNumberOfRaysFixed(numRays);
26+
tracer.setUseRandomSeeds(false);
27+
tracer.setParticleType(particle);
28+
29+
std::cout << "Starting Disk Benchmark\n";
30+
31+
for (int i = 0; i < numThreadsList.size(); i++) {
32+
std::cout << " T: " << numThreadsList[i] << "\n";
33+
omp_set_num_threads(numThreadsList[i]);
34+
auto domain = MAKE_GEO<NumericType>();
35+
36+
auto diskMesh = viennals::Mesh<NumericType>::New();
37+
auto translator = SmartPointer<TranslatorType>::New();
38+
viennals::ToDiskMesh<NumericType, D> mesher(domain->getSurface(),
39+
diskMesh);
40+
mesher.setTranslator(translator);
41+
42+
for (int j = 0; j < numRuns; j++) {
43+
std::cout << " Process Step: " << j + 1 << "\n";
44+
45+
Timer timer;
46+
47+
// MESHING
48+
timer.start();
49+
mesher.apply();
50+
const auto &materialIds = *diskMesh->getMaterialIds();
51+
const auto &normals = *diskMesh->getNormals();
52+
tracer.setGeometry(diskMesh->nodes, normals, domain->getGridDelta());
53+
tracer.setMaterialIds(materialIds);
54+
timer.finish();
55+
file << timer.currentDuration << ";";
56+
57+
// TRACING
58+
timer.start();
59+
tracer.apply();
60+
timer.finish();
61+
file << timer.currentDuration << ";";
62+
63+
// POSTPROCESSING
64+
timer.start();
65+
auto flux = std::move(*tracer.getLocalData().getScalarData(fluxLabel));
66+
tracer.normalizeFlux(flux);
67+
int smoothingNeighbors = 1;
68+
tracer.smoothFlux(flux, smoothingNeighbors);
69+
timer.finish();
70+
file << timer.currentDuration << ";";
71+
file << tracer.getRayTraceInfo().totalRaysTraced << ";";
72+
file << numThreadsList[i] << "\n";
73+
}
74+
}
75+
76+
file.close();
77+
}
78+
79+
if constexpr (runTriangle) { // Triangle
80+
std::ofstream file(std::string("CPU_Scaling_Triangle_") +
81+
std::to_string(particleType) + ".txt");
82+
file << "Meshing;Tracing;Postprocessing;RayTraced;NumThreads\n";
83+
84+
std::cout << "Starting Triangle Benchmark\n";
85+
86+
viennaray::TraceTriangle<NumericType, D> tracer;
87+
tracer.setNumberOfRaysPerPoint(raysPerPoint);
88+
if (FIXED_RAYS)
89+
tracer.setNumberOfRaysFixed(numRays);
90+
tracer.setUseRandomSeeds(false);
91+
tracer.setParticleType(particle);
92+
93+
const auto &dataLabels = particle->getLocalDataLabels();
94+
95+
for (int i = 0; i < numThreadsList.size(); i++) {
96+
std::cout << " T: " << numThreadsList[i] << "\n";
97+
omp_set_num_threads(numThreadsList[i]);
98+
auto domain = MAKE_GEO<NumericType>();
99+
100+
auto diskMesh = viennals::Mesh<NumericType>::New();
101+
auto translator = SmartPointer<TranslatorType>::New();
102+
viennals::ToDiskMesh<NumericType, D> diskMesher(domain->getSurface(),
103+
diskMesh);
104+
diskMesher.setTranslator(translator);
105+
106+
auto elementKdTree =
107+
SmartPointer<KDTree<NumericType, Vec3D<NumericType>>>::New();
108+
auto surfMesh = viennals::Mesh<NumericType>::New();
109+
110+
auto velocityField =
111+
SmartPointer<DefaultVelocityField<NumericType, D>>::New();
112+
auto translationField =
113+
SmartPointer<TranslationField<NumericType, D>>::New(
114+
velocityField, domain->getMaterialMap(), 1);
115+
translationField->setTranslator(translator);
116+
117+
for (int j = 0; j < numRuns; j++) {
118+
std::cout << " Process Step: " << j + 1 << "\n";
119+
120+
Timer timer;
121+
122+
// MESHING
123+
timer.start();
124+
diskMesher.apply();
125+
translationField->buildKdTree(diskMesh->nodes);
126+
setupTriangleGeometry<NumericType, D, decltype(tracer)>(
127+
domain, surfMesh, elementKdTree, tracer);
128+
timer.finish();
129+
file << timer.currentDuration << ";";
130+
131+
// TRACING
132+
timer.start();
133+
tracer.apply();
134+
timer.finish();
135+
file << timer.currentDuration << ";";
136+
137+
// POSTPROCESSING
138+
timer.start();
139+
auto pointData = PointData<NumericType>::New();
140+
auto fluxResult =
141+
std::move(*tracer.getLocalData().getScalarData(fluxLabel));
142+
tracer.normalizeFlux(fluxResult);
143+
std::vector<std::vector<NumericType>> fluxResultVec;
144+
fluxResultVec.push_back(std::move(fluxResult));
145+
if constexpr (particleType == 1) {
146+
fluxResult = std::move(*tracer.getLocalData().getScalarData(1));
147+
tracer.normalizeFlux(fluxResult);
148+
fluxResultVec.push_back(std::move(fluxResult));
149+
}
150+
ElementToPointData<NumericType, float, float> post(
151+
dataLabels, pointData, elementKdTree, diskMesh, surfMesh,
152+
domain->getGridDelta() * 2.0f);
153+
post.setElementDataArrays(std::move(fluxResultVec));
154+
post.apply();
155+
timer.finish();
156+
file << timer.currentDuration << ";";
157+
file << tracer.getRayTraceInfo().totalRaysTraced << ";";
158+
file << numThreadsList[i] << "\n";
159+
}
160+
}
161+
file.close();
162+
}
163+
}

gpu/benchmark/GPU_Benchmark.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ int main() {
1212
constexpr int D = DIM;
1313
auto context = DeviceContext::createContext();
1414

15+
constexpr bool preparePost = true;
16+
1517
CudaBuffer deviceParamsBuffer;
1618
if constexpr (particleType == 1) {
1719
auto deviceParams = getDeviceParams();
@@ -85,7 +87,8 @@ int main() {
8587
ElementToPointData<NumericType, float, viennaray::gpu::ResultType> post(
8688
dataLabels, pointData, elementKdTree, diskMesh, surfMesh,
8789
domain->getGridDelta() * 2.0f);
88-
post.prepare();
90+
if constexpr (preparePost)
91+
post.prepare();
8992
tracer.syncStreams();
9093
timer.finish();
9194
file << timer.currentDuration << ";";
@@ -94,6 +97,8 @@ int main() {
9497
timer.start();
9598
tracer.normalizeResults();
9699
post.setElementDataArrays(tracer.getResults());
100+
if constexpr (!preparePost)
101+
post.prepare();
97102
post.convert();
98103
timer.finish();
99104
file << timer.currentDuration << ";";

0 commit comments

Comments
 (0)