From 5329652f839b99b95d63cd471ff73d251f74d911 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Fri, 14 Jun 2024 14:33:22 +0200 Subject: Fixed calc of sycl vals --- modules/remote-sycl/c++/remote.hpp | 47 ++++++++++++++++++---- modules/remote-sycl/examples/SConscript | 1 + modules/remote-sycl/examples/sycl_basic.cpp | 41 +++++++++++++++++-- modules/remote-sycl/examples/sycl_basic_kernel.cpp | 3 +- 4 files changed, 79 insertions(+), 13 deletions(-) (limited to 'modules') diff --git a/modules/remote-sycl/c++/remote.hpp b/modules/remote-sycl/c++/remote.hpp index bcc8a3c..4510237 100644 --- a/modules/remote-sycl/c++/remote.hpp +++ b/modules/remote-sycl/c++/remote.hpp @@ -22,22 +22,34 @@ class remote_data { private: id id_; id_map* map_; - cl::sycl::queue* queue_; public: /** * Main constructor */ remote_data(const id& id, id_map& map, cl::sycl::queue& queue__): id_{id}, - map_{&map}, - queue_{&queue__} + map_{&map} {} /** * Wait for the data */ error_or> wait(){ + auto eov = map_->find(id_); + if(eov.is_error()){ + auto& err = eov.get_error(); + return std::move(err); + } + auto& val = eov.get_value(); + std::cout<<"Values Sycl in Map: "<size()<template copy_to_host(); + if(eocop.is_error()){ + return eocop; + } + return eocop.get_value(); + } } /** @@ -87,7 +99,9 @@ public: { if(!device_data_){ total_length_ = 0u; + return; } + queue_->wait(); } template @@ -102,6 +116,7 @@ public: return; } queue_->template copy>(&from.at(0), device_data_, total_length_); + queue_->wait(); } data(const data& from): @@ -116,7 +131,10 @@ public: // device_data_ = cl::sycl::malloc_device::type>(from.size(), *queue_); if(!device_data_){ total_length_ = 0u; + return; } + + queue_->template copy>(from.device_data_, device_data_, total_length_); } data& operator=(const data& rhs) { @@ -158,7 +176,20 @@ public: } } - data& at(uint64_t i){ + /** + * Allocate appropriate meta data and then copy to host + */ + template + error_or> copy_to_host() const { + data data_{total_length_}; + + /// TODO Check success + queue_->template copy>(device_data_, &data_.at(0), total_length_); + queue_->wait(); + return data_; + } + + data& at(uint64_t i){ //typename native_data_type::type& at(uint64_t i){ return device_data_[i]; } @@ -247,6 +278,9 @@ public: return std::get>(storage_.maps).next_free_id(); } + /** + * Main constructor + */ rpc_server(interface cl_iface): cmd_queue_{}, cl_interface_{std::move(cl_iface)}, @@ -255,12 +289,11 @@ public: template remote_data request_data(id dat_id){ - /// @TODO Fix so I can receive data - return {dat_id, std::get>(storage_.maps)}; + return {dat_id, std::get>(storage_.maps), cmd_queue_}; } /** - * Rpc call + * Rpc call based on the name */ template error_or< diff --git a/modules/remote-sycl/examples/SConscript b/modules/remote-sycl/examples/SConscript index 02e528b..015b492 100644 --- a/modules/remote-sycl/examples/SConscript +++ b/modules/remote-sycl/examples/SConscript @@ -15,6 +15,7 @@ examples_env = env.Clone(); examples_sycl_env = examples_env.Clone(); examples_sycl_env['CXX'] = 'acpp'; +examples_sycl_env['CXXFLAGS'] += ['-O2']; examples_env.sources = sorted(glob.glob(dir_path + "/*.cpp")) examples_env.headers = sorted(glob.glob(dir_path + "/*.hpp")) diff --git a/modules/remote-sycl/examples/sycl_basic.cpp b/modules/remote-sycl/examples/sycl_basic.cpp index 2e9a4f8..486aca1 100644 --- a/modules/remote-sycl/examples/sycl_basic.cpp +++ b/modules/remote-sycl/examples/sycl_basic.cpp @@ -22,8 +22,12 @@ int main(){ saw::rpc_client client{rpc_server}; saw::id> id_zero{0u}; + saw::data, saw::encode::Native> ex_data{1u}; + ex_data.at(0u).set(50u); { - auto eov = client.template call<"increment">(saw::data, saw::encode::Native>{1u}); + auto eov = client.template call<"increment">( + ex_data + ); if(eov.is_error()){ auto& err = eov.get_error(); std::cerr<<"Error: "<, saw::storage::Default>(id_zero); + auto eo_rd = rmt_data.wait(); + if(eo_rd.is_error()){ + auto& err = eo_rd.get_error(); + std::cerr<<"Error: "<> id_one{1u}; { auto eov = client.template call<"increment">(id_zero); if(eov.is_error()){ @@ -38,11 +59,23 @@ int main(){ std::cerr<<"Error: "<, saw::storage::Default>(id_one); + auto eo_rd = rmt_data.wait(); + if(eo_rd.is_error()){ + auto& err = eo_rd.get_error(); + std::cerr<<"Error: "< lis saw::interface iface{ [](saw::data, saw::encode::Native, saw::rmt::Sycl> in, cl::sycl::queue* q) -> saw::data, saw::encode::Native, saw::rmt::Sycl> { - q->submit([&](cl::sycl::handler& h){ - h.parallel_for(cl::sycl::range<1>(1u), [&] (cl::sycl::id<1> it){ + h.single_task([&] (){ in.at(0u).set(in.at(0u).get() + 1u); }); }); -- cgit v1.2.3