Пример #1
0
def test_multi_resource_communication_phase(slow_resource, mediocre_resource,
                                            fast_resource):
    read_phase = CommunicationPhase(
        name="read",
        resources=[slow_resource, mediocre_resource, fast_resource],
        direction="read",
    )
    write_phase = CommunicationPhase(
        name="write",
        resources=[slow_resource, mediocre_resource, fast_resource],
        direction="write",
    )

    expected_read_latency = (slow_resource.read_latency() +
                             mediocre_resource.read_latency() +
                             fast_resource.read_latency())
    expected_write_latency = (slow_resource.write_latency() +
                              mediocre_resource.write_latency() +
                              fast_resource.write_latency())
    assert expected_read_latency == read_phase.get_costs(0)
    assert expected_write_latency == write_phase.get_costs(0)

    assert int(
        round(expected_read_latency + 100 /
              slow_resource.read_throughput())) == read_phase.get_costs(100)
    assert int(
        round(expected_write_latency + 100 /
              slow_resource.write_throughput())) == write_phase.get_costs(100)
Пример #2
0
def test_single_phase_primitive(resource, mocker):
    read_phase = CommunicationPhase(name="read",
                                    resources=[resource],
                                    direction="read")
    write_phase = CommunicationPhase(name="write",
                                     resources=[resource],
                                     direction="write")
    src = mocker.Mock(name="src")
    sink = mocker.Mock(name="sink")
    prim = Primitive("prim")
    prim.add_consumer(sink, [read_phase])
    prim.add_producer(src, [write_phase])

    with pytest.raises(RuntimeError):
        prim.add_consumer(sink, [])
    with pytest.raises(RuntimeError):
        prim.add_producer(src, [])

    with pytest.raises(RuntimeError):
        prim.add_producer(sink, [read_phase])
    with pytest.raises(RuntimeError):
        prim.add_consumer(src, [write_phase])

    assert prim.static_consume_costs(sink) == read_phase.get_costs(8)
    assert prim.static_consume_costs(sink, 100) == read_phase.get_costs(100)

    assert prim.static_produce_costs(src) == write_phase.get_costs(8)
    assert prim.static_produce_costs(src, 100) == write_phase.get_costs(100)

    expected_costs_8 = write_phase.get_costs(8) + read_phase.get_costs(8)
    expected_costs_100 = write_phase.get_costs(100) + read_phase.get_costs(100)
    assert prim.static_costs(src, sink) == expected_costs_8
    assert prim.static_costs(src, sink, 100) == expected_costs_100
Пример #3
0
def test_single_resource_communication_phase(resource):
    read_phase = CommunicationPhase(name="read",
                                    resources=[resource],
                                    direction="read")
    write_phase = CommunicationPhase(name="write",
                                     resources=[resource],
                                     direction="write")

    assert resource.read_latency() == read_phase.get_costs(0)
    assert resource.write_latency() == write_phase.get_costs(0)

    assert int(
        round(resource.read_latency() +
              100 / resource.read_throughput())) == read_phase.get_costs(100)
    assert int(
        round(resource.write_latency() +
              100 / resource.write_throughput())) == write_phase.get_costs(100)