Skip to content

Commit

Permalink
Deprecate Cuda(cudaStream_t, bool)
Browse files Browse the repository at this point in the history
Whether to manage the stream or not should never have been exposed to
the user.
  • Loading branch information
dalg24 committed Sep 1, 2023
1 parent 393abd3 commit 7353bdf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
8 changes: 7 additions & 1 deletion core/src/Cuda/Kokkos_Cuda.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ struct CudaDispatchProperties {
CudaLaunchMechanism launch_mechanism = l;
};
} // namespace Experimental

enum class ManageStream : bool { no, yes };

} // namespace Impl
/// \class Cuda
/// \brief Kokkos Execution Space that uses CUDA to run on GPUs.
Expand Down Expand Up @@ -181,7 +184,10 @@ class Cuda {

Cuda();

Cuda(cudaStream_t stream, bool manage_stream = false);
Cuda(cudaStream_t stream,
Impl::ManageStream manage_stream = Impl::ManageStream::no);

KOKKOS_DEPRECATED Cuda(cudaStream_t stream, bool manage_stream);

//--------------------------------------------------------------------------
//! Free any resources being consumed by the device.
Expand Down
18 changes: 16 additions & 2 deletions core/src/Cuda/Kokkos_Cuda_Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -886,14 +886,18 @@ Cuda::Cuda()
"Cuda instance constructor");
}

Cuda::Cuda(cudaStream_t stream, bool manage_stream)
KOKKOS_DEPRECATED Cuda::Cuda(cudaStream_t stream, bool manage_stream)
: Cuda(stream,
manage_stream ? Impl::ManageStream::yes : Impl::ManageStream::no) {}

Cuda::Cuda(cudaStream_t stream, Impl::ManageStream manage_stream)
: m_space_instance(new Impl::CudaInternal, [](Impl::CudaInternal *ptr) {
ptr->finalize();
delete ptr;
}) {
Impl::CudaInternal::singleton().verify_is_initialized(
"Cuda instance constructor");
m_space_instance->initialize(stream, manage_stream);
m_space_instance->initialize(stream, static_cast<bool>(manage_stream));
}

void Cuda::print_configuration(std::ostream &os, bool /*verbose*/) const {
Expand Down Expand Up @@ -965,6 +969,16 @@ int g_cuda_space_factory_initialized =

} // namespace Kokkos

void Kokkos::Impl::create_Cuda_instances(std::vector<Cuda> &instances) {
for (int s = 0; s < int(instances.size()); s++) {
cudaStream_t stream;
KOKKOS_IMPL_CUDA_SAFE_CALL((
instances[s].impl_internal_space_instance()->cuda_stream_create_wrapper(
&stream)));
instances[s] = Cuda(stream, ManageStream::yes);
}
}

#else

void KOKKOS_CORE_SRC_CUDA_IMPL_PREVENT_LINK_ERROR() {}
Expand Down
17 changes: 3 additions & 14 deletions core/src/Cuda/Kokkos_Cuda_Instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ class CudaInternal {
void release_team_scratch_space(int scratch_pool_id);
};

void create_Cuda_instances(std::vector<Cuda>& instances);
} // Namespace Impl

namespace Experimental {
Expand All @@ -547,25 +548,13 @@ namespace Experimental {
// Customization point for backends
// Default behavior is to return the passed in instance

namespace Impl {
inline void create_Cuda_instances(std::vector<Cuda>& instances) {
for (int s = 0; s < int(instances.size()); s++) {
cudaStream_t stream;
KOKKOS_IMPL_CUDA_SAFE_CALL((
instances[s].impl_internal_space_instance()->cuda_stream_create_wrapper(
&stream)));
instances[s] = Cuda(stream, true);
}
}
} // namespace Impl

template <class... Args>
std::vector<Cuda> partition_space(const Cuda&, Args...) {
static_assert(
(... && std::is_arithmetic_v<Args>),
"Kokkos Error: partitioning arguments must be integers or floats");
std::vector<Cuda> instances(sizeof...(Args));
Impl::create_Cuda_instances(instances);
Kokkos::Impl::create_Cuda_instances(instances);
return instances;
}

Expand All @@ -578,7 +567,7 @@ std::vector<Cuda> partition_space(const Cuda&, std::vector<T> const& weights) {
// We only care about the number of instances to create and ignore weights
// otherwise.
std::vector<Cuda> instances(weights.size());
Impl::create_Cuda_instances(instances);
Kokkos::Impl::create_Cuda_instances(instances);
return instances;
}
} // namespace Experimental
Expand Down

0 comments on commit 7353bdf

Please sign in to comment.