diff options
author | Claudius "keldu" Holeksa <mail@keldu.de> | 2025-08-30 19:02:15 +0200 |
---|---|---|
committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2025-08-30 19:04:11 +0200 |
commit | a1583da62ea0f7e9affe868cd509557b5e91fae3 (patch) | |
tree | 5d5261d24c81f33f81a930bdfc42fe9904915d9e | |
parent | 6379fe9ca2cad3d0c9d886e7808b1d579ce349c2 (diff) |
Fixing sycldev
-rw-r--r-- | default.nix | 2 | ||||
-rw-r--r-- | modules/codec/c++/math.hpp | 13 | ||||
-rw-r--r-- | modules/codec/tests/math.cpp | 20 | ||||
-rw-r--r-- | modules/remote-sycl/.nix/derivation.nix | 11 | ||||
-rw-r--r-- | modules/remote-sycl/c++/remote.hpp | 26 | ||||
-rw-r--r-- | modules/remote-sycl/examples/sycl_basic.cpp | 4 | ||||
-rw-r--r-- | modules/remote/c++/remote_loopback_base.hpp | 6 |
7 files changed, 64 insertions, 18 deletions
diff --git a/default.nix b/default.nix index 5a3289f..fa8c2c0 100644 --- a/default.nix +++ b/default.nix @@ -126,7 +126,7 @@ in rec { inherit forstio; inherit stdenv; inherit clang-tools; - openmp = pkgs.llvmPackages_15.openmp; + openmp = pkgs.llvmPackages_17.openmp; build_examples = "true"; build_benchmarks = "true"; 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<typename T, typename Encoding = encode::Native> data<typename T::InnerType,Encoding> norm_2(const data<T,Encoding>& d){ return {}; } +*/ + +template<typename T, uint64_t D, typename Encoding = encode::Native> +data<schema::Scalar<T>, Encoding> dot(const data<schema::Vector<T,D>, Encoding>& left, const data<schema::Vector<T,D>, Encoding>& right){ + data<schema::Scalar<T>,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 <forstio/test/suite.hpp> #include "../c++/data.hpp" #include "../c++/data_math.hpp" +#include "../c++/math.hpp" #include "../c++/csv.hpp" #include <iostream> @@ -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<sch::Vector<sch::Float64, 2u>> a; + { + a.at({{0u}}) = 2.0; + a.at({{1u}}) = 1.0; + } + data<sch::Vector<sch::Float64, 2u>> 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<uint64_t,3> data; + + template<typename Schema, typename Encoding> + static key_t create(const remote_address<rmt::Loopback>& addr){ + key_t k; + k.data = std::array<uint64_t,3>{addr.get_address_id().get(), schema_hash<Schema>::apply(), schema_hash<Encoding>::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<schema::Array<schema::UInt64>>(id_zero); + auto rmt_data = rpc_server.template request_data<schema::Array<schema::UInt64>>(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<schema::Array<schema::UInt64>>(id_one); + auto rmt_data = rpc_server.template request_data<schema::Array<schema::UInt64>>(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<rmt::Loopback> { private: + /** + * Unique key for identifying an underlying data type without using typeid :) + */ struct key_t { std::array<uint64_t,3> data; + /** + * Create a key with all identifying elements + */ template<typename Schema, typename Encoding> static key_t create(const remote_address<rmt::Loopback>& addr){ key_t k; |