onnxruntime/winml/lib/Api.Image/DisjointBufferHelpers.cpp
Tiago Koji Castro Shibata 62c0d24340
Fix Windows Store build (#8753)
* Remove APIs unavailable in Store in #8349, #8178, #8065

* Add UWP stubs of C runtime functions

* Remove UWP incompatible tests from UWP build

* Remove incompatible tests from Store

* Use UWP stubs in store only

* Skip partition check outside of Windows

* Remove unused WRL include

* Workaround Windows header not including what it uses

* Fix precompiled header name clash

* Workaround SDK bugs

* DXCore workaround in Win7

* Fix warning

* Fix more warnings

* Bump WinML to target Windows 8

* Fix more warnings

* Remove unnecessary workarounds

* Remove Desktop only APIs from DML adapter
2021-08-23 11:19:03 -07:00

48 lines
1.5 KiB
C++

#include "lib/Api.Image/pch.h"
#include "inc/DisjointBufferHelpers.h"
namespace _winml {
static void LoadOrStoreDisjointBuffers(
bool should_load_buffer,
size_t num_buffers,
std::function<gsl::span<byte>(size_t)> get_buffer,
gsl::span<byte>& buffer_span) {
auto size_in_bytes = buffer_span.size_bytes();
auto buffer = buffer_span.data();
size_t offset_in_bytes = 0;
for (size_t i = 0; i < num_buffers && size_in_bytes > offset_in_bytes; i++) {
auto span = get_buffer(i);
auto current_size_in_bytes = span.size_bytes();
auto current_buffer = span.data();
if (size_in_bytes - offset_in_bytes < current_size_in_bytes) {
current_size_in_bytes = size_in_bytes - offset_in_bytes;
}
auto offset_buffer = buffer + offset_in_bytes;
if (should_load_buffer) {
memcpy(offset_buffer, current_buffer, current_size_in_bytes);
} else {
memcpy(current_buffer, offset_buffer, current_size_in_bytes);
}
offset_in_bytes += current_size_in_bytes;
}
}
void LoadSpanFromDisjointBuffers(
size_t num_buffers,
std::function<gsl::span<byte>(size_t)> get_buffer,
gsl::span<byte>& buffer_span) {
LoadOrStoreDisjointBuffers(true /*load into the span*/, num_buffers, get_buffer, buffer_span);
}
void StoreSpanIntoDisjointBuffers(
size_t num_buffers,
std::function<gsl::span<byte>(size_t)> get_buffer,
gsl::span<byte>& buffer_span) {
LoadOrStoreDisjointBuffers(false /*store into buffers*/, num_buffers, get_buffer, buffer_span);
}
} // namespace _winml