28template <
class RequestedLayout =
void,
class BackendSelector, MdspanLike InputMdspan>
29[[nodiscard]]
auto make_tensor(BackendSelector&& selector, InputMdspan&& input)
31 using input_type = std::remove_cvref_t<InputMdspan>;
32 using layout_type = detail::materialized_layout_t<RequestedLayout, input_type>;
36 result_type result(
uninitialized, convert_tensor_extents<typename result_type::extents_type>(input.extents()));
37 auto output_span = result.mdspan();
38 copy(std::forward<BackendSelector>(selector), output_span, std::forward<InputMdspan>(input));
47template <
class RequestedLayout =
void, TensorView InputTensor> [[nodiscard]]
auto make_tensor(InputTensor
const& input)
50 using layout_type = detail::materialized_layout_t<RequestedLayout, input_mdspan>;
53 return result_type(input);
61template <TensorView InputTensor>
62 requires(std::same_as<tensor_storage_policy_t<InputTensor>, CudaStorage> &&
63 detail::CanonicalReshapeLayout<typename tensor_mdspec_t<InputTensor>::layout_type>)
64[[nodiscard]]
auto to_host(InputTensor
const& input)
66 using input_mdspan = tensor_mdspec_t<InputTensor>;
67 using layout_type =
typename input_mdspan::layout_type;
68 using result_type = Tensor<tensor_element_t<InputTensor>, input_mdspan::rank(), HostStorage, layout_type>;
70 result_type result(
uninitialized, convert_tensor_extents<typename result_type::extents_type>(input.extents()));
79template <TensorView InputTensor>
80 requires detail::CanonicalReshapeLayout<typename tensor_mdspec_t<InputTensor>::layout_type>
81[[nodiscard]]
auto to_device(InputTensor
const& input, cuda::DeviceResources& resources)
83 using input_mdspan = tensor_mdspec_t<InputTensor>;
84 using layout_type =
typename input_mdspan::layout_type;
85 using result_type = Tensor<tensor_element_t<InputTensor>, input_mdspan::rank(), CudaStorage, layout_type>;
88 convert_tensor_extents<typename result_type::extents_type>(input.extents()));
94template <TensorView InputTensor>
95 requires detail::CanonicalReshapeLayout<typename tensor_mdspec_t<InputTensor>::layout_type>
96[[nodiscard]]
auto to_device(InputTensor
const& input,
int device)
102template <TensorView InputTensor>
103 requires detail::CanonicalReshapeLayout<typename tensor_mdspec_t<InputTensor>::layout_type>
104[[nodiscard]]
auto to_device(InputTensor
const& input, cuda::Device device)
106 return to_device(input, device.ordinal());
117template <
class RequestedLayout = void, TensorView InputTensor, std::integral... Extents>
118 requires(!OwningTensor<InputTensor> &&
119 (std::is_void_v<RequestedLayout> || detail::CanonicalReshapeLayout<RequestedLayout>) &&
120 (!std::is_void_v<RequestedLayout> || !StridedTensorView<InputTensor> ||
121 detail::CanonicalReshapeLayout<
typename tensor_mdspec_t<InputTensor>::layout_type>))
122[[nodiscard]]
auto reshape(InputTensor
const& input, Extents... requested_extents)
126 detail::CanonicalReshapeLayout<input_layout>)
129 return make_tensor<RequestedLayout>(view);
133 auto materialized = make_tensor<RequestedLayout>(input);
134 return reshape(std::move(materialized), requested_extents...);
General-purpose owning tensor with immediate or deferred mdspan metadata.
Definition basic_tensor.hpp:109
TensorView whose readable mdspec is strided.
Definition tensor/concepts.hpp:153
Backend-dispatched copies into existing mdspan and tensor outputs.
Mdspan concept and accessor extensions for Uni20.
DeviceResources & device_resources()
Return canonical resources for the installed runtime's default device.
Definition runtime.cpp:820
Definition async/async.hpp:26
constexpr uninitialized_t uninitialized
Explicit allocation tag for overwrite outputs and scratch space.
Definition common/initialization.hpp:22
auto reshape_view(Span &&source, Extents... requested_extents)
Return a no-copy mdspan reshape preserving a canonical source layout.
Definition reshape.hpp:175
auto make_tensor(async::Async< InputTensor > const &input)
Materialize an async Tensor view as an independent owning host Tensor.
Definition linalg/async/copy.hpp:199
void copy(BackendSelector selector, async::Async< OutputTensor > &output, async::Async< InputTensor > const &input)
Schedule a Tensor copy through an explicit backend selector.
Definition linalg/async/copy.hpp:174
auto reshape(async::Async< InputTensor > const &input, Extents... requested_extents)
Schedule a preserving owning reshape of an async Tensor.
Definition tensor/async.hpp:156
std::remove_cvref_t< detail::normalized_const_mdspec_t< T > > tensor_mdspec_t
Normalized readable MdspecLike type exposed by a tensor-level object.
Definition tensor/concepts.hpp:123
Default pageable-host tensor storage policy.
Definition host_storage.hpp:316
Shape preparation contracts for tensor operation outputs.
General-purpose owning tensors with runtime extents.