Esempio n. 1
0
def test_scalar_kernel_load_meta_err():
    ''' Check that the DynKern.load_meta() method raises the expected
    internal error if it encounters an unrecognised data type for
    a scalar descriptor.

    '''
    ast = fpapi.parse(CODE, ignore_comments=False)
    name = "testkern_qr_type"
    metadata = DynKernMetadata(ast, name=name)
    kernel = DynKern()
    # Get a scalar argument descriptor and set an invalid data type
    scalar_arg = metadata.arg_descriptors[5]
    scalar_arg._data_type = "gh_triple"
    with pytest.raises(InternalError) as err:
        kernel.load_meta(metadata)
    const = LFRicConstants()
    assert ("Expected one of {0} data types for "
            "a scalar argument but found 'gh_triple'.".
            format(const.VALID_SCALAR_DATA_TYPES) in
            str(err.value))
Esempio n. 2
0
def test_only_field_args():
    ''' Check that we reject an inter-grid kernel if it has any arguments
    that are not fields '''
    fparser.logging.disable(fparser.logging.CRITICAL)
    # Add a scalar argument to the kernel
    code = RESTRICT_MDATA.replace(
        "       arg_type(GH_FIELD, GH_REAL, GH_READ, ANY_SPACE_2, "
        "mesh_arg=GH_FINE  )  &",
        "       arg_type(GH_FIELD, GH_REAL, GH_READ, ANY_SPACE_2, "
        "mesh_arg=GH_FINE  ),  &\n"
        "       arg_type(GH_SCALAR, GH_REAL, GH_READ) &", 1)
    code = code.replace("(2)", "(3)", 1)

    ast = fpapi.parse(code, ignore_comments=False)
    name = "restrict_kernel_type"
    with pytest.raises(ParseError) as excinfo:
        _ = DynKernMetadata(ast, name=name)
    assert ("Inter-grid kernels in the Dynamo 0.3 API are only permitted to "
            "have field arguments but kernel restrict_kernel_type also has "
            "arguments of type ['gh_scalar']" in str(excinfo.value))
Esempio n. 3
0
def test_any_spaces():
    ''' Test that any_space and any_discontinuous_space metadata are handled
    correctly for kernel stubs.

    '''
    ast = fpapi.parse(ANY_SPACES, ignore_comments=False)
    metadata = DynKernMetadata(ast)
    kernel = DynKern()
    kernel.load_meta(metadata)
    generated_code = str(kernel.gen_stub)
    output = ("  MODULE dummy_mod\n"
              "    IMPLICIT NONE\n"
              "    CONTAINS\n"
              "    SUBROUTINE dummy_code(nlayers, field_1_adspc1_field_1, "
              "field_2_aspc7_field_2, field_3_adspc4_field_3, "
              "ndf_adspc1_field_1, undf_adspc1_field_1, map_adspc1_field_1, "
              "ndf_aspc7_field_2, undf_aspc7_field_2, map_aspc7_field_2, "
              "ndf_adspc4_field_3, undf_adspc4_field_3, map_adspc4_field_3)\n"
              "      USE constants_mod, ONLY: r_def, i_def\n"
              "      IMPLICIT NONE\n"
              "      INTEGER(KIND=i_def), intent(in) :: nlayers\n"
              "      INTEGER(KIND=i_def), intent(in) :: ndf_adspc1_field_1\n"
              "      INTEGER(KIND=i_def), intent(in), dimension("
              "ndf_adspc1_field_1) :: map_adspc1_field_1\n"
              "      INTEGER(KIND=i_def), intent(in) :: ndf_adspc4_field_3\n"
              "      INTEGER(KIND=i_def), intent(in), dimension("
              "ndf_adspc4_field_3) :: map_adspc4_field_3\n"
              "      INTEGER(KIND=i_def), intent(in) :: ndf_aspc7_field_2\n"
              "      INTEGER(KIND=i_def), intent(in), "
              "dimension(ndf_aspc7_field_2) :: map_aspc7_field_2\n"
              "      INTEGER(KIND=i_def), intent(in) :: undf_adspc1_field_1, "
              "undf_aspc7_field_2, undf_adspc4_field_3\n"
              "      REAL(KIND=r_def), intent(in), dimension"
              "(undf_adspc1_field_1) :: field_1_adspc1_field_1\n"
              "      REAL(KIND=r_def), intent(inout), dimension"
              "(undf_aspc7_field_2) :: field_2_aspc7_field_2\n"
              "      REAL(KIND=r_def), intent(inout), dimension"
              "(undf_adspc4_field_3) :: field_3_adspc4_field_3\n"
              "    END SUBROUTINE dummy_code\n"
              "  END MODULE dummy_mod")
    assert output in generated_code
Esempio n. 4
0
def test_lfricscalars_stub_err():
    ''' Check that LFRicScalarArgs._stub_declarations() raises the
    expected internal error if it encounters an unrecognised data
    type of a scalar argument when generating a kernel stub.

    '''
    ast = fpapi.parse(os.path.join(BASE_PATH,
                                   "testkern_one_int_scalar_mod.f90"),
                      ignore_comments=False)
    metadata = DynKernMetadata(ast)
    kernel = DynKern()
    kernel.load_meta(metadata)
    # Sabotage the scalar argument to make it have an invalid data type
    arg = kernel.arguments.args[1]
    arg.descriptor._data_type = "gh_invalid_scalar"
    with pytest.raises(InternalError) as err:
        LFRicScalarArgs(kernel)._stub_declarations(ModuleGen(name="my_mod"))
    const = LFRicConstants()
    assert ("Found an unsupported data type 'gh_invalid_scalar' for the "
            "scalar argument 'iscalar_2'. Supported types are {0}.".format(
                const.VALID_SCALAR_DATA_TYPES) in str(err.value))
Esempio n. 5
0
def test_dynscalars_stub_err():
    ''' Check that the DynScalarArgs constructor raises the expected
    internal error if it encounters an unrecognised intrinsic type of
    scalar when generating a kernel stub.

    '''
    from psyclone.dynamo0p3 import DynScalarArgs
    ast = fpapi.parse(os.path.join(BASE_PATH,
                                   "testkern_one_int_scalar_mod.f90"),
                      ignore_comments=False)
    metadata = DynKernMetadata(ast)
    kernel = DynKern()
    kernel.load_meta(metadata)
    # Sabotage the scalar argument to make it have an invalid intrinsic type
    arg = kernel.arguments.args[1]
    arg._intrinsic_type = "invalid-scalar-type"
    with pytest.raises(InternalError) as err:
        _ = DynScalarArgs(kernel)
    assert ("DynScalarArgs.__init__(): Found an unsupported intrinsic type "
            "'invalid-scalar-type' for the scalar argument 'iscalar_2'. "
            "Supported types are ['real', 'integer']." in str(err.value))
Esempio n. 6
0
def test_fs_anyspace_cells_write_or_readwrite_error():
    ''' Test that an error is raised if a field that is on 'any_space' "
    "(and therefore may be continuous) is specified as having 'gh_write' "
    "or 'gh_readwrite' access in the metadata.

    '''
    fparser.logging.disable(fparser.logging.CRITICAL)
    const = LFRicConstants()
    for fspace in const.VALID_ANY_SPACE_NAMES:
        for acc in ["gh_write", "gh_readwrite"]:
            code = FIELD_CODE.replace(
                "arg_type(gh_field,  gh_real,    gh_read,  w2)",
                "arg_type(gh_field, gh_real, " + acc + ", " + fspace + ")", 1)
            ast = fpapi.parse(code, ignore_comments=False)
            with pytest.raises(ParseError) as excinfo:
                _ = DynKernMetadata(ast, name="testkern_field_type")
            assert ("In the LFRic API, allowed accesses for fields on "
                    "continuous function spaces that are arguments to "
                    "kernels that operate on cell-columns are ['gh_read', "
                    "'gh_inc'], but found '{0}' for '{1}'".format(acc, fspace)
                    in str(excinfo.value))
