Skip to content

Commit efcf2f9

Browse files
committed
Make GPU integrator use vbd::Data interface
1 parent 82cdeca commit efcf2f9

37 files changed

+803
-668
lines changed

bindings/pypbat/gpu/vbd/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ target_sources(PhysicsBasedAnimationToolkit_Python
22
PUBLIC
33
FILE_SET api
44
FILES
5+
"Integrator.h"
56
"Vbd.h"
67
)
78

89
target_sources(PhysicsBasedAnimationToolkit_Python
910
PRIVATE
11+
"Integrator.cpp"
1012
"Vbd.cpp"
1113
)
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
#include "Integrator.h"
2+
3+
#include <pbat/gpu/Aliases.h>
4+
#include <pbat/gpu/vbd/Vbd.h>
5+
#include <pbat/profiling/Profiling.h>
6+
#include <pbat/sim/vbd/Data.h>
7+
#include <pbat/sim/vbd/Enums.h>
8+
#include <pybind11/eigen.h>
9+
#include <pybind11/stl.h>
10+
#include <utility>
11+
12+
namespace pbat {
13+
namespace py {
14+
namespace gpu {
15+
namespace vbd {
16+
17+
void BindIntegrator(pybind11::module& m)
18+
{
19+
namespace pyb = pybind11;
20+
#ifdef PBAT_USE_CUDA
21+
22+
using namespace pbat;
23+
using pbat::gpu::vbd::Integrator;
24+
using pbat::sim::vbd::Data;
25+
using pbat::sim::vbd::EInitializationStrategy;
26+
27+
pyb::class_<Integrator>(m, "Integrator")
28+
.def(
29+
pyb::init([](Data const& data) {
30+
return pbat::profiling::Profile("pbat.gpu.vbd.Integrator.Construct", [&]() {
31+
Integrator vbd(data);
32+
return vbd;
33+
});
34+
}),
35+
pyb::arg("data"),
36+
"Construct a VBD algorithm to run on the GPU using data.")
37+
.def(
38+
"step",
39+
[](Integrator& vbd,
40+
GpuScalar dt,
41+
GpuIndex iterations,
42+
GpuIndex substeps,
43+
GpuScalar rho) {
44+
pbat::profiling::Profile("pbat.gpu.vbd.Integrator.Step", [&]() {
45+
vbd.Step(dt, iterations, substeps, rho);
46+
});
47+
},
48+
pyb::arg("dt") = GpuScalar{0.01},
49+
pyb::arg("iterations") = GpuIndex{20},
50+
pyb::arg("substeps") = GpuIndex{1},
51+
pyb::arg("rho") = GpuScalar{1},
52+
"Integrate 1 time step in time using a uniform time discretization dt. Use iterations "
53+
"iterations for the time integration minimization. Substepping can be specified in "
54+
"substeps, such that substeps*iterations total iterations will be executed. rho < 1 "
55+
"yields a spectral radius estimate for Chebyshev semi-iterative method acceleration, "
56+
"inactive if rho >= 1.")
57+
.def_property(
58+
"x",
59+
[](Integrator const& vbd) {
60+
return pbat::profiling::Profile("pbat.gpu.vbd.Integrator.GetPositions", [&]() {
61+
GpuMatrixX X = vbd.GetPositions();
62+
return X;
63+
});
64+
},
65+
[](Integrator& vbd, Eigen::Ref<GpuMatrixX const> const& X) {
66+
pbat::profiling::Profile("pbat.gpu.vbd.Integrator.SetPositions", [&]() {
67+
vbd.SetPositions(X);
68+
});
69+
},
70+
"|#dims|x|#vertices| vertex positions")
71+
.def_property(
72+
"v",
73+
[](Integrator const& vbd) {
74+
return pbat::profiling::Profile("pbat.gpu.vbd.Integrator.GetVelocities", [&]() {
75+
GpuMatrixX v = vbd.GetVelocities();
76+
return v;
77+
});
78+
},
79+
[](Integrator& vbd, Eigen::Ref<GpuMatrixX const> const& v) {
80+
pbat::profiling::Profile("pbat.gpu.vbd.Integrator.SetVelocities", [&]() {
81+
vbd.SetVelocities(v);
82+
});
83+
},
84+
"|#dims|x|#vertices| vertex velocities")
85+
.def_property(
86+
"a",
87+
nullptr,
88+
[](Integrator& vbd, Eigen::Ref<GpuMatrixX const> const& a) {
89+
pbat::profiling::Profile("pbat.gpu.vbd.Integrator.SetExternalAcceleration", [&]() {
90+
vbd.SetExternalAcceleration(a);
91+
});
92+
},
93+
"|#dims|x|#vertices| vertex external accelerations")
94+
.def_property(
95+
"m",
96+
nullptr,
97+
[](Integrator& vbd, Eigen::Ref<GpuMatrixX const> const& m) {
98+
pbat::profiling::Profile("pbat.gpu.vbd.Integrator.SetMass", [&]() {
99+
vbd.SetMass(m);
100+
});
101+
},
102+
"|#vertices| lumped masses")
103+
.def_property(
104+
"wg",
105+
nullptr,
106+
[](Integrator& vbd, Eigen::Ref<GpuMatrixX const> const& wg) {
107+
pbat::profiling::Profile("pbat.gpu.vbd.Integrator.SetQuadratureWeights", [&]() {
108+
vbd.SetQuadratureWeights(wg);
109+
});
110+
},
111+
"|#elements| array of quadrature weights")
112+
.def_property(
113+
"GNe",
114+
nullptr,
115+
[](Integrator& vbd, Eigen::Ref<GpuMatrixX const> const& GP) {
116+
pbat::profiling::Profile(
117+
"pbat.gpu.vbd.Integrator.SetShapeFunctionGradients",
118+
[&]() { vbd.SetShapeFunctionGradients(GP); });
119+
},
120+
"4x3x|#elements| array of shape function gradients, stored column-wise (i.e. the 4x3 "
121+
"element shape function gradient matrices are flattened in column-major format)")
122+
.def_property(
123+
"lame",
124+
nullptr,
125+
[](Integrator& vbd, Eigen::Ref<GpuMatrixX const> const& lame) {
126+
pbat::profiling::Profile("pbat.gpu.vbd.Integrator.SetLameCoefficients", [&]() {
127+
vbd.SetLameCoefficients(lame);
128+
});
129+
},
130+
"2x|#elements| Lame coefficients")
131+
.def_property(
132+
"detH_residual",
133+
nullptr,
134+
[](Integrator& vbd, GpuScalar zero) {
135+
vbd.SetNumericalZeroForHessianDeterminant(zero);
136+
},
137+
"Numerical zero used in Hessian determinant check for approximate singularity "
138+
"detection")
139+
.def_property(
140+
"GVT",
141+
nullptr,
142+
[](Integrator& vbd,
143+
std::tuple<
144+
Eigen::Ref<GpuIndexVectorX const>,
145+
Eigen::Ref<GpuIndexVectorX const>,
146+
Eigen::Ref<GpuIndexVectorX const>> const& GVT) {
147+
pbat::profiling::Profile(
148+
"pbat.gpu.vbd.Integrator.SetVertexTetrahedronAdjacencyList",
149+
[&]() {
150+
vbd.SetVertexTetrahedronAdjacencyList(
151+
std::get<0>(GVT),
152+
std::get<1>(GVT),
153+
std::get<2>(GVT));
154+
});
155+
},
156+
"3-tuple (prefix,neighbours,data) representing the compressed column storage graph "
157+
"representation of the vertex-tetrahedron adjacency list. The data property yields the "
158+
"local vertex index associated with a pair (i,e) of vertex i adjacent to element e.")
159+
.def_property(
160+
"kD",
161+
nullptr,
162+
[](Integrator& vbd, GpuScalar kD) { vbd.SetRayleighDampingCoefficient(kD); },
163+
"Sets a uniform Rayleigh damping coefficient on the mesh.")
164+
.def_property(
165+
"partitions",
166+
nullptr,
167+
[](Integrator& vbd, std::vector<std::vector<GpuIndex>> const& partitions) {
168+
vbd.SetVertexPartitions(partitions);
169+
},
170+
"Set vertex partitions for the parallel time integration minimization solve as list of "
171+
"lists of vertex indices")
172+
.def_property(
173+
"strategy",
174+
nullptr,
175+
[](Integrator& vbd, EInitializationStrategy strategy) {
176+
vbd.SetInitializationStrategy(strategy);
177+
},
178+
"Set VBD's time step minimization initialization strategy")
179+
.def(
180+
"set_gpu_block_size",
181+
&Integrator::SetBlockSize,
182+
pyb::arg("num_threads_per_block") = 64,
183+
"Sets the number of threads per GPU thread block used for time integration "
184+
"minimization.");
185+
#endif // PBAT_USE_CUDA
186+
}
187+
188+
} // namespace vbd
189+
} // namespace gpu
190+
} // namespace py
191+
} // namespace pbat
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef PYPBAT_GPU_VBD_INTEGRATOR_H
2+
#define PYPBAT_GPU_VBD_INTEGRATOR_H
3+
4+
#include <pybind11/pybind11.h>
5+
6+
namespace pbat {
7+
namespace py {
8+
namespace gpu {
9+
namespace vbd {
10+
11+
void BindIntegrator(pybind11::module& m);
12+
13+
} // namespace vbd
14+
} // namespace gpu
15+
} // namespace py
16+
} // namespace pbat
17+
18+
#endif // PYPBAT_GPU_VBD_INTEGRATOR_H

0 commit comments

Comments
 (0)