Skip to content
Snippets Groups Projects
Commit 1a13ccaf authored by Frederik Hennig's avatar Frederik Hennig
Browse files

Merge branch 'master' into fhennig/cpptypes

parents 8dd55ef2 c70a1c03
No related branches found
No related tags found
1 merge request!12Improve versatility and robustness of `cpptype`, and document it in the user guide
Pipeline #71530 passed
from pystencils import Target, CreateKernelConfig, create_kernel, no_jit from pystencils import Target, CreateKernelConfig, no_jit
from lbmpy import create_lb_update_rule, LBMOptimisation from lbmpy import create_lb_update_rule, LBMOptimisation
from pystencilssfg import SourceFileGenerator, SfgConfiguration from pystencilssfg import SourceFileGenerator, SfgConfig
from pystencilssfg.lang.cpp import mdspan_ref
sfg_config = SfgConfiguration( sfg_config = SfgConfig()
output_directory="out/test_cuda", sfg_config.extensions.impl = "cu"
outer_namespace="gen_code", sfg_config.output_directory = "out/test_cuda"
impl_extension="cu" sfg_config.outer_namespace = "gen_code"
)
with SourceFileGenerator(sfg_config) as sfg: with SourceFileGenerator(sfg_config) as sfg:
gen_config = CreateKernelConfig(target=Target.CUDA, jit=no_jit) gen_config = CreateKernelConfig(target=Target.CUDA, jit=no_jit)
...@@ -15,6 +13,4 @@ with SourceFileGenerator(sfg_config) as sfg: ...@@ -15,6 +13,4 @@ with SourceFileGenerator(sfg_config) as sfg:
update = create_lb_update_rule() update = create_lb_update_rule()
kernel = sfg.kernels.create(update, "lbm_update", gen_config) kernel = sfg.kernels.create(update, "lbm_update", gen_config)
sfg.function("lb_update")( sfg.function("lb_update")(sfg.call(kernel))
sfg.call(kernel)
)
...@@ -3,3 +3,6 @@ python_version=3.10 ...@@ -3,3 +3,6 @@ python_version=3.10
[mypy-pystencils.*] [mypy-pystencils.*]
ignore_missing_imports=true ignore_missing_imports=true
[mypy-sympy.*]
ignore_missing_imports=true
...@@ -9,7 +9,7 @@ dependencies = [ ...@@ -9,7 +9,7 @@ dependencies = [
] ]
requires-python = ">=3.10" requires-python = ">=3.10"
readme = "README.md" readme = "README.md"
license = { file = "COPYING.txt" } license = { file = "LICENSE" }
dynamic = ["version"] dynamic = ["version"]
[project.scripts] [project.scripts]
......
...@@ -9,5 +9,6 @@ addopts = ...@@ -9,5 +9,6 @@ addopts =
--ignore=tests/generator_scripts/deps --ignore=tests/generator_scripts/deps
--ignore=tests/generator_scripts/expected --ignore=tests/generator_scripts/expected
--ignore=tests/data --ignore=tests/data
--ignore=tests/integration/cmake_project
doctest_optionflags = NORMALIZE_WHITESPACE IGNORE_EXCEPTION_DETAIL doctest_optionflags = NORMALIZE_WHITESPACE IGNORE_EXCEPTION_DETAIL
...@@ -24,6 +24,9 @@ class HeaderFile: ...@@ -24,6 +24,9 @@ class HeaderFile:
return header return header
system_header = False system_header = False
if header.startswith('"') and header.endswith('"'):
header = header[1:-1]
if header.startswith("<") and header.endswith(">"): if header.startswith("<") and header.endswith(">"):
header = header[1:-1] header = header[1:-1]
system_header = True system_header = True
......
FindPystencilsSfg.cmake
\ No newline at end of file
cmake_minimum_required( VERSION 3.22 )
project( sfg_cmake_project_test )
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
find_package( PystencilsSfg REQUIRED )
set( UseGlobalCfgModule OFF CACHE BOOL "Specify config module globally" )
set( UseLocalCfgModule OFF CACHE BOOL "Specify config module locally" )
if( $CACHE{UseGlobalCfgModule} )
set( PystencilsSfg_CONFIG_MODULE ${CMAKE_CURRENT_SOURCE_DIR}/gen_config.py )
endif()
add_executable( TestApp TestApp.cpp )
if( $CACHE{UseLocalCfgModule} )
pystencilssfg_generate_target_sources(
TestApp
SCRIPTS GenTest.py
CONFIG_MODULE ${CMAKE_CURRENT_SOURCE_DIR}/gen_config.py
)
else()
pystencilssfg_generate_target_sources(
TestApp
SCRIPTS GenTest.py
)
endif()
from pystencilssfg import SourceFileGenerator
with SourceFileGenerator() as sfg:
sfg.namespace("gen")
retval = 42 if sfg.context.project_info is None else sfg.context.project_info
sfg.function("getValue", return_type="int")(
f"return {retval};"
)
#include "gen/TestApp/GenTest.hpp"
int main(void) {
return int( gen::getValue() );
}
from pystencilssfg import SfgConfig
def configure_sfg(cfg: SfgConfig):
cfg.extensions.impl = "c++"
def project_info():
return 31
import pytest
import pathlib
import subprocess
THIS_DIR = pathlib.Path(__file__).parent
CMAKE_PROJECT_DIRNAME = "cmake_project"
CMAKE_PROJECT_DIR = THIS_DIR / CMAKE_PROJECT_DIRNAME
@pytest.mark.parametrize("config_source", [None, "UseGlobalCfgModule", "UseLocalCfgModule"])
def test_cmake_project(tmp_path, config_source):
obtain_find_module_cmd = ["sfg-cli", "cmake", "make-find-module"]
result = subprocess.run(obtain_find_module_cmd, cwd=CMAKE_PROJECT_DIR)
assert result.returncode == 0
cmake_configure_cmd = ["cmake", "-S", CMAKE_PROJECT_DIR, "-B", str(tmp_path)]
if config_source is not None:
cmake_configure_cmd.append(f"-D{config_source}=ON")
configure_result = subprocess.run(cmake_configure_cmd)
assert configure_result.returncode == 0
cmake_build_cmd = ["cmake", "--build", str(tmp_path), "--target", "TestApp"]
build_result = subprocess.run(cmake_build_cmd)
assert build_result.returncode == 0
run_cmd = [str(tmp_path / "TestApp")]
run_result = subprocess.run(run_cmd)
if config_source is not None:
assert (tmp_path / "sfg_sources" / "gen" / "TestApp" / "GenTest.c++").exists()
assert run_result.returncode == 31
else:
assert (tmp_path / "sfg_sources" / "gen" / "TestApp" / "GenTest.cpp").exists()
assert run_result.returncode == 42
from pystencilssfg.lang import HeaderFile
import pytest
def test_parse_system():
headerfile = HeaderFile.parse("<test>")
assert str(headerfile) == "<test>" and headerfile.system_header
@pytest.mark.parametrize("header_string", ["test.hpp", '"test.hpp"'])
def test_parse_private(header_string):
headerfile = HeaderFile.parse(header_string)
assert str(headerfile) == "test.hpp" and not headerfile.system_header
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment