summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2025-09-10 15:29:40 +0200
committerClaudius "keldu" Holeksa <mail@keldu.de>2025-09-10 15:29:40 +0200
commit461022ee5135a3bfcca4659cf73fadccc0594d3f (patch)
treeb81ab7f5952bcbc9dc05feb8186efc2cb0eb3bdb
parent3c2778f440a48ec809b6c9d176c393cbefbee69d (diff)
Moving towards gpu
-rw-r--r--.nix/adaptive-cpp.nix50
-rw-r--r--c++/SConscript3
-rw-r--r--c++/collision.hpp1
-rw-r--r--c++/lbm.hpp2
-rw-r--r--default.nix27
-rw-r--r--examples/cavity_2d_gpu/.nix/derivation.nix9
-rw-r--r--examples/cavity_2d_gpu/SConscript21
-rw-r--r--examples/cavity_2d_gpu/cavity_2d_gpu.cpp14
8 files changed, 95 insertions, 32 deletions
diff --git a/.nix/adaptive-cpp.nix b/.nix/adaptive-cpp.nix
new file mode 100644
index 0000000..f2d5f9b
--- /dev/null
+++ b/.nix/adaptive-cpp.nix
@@ -0,0 +1,50 @@
+{ lib
+, stdenv
+, fetchFromGitHub
+, cmake
+, makeWrapper
+, boost
+, llvmPackages
+, lld
+}:
+
+let
+ version = "25.02.0";
+in stdenv.mkDerivation {
+ pname = "adaptive-cpp-kel-custom";
+ inherit version;
+
+ src = fetchFromGitHub {
+ owner = "AdaptiveCpp";
+ repo = "AdaptiveCpp";
+ tag = "v${version}";
+ sha256 = "sha256-vXfw8+xn3/DYxUKp3QGdQ8sEbDwyk+8jDCyuvQOXigc=";
+ };
+
+ nativeBuildInputs = [
+ cmake
+ makeWrapper
+ ];
+
+ buildInputs = [
+ boost
+ llvmPackages.openmp
+ llvmPackages.libclang
+ llvmPackages.llvm
+ ];
+
+ cmakeFlags = [
+ "-DCLANG_INCLUDE_PATH=${llvmPackages.libclang.dev}/include"
+ ];
+
+ postFixup = ''
+ wrapProgram $out/bin/syclcc-clang \
+ --prefix PATH : ${lib.makeBinPath [ lld ]} \
+ --add-flags "-L${llvmPackages.openmp}/lib" \
+ --add-flags "-I${llvmPackages.openmp.dev}/include" \
+ '';
+
+ postPatch = ''
+ patchShebangs .
+ '';
+}
diff --git a/c++/SConscript b/c++/SConscript
index 3b79d1a..857ca77 100644
--- a/c++/SConscript
+++ b/c++/SConscript
@@ -23,3 +23,6 @@ env.headers += core_env.headers;
objects = []
core_env.add_source_files(objects, core_env.sources, shared=False);
env.library_static = core_env.StaticLibrary('#build/kel-lbm', [objects]);
+
+env.Install('$prefix/lib/', env.library_static);
+env.Install('$prefix/include/kel/lbm/', env.headers);
diff --git a/c++/collision.hpp b/c++/collision.hpp
index 1b8b82d..47870c1 100644
--- a/c++/collision.hpp
+++ b/c++/collision.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include "macroscopic.hpp"
#include "component.hpp"
#include "equilibrium.hpp"
diff --git a/c++/lbm.hpp b/c++/lbm.hpp
index a8d1f96..ddd4617 100644
--- a/c++/lbm.hpp
+++ b/c++/lbm.hpp
@@ -1,8 +1,10 @@
#pragma once
#include "descriptor.hpp"
+#include "boundary.hpp"
#include "converter.hpp"
#include "config.hpp"
+#include "collision.hpp"
#include "component.hpp"
#include "environment.hpp"
#include "equilibrium.hpp"
diff --git a/default.nix b/default.nix
index 883b70e..937a1de 100644
--- a/default.nix
+++ b/default.nix
@@ -10,10 +10,27 @@ let
}).outPath + "/default.nix"){
inherit stdenv;
inherit clang-tools;
- }).forstio;
+ }).forstio;
-in pkgs.callPackage ./.nix/derivation.nix {
- inherit forstio;
- inherit stdenv;
- inherit clang-tools;
+ adaptive-cpp = pkgs.callPackage ./.nix/adaptive-cpp.nix {
+ inherit stdenv;
+ llvmPackages = pkgs.llvmPackages_19;
+ lld = pkgs.lld_19;
+ };
+
+ pname = "kel-lbm";
+ version = "0.0.2";
+in rec {
+ lbm = pkgs.callPackage ./.nix/derivation.nix {
+ inherit forstio;
+ inherit stdenv;
+ inherit clang-tools;
+ };
+
+ examples = {
+ cavity_2d_gpu = pkgs.callPackage ./examples/cavity_2d_gpu/.nix/derivation.nix {
+ inherit pname version stdenv forstio adaptive-cpp;
+ kel-lbm = lbm;
+ };
+ };
}
diff --git a/examples/cavity_2d_gpu/.nix/derivation.nix b/examples/cavity_2d_gpu/.nix/derivation.nix
index a98795b..876bcb7 100644
--- a/examples/cavity_2d_gpu/.nix/derivation.nix
+++ b/examples/cavity_2d_gpu/.nix/derivation.nix
@@ -3,12 +3,15 @@
, scons
, clang-tools
, forstio
+, adaptive-cpp
, pname
, version
+, kel-lbm
}:
stdenv.mkDerivation {
- inherit pname version;
+ pname = pname + "-examples-" + "cavity_2d_gpu";
+ inherit version;
src = ./..;
nativeBuildInputs = [
@@ -21,7 +24,9 @@ stdenv.mkDerivation {
forstio.async
forstio.codec
forstio.codec-unit
- forstio.codec-json
+ forstio.codec-json
+ adaptive-cpp
+ kel-lbm
];
doCheck = true;
diff --git a/examples/cavity_2d_gpu/SConscript b/examples/cavity_2d_gpu/SConscript
index 077fb99..15b013d 100644
--- a/examples/cavity_2d_gpu/SConscript
+++ b/examples/cavity_2d_gpu/SConscript
@@ -10,7 +10,7 @@ Import('env')
dir_path = Dir('.').abspath
# Environment for base library
-cavity2d_env = examples_env.Clone();
+examples_env = env.Clone();
examples_env.sources = sorted(glob.glob(dir_path + "/*.cpp"))
examples_env.headers = sorted(glob.glob(dir_path + "/*.hpp"))
@@ -20,22 +20,13 @@ env.headers += examples_env.headers;
# Cavity2D
examples_objects = [];
-examples_env.add_source_files(examples_objects, ['cavity_2d.cpp'], shared=False);
-examples_env.cavity_2d = examples_env.Program('#bin/cavity_2d', [env.library_static, examples_objects]);
+examples_env.add_source_files(examples_objects, ['cavity_2d_gpu.cpp'], shared=False);
+examples_env.cavity_2d_gpu = examples_env.Program('#bin/cavity_2d_gpu', [examples_objects]);
# Set Alias
env.examples = [
- examples_env.meta_2d,
-# examples_env.cavity_2d,
-# examples_env.cavity_3d,
-# examples_env.particle_ibm_2d
- examples_env.poiseulle_2d,
- examples_env.poiseulle_channel_2d,
- examples_env.poiseulle_particles_channel_2d
+ examples_env.cavity_2d_gpu
];
env.Alias('examples', env.examples);
-
-if env["build_examples"]:
- env.targets += ['examples'];
- env.Install('$prefix/bin/', env.examples);
-#endif
+env.targets += ['examples'];
+env.Install('$prefix/bin/', env.examples);
diff --git a/examples/cavity_2d_gpu/cavity_2d_gpu.cpp b/examples/cavity_2d_gpu/cavity_2d_gpu.cpp
index a72cc6a..dc022a1 100644
--- a/examples/cavity_2d_gpu/cavity_2d_gpu.cpp
+++ b/examples/cavity_2d_gpu/cavity_2d_gpu.cpp
@@ -1,9 +1,4 @@
-#include "../c++/descriptor.hpp"
-#include "../c++/macroscopic.hpp"
-#include "../c++/lbm.hpp"
-#include "../c++/component.hpp"
-#include "../c++/collision.hpp"
-#include "../c++/boundary.hpp"
+#include <kel/lbm/lbm.hpp>
#include <forstio/codec/data.hpp>
// #include <forstio/remote/
@@ -27,14 +22,13 @@ using namespace saw::schema;
* Q factor
*/
using T = Float32;
-using D2Q5 = Descriptor<2u,5u>;
using D2Q9 = Descriptor<2u,9u>;
template<typename Desc>
using DfCell = Cell<T, Desc, 0u, 0u, 1u>;
template<typename Desc>
-using CellInfo = Cell<UInt8, D2Q9, 1u, 0u, 0u>;
+using CellInfo = Cell<UInt8, Desc, 1u, 0u, 0u>;
/**
* Basic type for simulation
@@ -217,11 +211,11 @@ void lbm_step(
switch(info({0u}).get()){
case 1u: {
- coll.apply(latt, index, time_step);
+ bb.apply(latt, index, time_step);
break;
}
case 2u: {
- bb.apply(latt, index, time_step);
+ coll.apply(latt, index, time_step);
break;
}
default: