Ejemplo n.º 1
0
def get_optimal_block_config(
        npu_op: vapi.NpuOperation,
        accel_config: vapi.NpuAccelerator) -> vapi.NpuShape3D:
    """
    "The NPU's unit of work is known as a block. It will fetch block(s) from Input
    Feature Map (IFM) and a compute block for Output Feature Map (OFM).
    Therefore, we need to pick an optimal block configuration considering bandwidth
    to bring IFM blocks and the number of OFM block computes need to happen
    to cover the OFM as indicated by the npu op.

    Parameters
    ----------
    npu_op : ethosu.vela.api.NpuOperation
        The NPU operation and its params
    accel_config : ethosu.vela.api.NpuAccelerator
        The NPU accelerator config

    Returns
    -------
    ethosu.vela.api.NpuShape3D :
        The optimal block config for the operator
    """
    options = tvm.transform.PassContext.current().config.get(
        "relay.ext.ethos-u.options", None)
    if options and options.dev_force_block_config:
        block_config = [
            int(v) for v in options.dev_force_block_config.split("x")
        ]
        return vapi.NpuShape3D(height=block_config[0],
                               width=block_config[1],
                               depth=block_config[2])
    all_valid_block_configs = vapi.npu_find_block_configs(npu_op, accel_config)
    return _get_optimal_block_config(all_valid_block_configs)
Ejemplo n.º 2
0
def get_optimal_block_config(
        npu_op: vapi.NpuOperation,
        accel_config: vapi.NpuAccelerator) -> vapi.NpuShape3D:
    """
    "The NPU's unit of work is known as a block. It will fetch block(s) from Input
    Feature Map (IFM) and a compute block for Output Feature Map (OFM).
    Therefore, we need to pick an optimal block configuration considering bandwidth
    to bring IFM blocks and the number of OFM block computes need to happen
    to cover the OFM as indicated by the npu op.

    Parameters
    ----------
    npu_op : ethosu.vela.api.NpuOperation
        The NPU operation and its params
    accel_config : ethosu.vela.api.NpuAccelerator
        The NPU accelerator config

    Returns
    -------
    ethosu.vela.api.NpuShape3D :
        The optimal block config for the operator
    """
    all_valid_block_configs = vapi.npu_find_block_configs(npu_op, accel_config)
    return _get_optimal_block_config(all_valid_block_configs)