示例#1
0
def test_apply_method_compilation_succeeds(tmp_path, apply_method, expected_regex):
    # This test could be improved by just compiling the body
    # and introducing fakes for `eval` and `gridtools::accessor`.
    assert isinstance(apply_method, GTApplyMethod)
    apply_method_code = GTCppCodegen().visit(apply_method, offset_limit=2)
    print(apply_method_code)
    match(apply_method_code, expected_regex)

    build_gridtools_test(
        tmp_path,
        GTCppCodegen.apply(_embed_apply_method_in_program(apply_method), gt_backend_t="cpu_ifirst"),
    )
示例#2
0
def test_variable_offset_accessor():
    out_name = "out_field"
    in_name = "in_field"
    index_name = "index"
    oir_stencil = StencilFactory(
        params=[
            FieldDeclFactory(name=out_name, dtype=DataType.FLOAT32),
            FieldDeclFactory(name=in_name, dtype=DataType.FLOAT32),
            FieldDeclFactory(name=index_name, dtype=DataType.FLOAT32),
        ],
        vertical_loops__0=VerticalLoopFactory(
            loop_order=LoopOrder.FORWARD,
            sections=[
                VerticalLoopSectionFactory(horizontal_executions=[
                    HorizontalExecutionFactory(body=[
                        AssignStmtFactory(
                            left__name=out_name,
                            right__name=in_name,
                            right__offset=VariableKOffsetFactory(
                                k__name=index_name),
                        )
                    ])
                ])
            ],
        ),
    )

    gtcpp_program = OIRToGTCpp().visit(oir_stencil)
    code = GTCppCodegen.apply(gtcpp_program, gt_backend_t="cpu_ifirst")
    print(code)
    match(
        code,
        r"eval\(out_field\(\)\) = eval\(in_field\(0, 0, eval\(index\(\)\)\)\)")
示例#3
0
def test_variable_offset_accessor():
    out_name = "out_field"
    in_name = "in_field"
    index_name = "index"
    oir_stencil = StencilFactory(vertical_loops__0=VerticalLoopFactory(
        loop_order=LoopOrder.FORWARD,
        sections__0__horizontal_executions__0__body=[
            AssignStmtFactory(
                left__name=out_name,
                right__name=in_name,
                right__offset=VariableKOffsetFactory(k__name=index_name),
            )
        ],
    ), )

    gtcpp_program = OIRToGTCpp().visit(oir_stencil)
    code = GTCppCodegen.apply(gtcpp_program, gt_backend_t="cpu_ifirst")
    print(code)
    match(
        code,
        rf"eval\({out_name}\(\)\) = eval\({in_name}\(0, 0, eval\({index_name}\(\)\)\)\)"
    )
示例#4
0
def test_program_compilation_succeeds(tmp_path, gtcpp_program, expected_regex):
    assert isinstance(gtcpp_program, Program)
    code = GTCppCodegen.apply(gtcpp_program, gt_backend_t="cpu_ifirst")
    print(code)
    match(code, expected_regex)
    build_gridtools_test(tmp_path, code)