Example #1
0
def trans(psy):
    '''
    Transformation routine for use with PSyclone. Applies the OpenCL
    transform to the first Invoke in the psy object.

    :param psy: the PSy object which this script will transform.
    :type psy: :py:class:`psyclone.psyGen.PSy`
    :returns: the transformed PSy object.
    :rtype: :py:class:`psyclone.psyGen.PSy`

    '''
    ocl_trans = OCLTrans()
    fold_trans = FoldConditionalReturnExpressionsTrans()
    move_boundaries_trans = GOMoveIterationBoundariesInsideKernelTrans()

    # Get the Schedule associated with the first Invoke
    invoke = psy.invokes.invoke_list[0]
    sched = invoke.schedule

    # Transform the Schedule
    ocl_trans.apply(sched, options={"end_barrier": True})

    # Provide kernel-specific OpenCL optimization options
    for kern in sched.kernels():
        # Move the PSy-layer loop boundaries inside the kernel as a kernel
        # mask, this allows to iterate through the whole domain
        move_boundaries_trans.apply(kern)
        # Change the syntax to remove the return statements introduced by the
        # previous transformation
        fold_trans.apply(kern.get_kernel_schedule())
        # Specify the OpenCL queue and workgroup size of the kernel
        kern.set_opencl_options({"queue_number": 1, 'local_size': 4})

    return psy
def test_transformation(fortran_reader, fortran_writer, test_case):
    ''' Check that the transformation works as expected. '''
    input_code, expected = test_cases[test_case]
    trans = FoldConditionalReturnExpressionsTrans()
    subroutine = fortran_reader.psyir_from_source(input_code)
    trans.apply(subroutine)
    assert fortran_writer(subroutine) == expected
def test_validation():
    ''' Check that the transformation can only be applied to routine nodes '''
    trans = FoldConditionalReturnExpressionsTrans()
    with pytest.raises(TransformationError) as info:
        trans.apply(None)
    assert ("Error in FoldConditionalReturnExpressionsTrans transformation. "
            "This transformation can only be applied to 'Routine' nodes, but "
            "found 'NoneType'." in str(info.value))
Example #4
0
def test_transformation(parser, test_case):
    ''' Check that the transformation works as expected. '''
    input_code, expected = test_cases[test_case]
    trans = FoldConditionalReturnExpressionsTrans()
    processor = Fparser2Reader()
    reader = FortranStringReader(input_code)
    parse_tree = parser(reader)
    subroutine = processor.generate_psyir(parse_tree)
    trans.apply(subroutine)
    writer = FortranWriter()
    assert writer(subroutine) == expected
def test_description():
    ''' Check that the transformation returns the expected strings '''
    trans = FoldConditionalReturnExpressionsTrans()
    assert trans.name == "FoldConditionalReturnExpressionsTrans"
    assert str(trans) == ("Re-structure kernel statements to eliminate "
                          "conditional Return expressions.")