File indexing completed on 2025-09-17 08:54:12
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <hip/hip_runtime.h>
0010
0011 #include <covfie/core/concepts.hpp>
0012 #include <covfie/core/parameter_pack.hpp>
0013
0014 namespace covfie::utility::hip {
0015 template <typename T, typename U>
0016 requires(concepts::field_backend<T> &&
0017 concepts::field_backend<typename std::decay_t<U>::parent_t>)
0018 typename T::owning_data_t
0019 copy_backend_with_stream(U && backend, const hipStream_t & stream)
0020 {
0021 constexpr bool can_construct_with_stream = std::
0022 constructible_from<typename T::owning_data_t, U, const hipStream_t &>;
0023
0024 static_assert(
0025 can_construct_with_stream ||
0026 (!std::decay_t<T>::is_initial && !std::decay_t<U>::parent_t::is_initial)
0027 );
0028
0029 if constexpr (can_construct_with_stream) {
0030 return typename T::owning_data_t(std::forward<U>(backend), stream);
0031 } else if constexpr (std::constructible_from<
0032 typename T::owning_data_t,
0033 decltype(backend.get_configuration()),
0034 typename T::backend_t::owning_data_t &&>)
0035 {
0036 return typename T::owning_data_t(
0037 backend.get_configuration(),
0038 copy_backend_with_stream<typename T::backend_t>(
0039 backend.get_backend(), stream
0040 )
0041 );
0042 } else {
0043 return typename T::owning_data_t(make_parameter_pack(
0044 backend.get_configuration(),
0045 copy_backend_with_stream<typename T::backend_t>(
0046 backend.get_backend(), stream
0047 )
0048 ));
0049 }
0050 }
0051
0052 template <typename T, typename U>
0053 requires(concepts::field_backend<typename T::backend_t> &&
0054 concepts::field_backend<typename std::decay_t<U>::backend_t>) T
0055 copy_field_with_stream(U && field, const hipStream_t & stream)
0056 {
0057 return T(
0058 copy_backend_with_stream<typename T::backend_t>(field.backend(), stream)
0059 );
0060 }
0061 }