Override to perform custom readback interpretation (e.g. image containers).
176 {
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) {
185 if (allocated > 0) {
186 std::vector<uint8_t> raw_bytes(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) {
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 }
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.