From 6a918f0827a6e8806f77e39e0348b1a2abed71f2 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Fri, 19 Dec 2025 14:11:57 +0100 Subject: Rewriting large portion for simpler approach --- .../heterogeneous_computing/.nix/derivation.nix | 39 ++++++++++ examples/heterogeneous_computing/SConscript | 34 +++++++++ examples/heterogeneous_computing/SConstruct | 82 ++++++++++++++++++++++ .../heterogeneous_computing.cpp | 33 +++++++++ examples/poiseulle_2d_gpu/poiseulle_2d_gpu.cpp | 48 ++++++------- 5 files changed, 210 insertions(+), 26 deletions(-) create mode 100644 examples/heterogeneous_computing/.nix/derivation.nix create mode 100644 examples/heterogeneous_computing/SConscript create mode 100644 examples/heterogeneous_computing/SConstruct create mode 100644 examples/heterogeneous_computing/heterogeneous_computing.cpp (limited to 'examples') diff --git a/examples/heterogeneous_computing/.nix/derivation.nix b/examples/heterogeneous_computing/.nix/derivation.nix new file mode 100644 index 0000000..48dfc7a --- /dev/null +++ b/examples/heterogeneous_computing/.nix/derivation.nix @@ -0,0 +1,39 @@ +{ lib +, stdenv +, scons +, clang-tools +, forstio +, pname +, version +, kel-lbm +}: + +stdenv.mkDerivation { + pname = pname + "-examples-" + "heterogeneous_computing"; + inherit version; + src = ./..; + + nativeBuildInputs = [ + scons + clang-tools + ]; + + buildInputs = [ + forstio.core + forstio.async + forstio.io + forstio.io_codec + forstio.codec + forstio.codec-unit + forstio.codec-json + forstio.remote + forstio.remote-filesystem + forstio.remote-io + forstio.remote-sycl + kel-lbm.core + ]; + + preferLocalBuild = true; + + outputs = [ "out" "dev" ]; +} diff --git a/examples/heterogeneous_computing/SConscript b/examples/heterogeneous_computing/SConscript new file mode 100644 index 0000000..1e52d88 --- /dev/null +++ b/examples/heterogeneous_computing/SConscript @@ -0,0 +1,34 @@ +#!/bin/false + +import os +import os.path +import glob + + +Import('env') + +dir_path = Dir('.').abspath + +# Environment for base library +examples_env = env.Clone(); +examples_env['CXX'] = 'syclcc-clang'; +examples_env['CXXFLAGS'] += ['-O3']; + +examples_env.sources = sorted(glob.glob(dir_path + "/*.cpp")) +examples_env.headers = sorted(glob.glob(dir_path + "/*.hpp")) + +env.sources += examples_env.sources; +env.headers += examples_env.headers; + +# Cavity2D +examples_objects = []; +examples_env.add_source_files(examples_objects, ['heterogeneous_computing.cpp'], shared=False); +examples_env.heterogeneous_computing = examples_env.Program('#bin/heterogeneous_computing', [examples_objects]); + +# Set Alias +env.examples = [ + examples_env.heterogeneous_computing +]; +env.Alias('examples', env.examples); +env.targets += ['examples']; +env.Install('$prefix/bin/', env.examples); diff --git a/examples/heterogeneous_computing/SConstruct b/examples/heterogeneous_computing/SConstruct new file mode 100644 index 0000000..fe206e1 --- /dev/null +++ b/examples/heterogeneous_computing/SConstruct @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 + +import sys +import os +import os.path +import glob +import re + + +if sys.version_info < (3,): + def isbasestring(s): + return isinstance(s,basestring) +else: + def isbasestring(s): + return isinstance(s, (str,bytes)) + +def add_kel_source_files(self, sources, filetype, lib_env=None, shared=False, target_post=""): + + if isbasestring(filetype): + dir_path = self.Dir('.').abspath + filetype = sorted(glob.glob(dir_path+"/"+filetype)) + + for path in filetype: + target_name = re.sub( r'(.*?)(\.cpp|\.c\+\+)', r'\1' + target_post, path ) + if shared: + target_name+='.os' + sources.append( self.SharedObject( target=target_name, source=path ) ) + else: + target_name+='.o' + sources.append( self.StaticObject( target=target_name, source=path ) ) + pass + +def isAbsolutePath(key, dirname, env): + assert os.path.isabs(dirname), "%r must have absolute path syntax" % (key,) + +env_vars = Variables( + args=ARGUMENTS +) + +env_vars.Add('prefix', + help='Installation target location of build results and headers', + default='/usr/local/', + validator=isAbsolutePath +) + +env_vars.Add('build_examples', + help='If examples should be built', + default="true" +) + +env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=[], + CPPDEFINES=['SAW_UNIX'], + CXXFLAGS=[ + '-std=c++20', + '-g', + '-Wall', + '-Wextra', + '-isystem', 'AdaptiveCpp' + ], + LIBS=[ + 'forstio-core', + 'acpp-rt', + 'omp' + ] +); +env.__class__.add_source_files = add_kel_source_files +env.Tool('compilation_db'); +env.cdb = env.CompilationDatabase('compile_commands.json'); + +env.objects = []; +env.sources = []; +env.headers = []; +env.targets = []; + +Export('env') +SConscript('SConscript') + +env.Alias('cdb', env.cdb); +env.Alias('all', [env.targets]); +env.Default('all'); + +env.Alias('install', '$prefix') diff --git a/examples/heterogeneous_computing/heterogeneous_computing.cpp b/examples/heterogeneous_computing/heterogeneous_computing.cpp new file mode 100644 index 0000000..990652a --- /dev/null +++ b/examples/heterogeneous_computing/heterogeneous_computing.cpp @@ -0,0 +1,33 @@ +#include +#include + +namespace kel { +namespace sch { +using namespace saw::schema; +using KelConfig = Struct< + Member +>; +} + +saw::error_or real_main(int argc, char** argv){ + return saw::make_void(); +} +} + +int main(int argc, char** argv){ + auto eov = kel::kel_main(argc, argv); + if(eov.is_error()){ + auto& err = eov.get_error(); + auto err_msg = err.get_message(); + std::cerr<<"[Error]: "< set_geometry( acpp::sycl::queue& sycl_q ){ using namespace kel::lbm; + + saw::data rho{1.0}; + saw::data> vel{{0.0,0.0}}; + auto eq = equilibrium(rho, vel); sycl_q.submit([&](acpp::sycl::handler& h){ h.parallel_for(acpp::sycl::range<2>{meta.at({0}).get(), meta.at({1}).get()},[=](acpp::sycl::id<2> idx){ @@ -79,6 +83,8 @@ saw::error_or set_geometry( size_t acc_id = j * meta.at({0u}).get() + i; auto& c = cells[acc_id]; auto& info = c.template get<"info">()({0}); + auto& dfs = c.template get<"dfs">(); + auto& dfs_old = c.template get<"dfs_old">(); if(i >= 2u and j >= 2u and (i+2u) < meta.at({0u}).get() and (j+2u) < meta.at({1u}).get()){ // Fluid @@ -95,23 +101,16 @@ saw::error_or set_geometry( }else { info.set({0u}); } + for(saw::data k{0u}; k < saw::data{Desc::Q}; ++k){ + dfs(k) = eq.at(k); + dfs_old(k) = eq.at(k); + } }); }); - return saw::make_void(); -} - -void set_initial_conditions( - saw::data* cells, - const saw::data>& meta, - acpp::sycl::queue& sycl_q -){ - using namespace kel::lbm; - - saw::data rho{1.0}; - saw::data> vel{{0.0,0.0}}; - auto eq = equilibrium(rho, vel); + sycl_q.wait(); + return saw::make_void(); } void lbm_step( @@ -178,26 +177,23 @@ saw::error_or kel_main(int argc, char** argv){ } } - sycl_q.wait(); - sycl_q.memcpy(&host_cells[0u], cells, x_d * y_d * sizeof(saw::data) ); - sycl_q.wait(); - acpp::sycl::free(cells, sycl_q); - sycl_q.wait(); - std::string vtk_f_name{"tmp/poiseulle_2d_gpu_"}; vtk_f_name += std::to_string(0u) + ".vtk"; // write_vtk_file(vtk_f_name,host_cells); - for(uint64_t i = 0u; i < x_d; ++i){ - for(uint64_t j = 0u; j < y_d; ++j){ + for(uint64_t i = 0u; i < 1024u*1204u; ++i){ + if(i%128u == 0u){ - size_t acc_id = j * x_d + i; - - std::cout<(host_cells.at(acc_id).template get<"info">()({0u}).get())<<" "; } - std::cout<<"\n"; + lbm_step(cells,meta,i,sycl_q); + } - std::cout<) ); + sycl_q.wait(); + acpp::sycl::free(cells, sycl_q); + sycl_q.wait(); return saw::make_void(); } -- cgit v1.2.3