summaryrefslogtreecommitdiff
path: root/examples/heterogeneous_computing/sim.cpp
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2026-01-19 13:35:25 +0100
committerClaudius "keldu" Holeksa <mail@keldu.de>2026-01-19 13:35:25 +0100
commit8b3ade73997e9f87f1232b9dc9af35969e6f50dd (patch)
tree832f62951389ffc5f5a593a57cc6d41e3da759ab /examples/heterogeneous_computing/sim.cpp
parent4fd241a9405124d9ac66fe7417bf628273a3762f (diff)
downloadlibs-lbm-8b3ade73997e9f87f1232b9dc9af35969e6f50dd.tar.gz
Rewriting parts to handle different ghost layers
Diffstat (limited to 'examples/heterogeneous_computing/sim.cpp')
-rw-r--r--examples/heterogeneous_computing/sim.cpp96
1 files changed, 96 insertions, 0 deletions
diff --git a/examples/heterogeneous_computing/sim.cpp b/examples/heterogeneous_computing/sim.cpp
new file mode 100644
index 0000000..d074ad8
--- /dev/null
+++ b/examples/heterogeneous_computing/sim.cpp
@@ -0,0 +1,96 @@
+#include <forstio/error.hpp>
+#include <iostream>
+
+#include <kel/lbm/lbm.hpp>
+
+namespace kel {
+namespace lbm {
+namespace sch {
+using namespace saw::schema;
+
+/**
+ * struct lbm_data {
+ * std::array<std::array<float,9>, 64u*64u> dfs;
+ * std::array<uint8_t, 64u*64u> info;
+ * };
+ *
+ * which leads to the form
+ *
+ * template<uint64_t Dim, uint64_t Size>
+ * struct lbm_data {
+ * std::array<std::array<float,9>, Size*Size> dfs;
+ * std::array<uint8_t, Size*Size> info;
+ * };
+ *
+ * which transferred into sycl requires us to go to
+ *
+ * template<uint64_t Dim, uint64_t Size>
+ * struct lbm_sycl_data {
+ * std::array<float,9>* dfs;
+ * uint8_t* info;
+ * };
+ *
+ * in data form on host
+ *
+ * template<uint64_t Dim, uint64_t Size>
+ * using LbmData = Struct<
+ * Member<FixedArray<FixedArray<Float32,9u>, Size*Size>, "dfs">,
+ * Member<FixedArray<UInt8, Size*Size>, "info">
+ * >;
+ *
+ * If we specialize the encode::Sycl<Encoding> data type, then we get
+ * With a helper class we can copy single values back and forth and the whole block is guaranteed
+ * to be allocated. And this one can be dynamic while the host definition might be compile time.
+ *
+ * template<...>
+ * class data<LbmData<...>,encode::Sycl<Encoding>> final {
+ * saw::data<sch::FixedArray<sch::UInt64,Dim>> meta;
+ * saw::data<FixedArray<Float32u,9>>* dfs;
+ * saw::data<UInt8>* info;
+ * };
+ */
+
+template<typename T, typename Desc>
+using CellStruct = Struct<
+ Member<Chunk<FixedArray<T,Desc::Q>,Desc::D, "dfs">,
+ Member<FixedArray<T,Desc::Q>, "dfs_old">,
+ Member<UInt8, "info">
+>;
+
+}
+template<typename T, typename Desc>
+saw::error_or<void> simulate(int argc, char** argv,
+ const saw::data<sch::FixedArray<sch::UInt64,Desc::D>>& meta
+{
+ constexpr auto cell_size = sizeof(saw::data<sch::CellStruct<T,Desc>>);
+
+ auto lbm_data = saw::heap<saw::data<sch::Chunk<CellStruct<>,Desc::D, 64u>>>{meta};
+
+ return saw::make_void();
+}
+
+}
+
+saw::error_or<void> lbm_main(int argc, char** argv){
+ using namespace lbm;
+ return simulate<sch::Float64,sch::D2Q9>(argc, argv);
+}
+}
+
+int main(int argc, char** argv){
+ auto eov = kel::lbm_main(argc, argv);
+ if(eov.is_error()){
+ auto& err = eov.get_error();
+ auto err_msg = err.get_message();
+ std::cerr<<"[Error]: "<<err.get_category();
+
+ if(not err_msg.empty()){
+ std::cerr<<" - "<<err_msg;
+ }
+ std::cerr<<std::endl;
+
+ return err.get_id();
+ }
+
+ return 0;
+}