Commit 9970c680 authored by Robert Kimball's avatar Robert Kimball

wip

parent 6430acb6
...@@ -91,8 +91,12 @@ std::shared_ptr<runtime::Executable> runtime::Backend::load(istream& input_strea ...@@ -91,8 +91,12 @@ std::shared_ptr<runtime::Executable> runtime::Backend::load(istream& input_strea
throw runtime_error("load opertion unimplemented."); throw runtime_error("load opertion unimplemented.");
} }
runtime::Backend::AsyncEvent::AsyncEvent(Type type, void* p, size_t size_in_bytes) runtime::Backend::AsyncEvent::AsyncEvent(Type type,
size_t buffer_number,
void* p,
size_t size_in_bytes)
: m_type{type} : m_type{type}
, m_buffer_number{buffer_number}
, m_data{p} , m_data{p}
, m_size_in_bytes{size_in_bytes} , m_size_in_bytes{size_in_bytes}
, m_executable{nullptr} , m_executable{nullptr}
...@@ -101,10 +105,12 @@ runtime::Backend::AsyncEvent::AsyncEvent(Type type, void* p, size_t size_in_byte ...@@ -101,10 +105,12 @@ runtime::Backend::AsyncEvent::AsyncEvent(Type type, void* p, size_t size_in_byte
{ {
} }
runtime::Backend::AsyncEvent::AsyncEvent(const shared_ptr<Executable>& executable, runtime::Backend::AsyncEvent::AsyncEvent(size_t buffer_number,
const shared_ptr<Executable>& executable,
const vector<shared_ptr<runtime::Tensor>>& outputs, const vector<shared_ptr<runtime::Tensor>>& outputs,
const vector<shared_ptr<runtime::Tensor>>& inputs) const vector<shared_ptr<runtime::Tensor>>& inputs)
: m_type{Type::EXECUTE} : m_type{Type::EXECUTE}
, m_buffer_number{buffer_number}
, m_data{nullptr} , m_data{nullptr}
, m_size_in_bytes{0} , m_size_in_bytes{0}
, m_executable{executable} , m_executable{executable}
...@@ -115,12 +121,14 @@ runtime::Backend::AsyncEvent::AsyncEvent(const shared_ptr<Executable>& executabl ...@@ -115,12 +121,14 @@ runtime::Backend::AsyncEvent::AsyncEvent(const shared_ptr<Executable>& executabl
void runtime::Backend::post_async_read_event(void* p, void runtime::Backend::post_async_read_event(void* p,
size_t size_in_bytes, size_t size_in_bytes,
size_t buffer_number,
std::promise<void>& promise) std::promise<void>& promise)
{ {
} }
void runtime::Backend::post_async_write_event(const void* p, void runtime::Backend::post_async_write_event(const void* p,
size_t size_in_bytes, size_t size_in_bytes,
size_t buffer_number,
std::promise<void>& promise) std::promise<void>& promise)
{ {
} }
...@@ -129,6 +137,7 @@ void runtime::Backend::post_async_execute_event( ...@@ -129,6 +137,7 @@ void runtime::Backend::post_async_execute_event(
const std::shared_ptr<Executable>& executable, const std::shared_ptr<Executable>& executable,
const std::vector<std::shared_ptr<runtime::Tensor>>& outputs, const std::vector<std::shared_ptr<runtime::Tensor>>& outputs,
const std::vector<std::shared_ptr<runtime::Tensor>>& inputs, const std::vector<std::shared_ptr<runtime::Tensor>>& inputs,
size_t buffer_number,
std::promise<void>& promise) std::promise<void>& promise)
{ {
} }
...@@ -163,11 +163,13 @@ protected: ...@@ -163,11 +163,13 @@ protected:
} }
const std::vector<std::shared_ptr<runtime::Tensor>>* get_inputs() const { return m_inputs; } const std::vector<std::shared_ptr<runtime::Tensor>>* get_inputs() const { return m_inputs; }
private: private:
AsyncEvent(Type, void* p, size_t size_in_bytes); AsyncEvent(Type type, size_t buffer_number, void* p, size_t size_in_bytes);
AsyncEvent(const std::shared_ptr<Executable>& m_executable, AsyncEvent(size_t buffer_number,
const std::shared_ptr<Executable>& m_executable,
const std::vector<std::shared_ptr<runtime::Tensor>>& m_outputs, const std::vector<std::shared_ptr<runtime::Tensor>>& m_outputs,
const std::vector<std::shared_ptr<runtime::Tensor>>& m_inputs); const std::vector<std::shared_ptr<runtime::Tensor>>& m_inputs);
const Type m_type; const Type m_type;
size_t m_buffer_number;
void* m_data; void* m_data;
const size_t m_size_in_bytes; const size_t m_size_in_bytes;
std::shared_ptr<Executable> m_executable; std::shared_ptr<Executable> m_executable;
...@@ -175,10 +177,17 @@ protected: ...@@ -175,10 +177,17 @@ protected:
const std::vector<std::shared_ptr<runtime::Tensor>>* m_inputs; const std::vector<std::shared_ptr<runtime::Tensor>>* m_inputs;
}; };
void post_async_read_event(void* p, size_t size_in_bytes, std::promise<void>& promise); void post_async_read_event(void* p,
void post_async_write_event(const void* p, size_t size_in_bytes, std::promise<void>& promise); size_t size_in_bytes,
size_t buffer_number,
std::promise<void>& promise);
void post_async_write_event(const void* p,
size_t size_in_bytes,
size_t buffer_number,
std::promise<void>& promise);
void post_async_execute_event(const std::shared_ptr<Executable>& executable, void post_async_execute_event(const std::shared_ptr<Executable>& executable,
const std::vector<std::shared_ptr<runtime::Tensor>>& outputs, const std::vector<std::shared_ptr<runtime::Tensor>>& outputs,
const std::vector<std::shared_ptr<runtime::Tensor>>& inputs, const std::vector<std::shared_ptr<runtime::Tensor>>& inputs,
size_t buffer_number,
std::promise<void>& promise); std::promise<void>& promise);
}; };
...@@ -98,12 +98,12 @@ void runtime::Tensor::copy_from(const ngraph::runtime::Tensor& source) ...@@ -98,12 +98,12 @@ void runtime::Tensor::copy_from(const ngraph::runtime::Tensor& source)
write(buffer.get_ptr(), 0, size); write(buffer.get_ptr(), 0, size);
} }
future<void> runtime::Tensor::begin_write(const void* p, size_t n) future<void> runtime::Tensor::begin_write(const void* p, size_t size_in_bytes, size_t buffer_number)
{ {
if (m_backend) if (m_backend)
{ {
auto f = m_promise.get_future(); auto f = m_promise.get_future();
m_backend->post_async_write_event(p, n, m_promise); m_backend->post_async_write_event(p, size_in_bytes, buffer_number, m_promise);
return f; return f;
} }
else else
...@@ -117,11 +117,21 @@ future<void> runtime::Tensor::begin_write(const void* p, size_t n) ...@@ -117,11 +117,21 @@ future<void> runtime::Tensor::begin_write(const void* p, size_t n)
// return f; // return f;
} }
future<void> runtime::Tensor::begin_read(void* p, size_t n) future<void> runtime::Tensor::begin_read(void* p, size_t size_in_bytes, size_t buffer_number)
{ {
using namespace std::placeholders; if (m_backend)
{
auto f = m_promise.get_future(); auto f = m_promise.get_future();
auto bound_f = bind(&Tensor::read, this, _1, _2, _3); m_backend->post_async_read_event(p, size_in_bytes, buffer_number, m_promise);
async(bound_f, p, 0, n);
return f; return f;
}
else
{
throw runtime_error("Async operations not supported for this backend");
}
// using namespace std::placeholders;
// auto f = m_promise.get_future();
// auto bound_f = bind(&Tensor::read, this, _1, _2, _3);
// async(bound_f, p, 0, n);
// return f;
} }
...@@ -119,16 +119,20 @@ namespace ngraph ...@@ -119,16 +119,20 @@ namespace ngraph
/// \brief Write bytes into the tensor. The data buffer pointed to by `p` must /// \brief Write bytes into the tensor. The data buffer pointed to by `p` must
/// be kept live until after the future is signaled complete /// be kept live until after the future is signaled complete
/// \param p Pointer to source of data /// \param p Pointer to source of data
/// \param n Number of bytes to write, must be integral number of elements. /// \param size_in_bytes Number of bytes to write, must be integral number of elements.
/// \param buffer_number For double-buffering, which buffer to write.
/// \return std::future to track the operation /// \return std::future to track the operation
virtual std::future<void> begin_write(const void* p, size_t n); virtual std::future<void>
begin_write(const void* p, size_t size_in_bytes, size_t buffer_number);
/// \brief Read bytes from the tensor. The data buffer pointed to by `p` must /// \brief Read bytes from the tensor. The data buffer pointed to by `p` must
/// be kept live until after the future is signaled complete /// be kept live until after the future is signaled complete
/// \param p Pointer to destination for data /// \param p Pointer to destination for data
/// \param n Number of bytes to read, must be integral number of elements. /// \param size_in_bytes Number of bytes to read, must be integral number of elements.
/// \param buffer_number For double-buffering, which buffer to read.
/// \return std::future to track the operation /// \return std::future to track the operation
virtual std::future<void> begin_read(void* p, size_t n); virtual std::future<void>
begin_read(void* p, size_t size_in_bytes, size_t buffer_number);
/// \brief copy bytes directly from source to this tensor /// \brief copy bytes directly from source to this tensor
/// \param source The source tensor /// \param source The source tensor
......
...@@ -70,9 +70,9 @@ TEST(async, tensor_read_write) ...@@ -70,9 +70,9 @@ TEST(async, tensor_read_write)
shared_ptr<runtime::Tensor> b = backend->create_tensor(element::f32, shape); shared_ptr<runtime::Tensor> b = backend->create_tensor(element::f32, shape);
shared_ptr<runtime::Tensor> r = backend->create_tensor(element::f32, shape); shared_ptr<runtime::Tensor> r = backend->create_tensor(element::f32, shape);
auto future_a = a->begin_write(data.data(), data.size() * sizeof(float)); auto future_a = a->begin_write(data.data(), data.size() * sizeof(float), 0);
auto future_b = b->begin_write(data.data(), data.size() * sizeof(float)); auto future_b = b->begin_write(data.data(), data.size() * sizeof(float), 0);
auto future_r = r->begin_read(data_r.data(), data_r.size() * sizeof(float)); auto future_r = r->begin_read(data_r.data(), data_r.size() * sizeof(float), 0);
ASSERT_TRUE(future_a.valid()); ASSERT_TRUE(future_a.valid());
ASSERT_TRUE(future_b.valid()); ASSERT_TRUE(future_b.valid());
ASSERT_TRUE(future_r.valid()); ASSERT_TRUE(future_r.valid());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment