Пример #1
0
def get_for_clauses(expr):
    # ...
    def _format_str(a):
        if isinstance(a, str):
            return a.strip('\'')
        else:
            return a
    # ...

    # ...
    d_attributs = {}
    d_args      = {}
    # ...

    # ... we first create a dictionary of attributs
    if isinstance(expr, Variable):
        if expr.cls_base:
            d_attributs = expr.cls_base.attributs_as_dict
    elif isinstance(expr, ConstructorCall):
        attrs = expr.attributs
        for i in attrs:
            d_attributs[str(i).replace('self.', '')] = i
    # ...

    # ...
    if not d_attributs:
        raise ValueError('Can not find attributs')
    # ...

    # ...
    if isinstance(expr, Variable):
        cls_base = expr.cls_base

        if not cls_base:
            return None, None

        if not(('openmp' in cls_base.options) and ('iterable' in cls_base.options)):
            return None, None
    elif isinstance(expr, ConstructorCall):
        # arguments[0] is 'self'
        # TODO must be improved in syntax, so that a['value'] is a sympy object
        for a in expr.arguments[1:]:
            if isinstance(a, dict):
                # we add '_' tp be conform with the private variables convention
                d_args['_{0}'.format(a['key'])] = a['value']
    else:
        return None, None
    # ...

    # ... get initial values for all attributs
    #     TODO do we keep 'self' hard coded?
    d = {}
    for k,v in d_attributs.items():
        i = DottedName('self', k)
        d[k] = get_initial_value(expr, i)
    # ...

    # ... update the dictionary with the class parameters
    for k,v in d_args.items():
        d[k] = d_args[k]
    # ...

    # ... initial values for clauses
    nowait       = None

    collapse     = None
    private      = None
    firstprivate = None
    lastprivate  = None
    reduction    = None
    schedule     = None
    ordered      = None
    linear       = None
    # ...

    # ... nowait
    nowait = d['_nowait']
    # ...

    # ... collapse
    if not(d['_collapse'] is None):
        if not isinstance(d['_collapse'], Nil):
            ls = [d['_collapse']]
            collapse = OMP_Collapse(*ls)
    # ...

    # ... private
    if not(d['_private'] is None):
        if not isinstance(d['_private'], Nil):
            ls = d['_private']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls = [_format_str(a) for a in ls]
            private = OMP_Private(*ls)
    # ...

    # ... firstprivate
    if not(d['_firstprivate'] is None):
        if not isinstance(d['_firstprivate'], Nil):
            ls = d['_firstprivate']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls = [_format_str(a) for a in ls]
            firstprivate = OMP_FirstPrivate(*ls)
    # ...

    # ... lastprivate
    if not(d['_lastprivate'] is None):
        if not isinstance(d['_lastprivate'], Nil):
            ls = d['_lastprivate']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls = [_format_str(a) for a in ls]
            lastprivate = OMP_LastPrivate(*ls)
    # ...

    # ... reduction
    if not(d['_reduction'] is None):
        if not isinstance(d['_reduction'], Nil):
            ls = d['_reduction']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls = [_format_str(a) for a in ls]
            reduction = OMP_Reduction(*ls)
    # ...

    # ... schedule
    if not(d['_schedule'] is None):
        if not isinstance(d['_schedule'], Nil):
            ls = d['_schedule']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls[0] = _format_str(ls[0])
            schedule = OMP_Schedule(*ls)
    # ...

    # ... ordered
    if not(d['_ordered'] is None):
        if not isinstance(d['_ordered'], Nil):
            ls = d['_ordered']

            args = []
            if isinstance(ls, (int, sp_Integer)):
                args.append(ls)

            ordered = OMP_Ordered(*args)
    # ...

    # ... linear
    if not(d['_linear'] is None):
        if not isinstance(d['_linear'], Nil):
            # we need to convert Tuple to list here
            ls = list(d['_linear'])

            if len(ls) < 2:
                raise ValueError('Expecting at least 2 entries, '
                                 'given {0}'.format(len(ls)))

            variables = [a.strip('\'') for a in ls[0:-1]]
            ls[0:-1]  = variables

            linear = OMP_Linear(*ls)
    # ...

    # ...
    clauses = (private, firstprivate, lastprivate,
               reduction, schedule,
               ordered, collapse, linear)
    clauses = [i for i in clauses if not(i is None)]
    clauses = Tuple(*clauses)
    # ...

    # ...
    info = {}
    info['nowait'] = nowait
    # ...

    return info, clauses
Пример #2
0
def get_for_clauses(expr):
    # ...
    def _format_str(a):
        if isinstance(a, str):
            return a.strip('\'')
        else:
            return a

    # ...

    # ...
    d_attributs = {}
    d_args = {}
    # ...

    # ... we first create a dictionary of attributs
    if isinstance(expr, Variable):
        if expr.cls_base:
            d_attributs = expr.cls_base.attributs_as_dict
    elif isinstance(expr, ConstructorCall):
        attrs = expr.attributs
        for i in attrs:
            d_attributs[str(i).replace('self.', '')] = i
    # ...

    # ...
    if not d_attributs:
        raise ValueError('Can not find attributs')
    # ...

    # ...
    if isinstance(expr, Variable):
        cls_base = expr.cls_base

        if not cls_base:
            return None, None

        if not (('openacc' in cls_base.options) and
                ('iterable' in cls_base.options)):
            return None, None
    elif isinstance(expr, ConstructorCall):
        # arguments[0] is 'self'
        # TODO must be improved in syntax, so that a['value'] is a sympy object
        for a in expr.arguments[1:]:
            if isinstance(a, dict):
                # we add '_' tp be conform with the private variables convention
                d_args['_{0}'.format(a['key'])] = a['value']
    else:
        return None, None
    # ...

    # ... get initial values for all attributs
    #     TODO do we keep 'self' hard coded?
    d = {}
    for k, v in d_attributs.items():
        i = DottedName('self', k)
        d[k] = get_initial_value(expr, i)
    # ...

    # ... update the dictionary with the class parameters
    for k, v in d_args.items():
        d[k] = d_args[k]
    # ...

    # ... initial values for clauses
    _collapse = None
    _gang = None
    _worker = None
    _vector = None
    _seq = None
    _auto = None
    _tile = None
    _device_type = None
    _independent = None
    _private = None
    _reduction = None
    # ...

    # ... auto
    if not (d['_auto'] is None):
        if not isinstance(d['_auto'], Nil):
            _auto = ACC_Auto()
    # ...

    # ... collapse
    if not (d['_collapse'] is None):
        if not isinstance(d['_collapse'], Nil):
            ls = [d['_collapse']]
            _collapse = ACC_Collapse(*ls)
    # ...

    # ... device_type
    if not (d['_device_type'] is None):
        if not isinstance(d['_device_type'], Nil):
            ls = d['_device_type']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls = [_format_str(a) for a in ls]
            _device_type = ACC_DeviceType(*ls)
    # ...

    # ... gang
    if not (d['_gang'] is None):
        if not isinstance(d['_gang'], Nil):
            ls = d['_gang']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls = [_format_str(a) for a in ls]
            _gang = ACC_Gang(*ls)
    # ...

    # ... independent
    if not (d['_independent'] is None):
        if not isinstance(d['_independent'], Nil):
            _independent = ACC_Independent()
    # ...

    # ... private
    if not (d['_private'] is None):
        if not isinstance(d['_private'], Nil):
            ls = d['_private']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls = [_format_str(a) for a in ls]
            _private = ACC_Private(*ls)
    # ...

    # ... reduction
    if not (d['_reduction'] is None):
        if not isinstance(d['_reduction'], Nil):
            ls = d['_reduction']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls = [_format_str(a) for a in ls]
            _reduction = ACC_Reduction(*ls)
    # ...

    # ... seq
    if not (d['_seq'] is None):
        if not isinstance(d['_seq'], Nil):
            _seq = ACC_Seq()
    # ...

    # ... tile
    if not (d['_tile'] is None):
        if not isinstance(d['_tile'], Nil):
            ls = d['_tile']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls = [_format_str(a) for a in ls]
            _tile = ACC_Tile(*ls)
    # ...

    # ... vector
    if not (d['_vector'] is None):
        if not isinstance(d['_vector'], Nil):
            ls = d['_vector']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls = [_format_str(a) for a in ls]
            _vector = ACC_Vector(*ls)
    # ...

    # ... worker
    if not (d['_worker'] is None):
        if not isinstance(d['_worker'], Nil):
            ls = d['_worker']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls = [_format_str(a) for a in ls]
            _worker = ACC_Worker(*ls)
    # ...

    # ...
    clauses = (_collapse, _gang, _worker, _vector, _seq, _auto, _tile,
               _device_type, _independent, _private, _reduction)

    clauses = [i for i in clauses if not (i is None)]
    clauses = Tuple(*clauses)
    # ...

    return clauses