Esempio n. 7
0
def test_lfric_stub_field_vector():
    '''Check variable usage detection field vectors.

    '''
    from psyclone.dynamo0p3 import DynKernMetadata, DynKern
    from psyclone.domain.lfric import KernStubArgList
    ast = get_ast("dynamo0.3", "testkern_stencil_vector_mod.f90")
    metadata = DynKernMetadata(ast)
    kernel = DynKern()
    kernel.load_meta(metadata)
    var_accesses = VariablesAccessInfo()
    create_arg_list = KernStubArgList(kernel)
    create_arg_list.generate(var_accesses=var_accesses)
    var_info = str(var_accesses)
    assert "field_1_w0_v1: READ" in var_info
    assert "field_1_w0_v2: READ" in var_info
    assert "field_1_w0_v3: READ" in var_info
    assert "field_2_w3_v1: READ" in var_info
    assert "field_2_w3_v2: READ" in var_info
    assert "field_2_w3_v3: READ" in var_info
    assert "field_2_w3_v4: READ" in var_info
Esempio n. 8
0
def test_dynscalars_err(monkeypatch):
    ''' Check that the DynScalarArgs constructor raises the expected error
    if it encounters an unrecognised type of scalar. '''
    from psyclone.dynamo0p3 import DynScalarArgs
    from psyclone import dynamo0p3
    ast = fpapi.parse(os.path.join(BASE_PATH,
                                   "testkern_one_int_scalar_mod.f90"),
                      ignore_comments=False)
    metadata = DynKernMetadata(ast)
    kernel = DynKern()
    kernel.load_meta(metadata)
    # Sabotage the scalar argument to make it have an invalid type.
    arg = kernel.arguments.args[1]
    arg._type = "invalid-scalar-type"
    # Monkeypatch the list of supported scalar types to include this one
    monkeypatch.setattr(dynamo0p3, "GH_VALID_SCALAR_NAMES",
                        ["gh_real", "gh_integer", "invalid-scalar-type"])
    with pytest.raises(InternalError) as err:
        _ = DynScalarArgs(kernel)
    assert ("Scalar type 'invalid-scalar-type' is in GH_VALID_SCALAR_NAMES "
            "but not handled" in str(err))
Esempio n. 9
0
def test_kernel_stub_ind_dofmap_errors():
    '''Check that we raise the expected exceptions if the wrong arguments
    are supplied to KernelStubArgList.indirection_dofmap() '''
    ast = fpapi.parse(os.path.join(BASE_PATH,
                                   "testkern_one_int_scalar_mod.f90"),
                      ignore_comments=False)
    metadata = DynKernMetadata(ast)
    kernel = DynKern()
    kernel.load_meta(metadata)
    # Now call KernStubArgList to raise an exception
    create_arg_list = KernStubArgList(kernel)
    # First call it without an argument object
    with pytest.raises(GenerationError) as excinfo:
        create_arg_list.indirection_dofmap("w3")
    assert "no CMA operator supplied" in str(excinfo)
    # Second, call it with an argument object but one that is not
    # an operator
    with pytest.raises(GenerationError) as excinfo:
        create_arg_list.indirection_dofmap("w3", kernel.arguments.args[1])
    assert ("a CMA operator (gh_columnwise_operator) must be supplied but "
            "got") in str(excinfo)
Esempio n. 10
0
def test_ad_scalar_init_wrong_data_type(monkeypatch):
    ''' Test that an error is raised if an invalid data type
    is passed to the LFRicArgDescriptor._init_scalar() method. '''
    ast = fpapi.parse(CODE, ignore_comments=False)
    name = "testkern_qr_type"
    metadata = DynKernMetadata(ast, name=name)
    # Get a scalar argument descriptor and set a wrong data type
    scalar_arg = metadata._inits[0]
    scalar_arg.args[1].name = "gh_double"
    const = LFRicConstants()
    # Now try to trip the error by making the initial test think
    # that 'gh_double' is actually a valid data type
    monkeypatch.setattr(target=LFRicConstants,
                        name="VALID_ARG_DATA_TYPES",
                        value=LFRicConstants.VALID_ARG_DATA_TYPES +
                        ["gh_double"])
    with pytest.raises(InternalError) as excinfo:
        LFRicArgDescriptor(scalar_arg,
                           metadata.iterates_over)._init_scalar(scalar_arg)
    assert ("Expected one of {0} as the scalar data type but got 'gh_double'.".
            format(const.VALID_SCALAR_DATA_TYPES) in str(excinfo.value))
Esempio n. 11
0
def test_fs_descriptor_wrong_type():
    ''' Tests that an error is raised when the function space descriptor
    metadata is not of type func_type. '''
    code = CODE.replace("func_type(w2", "funced_up_type(w2", 1)
    ast = fpapi.parse(code, ignore_comments=False)
    name = "testkern_qr_type"
    with pytest.raises(ParseError) as excinfo:
        _ = DynKernMetadata(ast, name=name)
    assert ("'meta_funcs' metadata must consist of an array of structure "
            "constructors, all of type 'func_type'" in str(excinfo.value))

    # Check that the DynFuncDescriptor03 rejects it too

    class FakeCls(object):
        ''' Class that just has a name property (which is not "func_type") '''
        name = "not-func-type"

    with pytest.raises(ParseError) as excinfo:
        DynFuncDescriptor03(FakeCls())
    assert ("each meta_func entry must be of type 'func_type' but found "
            in str(excinfo.value))
Esempio n. 12
0
def test_mesh_props_quad_stub_gen():
    ''' Check that correct stub code is produced when the kernel metadata
    specifies both mesh and quadrature properties (quadrature
    properties should be placed at the end of subroutine argument list). '''
    ast = fpapi.parse(MESH_PROP_MDATA, ignore_comments=False)
    metadata = DynKernMetadata(ast)
    kernel = DynKern()
    kernel.load_meta(metadata)
    gen = str(kernel.gen_stub)

    output1 = (
        "  SUBROUTINE testkern_mesh_prop_quad_code(nlayers, field_1_w1, "
        "field_2_wtheta, ndf_w1, undf_w1, map_w1, basis_w1_qr_xyoz, "
        "ndf_wtheta, undf_wtheta, map_wtheta, basis_wtheta_qr_xyoz, "
        "nfaces_re_h, nfaces_re, normals_to_horiz_faces, "
        "out_normals_to_faces, adjacent_face, np_xy_qr_xyoz, "
        "np_z_qr_xyoz, weights_xy_qr_xyoz, weights_z_qr_xyoz)")
    assert output1 in gen
    output2 = (
        "      INTEGER(KIND=i_def), intent(in) :: np_xy_qr_xyoz, "
        "np_z_qr_xyoz\n"
        "      REAL(KIND=r_def), intent(in), "
        "dimension(3,ndf_w1,np_xy_qr_xyoz,np_z_qr_xyoz) :: basis_w1_qr_xyoz\n"
        "      REAL(KIND=r_def), intent(in), "
        "dimension(1,ndf_wtheta,np_xy_qr_xyoz,np_z_qr_xyoz) :: "
        "basis_wtheta_qr_xyoz\n"
        "      REAL(KIND=r_def), intent(in), dimension(np_xy_qr_xyoz) :: "
        "weights_xy_qr_xyoz\n"
        "      REAL(KIND=r_def), intent(in), dimension(np_z_qr_xyoz) :: "
        "weights_z_qr_xyoz\n"
        "      INTEGER(KIND=i_def), intent(in) :: nfaces_re_h\n"
        "      INTEGER(KIND=i_def), intent(in) :: nfaces_re\n"
        "      REAL(KIND=r_def), intent(in), dimension(3,nfaces_re_h) :: "
        "normals_to_horiz_faces\n"
        "      REAL(KIND=r_def), intent(in), dimension(3,nfaces_re) :: "
        "out_normals_to_faces\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(nfaces_re_h) :: "
        "adjacent_face\n"
    )
    assert output2 in gen
