HPXCL
|
00001 // Copyright (c) 2013 Damond Howard 00002 // 2015 Patrick Diehl 00003 // Distributed under the Boost Software License, Version 1.0. (See accompanying 00004 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt 00005 #pragma once 00006 #ifndef HPX_CUDA_BUFFER_HPP_ 00007 #define HPX_CUDA_BUFFER_HPP_ 00008 00009 #include <hpx/hpx.hpp> 00010 00011 #include "cuda/server/buffer.hpp" 00012 00013 namespace hpx { 00014 namespace cuda { 00015 00016 class buffer: public hpx::components::client_base<buffer, cuda::server::buffer> { 00017 typedef hpx::components::client_base<buffer, cuda::server::buffer> base_type; 00018 00019 public: 00020 buffer() { 00021 } 00022 00023 buffer(hpx::future<hpx::naming::id_type> && gid) : 00024 base_type(std::move(gid)) { 00025 00026 is_local = (hpx::get_colocation_id_sync(get_id()) == hpx::find_here()); 00027 } 00028 00034 hpx::lcos::future<size_t> size() { 00035 HPX_ASSERT(this->get_gid()); 00036 typedef server::buffer::size_action action_type; 00037 return hpx::async<action_type>(this->get_gid()); 00038 00039 } 00040 00041 size_t size_sync() { 00042 return size().get(); 00043 00044 } 00045 00054 hpx::lcos::future<void> set_size(size_t size) { 00055 HPX_ASSERT(this->get_gid()); 00056 typedef server::buffer::set_size_action action_type; 00057 return hpx::async<action_type>(this->get_gid(), size); 00058 00059 } 00060 00061 void set_size_sync(size_t size) { 00062 set_size(size).get(); 00063 00064 } 00065 00074 template<typename T> 00075 T* enqueue_read_sync(size_t offset, size_t size) { 00076 00077 if (is_local) { 00078 00079 return reinterpret_cast<T*>(enqueue_read_local(offset, size).get()); 00080 00081 } else { 00082 00083 return (T*) enqueue_read(offset, size).get().data(); 00084 00085 } 00086 00087 } 00088 00098 hpx::future<hpx::serialization::serialize_buffer<char>> enqueue_read( 00099 size_t offset, size_t size) { 00100 HPX_ASSERT(this->get_gid()); 00101 00102 typedef server::buffer::enqueue_read_action action_type; 00103 return hpx::async<action_type>(this->get_gid(), offset, size); 00104 00105 } 00106 00116 hpx::future<uintptr_t> enqueue_read_local(size_t offset, size_t size) { 00117 HPX_ASSERT(this->get_gid()); 00118 00119 typedef server::buffer::enqueue_read_local_action action_type; 00120 return hpx::async<action_type>(this->get_gid(), offset, size); 00121 00122 } 00123 00131 hpx::future<void> enqueue_write(size_t offset, size_t size, 00132 const void* data) const { 00133 HPX_ASSERT(this->get_gid()); 00134 00135 if (is_local) { 00136 00137 typedef server::buffer::enqueue_write_local_action action_type; 00138 return hpx::async<action_type>(this->get_id(), offset, size, 00139 reinterpret_cast<uintptr_t>(data)); 00140 00141 } else { 00142 00143 hpx::serialization::serialize_buffer<char> serializable_data( 00144 (char*) data, size, 00145 hpx::serialization::serialize_buffer<char>::init_mode::reference); 00146 00147 typedef server::buffer::enqueue_write_action action_type; 00148 return hpx::async<action_type>(this->get_gid(), offset, size, 00149 serializable_data); 00150 } 00151 00152 } 00153 00154 private: 00155 hpx::naming::id_type device_gid; 00156 bool is_local; 00157 00158 }; 00159 } 00160 } 00161 #endif //BUFFER_1_HPP