Skip to content

Commit 1c6efc1

Browse files
authored
Merge pull request kokkos#8881 from dalg24/parallel_x_team_cuda_hip_destructors
Move release of level-1 scratch pad and fix broken copy semantics
2 parents 1707507 + d3d0328 commit 1c6efc1

File tree

3 files changed

+24
-32
lines changed

3 files changed

+24
-32
lines changed

core/src/Cuda/Kokkos_Cuda_Parallel_Team.hpp

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,12 @@ class ParallelFor<FunctorType, Kokkos::TeamPolicy<Properties...>,
533533
*this, grid, block, shmem_size_total,
534534
m_policy.space()
535535
.impl_internal_space_instance()); // copy to device and execute
536+
537+
if (m_scratch_pool_id >= 0) {
538+
m_policy.space()
539+
.impl_internal_space_instance()
540+
->release_team_scratch_space(m_scratch_pool_id);
541+
}
536542
}
537543

538544
ParallelFor(const FunctorType& arg_functor, const Policy& arg_policy)
@@ -606,14 +612,6 @@ class ParallelFor<FunctorType, Kokkos::TeamPolicy<Properties...>,
606612
Kokkos::Impl::throw_runtime_exception(error.str().c_str());
607613
}
608614
}
609-
610-
~ParallelFor() {
611-
if (m_scratch_pool_id >= 0) {
612-
m_policy.space()
613-
.impl_internal_space_instance()
614-
->release_team_scratch_space(m_scratch_pool_id);
615-
}
616-
}
617615
};
618616

619617
template <class CombinedFunctorReducerType, class... Properties>
@@ -894,6 +892,12 @@ class ParallelReduce<CombinedFunctorReducerType,
894892
m_functor_reducer.get_reducer().init(m_result_ptr);
895893
}
896894
}
895+
896+
if (m_scratch_pool_id >= 0) {
897+
m_policy.space()
898+
.impl_internal_space_instance()
899+
->release_team_scratch_space(m_scratch_pool_id);
900+
}
897901
}
898902

899903
template <class ViewType>
@@ -1017,14 +1021,6 @@ class ParallelReduce<CombinedFunctorReducerType,
10171021
Kokkos::Impl::throw_runtime_exception(error.str().c_str());
10181022
}
10191023
}
1020-
1021-
~ParallelReduce() {
1022-
if (m_scratch_pool_id >= 0) {
1023-
m_policy.space()
1024-
.impl_internal_space_instance()
1025-
->release_team_scratch_space(m_scratch_pool_id);
1026-
}
1027-
}
10281024
};
10291025

10301026
} // namespace Impl

core/src/HIP/Kokkos_HIP_ParallelFor_Team.hpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ class ParallelFor<FunctorType, Kokkos::TeamPolicy<Properties...>, HIP> {
9999
*this, grid, block, shmem_size_total,
100100
m_policy.space().impl_internal_space_instance(),
101101
true); // copy to device and execute
102+
103+
if (m_scratch_pool_id >= 0) {
104+
m_policy.space()
105+
.impl_internal_space_instance()
106+
->release_team_scratch_space(m_scratch_pool_id);
107+
}
102108
}
103109

104110
ParallelFor(FunctorType const& arg_functor, Policy const& arg_policy)
@@ -173,14 +179,6 @@ class ParallelFor<FunctorType, Kokkos::TeamPolicy<Properties...>, HIP> {
173179
Kokkos::Impl::throw_runtime_exception(error.str().c_str());
174180
}
175181
}
176-
177-
~ParallelFor() {
178-
if (m_scratch_pool_id >= 0) {
179-
m_policy.space()
180-
.impl_internal_space_instance()
181-
->release_team_scratch_space(m_scratch_pool_id);
182-
}
183-
}
184182
};
185183

186184
} // namespace Impl

core/src/HIP/Kokkos_HIP_ParallelReduce_Team.hpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,12 @@ class ParallelReduce<CombinedFunctorReducerType,
287287
reducer.init(m_result_ptr);
288288
}
289289
}
290+
291+
if (m_scratch_pool_id >= 0) {
292+
m_policy.space()
293+
.impl_internal_space_instance()
294+
->release_team_scratch_space(m_scratch_pool_id);
295+
}
290296
}
291297

292298
template <class ViewType>
@@ -410,14 +416,6 @@ class ParallelReduce<CombinedFunctorReducerType,
410416
Kokkos::Impl::throw_runtime_exception(error.str().c_str());
411417
}
412418
}
413-
414-
~ParallelReduce() {
415-
if (m_scratch_pool_id >= 0) {
416-
m_policy.space()
417-
.impl_internal_space_instance()
418-
->release_team_scratch_space(m_scratch_pool_id);
419-
}
420-
}
421419
};
422420

423421
} // namespace Impl

0 commit comments

Comments
 (0)