Skip to content
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

Closed
wants to merge 3 commits into from
Closed

Python models #3

wants to merge 3 commits into from

Conversation

patstew
Copy link
Contributor

@patstew patstew commented Oct 4, 2019

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.

@wsnyder
Copy link
Member

wsnyder commented Oct 4, 2019

As described in https://github.com/verilator/verilator/blob/master/docs/CONTRIBUTING.adoc
please certify your source-code contributions are open source. Either:

** Have your patch include the addition of your name to docs/CONTRIBUTORS. (This was missing, so the regression failed).
** Or, use "git -s" as part of your commit.
** Or, email, or post a statement that you certify your contributions.

Thanks

@madebr
Copy link
Contributor

madebr commented Oct 4, 2019

@wsnyder I should already be in the CONTRIBUTORS list.

@patstew Maybe test the coverage addition?
I should also say that I completely rewrote src/V3EmitPy.cpp in my pydpi branch.
This pydpi branch is not merge worthy yet as the python dpi example should be converted into a regression test.

@wsnyder
Copy link
Member

wsnyder commented Oct 4, 2019

@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
dist/t_dist_contributors: %Warning: dist/t_dist_contributors: Certify your contribution by appending 'Patrick Stewart' to CONTRIBUTORS
dist/t_dist_contributors: %Error: Certify your contribution by appending 'Anonymous Maarten' to CONTRIBUTORS

@madebr
Copy link
Contributor

madebr commented Oct 4, 2019

@wsnyder I'll git config change my name for this repo.

@patstew patstew force-pushed the python branch 2 times, most recently from 9f1280a to a707ca3 Compare October 7, 2019 17:07
@patstew
Copy link
Contributor Author

patstew commented Oct 7, 2019

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.

@patstew patstew force-pushed the python branch 6 times, most recently from 1eb7736 to e8996e9 Compare October 7, 2019 21:48
@patstew
Copy link
Contributor Author

patstew commented Oct 7, 2019

This should have a green light on travis now, I've fixed the test failures.

@patstew patstew force-pushed the python branch 3 times, most recently from c05a392 to c6d0381 Compare October 8, 2019 15:38
@madebr
Copy link
Contributor

madebr commented Oct 8, 2019

The cmake files in the python pr should also be modified to use 2 spaces.
(in examples and include/verilated_py.cmake)

You can btw squash my 3 python patches (and modify the author email address, the same with my patch in the cmake pr)

@patstew patstew force-pushed the python branch 3 times, most recently from ee5d9c3 to 2543094 Compare October 8, 2019 17:27
@@ -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];
Copy link
Contributor

@madebr madebr Oct 9, 2019

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@patstew patstew force-pushed the python branch 7 times, most recently from 86e5e9e to 38e05f1 Compare October 16, 2019 12:50
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
Copy link
Contributor

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
Copy link
Contributor

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"""
Copy link
Contributor

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"""
Copy link
Contributor

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"
Copy link
Contributor

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
Copy link
Contributor

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"""
Copy link
Contributor

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)"""
Copy link
Contributor

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"""
Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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"
Copy link
Contributor

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
Copy link
Contributor

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"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wsnyder wsnyder added the resolution: abandoned Closed; not enough information or otherwise never finished label Nov 9, 2020
@wsnyder
Copy link
Member

wsnyder commented Nov 9, 2020

Perhaps hopefully this will get refreshed, but as not being worked on closing out for now.

@wsnyder wsnyder closed this Nov 9, 2020
@wsnyder wsnyder mentioned this pull request Apr 14, 2022
VarunKoyyalagunta added a commit to VarunKoyyalagunta/verilator that referenced this pull request Jul 13, 2022
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
VarunKoyyalagunta added a commit to VarunKoyyalagunta/verilator that referenced this pull request Jul 13, 2022
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
resolution: abandoned Closed; not enough information or otherwise never finished
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants