From 8b3ade73997e9f87f1232b9dc9af35969e6f50dd Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Mon, 19 Jan 2026 13:35:25 +0100 Subject: Rewriting parts to handle different ghost layers --- lib/core/c++/chunk.hpp | 38 ++++++++++++++ lib/core/c++/common.hpp | 11 ++++ lib/core/c++/descriptor.hpp | 4 ++ lib/core/c++/lbm.hpp | 3 -- lib/sycl/.nix/derivation.nix | 4 +- lib/sycl/c++/common.hpp | 12 +++++ lib/sycl/c++/data.hpp | 117 +++++++++++++++++++++++++++++++++++++++++++ lib/sycl/c++/sycl.hpp | 4 ++ 8 files changed, 188 insertions(+), 5 deletions(-) create mode 100644 lib/core/c++/chunk.hpp create mode 100644 lib/core/c++/common.hpp create mode 100644 lib/sycl/c++/common.hpp create mode 100644 lib/sycl/c++/data.hpp create mode 100644 lib/sycl/c++/sycl.hpp (limited to 'lib') diff --git a/lib/core/c++/chunk.hpp b/lib/core/c++/chunk.hpp new file mode 100644 index 0000000..bfef358 --- /dev/null +++ b/lib/core/c++/chunk.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include "common.hpp" + +namespace kel { +namespace lbm { +namespace sch { +namespace impl { +template +struct chunk_schema_type_helper { + using Schema = typename chunk_schema_type_helper::Schema; +}; + +template +struct chunk_schema_type_helper { + using Schema = FixedArray; +}; +} + + +template +struct Chunk { + using InnerSchema = typename impl::chunk_schema_type_helper::Schema; +}; + +template +using SuperChunk = Array; +} +} +} + +namespace saw { +template +class data,Encode> final { +private: +public: +}; +} diff --git a/lib/core/c++/common.hpp b/lib/core/c++/common.hpp new file mode 100644 index 0000000..5f7129f --- /dev/null +++ b/lib/core/c++/common.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include + +namespace kel { +namespace lbm { +namespace sch { +using namespace saw::schema; +} +} +} diff --git a/lib/core/c++/descriptor.hpp b/lib/core/c++/descriptor.hpp index c6938e3..9cc2591 100644 --- a/lib/core/c++/descriptor.hpp +++ b/lib/core/c++/descriptor.hpp @@ -15,6 +15,10 @@ struct Descriptor { static constexpr uint64_t Q = QV; }; +using D2Q9 = Descriptor<2u,9u>; +//using D2Q5 = Descriptor<2u,5u>; +using D3Q27 = Descriptor<3u,27u>; + template struct Cell { using Descriptor = Desc; diff --git a/lib/core/c++/lbm.hpp b/lib/core/c++/lbm.hpp index 473ca69..aff38e9 100644 --- a/lib/core/c++/lbm.hpp +++ b/lib/core/c++/lbm.hpp @@ -19,9 +19,6 @@ #include namespace kel { -namespace sch { -using namespace saw::schema; -} namespace lbm { template void print_lbm_meta(const converter& conv, const saw::data>& kin_vis_si){ diff --git a/lib/sycl/.nix/derivation.nix b/lib/sycl/.nix/derivation.nix index 68fbab7..02032ba 100644 --- a/lib/sycl/.nix/derivation.nix +++ b/lib/sycl/.nix/derivation.nix @@ -5,7 +5,7 @@ , pname , version , forstio -, kel-lbm +, kel , adaptive-cpp }: @@ -27,7 +27,7 @@ stdenv.mkDerivation { forstio.codec-json forstio.remote forstio.remote-sycl - kel-lbm.core + kel.lbm.core adaptive-cpp ]; diff --git a/lib/sycl/c++/common.hpp b/lib/sycl/c++/common.hpp new file mode 100644 index 0000000..8ff76fc --- /dev/null +++ b/lib/sycl/c++/common.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include +#include + +namespace kel { +namespace lbm { +namespace sycl { +using namespace acpp::sycl; +} +} +} diff --git a/lib/sycl/c++/data.hpp b/lib/sycl/c++/data.hpp new file mode 100644 index 0000000..67422e2 --- /dev/null +++ b/lib/sycl/c++/data.hpp @@ -0,0 +1,117 @@ +#pragma once + +#include "common.hpp" + +namespace kel { +namespace lbm { +namespace encode { +template +struct Sycl { +}; +} + +namespace impl { +template +struct struct_has_only_equal_dimension_array +} +} +} + +namespace saw { +template +class data, Keys>...>, kel::lbm::encode::Sycl> final { +public: + static constexpr data*...>; +private: + + /** + * @todo Check by static assert that the members all have the same dimensions. Alternatively + * Do it here by specializing. + */ + StorageT members_; + kel::lbm::sycl::queue* q_; +public: + data(): + members_{}, + q_{nullptr} + {} + + ~data(){ + SAW_ASSERT(q_){ + exit(-1); + } + std::visit([this](auto arg){ + if(not arg){ + return; + } + sycl::free(arg,*q_); + arg = nullptr; + },members_); + } + + template + auto* get_ptr(){ + return std::get::value(members_); + } + + template + auto& get(){ + auto ptr = get_ptr(); + SAW_ASSERT(ptr); + return *ptr; + } + + void set_queue(kel::lbm::sycl::queue& q){ + q_ = &q; + } +}; + +} + +namespace kel { +namespace lbm { +namespace impl { +template +struct sycl_malloc_struct_helper; + +template +struct sycl_malloc_struct_helper, Encode> final { + template + static saw::error_or allocate_on_device_member(typename data>::StorageT& storage, sycl::queue& q){ + if constexpr (i < sizeof...(Members)){ + auto& ptr = std::get(storage); + + return allocate_on_device_member(sycl_data,q); + } + + return saw::make_void(); + } + + static saw::error_or allocate_on_device(data>& sycl_data, sycl::queue& q){ + typename data>::StorageT storage; + return allocate_on_device_member<0u>(storage,q); + } +}; +} +class device final { +private: + sycl::queue q_; + + SAW_FORBID_COPY(device); + SAW_FORBID_MOVE(device); +public: + device() = default; + ~device() = default; + + template + saw::error_or allocate_on_device(data>& sycl_data){ + auto eov = sycl_malloc_struct_helper::allocate_on_device(sycl_data, q_); + if(eov.is_error()){ + return eov; + } + sycl_data.set_queue(q_); + } +}; +} +} diff --git a/lib/sycl/c++/sycl.hpp b/lib/sycl/c++/sycl.hpp new file mode 100644 index 0000000..8ddc3cd --- /dev/null +++ b/lib/sycl/c++/sycl.hpp @@ -0,0 +1,4 @@ +#pragma once + +#include "common.hpp" +#include "data.hpp" -- cgit v1.2.3