Giter Site home page Giter Site logo

dpic-fw-example's Introduction

适用于chisel的DPI-C绑定生成框架

可以自动生成Verilog侧与C侧代码,受香山Difftest框架启发

使用方法

(具体可参考src/DPIC-fw-test.scala):

  1. 定以需要使用的信号列表,支持输入与输出。如:
class DpTestBundle extends DPICBundle{
  val in1 = Input(UInt(8.W))
  val out = Output(UInt(16.W))
}
  1. 实例化
val test1 = DPIC(new DpTestBundle)
  1. 在所有实例化完成后,在顶层模块的结尾使用该接口来生成C侧的代码
DPIC.collect()

构建:

使用make构建,默认目标即可。构建需要mill

HDL_gen与SRC_gen分别存放了生成的verilog与C代码 复制到仿真项目中即可使用

C侧的默认行为是把数据简单地复制到结构体内。但可以在其他文件内定义特殊命名的函数覆盖

如:对于dpic_DpTestBundle,定义dpic_DpTestBundle_override可以修改默认行为


问题:

Verilog的DPIC调用写在哪里都可以,但Chisel中只能作为一个模块存在

这会导致不好控制调用的时机(只能通过敏感列表,而不能通过代码位置)

我删减了很多香山Difftest框架中与DPIC有关,但又看不出来作用的代码。可能会导致一些边角情况的缺失。甚至可能删了一半留了一半

dpic-fw-example's People

Contributors

furryacetylcoa avatar

Stargazers

Xiao avatar  avatar  avatar Jiabin Wu avatar zhenwei avatar

Watchers

 avatar

dpic-fw-example's Issues

在Bundle存在嵌套的情况下,无法正常生成DPI-C

在Bundle存在嵌套的情况下,无法正常生成DPI-C

例如:
将示例代码中的测试用例改为下面这样,就会产生错误的结果:

class DpTestBundle extends DPICBundle{
  val in1 = Input(UInt(8.W))
  val out = Output(UInt(16.W))
  override val always_comb = true
}

class DpTestBundle2 extends DPICBundle{
  val in2 = Input(UInt(8.W))
  val in4 = Input(UInt(8.W))
  val out = new DpTestBundle // 原来是 val out = Output(UInt(16.W))
}

期望的结果可能是这样的:

// Generated by CIRCT firtool-1.44.0

 module DpTestBundle2(
  input        clock,
  input  [ 7:0] io_in2,
  input  [ 7:0] io_in4,
  input  [7:0]  io_out_in1,
  output [15:0] io_out_out
 );
/* verilator lint_off WIDTHEXPAND */
 
 import "DPI-C" function void dpic_DpTestBundle2(
  input  byte  io_in2,
  input  byte  io_in4,
  input  byte  io_out_in1,
  output int io_out_out
 );

 always @(posedge clock) begin
  dpic_DpTestBundle2 (io_in2, io_in4, io_out_in1, io_out_out);
 end
endmodule

但是实际上他生成的代码是这样的:

// Generated by CIRCT firtool-1.44.0

 module DpTestBundle2(
  input        clock,
  input  [ 7:0] io_in2,
  input  [ 7:0] io_in4,
  output [23:0] io_out
 );
/* verilator lint_off WIDTHEXPAND */
 
 import "DPI-C" function void dpic_DpTestBundle2(
  input  byte  io_in2,
  input  byte  io_in4,
  output int   io_out
 );

 always @(posedge clock) begin
  dpic_DpTestBundle2 (io_in2, io_in4, io_out);
 end
endmodule

也就是说他将val out = new DpTestBundle的这部分内容视为了一个24位的bit,这显然是不合理的.

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.