Esempio n. 13
0
def test_multi_qr_stub_gen():
    ''' Test that the stub generator correctly handles a kernel requiring
    more than one quadrature rule. '''
    ast = fpapi.parse(os.path.join(BASE_PATH, "testkern_2qr_mod.F90"),
                      ignore_comments=False)
    metadata = DynKernMetadata(ast)
    kernel = DynKern()
    kernel.load_meta(metadata)
    generated_code = str(kernel.gen_stub)
    assert ("SUBROUTINE testkern_2qr_code(nlayers, field_1_w1, field_2_w2, "
            "field_3_w2, field_4_w3, ndf_w1, undf_w1, map_w1, "
            "basis_w1_qr_face, basis_w1_qr_edge, ndf_w2, undf_w2, map_w2, "
            "diff_basis_w2_qr_face, diff_basis_w2_qr_edge, ndf_w3, undf_w3, "
            "map_w3, basis_w3_qr_face, basis_w3_qr_edge, "
            "diff_basis_w3_qr_face, diff_basis_w3_qr_edge, nfaces_qr_face, "
            "np_xyz_qr_face, weights_xyz_qr_face, nedges_qr_edge, "
            "np_xyz_qr_edge, weights_xyz_qr_edge)" in generated_code)
    assert ("INTEGER(KIND=i_def), intent(in) :: np_xyz_qr_face, "
            "nfaces_qr_face, np_xyz_qr_edge, nedges_qr_edge" in generated_code)
    assert ("      REAL(KIND=r_def), intent(in), dimension(3,ndf_w1,"
            "np_xyz_qr_face,nfaces_qr_face) :: basis_w1_qr_face\n"
            "      REAL(KIND=r_def), intent(in), dimension(3,ndf_w1,"
            "np_xyz_qr_edge,nedges_qr_edge) :: basis_w1_qr_edge\n"
            "      REAL(KIND=r_def), intent(in), dimension(1,ndf_w2,"
            "np_xyz_qr_face,nfaces_qr_face) :: diff_basis_w2_qr_face\n"
            "      REAL(KIND=r_def), intent(in), dimension(1,ndf_w2,"
            "np_xyz_qr_edge,nedges_qr_edge) :: diff_basis_w2_qr_edge\n"
            "      REAL(KIND=r_def), intent(in), dimension(1,ndf_w3,"
            "np_xyz_qr_face,nfaces_qr_face) :: basis_w3_qr_face\n"
            "      REAL(KIND=r_def), intent(in), dimension(3,ndf_w3,"
            "np_xyz_qr_face,nfaces_qr_face) :: diff_basis_w3_qr_face\n"
            "      REAL(KIND=r_def), intent(in), dimension(1,ndf_w3,"
            "np_xyz_qr_edge,nedges_qr_edge) :: basis_w3_qr_edge\n"
            "      REAL(KIND=r_def), intent(in), dimension(3,ndf_w3,"
            "np_xyz_qr_edge,nedges_qr_edge) :: diff_basis_w3_qr_edge"
            in generated_code)
    assert ("      REAL(KIND=r_def), intent(in), dimension(np_xyz_qr_face,"
            "nfaces_qr_face) :: weights_xyz_qr_face\n"
            "      REAL(KIND=r_def), intent(in), dimension(np_xyz_qr_edge,"
            "nedges_qr_edge) :: weights_xyz_qr_edge\n" in generated_code)
Esempio n. 14
0
def test_stub_stencil_vector():
    '''Check that correct stub code is produced when there is a stencil
    access which is a vector '''
    ast = fpapi.parse(os.path.join(BASE_PATH,
                                   "testkern_stencil_vector_mod.f90"),
                      ignore_comments=False)
    metadata = DynKernMetadata(ast)
    kernel = DynKern()
    kernel.load_meta(metadata)
    generated_code = str(kernel.gen_stub)
    result1 = (
        "    SUBROUTINE testkern_stencil_vector_code(nlayers, field_1_w0_v1, "
        "field_1_w0_v2, field_1_w0_v3, field_2_w3_v1, field_2_w3_v2, "
        "field_2_w3_v3, field_2_w3_v4, field_2_stencil_size, "
        "field_2_stencil_dofmap, ndf_w0, undf_w0, map_w0, ndf_w3, undf_w3, "
        "map_w3)")
    assert result1 in generated_code
    result2 = (
        "      INTEGER(KIND=i_def), intent(in) :: field_2_stencil_size\n"
        "      INTEGER(KIND=i_def), intent(in), "
        "dimension(ndf_w3,field_2_stencil_size) :: field_2_stencil_dofmap")
    assert result2 in generated_code
Esempio n. 15
0
def test_stub_stencil_direction():
    '''Check that correct stub code is produced when there is a stencil
    access which requires a direction argument '''
    ast = fpapi.parse(os.path.join(BASE_PATH,
                                   "testkern_stencil_xory1d_mod.f90"),
                      ignore_comments=False)
    metadata = DynKernMetadata(ast)
    kernel = DynKern()
    kernel.load_meta(metadata)
    generated_code = str(kernel.gen_stub)
    result1 = (
        "    SUBROUTINE testkern_stencil_xory1d_code(nlayers, field_1_w1, "
        "field_2_w2, field_2_stencil_size, field_2_direction, "
        "field_2_stencil_dofmap, field_3_w2, field_4_w3, ndf_w1, undf_w1, "
        "map_w1, ndf_w2, undf_w2, map_w2, ndf_w3, undf_w3, map_w3)")
    assert result1 in generated_code
    result2 = (
        "      INTEGER(KIND=i_def), intent(in) :: field_2_stencil_size\n"
        "      INTEGER(KIND=i_def), intent(in) :: field_2_direction\n"
        "      INTEGER(KIND=i_def), intent(in), "
        "dimension(ndf_w2,field_2_stencil_size) :: field_2_stencil_dofmap")
    assert result2 in generated_code
Esempio n. 16
0
def test_stub_basis_wrong_shape(monkeypatch):
    ''' Check that stub generation for a kernel requiring basis functions
    for quadrature raises the correct errors if the kernel meta-data is
    broken '''
    from psyclone import dynamo0p3
    ast = fpapi.parse(BASIS, ignore_comments=False)
    metadata = DynKernMetadata(ast)
    kernel = DynKern()
    kernel.load_meta(metadata)
    monkeypatch.setattr(kernel, "_eval_shape",
                        value="gh_quadrature_wrong")
    with pytest.raises(InternalError) as excinfo:
        _ = kernel.gen_stub
    assert ("Unrecognised evaluator shape (gh_quadrature_wrong)"
            in str(excinfo))
    monkeypatch.setattr(dynamo0p3, "VALID_QUADRATURE_SHAPES",
                        value=["gh_quadrature_xyz", "gh_quadrature_xyoz",
                               "gh_quadrature_xoyoz", "gh_quadrature_wrong"])
    with pytest.raises(GenerationError) as excinfo:
        _ = kernel.gen_stub
    assert ("shapes other than GH_QUADRATURE_XYoZ are not yet supported" in
            str(excinfo))
