From a725685ddaa2eaa0711ceb51e1f74d09349d618e Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Tue, 29 Oct 2019 21:04:53 +0100 Subject: Add example for C++ target --- ldc_2d/cpp/CMakeLists.txt | 37 +++++++++++++++++++++++++++++++++++++ ldc_2d/cpp/generate.py | 24 ++++++++++++++++++++++++ ldc_2d/cpp/ldc_2d.cc | 12 ++++++++++++ ldc_2d/cpp/shell.nix | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 115 insertions(+) create mode 100644 ldc_2d/cpp/CMakeLists.txt create mode 100755 ldc_2d/cpp/generate.py create mode 100644 ldc_2d/cpp/ldc_2d.cc create mode 100644 ldc_2d/cpp/shell.nix diff --git a/ldc_2d/cpp/CMakeLists.txt b/ldc_2d/cpp/CMakeLists.txt new file mode 100644 index 0000000..fe04297 --- /dev/null +++ b/ldc_2d/cpp/CMakeLists.txt @@ -0,0 +1,37 @@ +cmake_minimum_required(VERSION 3.10) +project(ldc_2d LANGUAGES CXX) + +add_custom_target( + boltzgen_kernel + COMMAND + ${CMAKE_CURRENT_SOURCE_DIR}/generate.py +) + +include_directories( + ${CMAKE_BINARY_DIR} +) + +add_executable( + ldc_2d + ldc_2d.cc +) + +add_dependencies( + ldc_2d + boltzgen_kernel +) + +target_compile_features( + ldc_2d + PUBLIC + cxx_std_17 +) + +find_package(OpenMP) +if(OpenMP_CXX_FOUND) + target_link_libraries( + ldc_2d + PUBLIC + OpenMP::OpenMP_CXX + ) +endif() diff --git a/ldc_2d/cpp/generate.py b/ldc_2d/cpp/generate.py new file mode 100755 index 0000000..a1aa561 --- /dev/null +++ b/ldc_2d/cpp/generate.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python + +from boltzgen import LBM, Generator, Geometry +from boltzgen.lbm.model import D2Q9 + +geometry = Geometry(256, 256) + +functions = ['collide_and_stream', 'equilibrilize', 'collect_moments', 'momenta_boundary', 'example'] +extras = ['omp_parallel_for', 'moments_vtk'] + +precision = 'double' + +lbm = LBM(D2Q9) +generator = Generator( + descriptor = D2Q9, + moments = lbm.moments(), + collision = lbm.bgk(f_eq = lbm.equilibrium(), tau = 0.52), + target = 'cpp', + precision = precision, + index = 'XYZ', + layout = 'AOS') + +with open("kernel.h", "w") as kernel: + kernel.write(generator.kernel(geometry, functions, extras)) diff --git a/ldc_2d/cpp/ldc_2d.cc b/ldc_2d/cpp/ldc_2d.cc new file mode 100644 index 0000000..d519490 --- /dev/null +++ b/ldc_2d/cpp/ldc_2d.cc @@ -0,0 +1,12 @@ +#include +#include +#include +#include +#include +#include + +#include "kernel.h" + +int main() { + test_ldc(10000); +} diff --git a/ldc_2d/cpp/shell.nix b/ldc_2d/cpp/shell.nix new file mode 100644 index 0000000..0b9db9f --- /dev/null +++ b/ldc_2d/cpp/shell.nix @@ -0,0 +1,42 @@ +{ pkgs ? import { }, ... }: + +pkgs.stdenvNoCC.mkDerivation rec { + name = "boltzgen-env"; + env = pkgs.buildEnv { name = name; paths = buildInputs; }; + + buildInputs = let + boltzgen = pkgs.python3.pkgs.buildPythonPackage rec { + pname = "boltzgen"; + version = "0.1"; + + src = pkgs.fetchFromGitHub { + owner = "KnairdA"; + repo = "boltzgen"; + rev = "v0.1.1"; + sha256 = "03fv7krhgc43gfjill8wb4aafr8xi69i2yh9zr68knnmrkrb8vpi"; + }; + + propagatedBuildInputs = with pkgs.python37Packages; [ + sympy + numpy + Mako + ]; + + doCheck = false; + }; + + local-python = pkgs.python3.withPackages (python-packages: with python-packages; [ + boltzgen + ]); + + in [ + local-python + pkgs.gcc9 + pkgs.cmake + ]; + + shellHook = '' + export NIX_SHELL_NAME="${name}" + export PYTHONPATH="$PWD:$PYTHONPATH" + ''; +} -- cgit v1.2.3