Esempio n. 1
0
    def generate(cls, graph: Graph, **kwargs):
        if flags.DEBUG:
            traverse.dump(graph)

        memory_layout = allocate(graph)

        console.debug(
            f"[FallbackDescriptorGenerator] memory_layout total size: {memory_layout.total_size * 4}"
        )
        console.debug(
            f"[FallbackDescriptorGenerator] memory_layout static size: {memory_layout.static_size * 4}"
        )
        console.debug(
            f"[FallbackDescriptorGenerator] memory_layout dynamic size: {memory_layout.dynamic_size * 4}"
        )

        constant_encoder = ConstantEncoder.get_encoder(
            kwargs.get("constant_encoder_name", None))
        constants_bytes = constant_encoder.encode(memory_layout)

        console.debug(
            f"[FallbackDescriptorGenerator] constants encoded size: {len(constants_bytes)}"
        )

        descriptor = GraphDescriptor(kernels=cls.generate_kernels(
            graph, memory_layout),
                                     memory_layout=memory_layout,
                                     inputs=graph.inputs,
                                     outputs=graph.outputs,
                                     constants_encoding=constant_encoder.name,
                                     licenses=graph.licenses)

        return GraphExecutionData(graph, descriptor, constants_bytes)
Esempio n. 2
0
    def generate(cls, graph: Graph, **kwargs):
        graph, _ = WebGPUOptimizeRule().optimize(graph)
        if flags.DEBUG:
            traverse.dump(graph)

        memory_layout = allocate(graph)
        console.debug(f"[WebGPUDescriptorGenerator] memory_layout total size: {memory_layout.total_size * 4}[B]")
        console.debug(f"[WebGPUDescriptorGenerator] memory_layout static size: {memory_layout.static_size * 4}[B]")
        console.debug(f"[WebGPUDescriptorGenerator] memory_layout dynamic size: {memory_layout.dynamic_size * 4}[B]")

        constant_encoder = ConstantEncoder.get_encoder(kwargs.get("constant_encoder_name", None))
        constants_bytes = constant_encoder.encode(memory_layout)

        console.debug(f"[WebGPUDescriptorGenerator] constants encoded size: {len(constants_bytes)}[B]")

        kernels = cls.generate_kernels(graph, memory_layout)

        descriptor = GraphDescriptor(
            kernels=kernels,
            memory_layout=memory_layout,
            inputs=graph.inputs,
            outputs=graph.outputs,
            constants_encoding=constant_encoder.name,
            licenses=graph.licenses
        )

        if flags.optimize.VALIDATE_GENERATED_SOURCE:
            validate_kernel_source(descriptor)

        return GraphExecutionData(graph, descriptor, constants_bytes)
Esempio n. 3
0
    def generate(cls, graph: Graph, **kwargs):
        graph, _ = WebassemblyOptimizeRule().optimize(graph)
        if flags.DEBUG:
            traverse.dump(graph)

        memory_layout = allocate(graph)

        console.debug(
            f"[WebassemblyDescriptorGenerator] memory_layout total size: {memory_layout.total_size * 4}"
        )
        console.debug(
            f"[WebassemblyDescriptorGenerator] memory_layout static size: {memory_layout.static_size * 4}"
        )
        console.debug(
            f"[WebassemblyDescriptorGenerator] memory_layout dynamic size: {memory_layout.dynamic_size * 4}"
        )

        constant_encoder = ConstantEncoder.get_encoder(
            kwargs.get("constant_encoder_name", None))
        constants_bytes = constant_encoder.encode(memory_layout)

        console.debug(
            f"[WebassemblyDescriptorGenerator] constants encoded size: {len(constants_bytes)}"
        )

        kernels = cls.generate_kernels(graph, memory_layout)

        heap_block_size = 16 * 1024 * 1024
        if isinstance(memory_layout.dynamic_size, int):
            dynamic_size_byte_int = memory_layout.dynamic_size * 4
        else:
            dynamic_size_byte_int = kwargs.get("dynamic_allocation_size",
                                               heap_block_size)
        total_size_byte = memory_layout.static_size * 4 + dynamic_size_byte_int

        # required for calculation (size ceiling to one block) + one block
        required_heap = (
            (total_size_byte + heap_block_size - 1) // heap_block_size +
            1) * heap_block_size

        descriptor = GraphDescriptor(kernels=kernels,
                                     memory_layout=memory_layout,
                                     inputs=graph.inputs,
                                     outputs=graph.outputs,
                                     constants_encoding=constant_encoder.name,
                                     required_heap=required_heap,
                                     licenses=graph.licenses)

        return GraphExecutionData(graph, descriptor, constants_bytes)
Esempio n. 4
0
    def generate(cls, graph: Graph, **kwargs):
        graph, _ = WebGLOptimizeRule().optimize(graph)
        if flags.DEBUG:
            traverse.dump(graph)
            with open("cg.dot", "w") as f:
                f.write(traverse.dump_dot(graph))

        memory_layout = allocate(graph)

        allocations = {}
        for v, a in memory_layout.allocations.items():
            allocations[v] = WebGLAllocation(
                allocation=a, channel_mode=ChannelMode.get_mode(v))

        constants_map = {}
        for constant in traverse.filter_nodes(
                traverse.listup_nodes(graph),
                ConstantVariable):  # type: ConstantVariable
            constants_map[constant.name] = {
                "byte_offset": memory_layout[constant].offset * 4,
                "size": constant.size
            }

        constant_encoder = ConstantEncoder.get_encoder(
            kwargs.get("constant_encoder_name", None))
        constants_bytes = constant_encoder.encode(memory_layout)

        kernels = cls.generate_kernels(graph)

        descriptor = GraphDescriptor(kernels=kernels,
                                     memory_layout=memory_layout,
                                     inputs=graph.inputs,
                                     outputs=graph.outputs,
                                     constants_encoding=constant_encoder.name,
                                     allocations=allocations,
                                     constants_map=constants_map,
                                     licenses=graph.licenses)

        return GraphExecutionData(graph, descriptor, constants_bytes)