[Mesa-dev] [PATCH 2/2] clover: clEnqueueMigrateMemObjects (host)
Serge Martin
edb+mesa at sigluy.net
Sat Sep 12 12:08:22 PDT 2015
implement memory objects migration back to host
---
src/gallium/state_trackers/clover/api/transfer.cpp | 5 +++-
src/gallium/state_trackers/clover/core/memory.cpp | 28 ++++++++++++++++++++++
src/gallium/state_trackers/clover/core/memory.hpp | 4 ++++
.../state_trackers/clover/core/resource.cpp | 3 +--
4 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/src/gallium/state_trackers/clover/api/transfer.cpp b/src/gallium/state_trackers/clover/api/transfer.cpp
index 55bab60..dab54c7 100644
--- a/src/gallium/state_trackers/clover/api/transfer.cpp
+++ b/src/gallium/state_trackers/clover/api/transfer.cpp
@@ -752,7 +752,10 @@ clEnqueueMigrateMemObjects(cl_command_queue d_q, cl_uint num_mems,
event::action act = [](event &){};
if (flags & CL_MIGRATE_MEM_OBJECT_HOST) {
- // XXX -- remove from the device
+ act = [=, &q](event &) {
+ for (auto &mem : mems)
+ mem.del_resource(q, copy_data);
+ };
} else {
act = [=, &q](event &) {
for (auto &mem : mems)
diff --git a/src/gallium/state_trackers/clover/core/memory.cpp b/src/gallium/state_trackers/clover/core/memory.cpp
index 47e31a3..24ca9db 100644
--- a/src/gallium/state_trackers/clover/core/memory.cpp
+++ b/src/gallium/state_trackers/clover/core/memory.cpp
@@ -20,6 +20,8 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
+#include <cstring>
+
#include "core/memory.hpp"
#include "core/resource.hpp"
#include "util/u_format.h"
@@ -98,6 +100,19 @@ root_buffer::resource(command_queue &q, bool copy_data) {
return *resources.find(&q.device())->second;
}
+void
+root_buffer::del_resource(command_queue &q, bool copy_data) {
+ if (!(flags() & (CL_MEM_ALLOC_HOST_PTR | CL_MEM_USE_HOST_PTR))) {
+ if (copy_data && resources.count(&q.device())) {
+ auto &r = *resources.find(&q.device())->second;
+ auto m = mapping(q, r, CL_MAP_READ, true, {{0}}, {{ size(), 1, 1 }});
+
+ data.assign(static_cast<const char *>(m), size());
+ }
+ resources.erase(&q.device());
+ }
+}
+
sub_buffer::sub_buffer(root_buffer &parent, cl_mem_flags flags,
size_t offset, size_t size) :
buffer(parent.context(), flags, size,
@@ -150,6 +165,19 @@ image::resource(command_queue &q, bool copy_data) {
return *resources.find(&q.device())->second;
}
+void
+image::del_resource(command_queue &q, bool copy_data) {
+ if (!(flags() & (CL_MEM_ALLOC_HOST_PTR | CL_MEM_USE_HOST_PTR))) {
+ if (copy_data && resources.count(&q.device())) {
+ auto &r = *resources.find(&q.device())->second;
+ auto m = mapping(q, r, CL_MAP_READ, true, {{0}}, {{ size(), 1, 1 }});
+
+ data.assign(static_cast<const char *>(m), size());
+ }
+ resources.erase(&q.device());
+ }
+}
+
cl_image_format
image::format() const {
return _format;
diff --git a/src/gallium/state_trackers/clover/core/memory.hpp b/src/gallium/state_trackers/clover/core/memory.hpp
index b3a91d2..0253bc9 100644
--- a/src/gallium/state_trackers/clover/core/memory.hpp
+++ b/src/gallium/state_trackers/clover/core/memory.hpp
@@ -51,6 +51,7 @@ namespace clover {
virtual cl_mem_object_type type() const = 0;
virtual clover::resource &resource(command_queue &q,
bool copy_data = true) = 0;
+ virtual void del_resource(command_queue &q, bool copy_data = true) = 0;
void destroy_notify(std::function<void ()> f);
cl_mem_flags flags() const;
@@ -85,6 +86,7 @@ namespace clover {
virtual clover::resource &resource(command_queue &q,
bool copy_data = true);
+ virtual void del_resource(command_queue &q, bool copy_data = true);
private:
std::map<device *,
@@ -98,6 +100,7 @@ namespace clover {
virtual clover::resource &resource(command_queue &q,
bool copy_data = true);
+ virtual void del_resource(command_queue &q, bool copy_data = true) {};
size_t offset() const;
const intrusive_ref<root_buffer> parent;
@@ -119,6 +122,7 @@ namespace clover {
public:
virtual clover::resource &resource(command_queue &q,
bool copy_data = true);
+ virtual void del_resource(command_queue &q, bool copy_data = true);
cl_image_format format() const;
size_t width() const;
size_t height() const;
diff --git a/src/gallium/state_trackers/clover/core/resource.cpp b/src/gallium/state_trackers/clover/core/resource.cpp
index 4346064..5d3c0cf 100644
--- a/src/gallium/state_trackers/clover/core/resource.cpp
+++ b/src/gallium/state_trackers/clover/core/resource.cpp
@@ -157,8 +157,7 @@ root_resource::root_resource(clover::device &dev, memory_obj &obj,
if (!pipe)
throw error(CL_OUT_OF_RESOURCES);
- if (copy_data &&
- (obj.flags() & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))) {
+ if (copy_data && (!data.empty() | (obj.flags() & CL_MEM_USE_HOST_PTR))) {
const void *data_ptr = !data.empty() ? data.data() : obj.host_ptr();
box rect { {{ 0, 0, 0 }}, {{ info.width0, info.height0, info.depth0 }} };
unsigned cpp = util_format_get_blocksize(info.format);
--
2.5.0
More information about the mesa-dev
mailing list