Esempio n. 17
0
def test_lfric_stub_cma_operators():
    '''Check variable usage detection cma operators.
    mesh_ncell2d, cma_operator

    '''
    ast = get_ast("dynamo0.3", "columnwise_op_mul_2scalars_kernel_mod.F90")
    metadata = DynKernMetadata(ast)
    kernel = DynKern()
    kernel.load_meta(metadata)
    var_accesses = VariablesAccessInfo()
    create_arg_list = KernStubArgList(kernel)
    create_arg_list.generate(var_accesses=var_accesses)
    var_info = str(var_accesses)
    for num in ["1", "3", "5"]:
        assert "ncell_2d: READ" in var_info
        assert "cma_op_"+num+": READ" in var_info
        assert "cma_op_"+num+"_nrow: READ" in var_info
        assert "cma_op_"+num+"_ncol: READ" in var_info
        assert "cma_op_"+num+"_bandwidth: READ" in var_info
        assert "cma_op_"+num+"_alpha: READ" in var_info
        assert "cma_op_"+num+"_beta: READ" in var_info
        assert "cma_op_"+num+"_gamma_m: READ" in var_info
        assert "cma_op_"+num+"_gamma_p: READ" in var_info
Esempio n. 18
0
def test_lfric_stub_args3():
    '''Check variable usage detection for cell position, operator

    '''
    from psyclone.dynamo0p3 import DynKernMetadata, DynKern
    from psyclone.domain.lfric import KernStubArgList
    ast = get_ast("dynamo0.3", "dummy_orientation_mod.f90")
    metadata = DynKernMetadata(ast)
    kernel = DynKern()
    kernel.load_meta(metadata)
    var_accesses = VariablesAccessInfo()
    create_arg_list = KernStubArgList(kernel)
    create_arg_list.generate(var_accesses=var_accesses)
    var_info = str(var_accesses)
    assert "cell: READ" in var_info
    assert "op_2_ncell_3d: READ" in var_info
    assert "op_2: READ" in var_info
    assert "op_4_ncell_3d: READ" in var_info
    assert "op_4: READ" in var_info
    assert "orientation_w0: READ" in var_info
    assert "orientation_w1: READ" in var_info
    assert "orientation_w2: READ" in var_info
    assert "orientation_w3: READ" in var_info
Esempio n. 19
0
def test_qr_plus_eval_stub_gen():
    ''' Test the stub generator for a kernel that requires both an evaluator
    and quadrature. '''
    ast = fpapi.parse(os.path.join(BASE_PATH, "testkern_qr_eval_mod.F90"),
                      ignore_comments=False)
    metadata = DynKernMetadata(ast)
    kernel = DynKern()
    kernel.load_meta(metadata)
    gen_code = str(kernel.gen_stub)
    assert (
        "SUBROUTINE testkern_qr_eval_code(nlayers, field_1_w1, field_2_w2,"
        " field_3_w2, field_4_w3, ndf_w1, undf_w1, map_w1, basis_w1_qr_face, "
        "basis_w1_on_w1, ndf_w2, undf_w2, map_w2, diff_basis_w2_qr_face, "
        "diff_basis_w2_on_w1, ndf_w3, undf_w3, map_w3, basis_w3_qr_face, "
        "basis_w3_on_w1, diff_basis_w3_qr_face, diff_basis_w3_on_w1, "
        "nfaces_qr_face, np_xyz_qr_face, weights_xyz_qr_face)" in gen_code)
    assert ("INTEGER(KIND=i_def), intent(in) :: np_xyz_qr_face, nfaces_qr_face"
            in gen_code)
    assert (
        "      REAL(KIND=r_def), intent(in), dimension(3,ndf_w1,np_xyz_qr_face"
        ",nfaces_qr_face) :: basis_w1_qr_face\n"
        "      REAL(KIND=r_def), intent(in), dimension(3,ndf_w1,ndf_w1) :: "
        "basis_w1_on_w1\n"
        "      REAL(KIND=r_def), intent(in), dimension(1,ndf_w2,np_xyz_qr_face"
        ",nfaces_qr_face) :: diff_basis_w2_qr_face\n"
        "      REAL(KIND=r_def), intent(in), dimension(1,ndf_w2,ndf_w1) :: "
        "diff_basis_w2_on_w1\n"
        "      REAL(KIND=r_def), intent(in), dimension(1,ndf_w3,np_xyz_qr_face"
        ",nfaces_qr_face) :: basis_w3_qr_face\n"
        "      REAL(KIND=r_def), intent(in), dimension(3,ndf_w3,np_xyz_qr_face"
        ",nfaces_qr_face) :: diff_basis_w3_qr_face\n"
        "      REAL(KIND=r_def), intent(in), dimension(1,ndf_w3,ndf_w1) :: "
        "basis_w3_on_w1\n"
        "      REAL(KIND=r_def), intent(in), dimension(3,ndf_w3,ndf_w1) :: "
        "diff_basis_w3_on_w1\n"
        "      REAL(KIND=r_def), intent(in), dimension(np_xyz_qr_face,"
        "nfaces_qr_face) :: weights_xyz_qr_face" in gen_code)
Esempio n. 20
0
def test_lfric_stub_args():
    '''Check that correct stub code is produced when there are multiple
    stencils.

    '''
    from psyclone.dynamo0p3 import DynKernMetadata, DynKern
    from psyclone.domain.lfric import KernStubArgList
    ast = get_ast("dynamo0.3", "testkern_stencil_multi_mod.f90")
    metadata = DynKernMetadata(ast)
    kernel = DynKern()
    kernel.load_meta(metadata)
    var_accesses = VariablesAccessInfo()
    create_arg_list = KernStubArgList(kernel)
    create_arg_list.generate(var_accesses=var_accesses)
    var_info = str(var_accesses)
    assert "field_1_w1: READ+WRITE" in var_info
    assert "field_2_stencil_dofmap: READ" in var_info
    assert "field_2_stencil_size: READ" in var_info
    assert "field_2_w2: READ" in var_info
    assert "field_3_direction: READ" in var_info
    assert "field_3_stencil_dofmap: READ" in var_info
    assert "field_3_stencil_size: READ" in var_info
    assert "field_3_w2: READ" in var_info
    assert "field_4_stencil_dofmap: READ" in var_info
    assert "field_4_stencil_size: READ" in var_info
    assert "field_4_w3: READ" in var_info
    assert "map_w1: READ" in var_info
    assert "map_w2: READ" in var_info
    assert "map_w3: READ" in var_info
    assert "ndf_w1: READ" in var_info
    assert "ndf_w2: READ" in var_info
    assert "ndf_w3: READ" in var_info
    assert "nlayers: READ" in var_info
    assert "undf_w1: READ" in var_info
    assert "undf_w2: READ" in var_info
    assert "undf_w3: READ" in var_info
