MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ collect_gpu_outputs()

template<ComputeData InputType = std::vector<Kakshya::DataVariant>, ComputeData OutputType = InputType>
virtual output_type MayaFlux::Yantra::GpuExecutionContext< InputType, OutputType >::collect_gpu_outputs ( const GpuChannelResult &  raw,
const std::vector< std::vector< double > > &  channels,
const DataStructureInfo &  structure_info 
)
inlineprotectedvirtual

Reconstruct Datum<OutputType> from a GpuChannelResult.

Branches on structure_info.original_type:

  • Non-double native types (float, uint8_t, uint16_t, uint32_t): reads raw bytes directly from the first OUTPUT binding via download_binding rather than the float readback path, then packs them into a DataVariant in the correct native type. No float reinterpretation of pixel bytes.
  • Double / complex / other: reads raw.primary as float, widens to double per channel, delegates to reconstruct_from_double. Unchanged from previous behaviour.

Override to perform custom readback interpretation (e.g. image containers).

Reimplemented in MayaFlux::Yantra::TextureExecutionContext.

Definition at line 179 of file GpuExecutionContext.hpp.

183 {
184 output_type result;
185
186 const auto& ot = structure_info.original_type;
187 const bool is_native_non_double = ot == std::type_index(typeid(std::vector<float>)) || ot == std::type_index(typeid(std::vector<uint8_t>)) || ot == std::type_index(typeid(std::vector<uint16_t>)) || ot == std::type_index(typeid(std::vector<uint32_t>));
188
189 if (is_native_non_double) {
190 const size_t out_idx = find_first_output_index();
191 const size_t allocated = m_resources.buffer_allocated_bytes(dispatch_key(), out_idx);
192 if (allocated > 0) {
193 std::vector<uint8_t> raw_bytes(allocated);
194 download_binding(out_idx, raw_bytes.data(), allocated);
195
196 auto native_variant = OperationHelper::reconstruct_from_double<Kakshya::DataVariant>(
197 { std::vector<double>(allocated / sizeof(double), 0.0) },
198 structure_info);
199 std::visit([&](auto& vec) {
200 using V = typename std::decay_t<decltype(vec)>::value_type;
201 vec.resize(allocated / sizeof(V));
202 std::memcpy(vec.data(), raw_bytes.data(), allocated);
203 },
204 native_variant);
205
206 if constexpr (std::is_same_v<OutputType, std::vector<Kakshya::DataVariant>>) {
207 result.data = { std::move(native_variant) };
208 } else if constexpr (std::is_same_v<OutputType, Kakshya::DataVariant>) {
209 result.data = std::move(native_variant);
210 }
211 }
212 for (const auto& [idx, bytes] : raw.aux)
213 result.metadata["gpu_output_" + std::to_string(idx)] = bytes;
214 return result;
215 }
216
217 const size_t total = std::accumulate(channels.begin(), channels.end(), size_t { 0 },
218 [](size_t s, const auto& ch) { return s + ch.size(); });
219 if (!raw.primary.empty() && !channels.empty() && raw.primary.size() >= total) {
220 size_t offset = 0;
221 std::vector<std::vector<double>> result_ch(channels.size());
222 for (size_t c = 0; c < channels.size(); ++c) {
223 result_ch[c].resize(channels[c].size());
224 for (size_t i = 0; i < channels[c].size(); ++i)
225 result_ch[c][i] = static_cast<double>(raw.primary[offset++]);
226 }
227 result = Datum<OutputType>(
228 OperationHelper::reconstruct_from_double<OutputType>(result_ch, structure_info));
229 }
230 for (const auto& [idx, bytes] : raw.aux)
231 result.metadata["gpu_output_" + std::to_string(idx)] = bytes;
232 return result;
233 }
uint64_t offset
Definition Composite.cpp:10
bool size
uint32_t total
std::unordered_map< std::string, std::string > metadata
uint32_t channels
void download_binding(size_t index, void *dest, size_t byte_size)
Read back a specific binding into a caller-provided destination.
const std::string & dispatch_key() const
The key used for this context's GpuResourceManager unit.
size_t buffer_allocated_bytes(const std::string &key, size_t index) const
constexpr std::string_view to_string(EventType type)
Converts an EventType to its string representation.
Definition EventBus.hpp:28

References MayaFlux::Yantra::GpuChannelResult::aux, MayaFlux::Yantra::GpuResourceManager::buffer_allocated_bytes(), channels, MayaFlux::Yantra::Datum< T >::data, MayaFlux::Yantra::GpuDispatchCore::dispatch_key(), MayaFlux::Yantra::GpuDispatchCore::download_binding(), MayaFlux::Yantra::GpuDispatchCore::find_first_output_index(), MayaFlux::Yantra::GpuDispatchCore::m_resources, MayaFlux::Yantra::Datum< T >::metadata, offset, MayaFlux::Yantra::DataStructureInfo::original_type, MayaFlux::Yantra::GpuChannelResult::primary, size, and total.

Referenced by MayaFlux::Yantra::GpuExecutionContext< InputType, OutputType >::execute().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: