Code Monkey home page Code Monkey logo

Comments (4)

mballance avatar mballance commented on July 18, 2024

Hi @walido78, this is interesting. I can certainly see the difference from your profiles. I setup a small testcase (see below). The strange thing is that this testcase shows the opposite: 64 wildcard bins in a single coverpoint are more efficient than 64 individual coverpoints.

def test_wildcard_bin_perf(self):
class uut(object):
def __init__(self):
self.value = 0
@vsc.covergroup
class internal_coverage(object):
def __init__(self,uut):
##Coverpoint with bins for individual carry bits)
self.caryallcount=vsc.coverpoint(lambda: uut.value , bins={
str(63-i) : vsc.wildcard_bin("0b" + "x" * (63-i) + "1" + "x" * (i)) for i in range(64)})
@vsc.covergroup
class internal_coverage_split_cp(object):
def __init__(self,uut):
##Coverpoint with bins for individual carry bits)
self.cp0 =vsc.coverpoint(lambda: ((uut.value >> 0) & 1), bins={"1" : vsc.bin(1)})
self.cp1 =vsc.coverpoint(lambda: ((uut.value >> 1) & 1), bins={"1" : vsc.bin(1)})
self.cp2 =vsc.coverpoint(lambda: ((uut.value >> 2) & 1), bins={"1" : vsc.bin(1)})
self.cp3 =vsc.coverpoint(lambda: ((uut.value >> 3) & 1), bins={"1" : vsc.bin(1)})
self.cp4 =vsc.coverpoint(lambda: ((uut.value >> 4) & 1), bins={"1" : vsc.bin(1)})
self.cp5 =vsc.coverpoint(lambda: ((uut.value >> 5) & 1), bins={"1" : vsc.bin(1)})
self.cp6 =vsc.coverpoint(lambda: ((uut.value >> 6) & 1), bins={"1" : vsc.bin(1)})
self.cp7 =vsc.coverpoint(lambda: ((uut.value >> 7) & 1), bins={"1" : vsc.bin(1)})
self.cp8 =vsc.coverpoint(lambda: ((uut.value >> 8) & 1), bins={"1" : vsc.bin(1)})
self.cp9 =vsc.coverpoint(lambda: ((uut.value >> 9) & 1), bins={"1" : vsc.bin(1)})
self.cp10 =vsc.coverpoint(lambda: ((uut.value >> 10) & 1), bins={"1" : vsc.bin(1)})
self.cp11 =vsc.coverpoint(lambda: ((uut.value >> 11) & 1), bins={"1" : vsc.bin(1)})
self.cp12 =vsc.coverpoint(lambda: ((uut.value >> 12) & 1), bins={"1" : vsc.bin(1)})
self.cp13 =vsc.coverpoint(lambda: ((uut.value >> 13) & 1), bins={"1" : vsc.bin(1)})
self.cp14 =vsc.coverpoint(lambda: ((uut.value >> 14) & 1), bins={"1" : vsc.bin(1)})
self.cp15 =vsc.coverpoint(lambda: ((uut.value >> 15) & 1), bins={"1" : vsc.bin(1)})
self.cp16 =vsc.coverpoint(lambda: ((uut.value >> 16) & 1), bins={"1" : vsc.bin(1)})
self.cp17 =vsc.coverpoint(lambda: ((uut.value >> 17) & 1), bins={"1" : vsc.bin(1)})
self.cp18 =vsc.coverpoint(lambda: ((uut.value >> 18) & 1), bins={"1" : vsc.bin(1)})
self.cp19 =vsc.coverpoint(lambda: ((uut.value >> 19) & 1), bins={"1" : vsc.bin(1)})
self.cp20 =vsc.coverpoint(lambda: ((uut.value >> 20) & 1), bins={"1" : vsc.bin(1)})
self.cp21 =vsc.coverpoint(lambda: ((uut.value >> 21) & 1), bins={"1" : vsc.bin(1)})
self.cp22 =vsc.coverpoint(lambda: ((uut.value >> 22) & 1), bins={"1" : vsc.bin(1)})
self.cp23 =vsc.coverpoint(lambda: ((uut.value >> 23) & 1), bins={"1" : vsc.bin(1)})
self.cp24 =vsc.coverpoint(lambda: ((uut.value >> 24) & 1), bins={"1" : vsc.bin(1)})
self.cp25 =vsc.coverpoint(lambda: ((uut.value >> 25) & 1), bins={"1" : vsc.bin(1)})
self.cp26 =vsc.coverpoint(lambda: ((uut.value >> 26) & 1), bins={"1" : vsc.bin(1)})
self.cp27 =vsc.coverpoint(lambda: ((uut.value >> 27) & 1), bins={"1" : vsc.bin(1)})
self.cp28 =vsc.coverpoint(lambda: ((uut.value >> 28) & 1), bins={"1" : vsc.bin(1)})
self.cp29 =vsc.coverpoint(lambda: ((uut.value >> 29) & 1), bins={"1" : vsc.bin(1)})
self.cp30 =vsc.coverpoint(lambda: ((uut.value >> 30) & 1), bins={"1" : vsc.bin(1)})
self.cp31 =vsc.coverpoint(lambda: ((uut.value >> 31) & 1), bins={"1" : vsc.bin(1)})
self.cp32 =vsc.coverpoint(lambda: ((uut.value >> 32) & 1), bins={"1" : vsc.bin(1)})
self.cp33 =vsc.coverpoint(lambda: ((uut.value >> 33) & 1), bins={"1" : vsc.bin(1)})
self.cp34 =vsc.coverpoint(lambda: ((uut.value >> 34) & 1), bins={"1" : vsc.bin(1)})
self.cp35 =vsc.coverpoint(lambda: ((uut.value >> 35) & 1), bins={"1" : vsc.bin(1)})
self.cp36 =vsc.coverpoint(lambda: ((uut.value >> 36) & 1), bins={"1" : vsc.bin(1)})
self.cp37 =vsc.coverpoint(lambda: ((uut.value >> 37) & 1), bins={"1" : vsc.bin(1)})
self.cp38 =vsc.coverpoint(lambda: ((uut.value >> 38) & 1), bins={"1" : vsc.bin(1)})
self.cp39 =vsc.coverpoint(lambda: ((uut.value >> 39) & 1), bins={"1" : vsc.bin(1)})
self.cp40 =vsc.coverpoint(lambda: ((uut.value >> 40) & 1), bins={"1" : vsc.bin(1)})
self.cp41 =vsc.coverpoint(lambda: ((uut.value >> 41) & 1), bins={"1" : vsc.bin(1)})
self.cp42 =vsc.coverpoint(lambda: ((uut.value >> 42) & 1), bins={"1" : vsc.bin(1)})
self.cp43 =vsc.coverpoint(lambda: ((uut.value >> 43) & 1), bins={"1" : vsc.bin(1)})
self.cp44 =vsc.coverpoint(lambda: ((uut.value >> 44) & 1), bins={"1" : vsc.bin(1)})
self.cp45 =vsc.coverpoint(lambda: ((uut.value >> 45) & 1), bins={"1" : vsc.bin(1)})
self.cp46 =vsc.coverpoint(lambda: ((uut.value >> 46) & 1), bins={"1" : vsc.bin(1)})
self.cp47 =vsc.coverpoint(lambda: ((uut.value >> 47) & 1), bins={"1" : vsc.bin(1)})
self.cp48 =vsc.coverpoint(lambda: ((uut.value >> 48) & 1), bins={"1" : vsc.bin(1)})
self.cp49 =vsc.coverpoint(lambda: ((uut.value >> 49) & 1), bins={"1" : vsc.bin(1)})
self.cp50 =vsc.coverpoint(lambda: ((uut.value >> 50) & 1), bins={"1" : vsc.bin(1)})
self.cp51 =vsc.coverpoint(lambda: ((uut.value >> 51) & 1), bins={"1" : vsc.bin(1)})
self.cp52 =vsc.coverpoint(lambda: ((uut.value >> 52) & 1), bins={"1" : vsc.bin(1)})
self.cp53 =vsc.coverpoint(lambda: ((uut.value >> 53) & 1), bins={"1" : vsc.bin(1)})
self.cp54 =vsc.coverpoint(lambda: ((uut.value >> 54) & 1), bins={"1" : vsc.bin(1)})
self.cp55 =vsc.coverpoint(lambda: ((uut.value >> 55) & 1), bins={"1" : vsc.bin(1)})
self.cp56 =vsc.coverpoint(lambda: ((uut.value >> 56) & 1), bins={"1" : vsc.bin(1)})
self.cp57 =vsc.coverpoint(lambda: ((uut.value >> 57) & 1), bins={"1" : vsc.bin(1)})
self.cp58 =vsc.coverpoint(lambda: ((uut.value >> 58) & 1), bins={"1" : vsc.bin(1)})
self.cp59 =vsc.coverpoint(lambda: ((uut.value >> 59) & 1), bins={"1" : vsc.bin(1)})
self.cp60 =vsc.coverpoint(lambda: ((uut.value >> 60) & 1), bins={"1" : vsc.bin(1)})
self.cp61 =vsc.coverpoint(lambda: ((uut.value >> 61) & 1), bins={"1" : vsc.bin(1)})
self.cp62 =vsc.coverpoint(lambda: ((uut.value >> 62) & 1), bins={"1" : vsc.bin(1)})
self.cp63 =vsc.coverpoint(lambda: ((uut.value >> 63) & 1), bins={"1" : vsc.bin(1)})
uut_i = uut()
cg = internal_coverage(uut_i)
cg_split = internal_coverage_split_cp(uut_i)
count_wc = 10000
start_wc_ms = int(round(time.time() * 1000))
for i in range(count_wc):
cg.sample()
end_wc_ms = int(round(time.time() * 1000))
count_split = 10000
start_split_ms = int(round(time.time() * 1000))
for i in range(count_split):
cg_split.sample()
end_split_ms = int(round(time.time() * 1000))
print("Sample wildcard bins %d times in %dmS" % (count_wc, (end_wc_ms-start_wc_ms)))
print("Sample split bins %d times in %dmS" % (count_split, (end_split_ms-start_split_ms)))