Пример #3
0
def get_with_clauses(expr):
    # ...
    def _format_str(a):
        if isinstance(a, str):
            return a.strip('\'')
        else:
            return a
    # ...

    # ...
    d_attributs = {}
    d_args      = {}
    # ...

    # ... we first create a dictionary of attributs
    if isinstance(expr, Variable):
        if expr.cls_base:
            d_attributs = expr.cls_base.attributs_as_dict

    elif isinstance(expr, ConstructorCall):
        attrs = expr.attributs
        for i in attrs:
            d_attributs[str(i).replace('self.', '')] = i
    # ...

    # ...
    if not d_attributs:
        raise ValueError('Can not find attributs')
    # ...

    # ...
    if isinstance(expr, Variable):
        cls_base = expr.cls_base

        if not cls_base:
            return None

        if not(('openmp' in cls_base.options) and ('with' in cls_base.options)):
            return None
    elif isinstance(expr, ConstructorCall):
        # arguments[0] is 'self'
        # TODO must be improved in syntax, so that a['value'] is a sympy object
        for a in expr.arguments[1:]:
            if isinstance(a, dict):
                # we add '_' tp be conform with the private variables convention
                d_args['_{0}'.format(a['key'])] = a['value']
    else:
        return None
    # ...

    # ... get initial values for all attributs
    #     TODO do we keep 'self' hard coded?
    d = {}
    for k,v in d_attributs.items():
        i = DottedName('self', k)
        d[k] = get_initial_value(expr, i)
    # ...

    # ... update the dictionary with the class parameters
    for k,v in d_args.items():
        d[k] = d_args[k]
    # ...

    # ... initial values for clauses
    private      = None
    firstprivate = None
    shared       = None
    reduction    = None
    copyin       = None
    default      = None
    proc_bind    = None
    num_threads  = None
    if_test      = None
    # ...

    # ... private
    if not(d['_private'] is None):
        if not isinstance(d['_private'], Nil):
            ls = d['_private']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls = [_format_str(a) for a in ls]
            private = OMP_Private(*ls)
    # ...

    # ... firstprivate
    if not(d['_firstprivate'] is None):
        if not isinstance(d['_firstprivate'], Nil):
            ls = d['_firstprivate']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls = [_format_str(a) for a in ls]
            firstprivate = OMP_FirstPrivate(*ls)
    # ...

    # ... shared
    if not(d['_shared'] is None):
        if not isinstance(d['_shared'], Nil):
            ls = d['_shared']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls = [_format_str(a) for a in ls]
            shared = OMP_Shared(*ls)
    # ...

    # ... reduction
    if not(d['_reduction'] is None):
        if not isinstance(d['_reduction'], Nil):
            ls = d['_reduction']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls = [_format_str(a) for a in ls]
            reduction = OMP_Reduction(*ls)
    # ...

    # ... copyin
    if not(d['_copyin'] is None):
        if not isinstance(d['_copyin'], Nil):
            ls = d['_copyin']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls = [_format_str(a) for a in ls]
            copyin = OMP_Copyin(*ls)
    # ...

    # ... default
    if not(d['_default'] is None):
        if not isinstance(d['_default'], Nil):
            ls = d['_default']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls[0] = _format_str(ls[0])
            default = OMP_Default(*ls)
    # ...

    # ... proc_bind
    if not(d['_proc_bind'] is None):
        if not isinstance(d['_proc_bind'], Nil):
            ls = d['_proc_bind']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls[0] = _format_str(ls[0])
            proc_bind = OMP_ProcBind(*ls)
    # ...

    # ... num_threads
    #     TODO improve this to take any int expression for arg.
    #     see OpenMP specifications for num_threads clause
    if not(d['_num_threads'] is None):
        if not isinstance(d['_num_threads'], Nil):
            arg = d['_num_threads']
            ls = [arg]
            num_threads = OMP_NumThread(*ls)
    # ...

    # ... if_test
    #     TODO improve this to take any boolean expression for arg.
    #     see OpenMP specifications for if_test clause
    if not(d['_if_test'] is None):
        if not isinstance(d['_if_test'], Nil):
            arg = d['_if_test']
            ls = [arg]
            if_test = OMP_If(*ls)
    # ...

    # ...
    clauses = (private, firstprivate, shared,
               reduction, default, copyin,
               proc_bind, num_threads, if_test)
    clauses = [i for i in clauses if not(i is None)]
    clauses = Tuple(*clauses)
    # ...

    return clauses