Esempio n. 21
0
def test_int_field_gen_stub():
    ''' Test that we generate correct code for kernel stubs that
    contain integer-valued fields with stencils and basis/differential
    basis functions.

    '''
    ast = fpapi.parse(INTEGER_FIELD_CODE, ignore_comments=False)
    metadata = DynKernMetadata(ast)
    kernel = DynKern()
    kernel.load_meta(metadata)
    generated_code = str(kernel.gen_stub)
    output = (
        "  MODULE testkern_int_field_mod\n"
        "    IMPLICIT NONE\n"
        "    CONTAINS\n"
        "    SUBROUTINE testkern_int_field_code(nlayers, field_1_wtheta, "
        "field_2_w3_v1, field_2_w3_v2, field_2_w3_v3, field_3_w2trace, "
        "field_3_stencil_size, field_3_stencil_dofmap, ndf_wtheta, "
        "undf_wtheta, map_wtheta, basis_wtheta_qr_xyoz, ndf_w3, undf_w3, "
        "map_w3, basis_w3_qr_xyoz, diff_basis_w3_qr_xyoz, ndf_w2trace, "
        "undf_w2trace, map_w2trace, np_xy_qr_xyoz, np_z_qr_xyoz, "
        "weights_xy_qr_xyoz, weights_z_qr_xyoz)\n"
        "      USE constants_mod, ONLY: r_def, i_def\n"
        "      IMPLICIT NONE\n"
        "      INTEGER(KIND=i_def), intent(in) :: nlayers\n"
        "      INTEGER(KIND=i_def), intent(in) :: ndf_w2trace\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(ndf_w2trace) :: "
        "map_w2trace\n"
        "      INTEGER(KIND=i_def), intent(in) :: ndf_w3\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(ndf_w3) :: map_w3\n"
        "      INTEGER(KIND=i_def), intent(in) :: ndf_wtheta\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(ndf_wtheta) :: "
        "map_wtheta\n"
        "      INTEGER(KIND=i_def), intent(in) :: undf_wtheta, undf_w3, "
        "undf_w2trace\n"
        "      INTEGER(KIND=i_def), intent(inout), dimension(undf_wtheta) :: "
        "field_1_wtheta\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(undf_w3) :: "
        "field_2_w3_v1\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(undf_w3) :: "
        "field_2_w3_v2\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(undf_w3) :: "
        "field_2_w3_v3\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(undf_w2trace) :: "
        "field_3_w2trace\n"
        "      INTEGER(KIND=i_def), intent(in) :: field_3_stencil_size\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(ndf_w2trace,"
        "field_3_stencil_size) :: field_3_stencil_dofmap\n"
        "      INTEGER(KIND=i_def), intent(in) :: "
        "np_xy_qr_xyoz, np_z_qr_xyoz\n"
        "      REAL(KIND=r_def), intent(in), dimension(1,ndf_wtheta,"
        "np_xy_qr_xyoz,np_z_qr_xyoz) :: basis_wtheta_qr_xyoz\n"
        "      REAL(KIND=r_def), intent(in), dimension(1,ndf_w3,"
        "np_xy_qr_xyoz,np_z_qr_xyoz) :: basis_w3_qr_xyoz\n"
        "      REAL(KIND=r_def), intent(in), dimension(3,ndf_w3,"
        "np_xy_qr_xyoz,np_z_qr_xyoz) :: diff_basis_w3_qr_xyoz\n"
        "      REAL(KIND=r_def), intent(in), dimension(np_xy_qr_xyoz) :: "
        "weights_xy_qr_xyoz\n"
        "      REAL(KIND=r_def), intent(in), dimension(np_z_qr_xyoz) :: "
        "weights_z_qr_xyoz\n"
        "    END SUBROUTINE testkern_int_field_code\n"
        "  END MODULE testkern_int_field_mod")
    assert output in generated_code
def test_qr_basis_stub():
    ''' Test that basis functions for quadrature are handled correctly for
    kernel stubs '''
    ast = fpapi.parse(BASIS, ignore_comments=False)
    metadata = DynKernMetadata(ast)
    kernel = DynKern()
    kernel.load_meta(metadata)
    generated_code = str(kernel.gen_stub)
    output = (
        "  MODULE dummy_mod\n"
        "    IMPLICIT NONE\n"
        "    CONTAINS\n"
        "    SUBROUTINE dummy_code(cell, nlayers, field_1_w0, op_2_ncell_3d, "
        "op_2, field_3_w2, op_4_ncell_3d, op_4, field_5_wtheta, "
        "op_6_ncell_3d, op_6, field_7_w2v, ndf_w0, undf_w0, map_w0, "
        "basis_w0, ndf_w1, basis_w1, ndf_w2, undf_w2, map_w2, basis_w2, "
        "ndf_w3, basis_w3, ndf_wtheta, undf_wtheta, map_wtheta, "
        "basis_wtheta, ndf_w2h, basis_w2h, ndf_w2v, undf_w2v, map_w2v, "
        "basis_w2v, np_xy, np_z, weights_xy, weights_z)\n"
        "      USE constants_mod, ONLY: r_def\n"
        "      IMPLICIT NONE\n"
        "      INTEGER, intent(in) :: cell\n"
        "      INTEGER, intent(in) :: nlayers\n"
        "      INTEGER, intent(in) :: ndf_w0\n"
        "      INTEGER, intent(in) :: undf_w0\n"
        "      INTEGER, intent(in) :: ndf_w1\n"
        "      INTEGER, intent(in) :: ndf_w2\n"
        "      INTEGER, intent(in) :: undf_w2\n"
        "      INTEGER, intent(in) :: ndf_w3\n"
        "      INTEGER, intent(in) :: ndf_wtheta\n"
        "      INTEGER, intent(in) :: undf_wtheta\n"
        "      INTEGER, intent(in) :: ndf_w2h\n"
        "      INTEGER, intent(in) :: ndf_w2v\n"
        "      INTEGER, intent(in) :: undf_w2v\n"
        "      REAL(KIND=r_def), intent(out), dimension(undf_w0) :: "
        "field_1_w0\n"
        "      INTEGER, intent(in) :: op_2_ncell_3d\n"
        "      REAL(KIND=r_def), intent(inout), dimension(ndf_w1,ndf_w1,"
        "op_2_ncell_3d) :: op_2\n"
        "      REAL(KIND=r_def), intent(in), dimension(undf_w2) :: "
        "field_3_w2\n"
        "      INTEGER, intent(in) :: op_4_ncell_3d\n"
        "      REAL(KIND=r_def), intent(out), dimension(ndf_w3,ndf_w3,"
        "op_4_ncell_3d) :: op_4\n"
        "      REAL(KIND=r_def), intent(out), dimension(undf_wtheta) :: "
        "field_5_wtheta\n"
        "      INTEGER, intent(in) :: op_6_ncell_3d\n"
        "      REAL(KIND=r_def), intent(inout), dimension(ndf_w2h,ndf_w2h,"
        "op_6_ncell_3d) :: op_6\n"
        "      REAL(KIND=r_def), intent(in), dimension(undf_w2v) :: "
        "field_7_w2v\n"
        "      INTEGER, intent(in), dimension(ndf_w0) :: map_w0\n"
        "      REAL(KIND=r_def), intent(in), dimension(1,ndf_w0,np_xy,np_z) "
        ":: basis_w0\n"
        "      REAL(KIND=r_def), intent(in), dimension(3,ndf_w1,np_xy,np_z) "
        ":: basis_w1\n"
        "      INTEGER, intent(in), dimension(ndf_w2) :: map_w2\n"
        "      REAL(KIND=r_def), intent(in), dimension(3,ndf_w2,np_xy,np_z) "
        ":: basis_w2\n"
        "      REAL(KIND=r_def), intent(in), dimension(1,ndf_w3,np_xy,np_z) "
        ":: basis_w3\n"
        "      INTEGER, intent(in), dimension(ndf_wtheta) :: map_wtheta\n"
        "      REAL(KIND=r_def), intent(in), dimension(1,ndf_wtheta,np_xy,"
        "np_z) :: basis_wtheta\n"
        "      REAL(KIND=r_def), intent(in), dimension(3,ndf_w2h,np_xy,np_z) "
        ":: basis_w2h\n"
        "      INTEGER, intent(in), dimension(ndf_w2v) :: map_w2v\n"
        "      REAL(KIND=r_def), intent(in), dimension(3,ndf_w2v,np_xy,np_z) "
        ":: basis_w2v\n"
        "      INTEGER, intent(in) :: np_xy, np_z\n"
        "      REAL(KIND=r_def), intent(in), dimension(np_xy) :: weights_xy\n"
        "      REAL(KIND=r_def), intent(in), dimension(np_z) :: weights_z\n"
        "    END SUBROUTINE dummy_code\n"
        "  END MODULE dummy_mod")
    print output
    print generated_code
    assert output in generated_code
Esempio n. 23
0
def test_qr_basis_stub():
    ''' Test that basis functions for quadrature are handled correctly for
    kernel stubs.

    '''
    ast = fpapi.parse(BASIS, ignore_comments=False)
    metadata = DynKernMetadata(ast)
    kernel = DynKern()
    kernel.load_meta(metadata)
    generated_code = str(kernel.gen_stub)
    output = (
        "  MODULE dummy_mod\n"
        "    IMPLICIT NONE\n"
        "    CONTAINS\n"
        "    SUBROUTINE dummy_code(cell, nlayers, field_1_w0, op_2_ncell_3d, "
        "op_2, field_3_w2, op_4_ncell_3d, op_4, field_5_wtheta, "
        "op_6_ncell_3d, op_6, field_7_w2v, op_8_ncell_3d, op_8, field_9_wchi, "
        "op_10_ncell_3d, op_10, field_11_w2htrace, op_12_ncell_3d, op_12, "
        "ndf_w0, undf_w0, map_w0, basis_w0_qr_xyoz, ndf_w1, basis_w1_qr_xyoz, "
        "ndf_w2, undf_w2, map_w2, basis_w2_qr_xyoz, ndf_w3, basis_w3_qr_xyoz, "
        "ndf_wtheta, undf_wtheta, map_wtheta, basis_wtheta_qr_xyoz, ndf_w2h, "
        "basis_w2h_qr_xyoz, ndf_w2v, undf_w2v, map_w2v, basis_w2v_qr_xyoz, "
        "ndf_w2broken, basis_w2broken_qr_xyoz, ndf_wchi, undf_wchi, map_wchi, "
        "basis_wchi_qr_xyoz, ndf_w2trace, basis_w2trace_qr_xyoz, "
        "ndf_w2htrace, undf_w2htrace, map_w2htrace, basis_w2htrace_qr_xyoz, "
        "ndf_w2vtrace, basis_w2vtrace_qr_xyoz, np_xy_qr_xyoz, np_z_qr_xyoz, "
        "weights_xy_qr_xyoz, weights_z_qr_xyoz)\n"
        "      USE constants_mod, ONLY: r_def, i_def\n"
        "      IMPLICIT NONE\n"
        "      INTEGER(KIND=i_def), intent(in) :: nlayers\n"
        "      INTEGER(KIND=i_def), intent(in) :: ndf_w0\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(ndf_w0) :: map_w0\n"
        "      INTEGER(KIND=i_def), intent(in) :: ndf_w2\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(ndf_w2) :: map_w2\n"
        "      INTEGER(KIND=i_def), intent(in) :: ndf_w2htrace\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(ndf_w2htrace) "
        ":: map_w2htrace\n"
        "      INTEGER(KIND=i_def), intent(in) :: ndf_w2v\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(ndf_w2v) "
        ":: map_w2v\n"
        "      INTEGER(KIND=i_def), intent(in) :: ndf_wchi\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(ndf_wchi) "
        ":: map_wchi\n"
        "      INTEGER(KIND=i_def), intent(in) :: ndf_wtheta\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(ndf_wtheta) "
        ":: map_wtheta\n"
        "      INTEGER(KIND=i_def), intent(in) :: undf_w0, ndf_w1, undf_w2, "
        "ndf_w3, undf_wtheta, ndf_w2h, undf_w2v, ndf_w2broken, undf_wchi, "
        "ndf_w2trace, undf_w2htrace, ndf_w2vtrace\n"
        "      REAL(KIND=r_def), intent(inout), dimension(undf_w0) "
        ":: field_1_w0\n"
        "      REAL(KIND=r_def), intent(in), dimension(undf_w2) "
        ":: field_3_w2\n"
        "      REAL(KIND=r_def), intent(out), dimension(undf_wtheta) "
        ":: field_5_wtheta\n"
        "      REAL(KIND=r_def), intent(in), dimension(undf_w2v) "
        ":: field_7_w2v\n"
        "      REAL(KIND=r_def), intent(in), dimension(undf_wchi) "
        ":: field_9_wchi\n"
        "      REAL(KIND=r_def), intent(inout), dimension(undf_w2htrace) "
        ":: field_11_w2htrace\n"
        "      INTEGER(KIND=i_def), intent(in) :: cell\n"
        "      INTEGER(KIND=i_def), intent(in) :: op_2_ncell_3d\n"
        "      REAL(KIND=r_def), intent(inout), dimension(ndf_w1,ndf_w1,"
        "op_2_ncell_3d) :: op_2\n"
        "      INTEGER(KIND=i_def), intent(in) :: op_4_ncell_3d\n"
        "      REAL(KIND=r_def), intent(out), dimension(ndf_w3,ndf_w3,"
        "op_4_ncell_3d) :: op_4\n"
        "      INTEGER(KIND=i_def), intent(in) :: op_6_ncell_3d\n"
        "      REAL(KIND=r_def), intent(inout), dimension(ndf_w2h,ndf_w2h,"
        "op_6_ncell_3d) :: op_6\n"
        "      INTEGER(KIND=i_def), intent(in) :: op_8_ncell_3d\n"
        "      REAL(KIND=r_def), intent(inout), dimension(ndf_w2broken,"
        "ndf_w2broken,op_8_ncell_3d) :: op_8\n"
        "      INTEGER(KIND=i_def), intent(in) :: op_10_ncell_3d\n"
        "      REAL(KIND=r_def), intent(out), dimension(ndf_w2trace,"
        "ndf_w2trace,op_10_ncell_3d) :: op_10\n"
        "      INTEGER(KIND=i_def), intent(in) :: op_12_ncell_3d\n"
        "      REAL(KIND=r_def), intent(in), dimension(ndf_w2vtrace,"
        "ndf_w2vtrace,op_12_ncell_3d) :: op_12\n"
        "      INTEGER(KIND=i_def), intent(in) :: np_xy_qr_xyoz, "
        "np_z_qr_xyoz\n"
        "      REAL(KIND=r_def), intent(in), dimension(1,ndf_w0,"
        "np_xy_qr_xyoz,np_z_qr_xyoz) :: basis_w0_qr_xyoz\n"
        "      REAL(KIND=r_def), intent(in), dimension(3,ndf_w1,"
        "np_xy_qr_xyoz,np_z_qr_xyoz) :: basis_w1_qr_xyoz\n"
        "      REAL(KIND=r_def), intent(in), dimension(3,ndf_w2,"
        "np_xy_qr_xyoz,np_z_qr_xyoz) :: basis_w2_qr_xyoz\n"
        "      REAL(KIND=r_def), intent(in), dimension(1,ndf_w3,"
        "np_xy_qr_xyoz,np_z_qr_xyoz) :: basis_w3_qr_xyoz\n"
        "      REAL(KIND=r_def), intent(in), dimension(1,ndf_wtheta,"
        "np_xy_qr_xyoz,np_z_qr_xyoz) :: basis_wtheta_qr_xyoz\n"
        "      REAL(KIND=r_def), intent(in), dimension(3,ndf_w2h,"
        "np_xy_qr_xyoz,np_z_qr_xyoz) :: basis_w2h_qr_xyoz\n"
        "      REAL(KIND=r_def), intent(in), dimension(3,ndf_w2v,"
        "np_xy_qr_xyoz,np_z_qr_xyoz) :: basis_w2v_qr_xyoz\n"
        "      REAL(KIND=r_def), intent(in), dimension(3,ndf_w2broken,"
        "np_xy_qr_xyoz,np_z_qr_xyoz) :: basis_w2broken_qr_xyoz\n"
        "      REAL(KIND=r_def), intent(in), dimension(1,ndf_wchi,"
        "np_xy_qr_xyoz,np_z_qr_xyoz) :: basis_wchi_qr_xyoz\n"
        "      REAL(KIND=r_def), intent(in), dimension(1,ndf_w2trace,"
        "np_xy_qr_xyoz,np_z_qr_xyoz) :: basis_w2trace_qr_xyoz\n"
        "      REAL(KIND=r_def), intent(in), dimension(1,ndf_w2htrace,"
        "np_xy_qr_xyoz,np_z_qr_xyoz) :: basis_w2htrace_qr_xyoz\n"
        "      REAL(KIND=r_def), intent(in), dimension(1,ndf_w2vtrace,"
        "np_xy_qr_xyoz,np_z_qr_xyoz) :: basis_w2vtrace_qr_xyoz\n"
        "      REAL(KIND=r_def), intent(in), dimension(np_xy_qr_xyoz) "
        ":: weights_xy_qr_xyoz\n"
        "      REAL(KIND=r_def), intent(in), dimension(np_z_qr_xyoz) "
        ":: weights_z_qr_xyoz\n"
        "    END SUBROUTINE dummy_code\n"
        "  END MODULE dummy_mod")
    assert output in generated_code
