Override to perform custom readback interpretation (e.g. image containers).
183 {
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) {
192 if (allocated > 0) {
193 std::vector<uint8_t> raw_bytes(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)
214 return result;
215 }
216
218 [](size_t s, const auto& ch) { return s + ch.size(); });
219 if (!raw.primary.empty() && !
channels.empty() && raw.primary.size() >=
total) {
221 std::vector<std::vector<double>> result_ch(
channels.size());
222 for (
size_t c = 0; c <
channels.size(); ++c) {
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)
232 return result;
233 }
std::unordered_map< std::string, std::string > metadata
GpuResourceManager m_resources
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 find_first_output_index() const
Datum< OutputType > output_type
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.