Looking more deeply at the profiles, it appears that accessing the whole value of addr in cocotb takes more time than accessing individual bits of addr. Note, for example, the calls to binary.py:37(resolve) and binary.py:396(binstr) that only appear in the 'wildcard' version of the test.

I do also see an area where PyVSC could help. From the profile, it appears that PyVSC is fetching the coverpoint value each time it is sampled. It should be possible for PyVSC to cache the sampled value and reuse it. This would at least minimize the overhead imposed by cocotb fetching the full value of signals.

from pyvsc.

mballance avatar mballance commented on July 18, 2024

Hi @walido78, I've released a new version of PyVSC (0.7.6) that implements per-coverpoint caching of the coverpoint target-expression value. Previously, the target value would be computed each time a bin in the coverpoint was sampled. Now, the target value is sampled once per coverpoint regardless of how many bins are in that coverpoint.
I'll be interested to see how the performance changes for you. Unless cocotb is >64x slower fetching the value of 'addr' vs fetching a single bit, your single-coverpoint version should be faster than the 64-coverpoint version now.

from pyvsc.

walido78 avatar walido78 commented on July 18, 2024

Hi @mballance , I actually tried with the new version and it's wayyy faster than I expected ! The profiling takes 9 seconds instead of 27 seconds !
Thank you very much