Esempio n. 24
0
def test_spaces():
    ''' Test that field spaces are handled correctly for kernel stubs.

    '''
    ast = fpapi.parse(SPACES, ignore_comments=False)
    metadata = DynKernMetadata(ast)
    kernel = DynKern()
    kernel.load_meta(metadata)
    generated_code = str(kernel.gen_stub)
    output = (
        "  MODULE dummy_mod\n"
        "    IMPLICIT NONE\n"
        "    CONTAINS\n"
        "    SUBROUTINE dummy_code(nlayers, field_1_w0, field_2_w1, "
        "field_3_w2, field_4_w2broken, field_5_w2trace, field_6_w3, "
        "field_7_wtheta, field_8_w2h, field_9_w2v, field_10_w2htrace, "
        "field_11_w2vtrace, field_12_wchi, "
        "ndf_w0, undf_w0, map_w0, ndf_w1, undf_w1, map_w1, "
        "ndf_w2, undf_w2, map_w2, ndf_w2broken, undf_w2broken, map_w2broken, "
        "ndf_w2trace, undf_w2trace, map_w2trace, ndf_w3, undf_w3, map_w3, "
        "ndf_wtheta, undf_wtheta, map_wtheta, ndf_w2h, undf_w2h, map_w2h, "
        "ndf_w2v, undf_w2v, map_w2v, ndf_w2htrace, undf_w2htrace, "
        "map_w2htrace, ndf_w2vtrace, undf_w2vtrace, map_w2vtrace, "
        "ndf_wchi, undf_wchi, map_wchi)\n"
        "      USE constants_mod, ONLY: r_def, i_def\n"
        "      IMPLICIT NONE\n"
        "      INTEGER(KIND=i_def), intent(in) :: nlayers\n"
        "      INTEGER(KIND=i_def), intent(in) :: ndf_w0\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(ndf_w0) :: map_w0\n"
        "      INTEGER(KIND=i_def), intent(in) :: ndf_w1\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(ndf_w1) :: map_w1\n"
        "      INTEGER(KIND=i_def), intent(in) :: ndf_w2\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(ndf_w2) :: map_w2\n"
        "      INTEGER(KIND=i_def), intent(in) :: ndf_w2broken\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(ndf_w2broken) "
        ":: map_w2broken\n"
        "      INTEGER(KIND=i_def), intent(in) :: ndf_w2h\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(ndf_w2h) "
        ":: map_w2h\n"
        "      INTEGER(KIND=i_def), intent(in) :: ndf_w2htrace\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(ndf_w2htrace) "
        ":: map_w2htrace\n"
        "      INTEGER(KIND=i_def), intent(in) :: ndf_w2trace\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(ndf_w2trace) "
        ":: map_w2trace\n"
        "      INTEGER(KIND=i_def), intent(in) :: ndf_w2v\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(ndf_w2v) "
        ":: map_w2v\n"
        "      INTEGER(KIND=i_def), intent(in) :: ndf_w2vtrace\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(ndf_w2vtrace) "
        ":: map_w2vtrace\n"
        "      INTEGER(KIND=i_def), intent(in) :: ndf_w3\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(ndf_w3) :: map_w3\n"
        "      INTEGER(KIND=i_def), intent(in) :: ndf_wchi\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(ndf_wchi) "
        ":: map_wchi\n"
        "      INTEGER(KIND=i_def), intent(in) :: ndf_wtheta\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(ndf_wtheta) "
        ":: map_wtheta\n"
        "      INTEGER(KIND=i_def), intent(in) :: undf_w0, undf_w1, undf_w2, "
        "undf_w2broken, undf_w2trace, undf_w3, undf_wtheta, undf_w2h, "
        "undf_w2v, undf_w2htrace, undf_w2vtrace, undf_wchi\n"
        "      REAL(KIND=r_def), intent(inout), dimension(undf_w0) "
        ":: field_1_w0\n"
        "      REAL(KIND=r_def), intent(inout), dimension(undf_w1) "
        ":: field_2_w1\n"
        "      REAL(KIND=r_def), intent(inout), dimension(undf_w2) "
        ":: field_3_w2\n"
        "      REAL(KIND=r_def), intent(inout), dimension(undf_w2broken) "
        ":: field_4_w2broken\n"
        "      REAL(KIND=r_def), intent(inout), dimension(undf_w2trace) "
        ":: field_5_w2trace\n"
        "      REAL(KIND=r_def), intent(inout), dimension(undf_w3) "
        ":: field_6_w3\n"
        "      REAL(KIND=r_def), intent(inout), dimension(undf_wtheta) "
        ":: field_7_wtheta\n"
        "      REAL(KIND=r_def), intent(inout), dimension(undf_w2h) "
        ":: field_8_w2h\n"
        "      REAL(KIND=r_def), intent(inout), dimension(undf_w2v) "
        ":: field_9_w2v\n"
        "      REAL(KIND=r_def), intent(inout), dimension(undf_w2htrace) "
        ":: field_10_w2htrace\n"
        "      REAL(KIND=r_def), intent(inout), dimension(undf_w2vtrace) "
        ":: field_11_w2vtrace\n"
        "      REAL(KIND=r_def), intent(in), dimension(undf_wchi) "
        ":: field_12_wchi\n"
        "    END SUBROUTINE dummy_code\n"
        "  END MODULE dummy_mod")
    assert output in generated_code
