Skip to content

Commit

Permalink
feat(kokkos): add kokkos finalize
Browse files Browse the repository at this point in the history
Add scope guards to Kokkos views so they are destroyed before Kokkos finalize is
called.
  • Loading branch information
pranav-sivaraman committed Jan 9, 2024
1 parent 03c4357 commit 22c8431
Showing 1 changed file with 41 additions and 28 deletions.
69 changes: 41 additions & 28 deletions src/kokkos/fasten.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,39 +195,52 @@ template <size_t PPWI> class IMPL_CLS final : public Bude<PPWI> {
if (!Kokkos::is_initialized()) {
Kokkos::initialize();
}

Sample sample(PPWI, wgsize, p.nposes());

auto contextStart = now();

auto protein = mkView("protein", p.protein);
auto ligand = mkView("ligand", p.ligand);
auto transforms_0 = mkView("transforms_0", p.poses[0]);
auto transforms_1 = mkView("transforms_1", p.poses[1]);
auto transforms_2 = mkView("transforms_2", p.poses[2]);
auto transforms_3 = mkView("transforms_3", p.poses[3]);
auto transforms_4 = mkView("transforms_4", p.poses[4]);
auto transforms_5 = mkView("transforms_5", p.poses[5]);
auto forcefield = mkView("forcefield", p.forcefield);
Kokkos::View<float *> results("results", sample.energies.size());
Kokkos::fence();
auto contextEnd = now();
sample.contextTime = {contextStart, contextEnd};

for (size_t i = 0; i < p.iterations + p.warmupIterations; ++i) {
auto kernelStart = now();
fasten_main(wgsize, p.ntypes(), p.nposes(), p.natlig(), p.natpro(), //
protein, ligand, forcefield, //
transforms_0, transforms_1, transforms_2, transforms_3, transforms_4, transforms_5, results);
{

auto hostToDeviceStart = now();

auto protein = mkView("protein", p.protein);
auto ligand = mkView("ligand", p.ligand);
auto transforms_0 = mkView("transforms_0", p.poses[0]);
auto transforms_1 = mkView("transforms_1", p.poses[1]);
auto transforms_2 = mkView("transforms_2", p.poses[2]);
auto transforms_3 = mkView("transforms_3", p.poses[3]);
auto transforms_4 = mkView("transforms_4", p.poses[4]);
auto transforms_5 = mkView("transforms_5", p.poses[5]);
auto forcefield = mkView("forcefield", p.forcefield);
Kokkos::View<float *> results("results", sample.energies.size());
Kokkos::fence();
auto kernelEnd = now();
sample.kernelTimes.emplace_back(kernelStart, kernelEnd);

auto hostToDeviceEnd = now();
sample.hostToDevice = {hostToDeviceStart, hostToDeviceEnd};

for (size_t i = 0; i < p.iterations + p.warmupIterations; ++i) {
auto kernelStart = now();
fasten_main(wgsize, p.ntypes(), p.nposes(), p.natlig(), p.natpro(), //
protein, ligand, forcefield, //
transforms_0, transforms_1, transforms_2, transforms_3, transforms_4, transforms_5, results);
Kokkos::fence();
auto kernelEnd = now();
sample.kernelTimes.emplace_back(kernelStart, kernelEnd);
}

auto deviceToHostStart = now();

auto result_mirror = Kokkos::create_mirror_view(results);
Kokkos::deep_copy(result_mirror, results);
for (size_t i = 0; i < results.size(); i++) {
sample.energies[i] = result_mirror[i];
}

auto deviceToHostEnd = now();
sample.deviceToHost = {deviceToHostStart, deviceToHostEnd};
}

auto result_mirror = Kokkos::create_mirror_view(results);
Kokkos::deep_copy(result_mirror, results);
for (size_t i = 0; i < results.size(); i++) {
sample.energies[i] = result_mirror[i];
if (!Kokkos::is_finalized()) {
Kokkos::finalize();
}

return sample;
Expand Down

0 comments on commit 22c8431

Please sign in to comment.