From 81426f07c953339951aafe1defd60e5599973200 Mon Sep 17 00:00:00 2001 From: Hannes Vogt Date: Fri, 19 Apr 2024 09:48:55 +0200 Subject: [PATCH] test[next]: delete cppbackend_tests (#1534) Remove the cpp_backend_tests. They were from a time when we couldn't run gtfn from python. --- .../cpp_backend_tests/.gitignore | 1 - .../cpp_backend_tests/CMakeLists.txt | 79 ------------ .../cpp_backend_tests/anton_lap.py | 77 ----------- .../cpp_backend_tests/anton_lap_driver.cpp | 40 ------ .../cmake/FetchGoogleTest.cmake | 14 -- .../cpp_backend_tests/copy_stencil.py | 56 -------- .../cpp_backend_tests/copy_stencil_driver.cpp | 42 ------ .../copy_stencil_field_view.py | 55 -------- .../copy_stencil_field_view_driver.cpp | 52 -------- .../cpp_backend_tests/fn_select_gt4py.hpp | 78 ----------- .../cpp_backend_tests/fvm_nabla.py | 106 --------------- .../cpp_backend_tests/fvm_nabla_driver.cpp | 122 ------------------ .../cpp_backend_tests/test_driver.py | 73 ----------- .../cpp_backend_tests/tridiagonal_solve.py | 78 ----------- .../tridiagonal_solve_driver.cpp | 54 -------- 15 files changed, 927 deletions(-) delete mode 100644 tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/.gitignore delete mode 100644 tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/CMakeLists.txt delete mode 100644 tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/anton_lap.py delete mode 100644 tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/anton_lap_driver.cpp delete mode 100644 tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/cmake/FetchGoogleTest.cmake delete mode 100644 tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/copy_stencil.py delete mode 100644 tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/copy_stencil_driver.cpp delete mode 100644 tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/copy_stencil_field_view.py delete mode 100644 tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/copy_stencil_field_view_driver.cpp delete mode 100644 tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/fn_select_gt4py.hpp delete mode 100644 tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/fvm_nabla.py delete mode 100644 tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/fvm_nabla_driver.cpp delete mode 100644 tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/test_driver.py delete mode 100644 tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/tridiagonal_solve.py delete mode 100644 tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/tridiagonal_solve_driver.cpp diff --git a/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/.gitignore b/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/.gitignore deleted file mode 100644 index 4ecaff7fe9..0000000000 --- a/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/.gitignore +++ /dev/null @@ -1 +0,0 @@ -build_*/ \ No newline at end of file diff --git a/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/CMakeLists.txt b/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/CMakeLists.txt deleted file mode 100644 index 0a1b19d2a9..0000000000 --- a/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/CMakeLists.txt +++ /dev/null @@ -1,79 +0,0 @@ -cmake_minimum_required(VERSION 3.18.1) - -project(cpp_backend_tests_driver LANGUAGES CXX) - -set(BACKEND NOTFOUND CACHE STRING "fn backend") -set_property(CACHE BACKEND PROPERTY STRINGS "NOTFOUND;naive;gpu") - -if(NOT BACKEND) - message(FATAL_ERROR "No backend selected") -else() - message(STATUS "Testing backend \"${BACKEND}\"") -endif() - -if(BACKEND STREQUAL "gpu") - enable_language(CUDA) - set(is_gpu ON) -endif() -string(TOUPPER ${BACKEND} backend_upper_case) - -include(FetchContent) -FetchContent_Declare(GridTools - GIT_REPOSITORY https://github.com/GridTools/gridtools.git - GIT_TAG master -) -FetchContent_MakeAvailable(GridTools) - -function(generate_computation) - set(options) - set(oneValueArgs NAME SRC_FILE GENERATED_FILENAME IMPERATIVE) - set(multiValueArgs) - cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - - add_custom_command(OUTPUT ${ARG_GENERATED_FILENAME} - COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_SRC_FILE} ${ARG_GENERATED_FILENAME} ${ARG_IMPERATIVE} - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_INPUT}) - add_custom_target(generated_${ARG_NAME} DEPENDS ${ARG_GENERATED_FILENAME}) -endfunction() - -add_library(regression_main ${gridtools_SOURCE_DIR}/tests/src/regression_main.cpp) -target_include_directories(regression_main PUBLIC ${gridtools_SOURCE_DIR}/tests/include) -target_link_libraries(regression_main PUBLIC gtest gmock gridtools) - -function(add_fn_codegen_test) - set(options) - set(oneValueArgs NAME SRC_FILE DRIVER_FILE IMPERATIVE) - set(multiValueArgs) - cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - - set(STENCIL_IMPL_SOURCE ${CMAKE_CURRENT_BINARY_DIR}/generated_${ARG_NAME}.hpp) - generate_computation(NAME ${ARG_NAME} SRC_FILE ${ARG_SRC_FILE} GENERATED_FILENAME ${STENCIL_IMPL_SOURCE} IMPERATIVE ${ARG_IMPERATIVE}) - add_executable(${ARG_NAME} ${ARG_DRIVER_FILE}) - target_link_libraries(${ARG_NAME} fn_${BACKEND} regression_main) - target_compile_definitions(${ARG_NAME} PRIVATE GT_FN_${backend_upper_case}) - target_compile_definitions(${ARG_NAME} PRIVATE GT_FN_BACKEND=${BACKEND}) - target_compile_definitions(${ARG_NAME} PRIVATE GENERATED_FILE=\"${STENCIL_IMPL_SOURCE}\") - if(is_gpu) - gridtools_setup_target(${ARG_NAME} CUDA_ARCH sm_60) #TODO - endif() - add_dependencies(${ARG_NAME} generated_${ARG_NAME}) - - add_test(NAME ${ARG_NAME} COMMAND $) -endfunction() - -include(CTest) -if(BUILD_TESTING) - find_package(Python3 COMPONENTS Interpreter REQUIRED) - - include(cmake/FetchGoogleTest.cmake) - fetch_googletest() - - add_fn_codegen_test(NAME copy_stencil SRC_FILE copy_stencil.py DRIVER_FILE copy_stencil_driver.cpp) - add_fn_codegen_test(NAME copy_stencil_field_view SRC_FILE copy_stencil_field_view.py DRIVER_FILE copy_stencil_field_view_driver.cpp) - add_fn_codegen_test(NAME anton_lap SRC_FILE anton_lap.py DRIVER_FILE anton_lap_driver.cpp) - add_fn_codegen_test(NAME fvm_nabla_fun SRC_FILE fvm_nabla.py DRIVER_FILE fvm_nabla_driver.cpp IMPERATIVE FALSE) - add_fn_codegen_test(NAME fvm_nabla_imp SRC_FILE fvm_nabla.py DRIVER_FILE fvm_nabla_driver.cpp IMPERATIVE TRUE) - add_fn_codegen_test(NAME tridiagonal_solve SRC_FILE tridiagonal_solve.py DRIVER_FILE tridiagonal_solve_driver.cpp) -endif() - - diff --git a/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/anton_lap.py b/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/anton_lap.py deleted file mode 100644 index 5af4605988..0000000000 --- a/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/anton_lap.py +++ /dev/null @@ -1,77 +0,0 @@ -# GT4Py - GridTools Framework -# -# Copyright (c) 2014-2023, ETH Zurich -# All rights reserved. -# -# This file is part of the GT4Py project and the GridTools framework. -# GT4Py is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the -# Free Software Foundation, either version 3 of the License, or any later -# version. See the LICENSE.txt file at the top-level directory of this -# distribution for a copy of the license or check . -# -# SPDX-License-Identifier: GPL-3.0-or-later - -import sys - -import gt4py.next as gtx -from gt4py.next.iterator.builtins import * -from gt4py.next.iterator.runtime import closure, fundef, offset -from gt4py.next.iterator.tracing import trace_fencil_definition -from gt4py.next.program_processors.runners.gtfn import run_gtfn - - -@fundef -def ldif(d): - return lambda inp: deref(shift(d, -1)(inp)) - deref(inp) - - -@fundef -def rdif(d): - return lambda inp: ldif(d)(shift(d, 1)(inp)) - - -@fundef -def dif2(d): - return lambda inp: ldif(d)(lift(rdif(d))(inp)) - - -i = offset("i") -j = offset("j") - - -@fundef -def lap(inp): - return dif2(i)(inp) + dif2(j)(inp) - - -IDim = gtx.Dimension("IDim") -JDim = gtx.Dimension("JDim") -KDim = gtx.Dimension("KDim") - - -def lap_fencil(i_size, j_size, k_size, i_off, j_off, k_off, out, inp): - closure( - cartesian_domain( - named_range(IDim, i_off, i_size + i_off), - named_range(JDim, j_off, j_size + j_off), - named_range(KDim, k_off, k_size + k_off), - ), - lap, - out, - [inp], - ) - - -if __name__ == "__main__": - if len(sys.argv) != 2: - raise RuntimeError(f"Usage: {sys.argv[0]} ") - output_file = sys.argv[1] - - prog = trace_fencil_definition(lap_fencil, [None] * 8, use_arg_types=False) - generated_code = run_gtfn.executor.otf_workflow.translation.generate_stencil_source( - prog, offset_provider={"i": IDim, "j": JDim}, column_axis=None - ) - - with open(output_file, "w+") as output: - output.write(generated_code) diff --git a/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/anton_lap_driver.cpp b/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/anton_lap_driver.cpp deleted file mode 100644 index e2dbcbb6ce..0000000000 --- a/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/anton_lap_driver.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include - -#include "fn_select_gt4py.hpp" -#include -#include GENERATED_FILE - -#include - -namespace { -using namespace gridtools; -using namespace fn; -using namespace literals; - -constexpr inline auto in = [](auto... indices) { return (... + indices); }; - -using backend_t = - fn_backend_t::values<32, 8, 1>>; - -GT_REGRESSION_TEST(fn_lap, test_environment<1>, backend_t) { - auto actual = TypeParam::make_storage(); - - auto expected = [&](auto i, auto j, auto k) { - return in(i + 1, j, k) + in(i - 1, j, k) + in(i, j + 1, k) + - in(i, j - 1, k) - 4 * in(i, j, k); - }; - - generated::lap_fencil(tuple{})( - backend_t(), at_key(TypeParam::fn_cartesian_sizes()), - at_key(TypeParam::fn_cartesian_sizes()), - at_key(TypeParam::fn_cartesian_sizes()), 1, 1, 0, - sid::rename_numbered_dimensions(actual), - sid::rename_numbered_dimensions( - TypeParam::make_const_storage(in))); - - TypeParam::verify(expected, actual); -} -} // namespace diff --git a/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/cmake/FetchGoogleTest.cmake b/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/cmake/FetchGoogleTest.cmake deleted file mode 100644 index 983cce8594..0000000000 --- a/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/cmake/FetchGoogleTest.cmake +++ /dev/null @@ -1,14 +0,0 @@ -function(fetch_googletest) - # The gtest library needs to be built as static library to avoid RPATH issues - set(BUILD_SHARED_LIBS OFF) - - include(FetchContent) - option(INSTALL_GTEST OFF) - mark_as_advanced(INSTALL_GTEST) - FetchContent_Declare( - GoogleTest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG release-1.11.0 - ) - FetchContent_MakeAvailable(GoogleTest) -endfunction() diff --git a/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/copy_stencil.py b/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/copy_stencil.py deleted file mode 100644 index 3e8b88ac66..0000000000 --- a/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/copy_stencil.py +++ /dev/null @@ -1,56 +0,0 @@ -# GT4Py - GridTools Framework -# -# Copyright (c) 2014-2023, ETH Zurich -# All rights reserved. -# -# This file is part of the GT4Py project and the GridTools framework. -# GT4Py is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the -# Free Software Foundation, either version 3 of the License, or any later -# version. See the LICENSE.txt file at the top-level directory of this -# distribution for a copy of the license or check . -# -# SPDX-License-Identifier: GPL-3.0-or-later - -import sys - -import gt4py.next as gtx -from gt4py.next.iterator.builtins import * -from gt4py.next.iterator.runtime import closure, fundef -from gt4py.next.iterator.tracing import trace_fencil_definition -from gt4py.next.program_processors.runners.gtfn import run_gtfn - - -IDim = gtx.Dimension("IDim") -JDim = gtx.Dimension("JDim") -KDim = gtx.Dimension("KDim") - - -@fundef -def copy_stencil(inp): - return deref(inp) - - -def copy_fencil(isize, jsize, ksize, inp, out): - closure( - cartesian_domain( - named_range(IDim, 0, isize), named_range(JDim, 0, jsize), named_range(KDim, 0, ksize) - ), - copy_stencil, - out, - [inp], - ) - - -if __name__ == "__main__": - if len(sys.argv) != 2: - raise RuntimeError(f"Usage: {sys.argv[0]} ") - output_file = sys.argv[1] - - prog = trace_fencil_definition(copy_fencil, [None] * 5, use_arg_types=False) - generated_code = run_gtfn.executor.otf_workflow.translation.generate_stencil_source( - prog, offset_provider={}, column_axis=None - ) - - with open(output_file, "w+") as output: - output.write(generated_code) diff --git a/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/copy_stencil_driver.cpp b/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/copy_stencil_driver.cpp deleted file mode 100644 index e226b78907..0000000000 --- a/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/copy_stencil_driver.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include - -#include "fn_select_gt4py.hpp" -#include -#include GENERATED_FILE - -#include - -namespace { -using namespace gridtools; -using namespace fn; -using namespace literals; - -constexpr inline auto in = [](auto... indices) { return (... + indices); }; - -using backend_t = - fn_backend_t::values<32, 8, 1>>; - -GT_REGRESSION_TEST(fn_cartesian_copy, test_environment<>, backend_t) { - auto out = TypeParam::make_storage(); - auto out_wrapped = - sid::rename_numbered_dimensions(out); - - auto in_wrapped = - sid::rename_numbered_dimensions( - TypeParam::make_const_storage(in)); - auto comp = [&] { - generated::copy_fencil(tuple{})( - backend_t{}, at_key(TypeParam::fn_cartesian_sizes()), - at_key(TypeParam::fn_cartesian_sizes()), - at_key(TypeParam::fn_cartesian_sizes()), in_wrapped, - out_wrapped); - }; - comp(); - - TypeParam::verify(in, out); -} - -} // namespace diff --git a/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/copy_stencil_field_view.py b/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/copy_stencil_field_view.py deleted file mode 100644 index fdc57449ee..0000000000 --- a/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/copy_stencil_field_view.py +++ /dev/null @@ -1,55 +0,0 @@ -# GT4Py - GridTools Framework -# -# Copyright (c) 2014-2023, ETH Zurich -# All rights reserved. -# -# This file is part of the GT4Py project and the GridTools framework. -# GT4Py is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the -# Free Software Foundation, either version 3 of the License, or any later -# version. See the LICENSE.txt file at the top-level directory of this -# distribution for a copy of the license or check . -# -# SPDX-License-Identifier: GPL-3.0-or-later - -import sys - -from numpy import float64 - -import gt4py.next as gtx -from gt4py.next import Field, field_operator, program -from gt4py.next.program_processors.runners.gtfn import run_gtfn - - -IDim = gtx.Dimension("IDim") -JDim = gtx.Dimension("JDim") -KDim = gtx.Dimension("KDim") - - -@field_operator -def copy_stencil(inp: Field[[IDim, JDim, KDim], float64]) -> Field[[IDim, JDim, KDim], float64]: - return inp - - -@program -def copy_program( - inp: Field[[IDim, JDim, KDim], float64], - out: Field[[IDim, JDim, KDim], float64], - out2: Field[[IDim, JDim, KDim], float64], -): - copy_stencil(inp, out=out) - copy_stencil(inp, out=out2) - - -if __name__ == "__main__": - if len(sys.argv) != 2: - raise RuntimeError(f"Usage: {sys.argv[0]} ") - output_file = sys.argv[1] - - prog = copy_program.itir - generated_code = run_gtfn.executor.otf_workflow.translation.generate_stencil_source( - prog, offset_provider={}, column_axis=None - ) - - with open(output_file, "w+") as output: - output.write(generated_code) diff --git a/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/copy_stencil_field_view_driver.cpp b/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/copy_stencil_field_view_driver.cpp deleted file mode 100644 index 19bd9fc3b9..0000000000 --- a/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/copy_stencil_field_view_driver.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include - -#include "fn_select_gt4py.hpp" -#include -#include GENERATED_FILE - -#include - -namespace { -using namespace gridtools; -using namespace fn; -using namespace literals; - -constexpr inline auto in = [](auto... indices) { return (... + indices); }; -using backend_t = - fn_backend_t::values<32, 8, 1>>; - -GT_REGRESSION_TEST(fn_cartesian_copy, test_environment<>, backend_t) { - auto out = TypeParam::make_storage(); - auto out_wrapped = - sid::rename_numbered_dimensions(out); - auto out2 = TypeParam::make_storage(); - auto out2_wrapped = - sid::rename_numbered_dimensions(out2); - - auto in_wrapped = - sid::rename_numbered_dimensions( - TypeParam::make_const_storage(in)); - auto comp = [&] { - generated::copy_program(tuple{})( - backend_t{}, in_wrapped, out_wrapped, out2_wrapped, - at_key(TypeParam::fn_cartesian_sizes()), - at_key(TypeParam::fn_cartesian_sizes()), - at_key(TypeParam::fn_cartesian_sizes()), - at_key(TypeParam::fn_cartesian_sizes()), - at_key(TypeParam::fn_cartesian_sizes()), - at_key(TypeParam::fn_cartesian_sizes()), - at_key(TypeParam::fn_cartesian_sizes()), - at_key(TypeParam::fn_cartesian_sizes()), - at_key(TypeParam::fn_cartesian_sizes())); - }; - comp(); - - TypeParam::verify(in, out); - TypeParam::verify(in, out2); -} - -} // namespace diff --git a/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/fn_select_gt4py.hpp b/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/fn_select_gt4py.hpp deleted file mode 100644 index a8f664c334..0000000000 --- a/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/fn_select_gt4py.hpp +++ /dev/null @@ -1,78 +0,0 @@ -#pragma once - -// COPIED AND SLIGHTLY MODIFIED FROM gritools/test/include/fn_select.hpp -// The gridtools fn_select assumes that dimensions are named -// integral_constant, the GT4Py generated code uses structs as dimension -// identifiers. - -#include - -#include - -// fn backend -#if defined(GT_FN_NAIVE) -#ifndef GT_STENCIL_NAIVE -#define GT_STENCIL_NAIVE -#endif -#ifndef GT_STORAGE_CPU_KFIRST -#define GT_STORAGE_CPU_KFIRST -#endif -#ifndef GT_TIMER_DUMMY -#define GT_TIMER_DUMMY -#endif -#include -namespace { -template using fn_backend_t = gridtools::fn::backend::naive; -} -#elif defined(GT_FN_GPU) -#ifndef GT_STENCIL_GPU -#define GT_STENCIL_GPU -#endif -#ifndef GT_STORAGE_GPU -#define GT_STORAGE_GPU -#endif -#ifndef GT_TIMER_CUDA -#define GT_TIMER_CUDA -#endif -#include -namespace { -template -using fn_backend_t = gridtools::fn::backend::gpu; -} // namespace -#endif - -#include "stencil_select.hpp" -#include "storage_select.hpp" -#include "timer_select.hpp" -namespace { -template struct block_sizes_t { - template - using values = gridtools::meta::zip< - gridtools::meta::list, - gridtools::meta::list...>>; -}; -} // namespace -namespace gridtools::fn::backend { -namespace naive_impl_ { -template struct naive_with_threadpool; -template -storage::cpu_kfirst backend_storage_traits(naive_with_threadpool); -template -timer_dummy backend_timer_impl(naive_with_threadpool); -template -inline char const *backend_name(naive_with_threadpool const &) { - return "naive"; -} -} // namespace naive_impl_ - -namespace gpu_impl_ { -template struct gpu; -template -storage::gpu backend_storage_traits(gpu); -template timer_cuda backend_timer_impl(gpu); -template -inline char const *backend_name(gpu const &) { - return "gpu"; -} -} // namespace gpu_impl_ -} // namespace gridtools::fn::backend diff --git a/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/fvm_nabla.py b/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/fvm_nabla.py deleted file mode 100644 index fe8b54f95c..0000000000 --- a/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/fvm_nabla.py +++ /dev/null @@ -1,106 +0,0 @@ -# GT4Py - GridTools Framework -# -# Copyright (c) 2014-2023, ETH Zurich -# All rights reserved. -# -# This file is part of the GT4Py project and the GridTools framework. -# GT4Py is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the -# Free Software Foundation, either version 3 of the License, or any later -# version. See the LICENSE.txt file at the top-level directory of this -# distribution for a copy of the license or check . -# -# SPDX-License-Identifier: GPL-3.0-or-later - -import sys -from dataclasses import dataclass - -import gt4py.next as gtx -from gt4py.next.iterator.builtins import * -from gt4py.next.iterator.runtime import closure, fundef, offset -from gt4py.next.iterator.tracing import trace_fencil_definition -from gt4py.next.program_processors.runners.gtfn import run_gtfn, run_gtfn_imperative - - -E2V = offset("E2V") -V2E = offset("V2E") - - -@fundef -def compute_zavgS(pp, S_M): - zavg = 0.5 * (deref(shift(E2V, 0)(pp)) + deref(shift(E2V, 1)(pp))) - return make_tuple(tuple_get(0, deref(S_M)) * zavg, tuple_get(1, deref(S_M)) * zavg) - - -@fundef -def tuple_dot_fun(acc, zavgS, sign): - return make_tuple( - tuple_get(0, acc) + tuple_get(0, zavgS) * sign, - tuple_get(1, acc) + tuple_get(1, zavgS) * sign, - ) - - -@fundef -def tuple_dot(a, b): - return reduce(tuple_dot_fun, make_tuple(0.0, 0.0))(a, b) - - -@fundef -def compute_pnabla(pp, S_M, sign, vol): - zavgS = lift(compute_zavgS)(pp, S_M) - pnabla_M = tuple_dot(neighbors(V2E, zavgS), deref(sign)) - return make_tuple(tuple_get(0, pnabla_M) / deref(vol), tuple_get(1, pnabla_M) / deref(vol)) - - -def zavgS_fencil(edge_domain, out, pp, S_M): - closure(edge_domain, compute_zavgS, out, [pp, S_M]) - - -Vertex = gtx.Dimension("Vertex") -K = gtx.Dimension("K", kind=gtx.DimensionKind.VERTICAL) - - -def nabla_fencil(n_vertices, n_levels, out, pp, S_M, sign, vol): - closure( - unstructured_domain(named_range(Vertex, 0, n_vertices), named_range(K, 0, n_levels)), - compute_pnabla, - out, - [pp, S_M, sign, vol], - ) - - -@dataclass -class DummyConnectivity: - max_neighbors: int - has_skip_values: int - origin_axis: gtx.Dimension = gtx.Dimension("dummy_origin") - neighbor_axis: gtx.Dimension = gtx.Dimension("dummy_neighbor") - index_type: type[int] = int - - def mapped_index(_, __) -> int: - return 0 - - -if __name__ == "__main__": - if len(sys.argv) != 3: - raise RuntimeError(f"Usage: {sys.argv[0]} ") - output_file = sys.argv[1] - imperative = sys.argv[2].lower() == "true" - - if imperative: - backend = run_gtfn_imperative - else: - backend = run_gtfn - - # prog = trace(zavgS_fencil, [None] * 4) # TODO allow generating of 2 fencils - prog = trace_fencil_definition(nabla_fencil, [None] * 7, use_arg_types=False) - offset_provider = { - "V2E": DummyConnectivity(max_neighbors=6, has_skip_values=True), - "E2V": DummyConnectivity(max_neighbors=2, has_skip_values=False), - } - generated_code = backend.executor.otf_workflow.translation.generate_stencil_source( - prog, offset_provider=offset_provider, column_axis=None - ) - - with open(output_file, "w+") as output: - output.write(generated_code) diff --git a/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/fvm_nabla_driver.cpp b/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/fvm_nabla_driver.cpp deleted file mode 100644 index f0112a1636..0000000000 --- a/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/fvm_nabla_driver.cpp +++ /dev/null @@ -1,122 +0,0 @@ -#include - -#include "fn_select_gt4py.hpp" -#include -#include GENERATED_FILE - -namespace { -using namespace gridtools; -using namespace fn; -using namespace literals; - -using backend_t = - fn_backend_t::values<32, 8>>; - -// copied from gridtools::fn test -constexpr inline auto pp = [](int vertex, int k) { return (vertex + k) % 19; }; -constexpr inline auto sign = [](int vertex) { - return array{0, 1, vertex % 2, 1, (vertex + 1) % 2, 0}; -}; -constexpr inline auto vol = [](int vertex) { return vertex % 13 + 1; }; -constexpr inline auto s = [](int edge, int k) { - return tuple((edge + k) % 17, (edge + k) % 7); -}; - -constexpr inline auto zavg = [](auto const &e2v) { - return [&e2v](int edge, int k) { - double tmp = 0.0; - for (int neighbor = 0; neighbor < 2; ++neighbor) - tmp += pp(e2v(edge)[neighbor], k); - tmp /= 2.0; - return tuple{tmp * get<0>(s(edge, k)), tmp * get<1>(s(edge, k))}; - }; -}; - -constexpr inline auto make_zavg_expected = [](auto const &mesh) { - return [e2v_table = mesh.e2v_table()](int edge, int k) { - auto e2v = e2v_table->const_host_view(); - return zavg(e2v)(edge, k); - }; -}; - -constexpr inline auto expected = [](auto const &v2e, auto const &e2v) { - return [&v2e, zavg = zavg(e2v)](int vertex, int k) { - auto res = tuple(0.0, 0.0); - for (int neighbor = 0; neighbor < 6; ++neighbor) { - int edge = v2e(vertex)[neighbor]; - if (edge != -1) { - get<0>(res) += get<0>(zavg(edge, k)) * sign(vertex)[neighbor]; - get<1>(res) += get<1>(zavg(edge, k)) * sign(vertex)[neighbor]; - } - } - get<0>(res) /= vol(vertex); - get<1>(res) /= vol(vertex); - return res; - }; -}; - -constexpr inline auto make_expected = [](auto const &mesh) { - return [v2e_table = mesh.v2e_table(), - e2v_table = mesh.e2v_table()](int vertex, int k) { - auto v2e = v2e_table->const_host_view(); - auto e2v = e2v_table->const_host_view(); - return expected(v2e, e2v)(vertex, k); - }; -}; - -// GT_REGRESSION_TEST(unstructured_zavg, test_environment<>, fn_backend_t) { -// using float_t = typename TypeParam::float_t; - -// auto mesh = TypeParam::fn_unstructured_mesh(); -// auto actual = mesh.template make_storage>( -// mesh.nedges(), mesh.nlevels()); - -// auto pp_ = mesh.make_const_storage(pp, mesh.nvertices(), mesh.nlevels()); -// auto s_ = mesh.template make_const_storage>( -// s, mesh.nedges(), mesh.nlevels()); - -// auto e2v_conn = -// connectivity(mesh.e2v_table()->get_const_target_ptr()); -// auto edge_domain = -// unstructured_domain({mesh.nedges(), mesh.nlevels()}, {}, e2v_conn); - -// generated::zavgS_fencil(fn_backend_t{}, edge_domain, actual, pp_, s_); - -// auto expected = make_zavg_expected(mesh); -// TypeParam::verify(expected, actual); -// } - -GT_REGRESSION_TEST(unstructured_nabla, test_environment<>, backend_t) { - using float_t = typename TypeParam::float_t; - - auto mesh = TypeParam::fn_unstructured_mesh(); - auto actual = mesh.template make_storage>( - mesh.nvertices(), mesh.nlevels()); - - auto pp_ = mesh.make_const_storage(pp, mesh.nvertices(), mesh.nlevels()); - auto sign_ = mesh.template make_const_storage>( - sign, mesh.nvertices()); - auto vol_ = mesh.make_const_storage(vol, mesh.nvertices()); - auto s_ = mesh.template make_const_storage>( - s, mesh.nedges(), mesh.nlevels()); - - auto v2e_tbl = mesh.v2e_table(); - auto v2e_conn = - connectivity(v2e_tbl->get_const_target_ptr()); - - auto e2v_tbl = mesh.e2v_table(); - auto e2v_conn = - connectivity(e2v_tbl->get_const_target_ptr()); - auto vertex_domain = unstructured_domain({mesh.nvertices(), mesh.nlevels()}, - {}, v2e_conn, e2v_conn); - - generated::nabla_fencil(e2v_conn, v2e_conn)(backend_t{}, mesh.nvertices(), - mesh.nlevels(), actual, pp_, s_, - sign_, vol_); - - auto expected = make_expected(mesh); - TypeParam::verify(expected, actual); -} - -} // namespace diff --git a/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/test_driver.py b/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/test_driver.py deleted file mode 100644 index 7de56cb5bb..0000000000 --- a/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/test_driver.py +++ /dev/null @@ -1,73 +0,0 @@ -# GT4Py - GridTools Framework -# -# Copyright (c) 2014-2023, ETH Zurich -# All rights reserved. -# -# This file is part of the GT4Py project and the GridTools framework. -# GT4Py is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the -# Free Software Foundation, either version 3 of the License, or any later -# version. See the LICENSE.txt file at the top-level directory of this -# distribution for a copy of the license or check . -# -# SPDX-License-Identifier: GPL-3.0-or-later - -import os -import subprocess -import sys -from pathlib import Path - -import pytest - - -def _source_dir(): - return Path(__file__).resolve().parent - - -def _build_dir(backend_dir: str): - return _source_dir() / f"build_{backend_dir}" - - -def _execute_cmake(backend_str: str): - build_dir = _build_dir(backend_str) - build_dir.mkdir(exist_ok=True) - cmake = ["cmake", "-B", build_dir, f"-DBACKEND={backend_str}"] - subprocess.run(cmake, cwd=_source_dir(), check=True, stderr=sys.stderr) - - -def _get_available_cpu_count(): - if hasattr(os, "sched_getaffinity"): - return len(os.sched_getaffinity(0)) - return os.cpu_count() - - -def _execute_build(backend_str: str): - build = [ - "cmake", - "--build", - _build_dir(backend_str), - "--parallel", - str(_get_available_cpu_count()), - ] - subprocess.run(build, check=True) - - -def _execute_ctest(backend_str: str): - ctest = "ctest" - subprocess.run(ctest, cwd=_build_dir(backend_str), check=True) - - -backends = ["naive"] -try: - import cupy # TODO actually cupy is not the requirement but a CUDA compiler... - - backends.append("gpu") -except ImportError: - pass - - -@pytest.mark.parametrize("backend_str", backends) -def test_driver_cpp_backends(backend_str): - _execute_cmake(backend_str) - _execute_build(backend_str) - _execute_ctest(backend_str) diff --git a/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/tridiagonal_solve.py b/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/tridiagonal_solve.py deleted file mode 100644 index 9755774fd0..0000000000 --- a/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/tridiagonal_solve.py +++ /dev/null @@ -1,78 +0,0 @@ -# GT4Py - GridTools Framework -# -# Copyright (c) 2014-2023, ETH Zurich -# All rights reserved. -# -# This file is part of the GT4Py project and the GridTools framework. -# GT4Py is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the -# Free Software Foundation, either version 3 of the License, or any later -# version. See the LICENSE.txt file at the top-level directory of this -# distribution for a copy of the license or check . -# -# SPDX-License-Identifier: GPL-3.0-or-later - -import sys - -import gt4py.next as gtx -from gt4py.next.iterator.builtins import * -from gt4py.next.iterator.runtime import closure, fundef -from gt4py.next.iterator.tracing import trace_fencil_definition -from gt4py.next.iterator.transforms import LiftMode -from gt4py.next.program_processors.runners.gtfn import run_gtfn - - -IDim = gtx.Dimension("IDim") -JDim = gtx.Dimension("JDim") -KDim = gtx.Dimension("KDim") - - -@fundef -def tridiag_forward(state, a, b, c, d): - return make_tuple( - deref(c) / (deref(b) - deref(a) * tuple_get(0, state)), - (deref(d) - deref(a) * tuple_get(1, state)) / (deref(b) - deref(a) * tuple_get(0, state)), - ) - - -@fundef -def tridiag_backward(x_kp1, cpdp): - cpdpv = deref(cpdp) - cp = tuple_get(0, cpdpv) - dp = tuple_get(1, cpdpv) - return dp - cp * x_kp1 - - -@fundef -def solve_tridiag(a, b, c, d): - cpdp = lift(scan(tridiag_forward, True, make_tuple(0.0, 0.0)))(a, b, c, d) - return scan(tridiag_backward, False, 0.0)(cpdp) - - -def tridiagonal_solve_fencil(isize, jsize, ksize, a, b, c, d, x): - closure( - cartesian_domain( - named_range(IDim, 0, isize), named_range(JDim, 0, jsize), named_range(KDim, 0, ksize) - ), - solve_tridiag, - x, - [a, b, c, d], - ) - - -if __name__ == "__main__": - if len(sys.argv) != 2: - raise RuntimeError(f"Usage: {sys.argv[0]} ") - output_file = sys.argv[1] - - prog = trace_fencil_definition(tridiagonal_solve_fencil, [None] * 8, use_arg_types=False) - offset_provider = {"I": gtx.Dimension("IDim"), "J": gtx.Dimension("JDim")} - generated_code = run_gtfn.executor.otf_workflow.translation.generate_stencil_source( - prog, - offset_provider=offset_provider, - runtime_lift_mode=LiftMode.SIMPLE_HEURISTIC, - column_axis=KDim, - ) - - with open(output_file, "w+") as output: - output.write(generated_code) diff --git a/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/tridiagonal_solve_driver.cpp b/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/tridiagonal_solve_driver.cpp deleted file mode 100644 index c51e3d4c41..0000000000 --- a/tests/next_tests/integration_tests/multi_feature_tests/cpp_backend_tests/tridiagonal_solve_driver.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include - -#include "fn_select_gt4py.hpp" -#include -#include GENERATED_FILE - -#include - -namespace { -using namespace gridtools; -using namespace fn; -using namespace literals; - -constexpr inline auto a = [](auto...) { return -1; }; -constexpr inline auto b = [](auto...) { return 3; }; -constexpr inline auto c = [](auto...) { return 1; }; -constexpr inline auto d = [](int ksize) { - return [kmax = ksize - 1](auto, auto, auto k) { - return k == 0 ? 4 : k == kmax ? 2 : 3; - }; -}; -constexpr inline auto expected = [](auto...) { return 1; }; -using backend_t = - fn_backend_t::values<32, 8, 1>>; - -GT_REGRESSION_TEST(fn_cartesian_tridiagonal_solve, vertical_test_environment<>, - backend_t) { - using float_t = typename TypeParam::float_t; - - auto wrap = [](auto &&storage) { - return sid::rename_numbered_dimensions( - std::forward(storage)); - }; - - auto x = TypeParam::make_storage(); - auto x_wrapped = wrap(x); - auto a_wrapped = wrap(TypeParam::make_const_storage(a)); - auto b_wrapped = wrap(TypeParam::make_const_storage(b)); - auto c_wrapped = wrap(TypeParam::make_const_storage(c)); - auto d_wrapped = wrap(TypeParam::make_const_storage(d(TypeParam::d(2)))); - auto comp = [&] { - generated::tridiagonal_solve_fencil(tuple{})( - backend_t(), at_key(TypeParam::fn_cartesian_sizes()), - at_key(TypeParam::fn_cartesian_sizes()), - at_key(TypeParam::fn_cartesian_sizes()), a_wrapped, - b_wrapped, c_wrapped, d_wrapped, x_wrapped); - }; - comp(); - TypeParam::verify(expected, x); -} - -} // namespace