Esempio n. 25
0
def test_real_int_field_gen_stub():
    ''' Test that we generate correct code for kernel stubs that
    contain real- and integer-valued fields with basis and differential
    basis functions on one real- and one integer-valued field.

    '''
    code = FIELD_CODE.replace("func_type(w1, gh_basis),",
                              "func_type(w1, gh_basis, gh_diff_basis),", 1)
    ast = fpapi.parse(code, ignore_comments=False)
    metadata = DynKernMetadata(ast)
    kernel = DynKern()
    kernel.load_meta(metadata)
    generated_code = str(kernel.gen_stub)
    output = (
        "  MODULE testkern_field_mod\n"
        "    IMPLICIT NONE\n"
        "    CONTAINS\n"
        "    SUBROUTINE testkern_field_code(nlayers, rscalar_1, field_2_w1, "
        "field_3_w2, field_4_wtheta, field_5_w3, iscalar_6, ndf_w1, undf_w1, "
        "map_w1, basis_w1_qr_xyoz, diff_basis_w1_qr_xyoz, ndf_w2, undf_w2, "
        "map_w2, ndf_wtheta, undf_wtheta, map_wtheta, ndf_w3, undf_w3, "
        "map_w3, basis_w3_qr_xyoz, diff_basis_w3_qr_xyoz, np_xy_qr_xyoz, "
        "np_z_qr_xyoz, weights_xy_qr_xyoz, weights_z_qr_xyoz)\n"
        "      USE constants_mod, ONLY: r_def, i_def\n"
        "      IMPLICIT NONE\n"
        "      INTEGER(KIND=i_def), intent(in) :: nlayers\n"
        "      INTEGER(KIND=i_def), intent(in) :: ndf_w1\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(ndf_w1) :: map_w1\n"
        "      INTEGER(KIND=i_def), intent(in) :: ndf_w2\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(ndf_w2) :: map_w2\n"
        "      INTEGER(KIND=i_def), intent(in) :: ndf_w3\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(ndf_w3) :: map_w3\n"
        "      INTEGER(KIND=i_def), intent(in) :: ndf_wtheta\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(ndf_wtheta) :: "
        "map_wtheta\n"
        "      INTEGER(KIND=i_def), intent(in) :: undf_w1, undf_w2, "
        "undf_wtheta, undf_w3\n"
        "      REAL(KIND=r_def), intent(in) :: rscalar_1\n"
        "      INTEGER(KIND=i_def), intent(in) :: iscalar_6\n"
        "      REAL(KIND=r_def), intent(inout), dimension(undf_w1) :: "
        "field_2_w1\n"
        "      REAL(KIND=r_def), intent(in), dimension(undf_w2) :: "
        "field_3_w2\n"
        "      INTEGER(KIND=i_def), intent(inout), dimension(undf_wtheta) :: "
        "field_4_wtheta\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(undf_w3) :: "
        "field_5_w3\n"
        "      INTEGER(KIND=i_def), intent(in) :: np_xy_qr_xyoz, "
        "np_z_qr_xyoz\n"
        "      REAL(KIND=r_def), intent(in), dimension(3,ndf_w1,"
        "np_xy_qr_xyoz,np_z_qr_xyoz) :: basis_w1_qr_xyoz\n"
        "      REAL(KIND=r_def), intent(in), dimension(3,ndf_w1,"
        "np_xy_qr_xyoz,np_z_qr_xyoz) :: diff_basis_w1_qr_xyoz\n"
        "      REAL(KIND=r_def), intent(in), dimension(1,ndf_w3,"
        "np_xy_qr_xyoz,np_z_qr_xyoz) :: basis_w3_qr_xyoz\n"
        "      REAL(KIND=r_def), intent(in), dimension(3,ndf_w3,"
        "np_xy_qr_xyoz,np_z_qr_xyoz) :: diff_basis_w3_qr_xyoz\n"
        "      REAL(KIND=r_def), intent(in), dimension(np_xy_qr_xyoz) :: "
        "weights_xy_qr_xyoz\n"
        "      REAL(KIND=r_def), intent(in), dimension(np_z_qr_xyoz) :: "
        "weights_z_qr_xyoz\n"
        "    END SUBROUTINE testkern_field_code\n"
        "  END MODULE testkern_field_mod")
    assert output in generated_code
Esempio n. 26
0
def test_operators():
    ''' Test that operators are handled correctly for kernel stubs (except
    for Wchi space as the fields on this space are read-only).

    '''
    ast = fpapi.parse(OPERATORS, ignore_comments=False)
    metadata = DynKernMetadata(ast)
    kernel = DynKern()
    kernel.load_meta(metadata)
    generated_code = str(kernel.gen_stub)
    output = (
        "  MODULE dummy_mod\n"
        "    IMPLICIT NONE\n"
        "    CONTAINS\n"
        "    SUBROUTINE dummy_code(cell, nlayers, op_1_ncell_3d, op_1, "
        "op_2_ncell_3d, op_2, op_3_ncell_3d, op_3, op_4_ncell_3d, op_4, "
        "op_5_ncell_3d, op_5, op_6_ncell_3d, op_6, op_7_ncell_3d, op_7, "
        "op_8_ncell_3d, op_8, op_9_ncell_3d, op_9, op_10_ncell_3d, op_10, "
        "op_11_ncell_3d, op_11, op_12_ncell_3d, op_12, op_13_ncell_3d, "
        "op_13, ndf_w0, ndf_w1, ndf_w2, ndf_w2h, ndf_w2v, ndf_w2broken, "
        "ndf_w2trace, ndf_w2htrace, ndf_w2vtrace, ndf_w3, ndf_wtheta, "
        "ndf_aspc1_op_12, ndf_adspc1_op_13)\n"
        "      USE constants_mod, ONLY: r_def, i_def\n"
        "      IMPLICIT NONE\n"
        "      INTEGER(KIND=i_def), intent(in) :: nlayers\n"
        "      INTEGER(KIND=i_def), intent(in) :: ndf_w0, ndf_w1, ndf_w2, "
        "ndf_w2h, ndf_w2v, ndf_w2broken, ndf_w2trace, ndf_w2htrace, "
        "ndf_w2vtrace, ndf_w3, ndf_wtheta, ndf_aspc1_op_12, ndf_adspc1_op_13\n"
        "      INTEGER(KIND=i_def), intent(in) :: cell\n"
        "      INTEGER(KIND=i_def), intent(in) :: op_1_ncell_3d\n"
        "      REAL(KIND=r_def), intent(inout), dimension(ndf_w0,ndf_w0,"
        "op_1_ncell_3d) :: op_1\n"
        "      INTEGER(KIND=i_def), intent(in) :: op_2_ncell_3d\n"
        "      REAL(KIND=r_def), intent(inout), dimension(ndf_w1,ndf_w1,"
        "op_2_ncell_3d) :: op_2\n"
        "      INTEGER(KIND=i_def), intent(in) :: op_3_ncell_3d\n"
        "      REAL(KIND=r_def), intent(in), dimension(ndf_w2,ndf_w2,"
        "op_3_ncell_3d) :: op_3\n"
        "      INTEGER(KIND=i_def), intent(in) :: op_4_ncell_3d\n"
        "      REAL(KIND=r_def), intent(in), dimension(ndf_w2h,ndf_w2h,"
        "op_4_ncell_3d) :: op_4\n"
        "      INTEGER(KIND=i_def), intent(in) :: op_5_ncell_3d\n"
        "      REAL(KIND=r_def), intent(inout), dimension(ndf_w2v,ndf_w2v,"
        "op_5_ncell_3d) :: op_5\n"
        "      INTEGER(KIND=i_def), intent(in) :: op_6_ncell_3d\n"
        "      REAL(KIND=r_def), intent(inout), dimension(ndf_w2broken,"
        "ndf_w2broken,op_6_ncell_3d) :: op_6\n"
        "      INTEGER(KIND=i_def), intent(in) :: op_7_ncell_3d\n"
        "      REAL(KIND=r_def), intent(in), dimension(ndf_w2trace,"
        "ndf_w2trace,op_7_ncell_3d) :: op_7\n"
        "      INTEGER(KIND=i_def), intent(in) :: op_8_ncell_3d\n"
        "      REAL(KIND=r_def), intent(in), dimension(ndf_w2htrace,"
        "ndf_w2htrace,op_8_ncell_3d) :: op_8\n"
        "      INTEGER(KIND=i_def), intent(in) :: op_9_ncell_3d\n"
        "      REAL(KIND=r_def), intent(inout), dimension(ndf_w2vtrace,"
        "ndf_w2vtrace,op_9_ncell_3d) :: op_9\n"
        "      INTEGER(KIND=i_def), intent(in) :: op_10_ncell_3d\n"
        "      REAL(KIND=r_def), intent(inout), dimension(ndf_w3,ndf_w3,"
        "op_10_ncell_3d) :: op_10\n"
        "      INTEGER(KIND=i_def), intent(in) :: op_11_ncell_3d\n"
        "      REAL(KIND=r_def), intent(inout), dimension(ndf_wtheta,"
        "ndf_wtheta,op_11_ncell_3d) :: op_11\n"
        "      INTEGER(KIND=i_def), intent(in) :: op_12_ncell_3d\n"
        "      REAL(KIND=r_def), intent(in), dimension(ndf_aspc1_op_12,"
        "ndf_aspc1_op_12,op_12_ncell_3d) :: op_12\n"
        "      INTEGER(KIND=i_def), intent(in) :: op_13_ncell_3d\n"
        "      REAL(KIND=r_def), intent(in), dimension(ndf_adspc1_op_13,"
        "ndf_adspc1_op_13,op_13_ncell_3d) :: op_13\n"
        "    END SUBROUTINE dummy_code\n"
        "  END MODULE dummy_mod")
    assert output in generated_code