如何在Pythoncootb测试中使用多处理



我有一个工作的cocotb设置,如下所示。我想在Python中使用多处理来在循环中运行迭代,以并行化执行。

当前设置:

from cocotb.decorators import coroutine
factory = TestFactory(Run)
@coroutine
def Run(dut,arg1, arg2):
for i in range(N):
ret = yield host.run_test(arg1, arg2)

我尝试了什么:

from cocotb.decorators import coroutine
from multiprocessing import Process, Queue, Manager, Value
factory = TestFactory(Run)
@coroutine
def run_thread(arg1, arg2):
for i in range(N/n_threads):
ret = yield host.run_test(arg1, arg2)
@coroutine
def Run(dut,arg1, arg2):
threads = []
for n in range(0, n_threads):
threads.append(Process(target=run_thread, args=(arg1, arg2)))
for n in range(0, n_threads):
threads[n].start()
for n in range(0, n_threads):
threads[n].join()

如上所示,我尝试将循环的所有内容放入一个函数中,并使用multiprocessing.Process调用它。但当我以这种方式执行它时,run_test没有被正确调用。

我相信这是因为我有一个run_test的yield命令,run_thread函数因此返回了一个生成器。然而,我看不出有任何方法可以迭代run_thread函数的输出,因为我在线程中调用它。

有什么办法可以让我这样做吗?非常感谢任何指导。

PS:我在run_thread函数的第二段代码中犯了一个小错误。我们需要有一个for循环。我现在纠正了它。

cocotb模拟设计的单个实例进行操作,如果您试图并行运行多个测试,则还必须复制您的设计。在这种情况下,最好在shell中进行并行化,这样您就可以启动多个模拟器实例。

如果您只是想在测试台中实现并行性,以便每个作业相对于模拟同时运行,那么您应该考虑并发执行。

最新更新