MayaFlux 0.5.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 172 of file GpuExecutionContext.hpp.

176 {
177 output_type result;
178
179 const auto& ot = structure_info.original_type;
180 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>));
181
182 if (is_native_non_double) {
183 const size_t out_idx = find_first_output_index();
184 const size_t allocated = m_resources.buffer_allocated_bytes(dispatch_key(), out_idx);
185 if (allocated > 0) {
186 std::vector<uint8_t> raw_bytes(allocated);
187 download_binding(out_idx, raw_bytes.data(), allocated);
188
189 auto native_variant = OperationHelper::reconstruct_from_double<Kakshya::DataVariant>(
190 { std::vector<double>(allocated / sizeof(double), 0.0) },
191 structure_info);
192 std::visit([&](auto& vec) {
193 using V = typename std::decay_t<decltype(vec)>::value_type;
194 vec.resize(allocated / sizeof(V));
195 std::memcpy(vec.data(), raw_bytes.data(), allocated);
196 },
197 native_variant);
198
199 if constexpr (std::is_same_v<OutputType, std::vector<Kakshya::DataVariant>>) {
200 result.data = { std::move(native_variant) };
201 } else if constexpr (std::is_same_v<OutputType, Kakshya::DataVariant>) {
202 result.data = std::move(native_variant);
203 }
204 }
205 for (const auto& [idx, bytes] : raw.aux)
206 result.metadata["gpu_output_" + std::to_string(idx)] = bytes;
207 return result;
208 }
209
210 const size_t total = std::accumulate(channels.begin(), channels.end(), size_t { 0 },
211 [](size_t s, const auto& ch) { return s + ch.size(); });
212 if (!raw.primary.empty() && !channels.empty() && raw.primary.size() >= total) {
213 size_t offset = 0;
214 std::vector<std::vector<double>> result_ch(channels.size());
215 for (size_t c = 0; c < channels.size(); ++c) {
216 result_ch[c].resize(channels[c].size());
217 for (size_t i = 0; i < channels[c].size(); ++i)
218 result_ch[c][i] = static_cast<double>(raw.primary[offset++]);
219 }
220 result = Datum<OutputType>(
221 OperationHelper::reconstruct_from_double<OutputType>(result_ch, structure_info));
222 }
223 for (const auto& [idx, bytes] : raw.aux)
224 result.metadata["gpu_output_" + std::to_string(idx)] = bytes;
225 return result;
226 }
float offset
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(), 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, and MayaFlux::Yantra::GpuChannelResult::primary.

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

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