Ejemplo n.º 1
0
def test_lfric_stub_args():
    '''Check that correct stub code is produced when there are multiple
    stencils.

    '''
    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
Ejemplo n.º 2
0
def test_lfric_stub_cma_operators():
    '''Check variable usage detection cma operators.
    mesh_ncell2d, cma_operator

    '''
    from psyclone.dynamo0p3 import DynKernMetadata, DynKern
    from psyclone.domain.lfric import KernStubArgList
    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
Ejemplo n.º 3
0
def test_lfric_stub_boundary_dofs():
    '''Check variable usage detection for boundary dofs.

    '''
    ast = get_ast("dynamo0.3", "enforce_bc_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)
    assert "boundary_dofs_field_1: READ" in str(var_accesses)
Ejemplo n.º 4
0
def test_lfric_stub_indirection_dofmap():
    '''Check variable usage detection in indirection dofmap.
    '''
    ast = get_ast("dynamo0.3", "columnwise_op_app_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)
    assert "cma_indirection_map_aspc1_field_1: READ" in var_info
    assert "cma_indirection_map_aspc2_field_2: READ" in var_info
Ejemplo n.º 5
0
def test_lfric_stub_banded_dofmap():
    '''Check variable usage detection for banded dofmaps.

    '''
    ast = get_ast("dynamo0.3", "columnwise_op_asm_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)
    assert "cbanded_map_adspc1_op_1: READ" in var_info
    assert "cbanded_map_adspc2_op_1: READ" in var_info
Ejemplo n.º 6
0
def test_lfric_stub_boundary_dofmap():
    '''Check variable usage detection in boundary_dofs array fix
    for operators.

    '''
    from psyclone.dynamo0p3 import DynKernMetadata, DynKern
    from psyclone.domain.lfric import KernStubArgList
    ast = get_ast("dynamo0.3", "enforce_operator_bc_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)
    assert "boundary_dofs_op_1: READ" in str(var_accesses)
Ejemplo n.º 7
0
def test_lfric_stub_args3():
    '''Check variable usage detection for cell position, operator

    '''
    ast = get_ast("dynamo0.3", "testkern_any_discontinuous_space_op_1_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_3: READ" in var_info
    assert "op_3_ncell_3d: READ" in var_info
    assert "op_4: READ" in var_info
    assert "op_4_ncell_3d: READ" in var_info
Ejemplo n.º 8
0
def test_kernel_stub_invalid_scalar_argument():
    ''' Check that we raise an exception if an unexpected datatype is found
    when using the KernStubArgList scalar method. '''
    ast = get_ast(TEST_API, "testkern_one_int_scalar_mod.f90")

    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._argument_type = "invalid"
    # Now call KernStubArgList to raise an exception
    create_arg_list = KernStubArgList(kernel)
    with pytest.raises(InternalError) as excinfo:
        create_arg_list.scalar(arg)
    const = LFRicConstants()
    assert ("Expected argument type to be one of {0} but got "
            "'invalid'".format(const.VALID_SCALAR_NAMES) in str(excinfo.value))
Ejemplo n.º 9
0
def test_lfric_stub_basis():
    '''Check variable usage detection of basis, diff-basis.

    '''
    ast = get_ast("dynamo0.3", "testkern_qr_eval_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 "basis_w1_on_w1: READ" in var_info
    assert "diff_basis_w2_qr_face: READ" in var_info
    assert "diff_basis_w2_on_w1: READ" in var_info
    assert "basis_w3_on_w1: READ" in var_info
    assert "diff_basis_w3_qr_face: READ" in var_info
    assert "diff_basis_w3_on_w1: READ" in var_info
Ejemplo n.º 10
0
def test_lfric_stub_args2():
    '''Check variable usage detection for scalars, basis_name, quad rule
    and mesh properties.

    '''
    ast = get_ast("dynamo0.3", "testkern_mesh_prop_face_qr_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 "rscalar_1: READ" in var_info
    assert "basis_w1_qr_face: READ" in var_info
    assert "nfaces_qr_face: READ" in var_info
    assert "np_xyz_qr_face: READ" in var_info
    assert "weights_xyz_qr_face: READ" in var_info
Ejemplo n.º 11
0
def test_lfric_stub_field_vector():
    '''Check variable usage detection field vectors.

    '''
    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
Ejemplo n.º 12
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
Ejemplo n.º 13
0
def test_kernstubarglist_arglist_error():
    '''Check that we raise an exception if we call the arglist method in
    kernstubarglist without first calling the generate method'''
    ast = get_ast(TEST_API, "testkern_one_int_scalar_mod.f90")

    metadata = DynKernMetadata(ast)
    kernel = DynKern()
    kernel.load_meta(metadata)
    # Now call KernStubArgList to raise an exception
    create_arg_list = KernStubArgList(kernel)
    with pytest.raises(InternalError) as excinfo:
        _ = create_arg_list.arglist
    assert ("The argument list in KernStubArgList is "
            "empty. Has the generate() method been "
            "called?") in str(excinfo.value)
Ejemplo n.º 14
0
def test_refelem_stub_arglist_err():
    ''' Check that the KernStubArgList.ref_element_properties method raises
    the expected error if it encounters an unsupported property. '''
    # Create the Kernel object
    ast = get_ast(TEST_API, "testkern_ref_elem_all_faces_mod.F90")
    metadata = DynKernMetadata(ast)
    kernel = DynKern()
    kernel.load_meta(metadata)
    # Break the list of ref-element properties required by the Kernel
    kernel.reference_element.properties.append("Wrong property")
    with pytest.raises(InternalError) as err:
        KernStubArgList(kernel).generate()
    assert "('Wrong property') " in str(err.value)
    assert (
        "Supported properties are: ['Property.NORMALS_TO_HORIZONTAL_FACES', "
        "'Property.NORMALS_TO_VERTICAL_FACES', 'Property.NORMALS_TO_FACES', "
        "'Property.OUTWARD_NORMALS_TO_HORIZONTAL_FACES', "
        "'Property.OUTWARD_NORMALS_TO_VERTICAL_FACES', "
        "'Property.OUTWARD_NORMALS_TO_FACES']" in str(err.value))
Ejemplo n.º 15
0
def test_kernstubarglist_eval_shape_error():
    ''' Check that we raise the expected exception if we call the basis() or
    diff_basis() methods and one of the kernel's evaluator shapes is
    invalid. '''
    ast = get_ast(TEST_API, "testkern_qr_faces_mod.F90")
    metadata = DynKernMetadata(ast)
    kernel = DynKern()
    kernel.load_meta(metadata)
    create_arg_list = KernStubArgList(kernel)
    # Break the list of qr rules
    kernel.eval_shapes.insert(0, "broken")
    with pytest.raises(InternalError) as err:
        create_arg_list.basis(None)
    assert ("Unrecognised evaluator shape ('broken'). Expected one of: "
            "['gh_quadrature_xyoz'" in str(err.value))
    with pytest.raises(InternalError) as err:
        create_arg_list.diff_basis(None)
    assert ("Unrecognised evaluator shape ('broken'). Expected one of: "
            "['gh_quadrature_xyoz'" in str(err.value))
Ejemplo n.º 16
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 = get_ast(TEST_API, "testkern_one_int_scalar_mod.f90")
    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(InternalError) as excinfo:
        create_arg_list.indirection_dofmap("w3")
    assert "No CMA operator supplied" in str(excinfo.value)
    # Second, call it with an argument object but one that is not
    # an operator
    with pytest.raises(InternalError) 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.value)