示例#1
0
def create_buffer_views_from_layout(layout, buffers, hubs, existing_view=None):
    if '@slice' in layout:
        buffer_nr = layout['@hub']
        feature_slice = slice(*layout['@slice'])
        structure = BufferStructure.from_layout(layout)
        full_buffer = structure.create_from_buffer_hub(
            buffers[buffer_nr], hubs[buffer_nr], feature_slice)
    else:
        full_buffer = None

    if layout['@type'] == 'BufferView':
        names, child_buffers = [], []
        for n, sub_node in sorted(layout.items(), key=sort_by_index_key):
            if n.startswith('@'):
                continue
            if existing_view:
                assert n in existing_view
                c = create_buffer_views_from_layout(
                    sub_node, buffers, hubs, existing_view=existing_view[n])
            else:
                c = create_buffer_views_from_layout(sub_node, buffers, hubs)
            names.append(n)
            child_buffers.append(c)

        if existing_view:
            return existing_view.adjust(names, child_buffers, full_buffer)
        else:
            return BufferView(names, child_buffers, full_buffer)
    else:  # layout['@type'] == 'array':
        assert full_buffer is not None, layout
        return full_buffer
示例#2
0
    def create(source_set, sink_set, layout, connections):
        def ensure_uniform(l):
            assert min(l) == max(l)
            return l[0]

        sorted_sources = sorted(source_set)
        flat_sources = list(flatten(sorted_sources))
        nesting = convert_to_nested_indices(sorted_sources)

        # get buffer type for hub and assert its uniform
        structs = [
            BufferStructure.from_layout(get_by_path(layout, s))
            for s in flat_sources
        ]
        btype = ensure_uniform([s.buffer_type for s in structs])
        # max context size
        context_size = max([s.context_size for s in structs])

        hub = Hub(flat_sources, nesting, sorted(sink_set), btype, context_size)
        hub.setup(connections)
        hub.sizes = [structs[i].feature_size for i in hub.perm]
        hub.size = sum(hub.sizes)
        hub.is_backward_only = ensure_uniform(
            [structs[i].is_backward_only for i in hub.perm])
        return hub
示例#3
0
def create_buffer_views_from_layout(layout, buffers, hubs, existing_view=None):
    if '@slice' in layout:
        buffer_nr = layout['@hub']
        feature_slice = slice(*layout['@slice'])
        structure = BufferStructure.from_layout(layout)
        full_buffer = structure.create_from_buffer_hub(buffers[buffer_nr],
                                                       hubs[buffer_nr],
                                                       feature_slice)
    else:
        full_buffer = None

    if layout['@type'] == 'BufferView':
        names, child_buffers = [], []
        for n, sub_node in sorted(layout.items(), key=sort_by_index_key):
            if n.startswith('@'):
                continue
            if existing_view:
                assert n in existing_view
                c = create_buffer_views_from_layout(
                    sub_node, buffers, hubs, existing_view=existing_view[n])
            else:
                c = create_buffer_views_from_layout(sub_node, buffers, hubs)
            names.append(n)
            child_buffers.append(c)

        if existing_view:
            return existing_view.adjust(names, child_buffers, full_buffer)
        else:
            return BufferView(names, child_buffers, full_buffer)
    else:  # layout['@type'] == 'array':
        assert full_buffer is not None, layout
        return full_buffer
示例#4
0
    def create(source_set, sink_set, layout, connections):
        def ensure_uniform(l):
            assert min(l) == max(l)
            return l[0]

        sorted_sources = sorted(source_set)
        flat_sources = list(flatten(sorted_sources))
        nesting = convert_to_nested_indices(sorted_sources)

        # get buffer type for hub and assert its uniform
        structs = [BufferStructure.from_layout(get_by_path(layout, s)) for s in flat_sources]
        btype = ensure_uniform([s.buffer_type for s in structs])
        # max context size
        context_size = max([s.context_size for s in structs])

        hub = Hub(flat_sources, nesting, sorted(sink_set), btype, context_size)
        hub.setup(connections)
        hub.sizes = [structs[i].feature_size for i in hub.perm]
        hub.size = sum(hub.sizes)
        hub.is_backward_only = ensure_uniform([structs[i].is_backward_only for i in hub.perm])
        return hub