question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Change VPI callback for ReadWrite

See original GitHub issue

Discussion of proposed solution following #1611. #1060 likely related.

Background

After waiting on an edge trigger on a signal, we exist in a state where computations based on the change in value on the signal have not been resolved. Reading values at this point yields previous values for the related signals. If want to read the resolved values and respond in the same time cycle (modelling combinational logic), we need to move to a state where the HDL assignments are resolved, but we can still write values. This is the point of ReadWrite.

We currently use the cbReadWriteSynch trigger to move us into that context; however, as https://github.com/cocotb/cocotb/issues/1611#issuecomment-613076767 points out, there is some contention on what that trigger actually means. @themperek has done investigative testing showing that Questa and VCS’s implementation of cbReadWriteSynch do not put us after the values resolve. So the ReadWrite trigger behaves differently under different simulators. There is no proper way to model combinational logic in cocotb in those simulators (you could still use NextTimeStep or Timer(1), but the timing will be off).

Solution

If we move the implementation of ReadWrite to use the cbAtEndOfSimTime trigger, VCS will function as intended. However, Questa’s VPI implementation does not implement this trigger. So with Questa we can choose between an implementation of cbReadWriteSynch that doesn’t work how we want it to, or something that doesn’t work at all. We should leave Questa alone for right now, the regressions pass and existing code (likely) works and will continue to work.

Kudos to @themperek for doing all the investigative legwork on this.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
themperekcommented, Apr 16, 2020

Maybe on simple D flip-flop ?

import random
import cocotb
from cocotb.triggers import RisingEdge, ReadWrite, Timer

async def custom_clock(dut):
    while True:
        dut.clk <= 0
        await Timer(5, units="us")
        dut.clk <= 1
        await Timer(5, units="us")

@cocotb.test()
async def test_dff_simple(dut):

    cocotb.fork(custom_clock(dut))

    for i in range(10):
        val = random.randint(0, 1)
        dut.d <= val
        await RisingEdge(dut.clk)
        await ReadWrite() # fails to sample correct dut.q
        #await Timer(1) # works
        assert dut.q == val, "output q was incorrect on the {}th cycle".format(i)
1reaction
mballancecommented, Apr 16, 2020

@imphil, good question. I’ll be happy to take a look at it myself initially, though it won’t be until the weekend. Is there a testcase that I can use to observe the current behavior?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Synchronizing to Simulations Using VPI Callbacks
Registering callbacks for when logic value changes occur ... VPI standard refers to these calls as callback routines to the PLI application. The...
Read more >
SystemVerilog VPI release a callback handle after a ...
I do it using a callback function release_reg() triggered by cbForce . My issue is that because I am looping over many nets...
Read more >
ModelSim User's Manual - Microsemi
This document is for information and instruction purposes. Mentor Graphics reserves the right to make changes in specifications and other information contained ...
Read more >
VCS/VCSi User Guide
Integrating a VPI Application With VCS. ... VCSD/PLI (acc/vpi) that needs to use value change callbacks on memories or ... read - write...
Read more >
NVIDIA DRIVE OS 5.2 Linux SDK Developer Guide : NvMedia ...
This section discusses the NvMedia API changes between DRIVE OS 5.2.0.0 and ... use queue-based SetPiplelineCfg() instead of the callback-based version.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found