From ea306799624d0390074f6afa5d38644cce076c9f Mon Sep 17 00:00:00 2001 From: Claudius 'keldu' Holeksa Date: Wed, 24 Jul 2024 11:09:55 +0200 Subject: wip --- modules/codec/c++/transport.hpp | 18 +-- modules/io_codec/c++/io_peer.hpp | 22 ++-- modules/io_codec/c++/io_peer.tmpl.hpp | 36 ++--- modules/io_codec/examples/peer_echo_client.cpp | 4 +- .../benchmarks/kernel_mixed_precision.cpp | 1 + modules/tools/c++/c_gen_iface.hpp | 146 +++++++++++++++++++-- modules/tools/tests/c_iface.cpp | 3 +- 7 files changed, 181 insertions(+), 49 deletions(-) (limited to 'modules') diff --git a/modules/codec/c++/transport.hpp b/modules/codec/c++/transport.hpp index db277d1..430f719 100644 --- a/modules/codec/c++/transport.hpp +++ b/modules/codec/c++/transport.hpp @@ -1,5 +1,8 @@ #pragma once +#include +#include "data.hpp" + namespace saw { namespace transport { template @@ -12,23 +15,16 @@ struct NewLine {}; struct CarriageReturnNewLine {}; } -template -struct transport { -private: - static_assert(always_false, "Transport kind not supported."); -public: - - -template -struct transport> { +template +struct codec> { private: public: - error_or view_slice(const buffer& buff) const { + error_or view_slice(buffer& buff) const { (void) buff; return make_error(); } - error_or chain_slice(buffer& buff) const { + error_or chain_slice(chain_array_buffer& buff) const { (void) buff; return make_error(); } diff --git a/modules/io_codec/c++/io_peer.hpp b/modules/io_codec/c++/io_peer.hpp index f576cbe..613f60e 100644 --- a/modules/io_codec/c++/io_peer.hpp +++ b/modules/io_codec/c++/io_peer.hpp @@ -11,19 +11,21 @@ template class streaming_io_peer { +private: + static_assert(not std::is_same_v, "The native encoding by definition is not fit for transport."); public: /** * Constructor with the option to provide a custom codec, in and out buffer */ streaming_io_peer( - own>> feed, - own stream, codec in_codec, codec out_codec, BufferT in, BufferT out); + own>> feed, + own stream, codec in_codec, codec out_codec, BufferT in, BufferT out); /** * Constructor with mostly default assignements */ streaming_io_peer( - own>> feed, + own>> feed, own stream); /** @@ -35,25 +37,25 @@ public: /** * Send a message to the remote peer */ - error_or send(data builder); + error_or send(data builder); /** * A phantom conveyor feeder. Meant for interfacing with other components */ - conveyor_feeder> &feeder(); + conveyor_feeder> &feeder(); conveyor on_read_disconnected(); private: /// @unimplemented class peer_conveyor_feeder final - : public conveyor_feeder> { + : public conveyor_feeder> { public: peer_conveyor_feeder( streaming_io_peer &peer_) : peer_{peer_} {} - void feed(data &&data_) override { + void feed(data &&data_) override { (void)data_; } @@ -63,14 +65,14 @@ private: size_t queued() const override { return 0; } - error_or swap(conveyor> &&conveyor) noexcept override { return make_error();} + error_or swap(conveyor> &&) noexcept override { return make_error();} private: streaming_io_peer &peer_; }; private: - own>> + own>> incoming_feeder_ = nullptr; own io_stream_; @@ -95,7 +97,7 @@ template std::pair>, - conveyor>> + conveyor>> new_streaming_io_peer(own stream); } // namespace saw diff --git a/modules/io_codec/c++/io_peer.tmpl.hpp b/modules/io_codec/c++/io_peer.tmpl.hpp index d9dfe04..b7ccb49 100644 --- a/modules/io_codec/c++/io_peer.tmpl.hpp +++ b/modules/io_codec/c++/io_peer.tmpl.hpp @@ -1,20 +1,20 @@ namespace saw { -template streaming_io_peer:: streaming_io_peer( - own>> feed, + own>> feed, own str) : streaming_io_peer{std::move(feed), std::move(str), {}, {}, {}, {}} {} -template +template streaming_io_peer:: streaming_io_peer( - own>> feed, - own stream, codec in_codec, codec out_codec, BufferT in, BufferT out) + own>> feed, + own stream, codec in_codec, codec out_codec, BufferT in, BufferT out) : incoming_feeder_{std::move(feed)}, io_stream_{std::move(stream)}, in_codec_{std::move(in_codec)}, @@ -34,7 +34,7 @@ streaming_io_peer{in_view}; + auto in_data = data{in_view}; incoming_feeder_->feed(std::move(in_data)); } @@ -61,14 +61,14 @@ streaming_io_peerread(&in_buffer_.write(), 1, in_buffer_.write_segment_length()); } -template -error_or streaming_io_peer::send(data +template +error_or streaming_io_peer::send(data msg) { bool restart_write = out_buffer_.read_segment_length() == 0; - data enc; + data enc; auto eov = out_codec_.encode(msg, enc);//msg.read(), out_buffer_); @@ -84,22 +84,22 @@ error_or streaming_io_peer conveyor -streaming_io_peer::on_read_disconnected() { return io_stream_->on_read_disconnected(); } -template -std::pair>, - conveyor>> +template +std::pair>, + conveyor>> new_streaming_io_peer(own stream) { auto caf = - new_conveyor_and_feeder>(); + new_conveyor_and_feeder>(); - return {heap>( + return {heap>( std::move(caf.feeder), std::move(stream)), std::move(caf.conveyor)}; } diff --git a/modules/io_codec/examples/peer_echo_client.cpp b/modules/io_codec/examples/peer_echo_client.cpp index f1836e4..b09a51a 100644 --- a/modules/io_codec/examples/peer_echo_client.cpp +++ b/modules/io_codec/examples/peer_echo_client.cpp @@ -4,6 +4,8 @@ #include +#include + int main(){ using namespace saw; @@ -34,7 +36,7 @@ int main(){ network.connect(*addr).then([](saw::own client){ auto echo_stream = saw::heap(std::move(client)); - auto echo_peer_stream_p = saw::new_streaming_io_peer(std::move(echo_stream)); + auto echo_peer_stream_p = saw::new_streaming_io_peer, encode::KelSimple, ring_buffer>(std::move(echo_stream)); echo_peer_stream_p.first->on_read_disconnected().attach(std::move(echo_peer_stream_p.first)).detach(); }).detach(); diff --git a/modules/remote-sycl/benchmarks/kernel_mixed_precision.cpp b/modules/remote-sycl/benchmarks/kernel_mixed_precision.cpp index 591ded2..e99de53 100644 --- a/modules/remote-sycl/benchmarks/kernel_mixed_precision.cpp +++ b/modules/remote-sycl/benchmarks/kernel_mixed_precision.cpp @@ -12,6 +12,7 @@ saw::interface(h); h.parallel_for(cl::sycl::range<1>(in_size), [=] (cl::sycl::id<1> it){ + saw::data foo = {acc_buff[0u].at(it[0u]).get()}; for(uint64_t i = 0; i < arithmetic_intensity; ++i){ if( foo.get() == 1.1e12 ){ diff --git a/modules/tools/c++/c_gen_iface.hpp b/modules/tools/c++/c_gen_iface.hpp index 3a648a1..4fa881c 100644 --- a/modules/tools/c++/c_gen_iface.hpp +++ b/modules/tools/c++/c_gen_iface.hpp @@ -159,8 +159,10 @@ struct lang_bind_helper { } template - static error_or append_translation_func(std::string& buff, const std::string_view& prefix, bool c_to_cpp){ + static error_or append_translation_func(std::string& buff, const std::string_view& prefix, bool c_to_cpp, bool with_return_type = true){ constexpr uint32_t hash = schema_hash::apply(); + + if(with_return_type) { auto eov = lang_bind_helper::append_string(buff, "saw::error_or "); if(eov.is_error()){ @@ -488,29 +490,127 @@ struct lang_bind...>, binding::SyncC> { using Schema = schema::Struct...>; template - static error_or generate_translation_func(const language_binding_config& cfg, language_binding_state& state, std::string& buff, bool c_to_cpp){ + static error_or generate_translation_func(const language_binding_config& cfg, language_binding_state& state, bool c_to_cpp, uint64_t id){ using MT = typename parameter_pack_type::type; static constexpr string_literal Lit = parameter_key_pack_type::literal; constexpr uint32_t hash = schema_hash::apply(); auto& tpe = state.tp_elements; - uint64_t id; + if constexpr (i == 0){ + auto eov = lang_bind_helper::append_translation_func(tpe.at(id).source, cfg.prefix, c_to_cpp); + if(eov.is_error()){ + return eov; + } + } + if constexpr (i == 0) { - std::string hash_type_str = cfg.prefix + "_" + std::to_string(hash) + "_t"; + auto eov = lang_bind_helper::append_string(tpe.at(id).source, "{\n\t"); + if(eov.is_error()){ + return eov; + } } { - auto eov = lang_bind_helper::append_string(tpe.at(id).source, "\treturn void_t{};\n}\n"); + auto eov = lang_bind_helper::append_string(tpe.at(id).source, "{\n\t\tauto eov = "); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_hashed_type(tpe.at(id).source, cfg.prefix, hash); + if(eov.is_error()){ + return eov; + } + } + { + std::string_view trans = c_to_cpp ? "_translate_c_to_cpp (" : "_translate_cpp_to_c ("; + auto eov = lang_bind_helper::append_string(tpe.at(id).source, trans); + if(eov.is_error()){ + return eov; + } + } + if(c_to_cpp){ + auto eov = lang_bind_helper::append_string(tpe.at(id).source, "&((*c_val)."); + if(eov.is_error()){ + return eov; + } + } + if(c_to_cpp){ + auto eov = lang_bind_helper::append_string(tpe.at(id).source, std::string{Lit.view()}); + if(eov.is_error()){ + return eov; + } + } + if(c_to_cpp){ + auto eov = lang_bind_helper::append_string(tpe.at(id).source, "), cpp_val.template get<\""); + if(eov.is_error()){ + return eov; + } + } + if(c_to_cpp){ + auto eov = lang_bind_helper::append_string(tpe.at(id).source, std::string{Lit.view()}); + if(eov.is_error()){ + return eov; + } + } + if(c_to_cpp){ + auto eov = lang_bind_helper::append_string(tpe.at(id).source, "\">()"); + if(eov.is_error()){ + return eov; + } + } + if(!c_to_cpp){ + auto eov = lang_bind_helper::append_string(tpe.at(id).source, " cpp_val.template get<\""); + if(eov.is_error()){ + return eov; + } + } + if(!c_to_cpp){ + auto eov = lang_bind_helper::append_string(tpe.at(id).source, std::string{Lit.view()}); + if(eov.is_error()){ + return eov; + } + } + if(!c_to_cpp){ + auto eov = lang_bind_helper::append_string(tpe.at(id).source, "\">(), &((*c_val)."); + if(eov.is_error()){ + return eov; + } + } + if(!c_to_cpp){ + auto eov = lang_bind_helper::append_string(tpe.at(id).source, std::string{Lit.view()}); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_string(tpe.at(id).source, ") );\n\t\t");//cpp_output.set(*c_input);\n"); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_string(tpe.at(id).source, "if(eov.is_error()) return eov.get_error();\n\t}\n\t");//cpp_output.set(*c_input);\n"); if(eov.is_error()){ return eov; } } + if constexpr ( (i+1) < sizeof...(V) ){ + return generate_translation_func(cfg, state, c_to_cpp, id); + } + + { + auto eov = lang_bind_helper::append_string(tpe.at(id).source, "return void_t{};\n}\n"); + if(eov.is_error()){ + return eov; + } + } return void_t{}; } template - static error_or generate_ele(const language_binding_config& cfg, language_binding_state& state, int64_t id){ + static error_or generate_ele(const language_binding_config& cfg, language_binding_state& state, uint64_t id){ using MT = typename parameter_pack_type::type; static constexpr string_literal Lit = parameter_key_pack_type::literal; @@ -621,14 +721,16 @@ struct lang_bind...>, binding::SyncC> { return eov; } } + if constexpr ( sizeof...(V) > 0 ) { - auto eov = generate_translation_func<0>(tpe.at(id).source, cfg.prefix, true); + auto eov = generate_translation_func<0>(cfg, state, true, id); if(eov.is_error()){ return eov; } } + if constexpr ( sizeof...(V) > 0 ) { - auto eov = generate_translation_func<0>(tpe.at(id).source, cfg.prefix, false); + auto eov = generate_translation_func<0>(cfg, state, false, id); if(eov.is_error()){ return eov; } @@ -741,6 +843,34 @@ struct lang_bind, binding::SyncC> { return eov; } } + /** + * Source + */ + { + auto eov = lang_bind_helper::append_string(tpe.at(id).source, "namespace {\n"); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_translation_func(tpe.at(id).source, cfg.prefix, true); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_translation_func(tpe.at(id).source, cfg.prefix, false); + if(eov.is_error()){ + return eov; + } + } + { + auto eov = lang_bind_helper::append_string(tpe.at(id).source, "\n}\n"); + if(eov.is_error()){ + return eov; + } + } + } return void_t{}; diff --git a/modules/tools/tests/c_iface.cpp b/modules/tools/tests/c_iface.cpp index 35591f8..25a5d04 100644 --- a/modules/tools/tests/c_iface.cpp +++ b/modules/tools/tests/c_iface.cpp @@ -19,7 +19,8 @@ using TestArray = Array< >; using TestStructArray = Struct< - Member + Member, + Member >; using TestStructMore = Struct< -- cgit v1.2.3