New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python models #3
Conversation
As described in https://github.com/verilator/verilator/blob/master/docs/CONTRIBUTING.adoc ** Have your patch include the addition of your name to docs/CONTRIBUTORS. (This was missing, so the regression failed). Thanks |
@wsnyder I should already be in the @patstew Maybe test the coverage addition? |
@madebr, you are certified, but if you're going to continue to use Anonymous Maartin rather than your other name, let me know as I'll also add that as otherwise it breaks this auto-test. Need a certification from @patstew. https://github.com/verilator/verilator/pull/3/checks?check_run_id=248461150 |
@wsnyder I'll |
9f1280a
to
a707ca3
Compare
I've just pushed a new version that addresses the issues raised on the bug tracker. I've renamed all Maarten's contributions to match his name in CONTRIBUTORS, I hope that's OK @madebr. |
1eb7736
to
e8996e9
Compare
This should have a green light on travis now, I've fixed the test failures. |
c05a392
to
c6d0381
Compare
The cmake files in the python pr should also be modified to use 2 spaces. You can btw squash my 3 python patches (and modify the author email address, the same with my patch in the cmake pr) |
ee5d9c3
to
2543094
Compare
include/verilated_py.cpp
Outdated
@@ -41,41 +41,34 @@ namespace py = pybind11; | |||
namespace vl_py { | |||
namespace impl { | |||
py::int_ read_port(const vluint32_t* words, size_t width, bool is_signed) { | |||
const size_t nb_words = (width + 31) / 32; | |||
const size_t nb_bytes = (width + 7) / 8; | |||
vluint8_t bytes[nb_bytes]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An alternative can be to use
std::vector<vluint8_t> buffer;
buffer.resize(nb_bytes);
I checked PyPy has _PyLong_FromByteArray since version 5.0.
But granted, I don't know the performance impact.
I believe encryption modules will be mostly impacted by this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I needed to get rid of the VLA because MSVC doesn't support them. The other issue is that if you have a signed integer that's not a multiple of 8 bits, then you'll get a positive number with _PyLong_FromByteArray because verilator doesn't sign extend. I suppose that could be fixed the same as I've done for small integers though. Maybe I'll switch it back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My performance claim is totally unfounded. I don't know whether this has impact.
Apparently, I did not check for this sign problem.
I think a test_regress would be useful.
86e5e9e
to
38e05f1
Compare
example.Verilated.calculate_unused_signals = False | ||
assert example.Verilated.calculate_unused_signals == False | ||
example.Verilated.calculate_unused_signals = True | ||
assert example.Verilated.calculate_unused_signals == True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert example.Verilated.profiling_threads_filename == "profile_threads.dat" | ||
|
||
example.Verilated.profiling_threads_start = 4 | ||
assert example.Verilated.profiling_threads_start == 4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
def test_signed_width_16(): | ||
"""Test properties of a signed 16 bit signal""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
def test_width_1(): | ||
"""Test basic properties of a 1 bit signal""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a.value = 42 | ||
a.cycle() | ||
assert example.Verilated.finished == True, "The default callback sets the global variable" | ||
assert example2.Verilated.finished == False, "and keep its hand of other global variables" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a2.cycle() | ||
|
||
assert example.Verilated.finished == True | ||
assert example2.Verilated.finished == False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
def test_threads_profiling_properties(): | ||
"""Test setting global profiling threads option""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
def test_width_128_2(): | ||
"""Test basic properties of an 128 bit signal (which is defined with start/end bit inex != 0)""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
def test_product_name_version(): | ||
"""Test fetching product_name and product_version""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
example.Verilated.profiling_threads_start = 4 | ||
assert example.Verilated.profiling_threads_start == 4 | ||
example.Verilated.profiling_threads_start = 0 | ||
assert example.Verilated.profiling_threads_start == 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
def test_assertions(): | ||
"""Test setting global assertions""" | ||
assert 'assertions' in dir(example.Verilated) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Test setting global profiling threads option""" | ||
assert 'profiling_threads_filename' in dir(example.Verilated) | ||
assert 'profiling_threads_start' in dir(example.Verilated) | ||
assert 'profiling_threads_window' in dir(example.Verilated) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
example.Verilated.reset_randomized = False | ||
assert example.Verilated.reset_randomized == False | ||
example.Verilated.reset_randomized = True | ||
assert example.Verilated.reset_randomized == True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
limit += 1 | ||
if limit > 1000: | ||
assert False, "hit limit" | ||
assert cb.finished == True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert example.Verilated.profiling_threads_start == 1 | ||
|
||
example.Verilated.profiling_threads_window = 9 | ||
assert example.Verilated.profiling_threads_window == 9 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert 'profiling_threads_window' in dir(example.Verilated) | ||
|
||
example.Verilated.profiling_threads_filename = "test.dat" | ||
assert example.Verilated.profiling_threads_filename == "test.dat" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vcd.dump(1) | ||
vcd.flush() | ||
vcd.close() | ||
assert vcd.closed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
def test_unsigned_width_64(): | ||
"""Test properties of an unsigned 64 bit signal""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps hopefully this will get refreshed, but as not being worked on closing out for now. |
Causes verilator to segfault when there's no DPI export, or produce bad code when there is $ ./test_regress/t/t_trace_split_cfuncs.pl -- debug --gdbbt Program received signal SIGSEGV, Segmentation fault. V3OutFormatter::puts (this=0x0, strg=0x5555562e2ba0 "\nvoid Vt_trace_split_cfuncs__Syms::_traceDump() {\n") at ../V3File.cpp:699 699 if (m_prependIndent && strg[0] != '\n') { #0 V3OutFormatter::puts (this=0x0, strg=0x5555562e2ba0 "\nvoid Vt_trace_split_cfuncs__Syms::_traceDump() {\n") at ../V3File.cpp:699 verilator#1 0x00005555559798f1 in V3OutFormatter::puts (strg=..., this=<optimized out>) at /usr/include/c++/9/bits/basic_string.h:2304 verilator#2 EmitCBaseVisitor::puts (str=..., this=0x7fffffffd8f0) at ../V3EmitCBase.h:58 verilator#3 EmitCSyms::emitSymImp (this=this@entry=0x7fffffffd8f0) at ../V3EmitCSyms.cpp:928 verilator#4 0x00005555559abe1e in EmitCSyms::visit (this=0x7fffffffd8f0, nodep=<optimized out>) at ../V3EmitCSyms.cpp:275 verilator#5 0x000055555579324a in AstNetlist::accept (this=<optimized out>, v=...) at ../V3AstNodes.h:9348 verilator#6 0x0000555555974795 in VNVisitor::iterate (nodep=0x555556255f80, this=0x7fffffffd8f0) at ../V3Ast.h:3245 verilator#7 EmitCSyms::EmitCSyms (dpiHdrOnly=false, nodep=0x555556255f80, this=0x7fffffffd8f0) at ../V3EmitCSyms.cpp:369 verilator#8 V3EmitC::emitcSyms (dpiHdrOnly=<optimized out>) at ../V3EmitCSyms.cpp:1071 verilator#9 0x0000555555742333 in process () at ../Verilator.cpp:524 verilator#10 0x0000555555742c7a in verilate (argString=...) at ../Verilator.cpp:607 verilator#11 0x0000555555745319 in main (argc=<optimized out>, argv=<optimized out>, env=<optimized out>) at ../Verilator.cpp:733 $ ./test_regress/t/t_trace_split_cfuncs_dpi_export.pl vlt/t_trace_split_cfuncs_dpi_export: %Error: Exec of make failed: g++ -I. -MMD -I/home/ubuntu/src/verilator/test_regress/../include -I/home/ubuntu/src/verilator/test_regress/../include/vltstd -DVM_COVERAGE=0 -DVM_SC=0 -DVM_TRACE=1 -DVM_TRACE_FST=0 -DVM_TRACE_VCD=1 -faligned-new -fcf-protection=none -Wno-bool-operation -Wno-sign-compare -Wno-uninitialized -Wno-unused-but-set-variable -Wno-unused-parameter -Wno-unused-variable -Wno-shadow -std=gnu++14 -DVERILATOR=1 -DVL_DEBUG=1 -DTEST_OBJ_DIR=obj_vlt/t_trace_split_cfuncs_dpi_export -DVM_PREFIX=Vt_trace_split_cfuncs_dpi_export -DVM_PREFIX_INCLUDE="<Vt_trace_split_cfuncs_dpi_export.h>" -DVM_PREFIX_ROOT_INCLUDE="<Vt_trace_split_cfuncs_dpi_export___024root.h>" -DT_TRACE_SPLIT_CFUNCS_DPI_EXPORT -O0 -c -o Vt_trace_split_cfuncs_dpi_export__main.o ../../obj_vlt/t_trace_split_cfuncs_dpi_export/Vt_trace_split_cfuncs_dpi_export__main.cpp
Causes verilator to segfault when there's no DPI export, or produce bad code when there is $ ./test_regress/t/t_trace_split_cfuncs.pl -- debug --gdbbt Program received signal SIGSEGV, Segmentation fault. V3OutFormatter::puts (this=0x0, strg=0x5555562e2ba0 "\nvoid Vt_trace_split_cfuncs__Syms::_traceDump() {\n") at ../V3File.cpp:699 699 if (m_prependIndent && strg[0] != '\n') { #0 V3OutFormatter::puts (this=0x0, strg=0x5555562e2ba0 "\nvoid Vt_trace_split_cfuncs__Syms::_traceDump() {\n") at ../V3File.cpp:699 verilator#1 0x00005555559798f1 in V3OutFormatter::puts (strg=..., this=<optimized out>) at /usr/include/c++/9/bits/basic_string.h:2304 verilator#2 EmitCBaseVisitor::puts (str=..., this=0x7fffffffd8f0) at ../V3EmitCBase.h:58 verilator#3 EmitCSyms::emitSymImp (this=this@entry=0x7fffffffd8f0) at ../V3EmitCSyms.cpp:928 verilator#4 0x00005555559abe1e in EmitCSyms::visit (this=0x7fffffffd8f0, nodep=<optimized out>) at ../V3EmitCSyms.cpp:275 verilator#5 0x000055555579324a in AstNetlist::accept (this=<optimized out>, v=...) at ../V3AstNodes.h:9348 verilator#6 0x0000555555974795 in VNVisitor::iterate (nodep=0x555556255f80, this=0x7fffffffd8f0) at ../V3Ast.h:3245 verilator#7 EmitCSyms::EmitCSyms (dpiHdrOnly=false, nodep=0x555556255f80, this=0x7fffffffd8f0) at ../V3EmitCSyms.cpp:369 verilator#8 V3EmitC::emitcSyms (dpiHdrOnly=<optimized out>) at ../V3EmitCSyms.cpp:1071 verilator#9 0x0000555555742333 in process () at ../Verilator.cpp:524 verilator#10 0x0000555555742c7a in verilate (argString=...) at ../Verilator.cpp:607 verilator#11 0x0000555555745319 in main (argc=<optimized out>, argv=<optimized out>, env=<optimized out>) at ../Verilator.cpp:733 $ ./test_regress/t/t_trace_split_cfuncs_dpi_export.pl vlt/t_trace_split_cfuncs_dpi_export: %Error: Exec of make failed: g++ -I. -MMD -I/home/ubuntu/src/verilator/test_regress/../include -I/home/ubuntu/src/verilator/test_regress/../include/vltstd -DVM_COVERAGE=0 -DVM_SC=0 -DVM_TRACE=1 -DVM_TRACE_FST=0 -DVM_TRACE_VCD=1 -faligned-new -fcf-protection=none -Wno-bool-operation -Wno-sign-compare -Wno-uninitialized -Wno-unused-but-set-variable -Wno-unused-parameter -Wno-unused-variable -Wno-shadow -std=gnu++14 -DVERILATOR=1 -DVL_DEBUG=1 -DTEST_OBJ_DIR=obj_vlt/t_trace_split_cfuncs_dpi_export -DVM_PREFIX=Vt_trace_split_cfuncs_dpi_export -DVM_PREFIX_INCLUDE="<Vt_trace_split_cfuncs_dpi_export.h>" -DVM_PREFIX_ROOT_INCLUDE="<Vt_trace_split_cfuncs_dpi_export___024root.h>" -DT_TRACE_SPLIT_CFUNCS_DPI_EXPORT -O0 -c -o Vt_trace_split_cfuncs_dpi_export__main.o ../../obj_vlt/t_trace_split_cfuncs_dpi_export/Vt_trace_split_cfuncs_dpi_export__main.cpp
This is the python support (on top of the CMake patches in #2) as discussed in issue #1489. I have added support for coverage, and made a couple of small fixes on top of Maarten's most recent work.