Skip to content

Commit

Permalink
[cpp] More cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiashienzsch committed Jul 14, 2024
1 parent c117eee commit 801a80a
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 23 deletions.
6 changes: 5 additions & 1 deletion src/cpp/main_3d/engine_cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
#include <cstdlib>
#include <vector>

auto runSim(Simulation3D& sd) -> double {
namespace pffdtd {

auto run(Simulation3D& sd) -> double {
// keep local ints, scalars
int64_t Ns = sd.Ns;
int64_t Nr = sd.Nr;
Expand Down Expand Up @@ -416,3 +418,5 @@ double process_bnl_pts_fd(
}
return omp_get_wtime() - tstart;
}

} // namespace pffdtd
6 changes: 5 additions & 1 deletion src/cpp/main_3d/engine_cpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

#include <cstdint>

auto runSim(Simulation3D& sd) -> double;
namespace pffdtd {

auto run(Simulation3D& sd) -> double;
double process_bnl_pts_fd(
Real* u0b,
Real const* u2b,
Expand All @@ -33,3 +35,5 @@ double process_bnl_pts_fd(
MatQuad const* mat_quads,
Real const* mat_beta
);

} // namespace pffdtd
4 changes: 2 additions & 2 deletions src/cpp/main_3d/engine_cuda.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ __constant__ int8_t cuMb[MNm]; //to store Mb per mat (MNm has to be hash-defined
uint64_t print_gpu_details(int i);
void check_sorted( Simulation3D const& sd);
void split_data( Simulation3D const& sd, struct gpuHostData *ghds, int ngpus);
double runSim(Simulation3D &sd);
double run(Simulation3D &sd);
//CUDA kernels
__global__ void KernelAirCart(Real * __restrict__ u0, const Real * __restrict__ u1, const uint8_t * __restrict__ bn_mask);
__global__ void KernelAirFCC(Real * __restrict__ u0, const Real * __restrict__ u1, const uint8_t * __restrict__ bn_mask);
Expand Down Expand Up @@ -648,7 +648,7 @@ void split_data( Simulation3D const& sd, struct gpuHostData *ghds, int ngpus) {
}

//run the sim!
double runSim(Simulation3D &sd)
double run(Simulation3D &sd)
{
//if you want to test synchronous, env variable for that
const char* s = getenv("CUDA_LAUNCH_BLOCKING");
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/main_3d/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
auto main(int /*argc*/, char** /*argv*/) -> int {
auto const start = std::chrono::steady_clock::now();

auto sim = Simulation3D{};
auto sim = pffdtd::Simulation3D{};
loadSimulation3D(sim);
scaleInput(sim);
runSim(sim);
run(sim);
rescaleOutput(sim);
writeOutputs(sim);
printLastSample(sim);
Expand Down
8 changes: 8 additions & 0 deletions src/cpp/pffdtd/hdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@

namespace pffdtd {

enum DataType : unsigned char {
FLOAT64,
FLOAT32,
INT64,
INT8,
BOOL,
};

template<typename T>
inline constexpr auto isStdVector = false;

Expand Down
9 changes: 5 additions & 4 deletions src/cpp/pffdtd/simulation_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@

#include "simulation_3d.hpp"

#include "pffdtd/hdf.hpp"

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <filesystem>

namespace {

#include <cassert>

// linear indices to sub-indices in 3d, Nz continguous
void ind2sub3d(
int64_t idx,
Expand Down Expand Up @@ -62,6 +59,8 @@ void check_inside_grid(
}
} // namespace

namespace pffdtd {

// load the sim data from Python-written HDF5 files
void loadSimulation3D(Simulation3D& sim) {
// local values, to read in and attach to struct at end
Expand Down Expand Up @@ -970,3 +969,5 @@ void writeOutputs(Simulation3D& sim) {
writer.write("u_out", std::span{u_out}, Nr, Nt);
std::puts("wrote output dataset");
}

} // namespace pffdtd
7 changes: 5 additions & 2 deletions src/cpp/pffdtd/simulation_3d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
#pragma once

#include "pffdtd/config.hpp"
#include "pffdtd/hdf.hpp"
#include "pffdtd/utility.hpp"

#include "hdf5.h"

#include <cstdint>

// maximum number of RLC branches in freq-dep (FD) boundaries (needed at
Expand All @@ -28,6 +27,8 @@
// maximum number of materials allows (needed at compile-time for CUDA)
#define MNm 64 // change as necssary

namespace pffdtd {

// main sim data, on host
struct Simulation3D {
int64_t* bn_ixyz; // boundary node indices
Expand Down Expand Up @@ -93,3 +94,5 @@ void readH5Dataset(
DataType t
);
void readH5Constant(hid_t file, char* dset_str, void* out, DataType t);

} // namespace pffdtd
8 changes: 0 additions & 8 deletions src/cpp/pffdtd/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@
#define SET_BIT_VAL(var, pos, val) \
((var) = ((var) & ~(1ULL << (pos))) | ((val) << (pos)))

enum DataType : unsigned char {
FLOAT64,
FLOAT32,
INT64,
INT8,
BOOL,
};

void allocate_zeros(void** arr, uint64_t Nbytes);
int cmpfunc_int64_keys(void const* a, void const* b);
void sort_keys(int64_t* val_arr, int64_t* key_arr, int64_t N);
2 changes: 2 additions & 0 deletions src/cpp/pffdtd/video.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "video.hpp"

#include "pffdtd/exception.hpp"

#include <opencv2/imgproc.hpp>

namespace pffdtd {
Expand Down
3 changes: 0 additions & 3 deletions src/cpp/pffdtd/video.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#pragma once

#include "pffdtd/exception.hpp"

#include <opencv2/videoio.hpp>

#include <filesystem>
#include <span>

namespace pffdtd {

Expand Down

0 comments on commit 801a80a

Please sign in to comment.