Skip to content

Commit b219aa6

Browse files
committed
Port interpolated bounce back
1 parent 1825c3e commit b219aa6

6 files changed

Lines changed: 51 additions & 7 deletions

File tree

src/ArbConnectivity.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <memory>
55
#include <numeric>
66
#include <vector>
7+
#include "types.h"
78

89
struct ArbLatticeConnectivity {
910
using Index = long;
@@ -15,6 +16,7 @@ struct ArbLatticeConnectivity {
1516
std::unique_ptr<Index[]> nbrs;
1617
std::unique_ptr<ZoneIndex[]> zones_per_node;
1718
std::vector<ZoneIndex> zones;
19+
std::unique_ptr<cut_t[]> cuts;
1820
double grid_size{};
1921

2022
ArbLatticeConnectivity() = default;
@@ -26,7 +28,8 @@ struct ArbLatticeConnectivity {
2628
coords(std::make_unique<double[]>(3 * (chunk_end_ - chunk_begin_))),
2729
og_index(std::make_unique<Index[]>(chunk_end_ - chunk_begin_)),
2830
nbrs(std::make_unique<Index[]>((chunk_end_ - chunk_begin_) * Q)),
29-
zones_per_node(std::make_unique<ZoneIndex[]>(chunk_end_ - chunk_begin_)) {
31+
zones_per_node(std::make_unique<ZoneIndex[]>(chunk_end_ - chunk_begin_)),
32+
cuts(std::make_unique<cut_t[]>(26 * (chunk_end_ - chunk_begin_))) {
3033
zones.reserve(getLocalSize());
3134
}
3235

@@ -52,6 +55,8 @@ struct ArbLatticeConnectivity {
5255
double coord(size_t dim, size_t local_node_ind) const { return coords[local_node_ind + dim * getLocalSize()]; }
5356
Index& neighbor(size_t q, size_t local_node_ind) { return nbrs[local_node_ind + q * getLocalSize()]; }
5457
Index neighbor(size_t q, size_t local_node_ind) const { return nbrs[local_node_ind + q * getLocalSize()]; }
58+
cut_t& cut_distance(size_t d, size_t local_node_ind) { return cuts[local_node_ind + d * getLocalSize()]; }
59+
cut_t cut_distance(size_t d, size_t local_node_ind) const { return cuts[local_node_ind + d * getLocalSize()]; }
5560
};
5661

5762
inline auto computeInitialNodeDist(size_t num_nodes_global, size_t comm_size) -> std::vector<long> {

src/ArbLattice.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ void ArbLattice::readFromCxn(const std::string& cxn_path) {
192192
auto& zone = connect.zones.emplace_back();
193193
file >> zone;
194194
}
195+
196+
for (size_t d = 0; d != 26; ++d) {
197+
auto& cut = connect.cut_distance(d, local_node_ind);
198+
file >> cut;
199+
}
195200

196201
check_file_ok("Failed to read node data");
197202
}
@@ -293,6 +298,8 @@ void ArbLattice::allocDeviceMemory() {
293298
neighbors_device = cudaMakeUnique2D<unsigned>(sizes.neighbors_pitch, Q);
294299
sizes.coords_pitch = local_sz;
295300
coords_device = cudaMakeUnique2D<real_t>(sizes.coords_pitch, 3);
301+
sizes.cuts_pitch = local_sz;
302+
cut_distances_device = cudaMakeUnique2D<cut_t>(sizes.cuts_pitch, 26);
296303
sizes.snaps_pitch = local_sz + ghost_nodes.size() + 1;
297304
snaps_device = cudaMakeUnique2D<storage_t>(sizes.snaps_pitch, sizes.snaps * NF);
298305
node_types_device = cudaMakeUnique<flag_t>(local_sz);
@@ -358,6 +365,17 @@ std::vector<real_t> ArbLattice::computeCoords() const {
358365
return retval;
359366
}
360367

368+
std::vector<cut_t> ArbLattice::computeCutDistances() const {
369+
const auto local_sz = connect.getLocalSize();
370+
std::vector<cut_t> retval(sizes.cuts_pitch * 26);
371+
for (size_t d = 0; d != 26; ++d) {
372+
size_t i = 0;
373+
for (; i != local_sz; ++i) retval[local_permutation[i] + d * sizes.cuts_pitch] = connect.cut_distance(d, i);
374+
for (; i != sizes.cuts_pitch; ++i) retval[i + d * sizes.cuts_pitch] = NO_CUT; // padding
375+
}
376+
return retval;
377+
}
378+
361379
unsigned int ArbLattice::lookupLocalGhostIndex(ArbLatticeConnectivity::Index gid) const {
362380
const unsigned local_sz = connect.getLocalSize();
363381
const auto it = std::lower_bound(ghost_nodes.begin(), ghost_nodes.end(), gid);
@@ -393,6 +411,8 @@ void ArbLattice::initDeviceData(pugi::xml_node arb_node, const std::map<std::str
393411
copyVecToDeviceAsync(neighbors_device.get(), nbrs, inStream);
394412
const auto coords = computeCoords();
395413
copyVecToDeviceAsync(coords_device.get(), coords, inStream);
414+
const auto cuts = computeCutDistances();
415+
copyVecToDeviceAsync(cut_distances_device.get(), cuts, inStream);
396416
CudaStreamSynchronize(inStream);
397417
}
398418

@@ -404,6 +424,8 @@ void ArbLattice::initContainer() {
404424
#endif
405425
launcher.container.nbrs = neighbors_device.get();
406426
launcher.container.coords = coords_device.get();
427+
launcher.container.Q = cut_distances_device.get();
428+
launcher.container.cuts_pitch = sizes.cuts_pitch;
407429
launcher.container.node_types = node_types_device.get();
408430
launcher.container.nbrs_pitch = sizes.neighbors_pitch;
409431
launcher.container.coords_pitch = sizes.coords_pitch;
@@ -843,4 +865,4 @@ void ArbLattice::resetAverage(){
843865
CudaMemset(&getSnapPtr(Snap)[f.id*sizes.snaps_pitch], 0, sizes.snaps_pitch*sizeof(real_t));
844866
}
845867
}
846-
}
868+
}

src/ArbLattice.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class ArbLattice : public LatticeBase {
3333
size_t neighbors_pitch; /// B + I + padding
3434
size_t coords_pitch; /// B + I + padding (should be the same as neighbors_pitch, but let's be extra safe since they come from separate pitched allocation calls)
3535
size_t snaps_pitch; /// B + I + G + 1 + padding
36+
size_t cuts_pitch; /// B + I + padding (should be the same as neighbors_pitch, but same as above)
3637
};
3738

3839
struct CommManager {
@@ -63,6 +64,7 @@ class ArbLattice : public LatticeBase {
6364
std::unordered_map<std::string, int> label_to_ind_map; /// Label string to unique ID
6465
CudaUniquePtr<unsigned> neighbors_device; /// Device allocation of the neighbor table: (B + I) x Q
6566
CudaUniquePtr<real_t> coords_device; /// Device allocation of node coordinates: (B + I) x 3
67+
CudaUniquePtr<cut_t> cut_distances_device; /// Device allocation of cut-distances: (B + I) x 26
6668
CudaUniquePtr<storage_t> snaps_device; /// Device allocation of snaps: (B + I + G + 1) x NF x num_snaps
6769
CudaUniquePtr<flag_t> node_types_device; /// Device allocation of node type array: (B + I)
6870
std::vector<flag_t, pinned_allocator<flag_t> > node_types_host; /// Host (pinned) allocation of node type array: (B + I)
@@ -145,6 +147,7 @@ class ArbLattice : public LatticeBase {
145147
void computeNodeTypesOnHost(pugi::xml_node arb_node, const std::map<std::string, int>& setting_zones, bool permute); /// Compute the node types to be stored on the device, `permute` enables better code reuse
146148
std::vector<real_t> computeCoords() const; /// Compute the coordinates 2D array to be stored on the device
147149
std::vector<unsigned> computeNeighbors() const; /// Compute the neighbors 2D array to be stored on the device
150+
std::vector<cut_t> computeCutDistances() const; /// Compute the cut-distances 2D array to be stored on the device
148151
void initDeviceData(pugi::xml_node arb_node, const std::map<std::string, int>& setting_zones); /// Initialize data residing in device memory
149152
void initCommManager(); /// Compute which fields need to be sent to/received from which neighbors
150153
void initContainer(); /// Initialize the data residing in launcher.container

src/ArbLatticeAccess.hpp.Rt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,9 @@ class ArbLatticeAccess {
8686
CudaDeviceFunction real_t getY() const { return getDim(1); }
8787
CudaDeviceFunction real_t getZ() const { return getDim(2); }
8888
CudaDeviceFunction flag_t getNodeType() const { return node_type; }
89-
CudaDeviceFunction cut_t getQ(int) const { /// TODO
90-
printf("Cuts not implemented for arbitrary lattice");
91-
assert(false);
92-
return NO_CUT;
89+
CudaDeviceFunction cut_t getQ(int d) const {
90+
if (container->Q == nullptr) return NO_CUT;
91+
return container->Q[container->cuts_pitch*d + lid];
9392
}
9493
<?R
9594
for (f in rows(Fields)) { ?>

src/ArbLatticeContainer.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
struct ArbLatticeContainer {
1111
const unsigned* nbrs;
1212
const real_t* coords;
13+
cut_t* Q; // cut-distances
1314
const storage_t* snap_in;
1415
storage_t* snap_out;
1516
#ifdef ADJOINT
1617
const storage_t* adj_snap_in;
1718
storage_t* adj_snap_out;
1819
#endif
1920
const flag_t* node_types;
20-
unsigned nbrs_pitch, coords_pitch, snaps_pitch, num_border_nodes, num_interior_nodes;
21+
unsigned nbrs_pitch, coords_pitch, cuts_pitch, snaps_pitch, num_border_nodes, num_interior_nodes;
2122

2223
// Packing/unpacking on device
2324
storage_t* pack_buf;

src/toArb.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,20 @@ static int writeArbLatticeNodes(const Geometry& geo,
120120
if (zone_flag == zf) file << gz_ind << ' ';
121121
++gz_ind;
122122
}
123+
124+
if (geo.Q != nullptr){
125+
size_t regsize = geo.region.sizeL();
126+
for (int d=0; d < 26; d++){
127+
size_t k = geo.region.offset(x, y, z);
128+
const cut_t q = geo.Q[regsize*d + k];
129+
file << q << ' ';
130+
}
131+
} else {
132+
for (int i=0; i < 26; i++){
133+
const cut_t q = NO_CUT;
134+
file << q << ' ';
135+
}
136+
}
123137
file << '\n';
124138
if (!file.good()) break; // Fail early
125139
}

0 commit comments

Comments
 (0)