Cyc 0015219: INFO     **************************************Profiling ****************************************
         12460588 function calls (12384113 primitive calls) in 9.334 seconds

   Ordered by: cumulative time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
65543/44550    0.085    0.000    8.114    0.000 scheduler.py:330(react)
    44548    0.474    0.000    8.045    0.000 scheduler.py:355(_event_loop)
71689/65543    0.248    0.000    7.174    0.000 scheduler.py:744(schedule)
71689/65543    0.065    0.000    5.735    0.000 decorators.py:137(_advance)
71689/65543    0.036    0.000    5.671    0.000 outcomes.py:35(send)
71689/65543    0.035    0.000    5.637    0.000 {method 'send' of 'coroutine' objects}
     7425    0.046    0.000    4.308    0.001 sampler.py:23(sampler)
    22272    0.069    0.000    3.884    0.000 coverage.py:114(sample)
44544/22272    0.193    0.000    3.747    0.000 covergroup_model.py:64(sample)
   103936    0.341    0.000    3.435    0.000 coverpoint_model.py:185(sample)
  1395712    0.284    0.000    1.799    0.000 coverpoint_model.py:225(get_val)
    51968    0.035    0.000    1.516    0.000 expr_ref_model.py:33(val)
   950272    0.663    0.000    1.373    0.000 coverpoint_bin_single_wildcard_model.py:27(sample)
   311808    0.246    0.000    1.212    0.000 coverpoint_bin_single_bag_model.py:75(sample)
   118920    0.750    0.000    1.202    0.000 stagemanager.py:55(set_stage_name)
     4609    0.007    0.000    0.994    0.000 decorators.py:257(_advance)
    67849    0.167    0.000    0.991    0.000 scheduler.py:524(_resume_coro_upon)
     4609    0.021    0.000    0.978    0.000 calc1_tb.py:105(test_cmds)
    61440    0.102    0.000    0.934    0.000 handle.py:718(value)

from pyvsc.

mballance avatar mballance commented on July 18, 2024

Excellent, @walido78! Thanks for sharing the updated results!

from pyvsc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.