Пример #4
0
def get_with_clauses(expr):
    # ...
    def _format_str(a):
        if isinstance(a, str):
            return a.strip('\'')
        else:
            return a

    # ...

    # ...
    d_attributs = {}
    d_args = {}
    # ...

    # ... we first create a dictionary of attributs
    if isinstance(expr, Variable):
        if expr.cls_base:
            d_attributs = expr.cls_base.attributs_as_dict
    elif isinstance(expr, ConstructorCall):
        attrs = expr.attributs
        for i in attrs:
            d_attributs[str(i).replace('self.', '')] = i
    # ...

    # ...
    if not d_attributs:
        raise ValueError('Can not find attributs')
    # ...

    # ...
    if isinstance(expr, Variable):
        cls_base = expr.cls_base

        if not cls_base:
            return None

        if not (('openacc' in cls_base.options) and
                ('with' in cls_base.options)):
            return None
    elif isinstance(expr, ConstructorCall):
        # arguments[0] is 'self'
        # TODO must be improved in syntax, so that a['value'] is a sympy object
        for a in expr.arguments[1:]:
            if isinstance(a, dict):
                # we add '_' tp be conform with the private variables convention
                d_args['_{0}'.format(a['key'])] = a['value']
    else:
        return None
    # ...

    # ... get initial values for all attributs
    #     TODO do we keep 'self' hard coded?
    d = {}
    for k, v in d_attributs.items():
        i = DottedName('self', k)
        d[k] = get_initial_value(expr, i)
    # ...

    # ... update the dictionary with the class parameters
    for k, v in d_args.items():
        d[k] = d_args[k]
    # ...

    # ... initial values for clauses
    _async = None
    _wait = None
    _num_gangs = None
    _num_workers = None
    _vector_length = None
    _device_type = None
    _if = None
    _reduction = None
    _copy = None
    _copyin = None
    _copyout = None
    _create = None
    _present = None
    _deviceptr = None
    _private = None
    _firstprivate = None
    _default = None
    # ...

    # ... async
    if not (d['_async'] is None):
        if not isinstance(d['_async'], Nil):
            ls = d['_async']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls = [_format_str(a) for a in ls]
            _async = ACC_Async(*ls)
    # ...

    # ... copy
    if not (d['_copy'] is None):
        if not isinstance(d['_copy'], Nil):
            ls = d['_copy']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls = [_format_str(a) for a in ls]
            _copy = ACC_Copy(*ls)
    # ...

    # ... copyin
    if not (d['_copyin'] is None):
        if not isinstance(d['_copyin'], Nil):
            ls = d['_copyin']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls = [_format_str(a) for a in ls]
            _copyin = ACC_Copyin(*ls)
    # ...

    # ... copyout
    if not (d['_copyout'] is None):
        if not isinstance(d['_copyout'], Nil):
            ls = d['_copyout']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls = [_format_str(a) for a in ls]
            _copyout = ACC_Copyout(*ls)
    # ...

    # ... create
    if not (d['_create'] is None):
        if not isinstance(d['_create'], Nil):
            ls = d['_create']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls = [_format_str(a) for a in ls]
            _create = ACC_Copyin(*ls)
    # ...

    # ... default
    if not (d['_default'] is None):
        if not isinstance(d['_default'], Nil):
            ls = d['_default']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls[0] = _format_str(ls[0])
            _default = ACC_Default(*ls)
    # ...

    # ... deviceptr
    if not (d['_deviceptr'] is None):
        if not isinstance(d['_deviceptr'], Nil):
            ls = d['_deviceptr']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls = [_format_str(a) for a in ls]
            _deviceptr = ACC_DevicePtr(*ls)
    # ...

    # ... devicetype
    if not (d['_device_type'] is None):
        if not isinstance(d['_device_type'], Nil):
            ls = d['_device_type']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls = [_format_str(a) for a in ls]
            _device_type = ACC_DeviceType(*ls)
    # ...

    # ... firstprivate
    if not (d['_firstprivate'] is None):
        if not isinstance(d['_firstprivate'], Nil):
            ls = d['_firstprivate']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls = [_format_str(a) for a in ls]
            _firstprivate = ACC_FirstPrivate(*ls)
    # ...

    # ... if
    #     TODO improve this to take any boolean expression for arg.
    #     see OpenACC specifications
    if not (d['_if'] is None):
        if not isinstance(d['_if'], Nil):
            arg = d['_if']
            ls = [arg]
            _if = ACC_If(*ls)
    # ...

    # ... num_gangs
    #     TODO improve this to take any int expression for arg.
    #     see OpenACC specifications
    if not (d['_num_gangs'] is None):
        if not isinstance(d['_num_gangs'], Nil):
            arg = d['_num_gangs']
            ls = [arg]
            _num_gangs = ACC_NumGangs(*ls)
    # ...

    # ... num_workers
    #     TODO improve this to take any int expression for arg.
    #     see OpenACC specifications
    if not (d['_num_workers'] is None):
        if not isinstance(d['_num_workers'], Nil):
            arg = d['_num_workers']
            ls = [arg]
            _num_workers = ACC_NumWorkers(*ls)
    # ...

    # ... present
    if not (d['_present'] is None):
        if not isinstance(d['_present'], Nil):
            ls = d['_present']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls = [_format_str(a) for a in ls]
            _present = ACC_Present(*ls)
    # ...

    # ... private
    if not (d['_private'] is None):
        if not isinstance(d['_private'], Nil):
            ls = d['_private']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls = [_format_str(a) for a in ls]
            _private = ACC_Private(*ls)
    # ...

    # ... reduction
    if not (d['_reduction'] is None):
        if not isinstance(d['_reduction'], Nil):
            ls = d['_reduction']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls = [_format_str(a) for a in ls]
            _reduction = ACC_Reduction(*ls)
    # ...

    # ... vector_length
    if not (d['_vector_length'] is None):
        if not isinstance(d['_vector_length'], Nil):
            arg = d['_vector_length']
            ls = [arg]
            _vector_length = ACC_VectorLength(*ls)
    # ...

    # ... wait
    if not (d['_wait'] is None):
        if not isinstance(d['_wait'], Nil):
            ls = d['_wait']
            if not isinstance(ls, (list, tuple, Tuple)):
                ls = [ls]

            ls = [_format_str(a) for a in ls]
            _wait = ACC_Wait(*ls)
    # ...

    # ...
    clauses = (_async, _wait, _num_gangs, _num_workers, _vector_length,
               _device_type, _if, _reduction, _copy, _copyin, _copyout,
               _create, _present, _deviceptr, _private, _firstprivate,
               _default)

    clauses = [i for i in clauses if not (i is None)]
    clauses = Tuple(*clauses)
    # ...

    return clauses