From a1583da62ea0f7e9affe868cd509557b5e91fae3 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Sat, 30 Aug 2025 19:02:15 +0200 Subject: Fixing sycl --- modules/codec/c++/math.hpp | 13 +++++++++++++ modules/codec/tests/math.cpp | 20 ++++++++++++++++++++ modules/remote-sycl/.nix/derivation.nix | 11 ++++++++--- modules/remote-sycl/c++/remote.hpp | 26 ++++++++++++++------------ modules/remote-sycl/examples/sycl_basic.cpp | 4 ++-- modules/remote/c++/remote_loopback_base.hpp | 6 ++++++ 6 files changed, 63 insertions(+), 17 deletions(-) (limited to 'modules') diff --git a/modules/codec/c++/math.hpp b/modules/codec/c++/math.hpp index dd9e49b..ddeea3f 100644 --- a/modules/codec/c++/math.hpp +++ b/modules/codec/c++/math.hpp @@ -4,9 +4,22 @@ namespace saw { namespace math { +/* template data norm_2(const data& d){ return {}; } +*/ + +template +data, Encoding> dot(const data, Encoding>& left, const data, Encoding>& right){ + data,Encoding> val; + auto& inner = val({}); + for(uint64_t i = 0u; i < D; ++i){ + inner = inner + left({{i}}) * right({{i}}); + } + + return val; +} } } diff --git a/modules/codec/tests/math.cpp b/modules/codec/tests/math.cpp index ad2d9a6..4fb012f 100644 --- a/modules/codec/tests/math.cpp +++ b/modules/codec/tests/math.cpp @@ -1,6 +1,7 @@ #include #include "../c++/data.hpp" #include "../c++/data_math.hpp" +#include "../c++/math.hpp" #include "../c++/csv.hpp" #include @@ -55,4 +56,23 @@ SAW_TEST("Math/Tensor"){ SAW_EXPECT(d.at({{1u,1u}}).get() == 1.0, std::string{"Unexpected value at (1,1): "} + std::to_string(d.at({{1u,1u}}).get())); } } + +SAW_TEST("Math/Dot"){ + using namespace saw; + + data> a; + { + a.at({{0u}}) = 2.0; + a.at({{1u}}) = 1.0; + } + data> b; + { + b.at({{0u}}) = -1.0; + b.at({{1u}}) = 5.0; + } + + auto c = math::dot(a,b); + + SAW_EXPECT(c.at({}).get() == 3.0, std::string{"Unexpected value for dot product "} + std::to_string(c.at({}).get()) ); +} } diff --git a/modules/remote-sycl/.nix/derivation.nix b/modules/remote-sycl/.nix/derivation.nix index 28e3cc8..33317eb 100644 --- a/modules/remote-sycl/.nix/derivation.nix +++ b/modules/remote-sycl/.nix/derivation.nix @@ -7,7 +7,7 @@ , openmp , keldu , ocl-icd -, lld_15 +, lld_17 , python3 , bash @@ -16,7 +16,12 @@ }: let - + adaptivecpp_custom = (import ((builtins.fetchGit { + url = "git@git.keldu.de:forstio/forstio"; + ref = "dev"; + }).outPath + "/default.nix"){ + inherit stdenv; + }); in stdenv.mkDerivation { pname = "forstio-remote-sycl"; inherit version; @@ -38,7 +43,7 @@ in stdenv.mkDerivation { keldu.adaptivecpp-dev ocl-icd openmp - lld_15 + lld_17 ]; buildPhase = '' diff --git a/modules/remote-sycl/c++/remote.hpp b/modules/remote-sycl/c++/remote.hpp index a481740..fd2f64a 100644 --- a/modules/remote-sycl/c++/remote.hpp +++ b/modules/remote-sycl/c++/remote.hpp @@ -28,19 +28,21 @@ private: SAW_FORBID_MOVE(remote); struct key_t { - uint64_t device_id; - uint32_t sch_id; - uint32_t enc_id; - + std::array data; + + template + static key_t create(const remote_address& addr){ + key_t k; + k.data = std::array{addr.get_address_id().get(), schema_hash::apply(), schema_hash::apply()}; + + return k; + } + bool operator<(const key_t& rhs) const { - if(device_id != rhs.device_id){ - return device_id < rhs.device_id; - } - if(sch_id != rhs.sch_id){ - return sch_id < rhs.sch_id; - } - if(enc_id != rhs.enc_id){ - return enc_id < rhs.enc_id; + for(uint64_t i = 0u; i < 3; ++i){ + if(data[i] != rhs.data[i]){ + return data[i] < rhs.data[i]; + } } return false; } diff --git a/modules/remote-sycl/examples/sycl_basic.cpp b/modules/remote-sycl/examples/sycl_basic.cpp index 499ef2b..63d3713 100644 --- a/modules/remote-sycl/examples/sycl_basic.cpp +++ b/modules/remote-sycl/examples/sycl_basic.cpp @@ -36,7 +36,7 @@ int main(){ id_zero = eov.get_value(); } { - auto rmt_data = rpc_server.request_data>(id_zero); + auto rmt_data = rpc_server.template request_data>(id_zero); auto eo_rd = rmt_data.wait(); if(eo_rd.is_error()){ auto& err = eo_rd.get_error(); @@ -62,7 +62,7 @@ int main(){ id_one = eov.get_value(); } { - auto rmt_data = rpc_server.request_data>(id_one); + auto rmt_data = rpc_server.template request_data>(id_one); auto eo_rd = rmt_data.wait(); if(eo_rd.is_error()){ auto& err = eo_rd.get_error(); diff --git a/modules/remote/c++/remote_loopback_base.hpp b/modules/remote/c++/remote_loopback_base.hpp index 82857a9..5224d95 100644 --- a/modules/remote/c++/remote_loopback_base.hpp +++ b/modules/remote/c++/remote_loopback_base.hpp @@ -28,9 +28,15 @@ public: template<> class remote { private: + /** + * Unique key for identifying an underlying data type without using typeid :) + */ struct key_t { std::array data; + /** + * Create a key with all identifying elements + */ template static key_t create(const remote_address& addr){ key_t k; -- cgit v1.2.3