Skip to content

Commit dc67ffa

Browse files
committed
add some computer architeture introduciton chipyard, chisel and QA
1 parent 2b04c97 commit dc67ffa

File tree

5 files changed

+249
-13
lines changed

5 files changed

+249
-13
lines changed

人工智能-ISEE/python notebooks.md

+1-13
Original file line numberDiff line numberDiff line change
@@ -492,22 +492,14 @@ int()方法将字符转换成ASCII码
492492

493493
#### 报错
494494

495-
【python报错】Non-ASCII character '\xe5'
495+
【python报错】`Non-ASCII character '\xe5' `
496496

497497
解决方法:
498498
在Python源文件的最开始一行,加入一句:
499499

500500
coding=UTF-8 或者 -*- coding:UTF-8 -*-
501501

502-
[python报错]"IndentationError: unexpected indent"的两三解决方法
503-
504-
这个是缩进错误,我们可以通过下面几步解决他:
505-
首先检查代码是不是有错误的索引
506-
如果没有,全都正确,可以看看是不是使用'''进行了整段的注释,如果是,一定要保证其与上下相邻代码缩进一致,而#就无所谓
507-
如果还有错,使用notepad++打开文件,选择视图->显示符号->显示空格和制表符,然后查看是不是有空格与制表符混用的情况
508502
vim可以用: set list 显示空格和制表符.
509-
unexpected indent 就是说“n”是一个“意外的”缩进。也就是说,这里的问题就是指“n”是一个意外的缩进。通过查看源代码可知这里的确是缩进了一个字符位。
510-
据此推断,我们把这句话的缩进取消,也就是顶格写,
511503

512504
[python报错]出现了AttributeError: object 'L2Cache' has no attribute 'connectCPUSideBus'
513505

@@ -521,10 +513,6 @@ class FooChild(FooParent):
521513
super(FooChild,self)
522514
#首先找到 FooChild 的父类(就是类 FooParent),然后把类 FooChild 的对象转换为类 FooParent 的对象
523515

524-
TypeError: 'type' object is not subscriptable
525-
526-
该对象是不可进行下标操作的.NameError: name 'List' is not defined
527-
528516
#### Sccons
529517

530518
Scons是一个开放源码、以Python语言编码的自动化构建工具,可用来替代make编写复杂的makefile。并且scons是跨平台的,只要scons脚本写的好,可以在Linux和Windows下随意编译。
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
## chipyard和一些任务
2+
3+
## chipyard
4+
5+
chipyard好像能直接配置一个cpu核
6+
7+
chipyard里面有 boom 和 rocket
8+
9+
documentation包含了chipyard的基本思想和用法,但没有chisel代码相关的内容。
10+
11+
需要用chisel写好各个基础部件(比如cpu、fpu等)然后在一个scala文件中进行组合(也称配置)。chipyard工具链可以编译该配置文件。
12+
13+
Chipyard’s documentation: https://chipyard.readthedocs.io/en/dev/index.html
14+
15+
- If you intend to run a simulation of one of the vanilla Chipyard examples, go to [Software RTL Simulation](https://chipyard.readthedocs.io/en/latest/Simulation/Software-RTL-Simulation.html#sw-rtl-sim-intro) and follow the instructions.
16+
- If you intend to run a simulation of a custom Chipyard SoC Configuration, go to [Simulating A Custom Project](https://chipyard.readthedocs.io/en/latest/Simulation/Software-RTL-Simulation.html#simulating-a-custom-project) and follow the instructions.
17+
- If you intend to add a new accelerator, go to [Basic customization](https://docs.python.org/3/reference/datamodel.html#customization) and follow the instructions.
18+
- If you want to learn about the structure of Chipyard, go to [Chipyard Components](https://chipyard.readthedocs.io/en/latest/Chipyard-Basics/Chipyard-Components.html#chipyard-components).
19+
- If you intend to change the generators (BOOM, Rocket, etc) themselves, see [Included RTL Generators](https://chipyard.readthedocs.io/en/latest/Generators/index.html#generator-index).
20+
- If you intend to run a tutorial VLSI flow using one of the Chipyard examples, go to [ASAP7 Tutorial](https://chipyard.readthedocs.io/en/latest/VLSI/Tutorial.html#tutorial) and follow the instructions.
21+
- If you intend to build a chip using one of the vanilla Chipyard examples, go to [Building A Chip](https://chipyard.readthedocs.io/en/latest/VLSI/Building-A-Chip.html#build-a-chip) and follow the instructions.
22+
23+
用Verilator编译生成可执行文件:https://www.veripool.org/verilator/
24+
25+
https://github.com/ucb-bar/riscv-sodor这是chipyard关于sodor的官方仓库
26+
27+
1.找到生成32位riscv文件的方法可参考网页
28+
29+
我使用的编译链接命令 https://blog.csdn.net/l471094842/article/details/108118939
30+
31+
报告可以参考这个:
32+
33+
https://blog.csdn.net/weixin_30832405/article/details/99880180
34+
35+
基于五阶段流水线的RISC-V CPU模拟器实现
36+
37+
github上相关的提问与解答
38+
39+
https://stackoverflow.com/questions/46732729/gcc-7-1-1-riscv-compilation-link-failures-incompatible-abi
40+
41+
https://github.com/riscv/riscv-tools/issues/310
42+
43+
https://github.com/riscv/riscv-tools/issues/287
44+
45+
测试的可能方向:
46+
47+
1.testbench自己能测出来各种指标,这个会导致testbench的接口更加复杂,testbench的汇编内容更复杂。且裁剪数据通路需要根据testbench进行裁剪。
48+
49+
问题:没有生成riscv32文件的工具,可能没办法测hazard之类的数据。 已经有了, 就gcc就可以生成,
50+
51+
2.使用现有的模拟器比如qemu进行测试。可能是用./qemu file.riscv这样的指令进行的,类似于这样的
52+
53+
这样的话就可以直接根据没有接口的矩阵乘法汇编进行数据通路裁剪。
54+
55+
问题:还不会使用,也不确定这种模拟器的功能能到哪种程度;同样需要riscv32位的工具生成矩阵乘法的可执行文件。 不用qemu,
56+
57+
所以无论哪个方向都需要生成32位riscv可执行文件的工具
58+
59+
3 一个人可以https://docs.boom-core.org/en/latest/sections/parameterization.html#sample-configurations
60+
61+
https://docs.boom-core.org/en/latest/sections/parameterization.html
62+
63+
hzp 乘法器用scala编译了,
64+
65+
estbench里面有mul是因为riscv32 tool的架构选的是rv32imc,
66+
67+
把架构换成rv32i重新编译一下工具链,.riscv里面没有mul和div了
68+
69+
6.14日, 可以testbench自己计时测得, 只能测cpi , 但是不是嵌在datapath里面的print , 只有用嵌在datapath里面的print,然后统计输出的命令,才能测分支预测这些
70+
71+
我们想测自己mul程序的brnach predict ,所以想要看一下怎么用嵌在datapath里面的print,然后统计输出的命令,才能测分支预测这些
72+
73+
我需要 看project1 ,这里有
74+
75+
最好能弄出这个4-Designing-a-custom-RISC-V-core-using-Chisel-Alex-Badicioiu-NXP
76+
77+
78+
79+
# 一些QA
80+
81+
1.没有chisel代码的细节 其实是有的, 就在源代码里, 然后文档也有.
82+
83+
2.使用chipyard的方法 文档里也有, 就是费时间多试试.
84+
85+
1. cpu需要自己写吗? 还是直接用已经有的代码? cpu可以自己写,我们是用sodor 改进. 加个cache
86+
2. **仿真工具的选择**Chipyard(包括Rocket-Chip)项目支持使用Verilator或Synopsys VCS进行精确到时钟周期的仿真。前者是可免费使用的开源软件,本文接下来介绍一下如何使用开源的Verilator进行仿真。 老师有推荐什么仿真吗?[RISC-V的“Demo”级项目——Rocket-chip](https://zhuanlan.zhihu.com/p/140360043)  用spike测试.
87+
3. chip yard自带的chisel代码都跑不通 ,make就会出问题. 虚拟机内存调大到16g才行. 其实文档里也都有, rocketchip就要 6.5gb 内存.
88+
89+
6.我不知道soc 生成器和加速器有什么区别? 加速器是gimmi , 可以挂在cpu上. soc生成器可以直接生成cpu 的verilog代码.
90+
91+
1. 怎么精简指令集: 有一个生成riscv核心, 应该可以配置一下让他只生成需要的指令. 我们是打算精简数据通路, 然后
92+
2. 怎么make

计算机组成与系统结构/group project/scala.md

+43
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,46 @@ foreach
9696
names zip scores res1: Array[(String, Int)] = Array((zhangsan,60), (lisi,70), (wangmazi,90))
9797

9898
我们调用poke来驱动输入,调用expect来检查输出。如果不使用expect来比较期望值的话(没有断言的话),也可以使用peek来读出输出值。
99+
100+
## chisel
101+
102+
Chisel开发的“Demo”级RISC-V开源项目
103+
104+
Rocket-core是一个标准的五级流水处理器,它支持开源RV64GC RISC-V指令集,并使用Chisel硬件构造语言编写。对于浮点运算,Rocket利用Berkeley的Chisel浮点运算单元实现。Rocket-core其实就是berkeley写的chisel的cpu代码。
105+
106+
rocket chip看样子不太一样?
107+
108+
开源处理器Rocket的源代码文件作用说明: https://www.cnblogs.com/god_like_donkey/p/7876070.html
109+
110+
Chisel教程:https://blog.csdn.net/qq_34291505/article/details/86744581
111+
112+
Chisel教程包括Scala的语法和例子,以及Chisel的语法。
113+
114+
模块化描述,can be converted to Verilog using ChiselStage
115+
116+
学习chisel, 下面是总仓库
117+
118+
[chipsalliance/chisel3](https://github.com/chipsalliance/chisel3#getting-started)
119+
120+
### **Bootcamp Interactive Tutorial**
121+
122+
The **[online Chisel Bootcamp](https://mybinder.org/v2/gh/freechipsproject/chisel-bootcamp/master)** is the recommended way to get started with and learn Chisel. **No setup is required** (it runs in the browser), nor does it assume any prior knowledge of Scala.
123+
124+
The **[classic Chisel tutorial](https://github.com/ucb-bar/chisel-tutorial)** contains small exercises and runs on your computer.
125+
126+
If you like a textbook to learn Chisel and also a bit of digital design in general, you may be interested in reading [Digital Design with Chisel.](http://www.imm.dtu.dk/~masca/chisel-book.html) It is available in English, Chinese, Japanese, and Vietnamese.
127+
128+
数据类型
129+
130+
![https://raw.githubusercontent.com/chipsalliance/chisel3/master/docs/src/images/type_hierarchy.svg?sanitize=true](https://raw.githubusercontent.com/chipsalliance/chisel3/master/docs/src/images/type_hierarchy.svg?sanitize=true)
131+
132+
:= 表示“定义为”
133+
134+
In Chisel provides two constructs to group related signals
135+
136+
- A Bundle to group signals of different type.
137+
- A Vec represents the collection of signal of same type.
138+
139+
[chisel3 3.4.3 - chisel3](https://www.chisel-lang.org/api/latest/chisel3/index.html)
140+
141+
https://www.cnblogs.com/tonglin0325/p/8884470.html这个可以用来下载sbt修改sbt的源用华为云可以成功安装https://repo.huaweicloud.com/java/jdk/8u181-b13/

计算机组成与系统结构/group project/sodor的一些笔记.md

+26
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,31 @@ make run 做了什么:
6969

7070

7171

72+
sodor内部代码
7273

74+
All processors talk to a simple scratchpad memory (asynchronous, single-cycle), with no backing outer memory (the 3-stage is the exception - its scratchpad is synchronous). Programs are loaded in via a Host-target Interface (HTIF) port (while the core is kept in reset), effectively making the scratchpads 3-port memories (instruction, data, HTIF).
75+
76+
https://github.com/ucb-bar/riscv-sodor/blob/master/doc/lab1.pdf 这个很详细
77+
78+
chipyard里没有sodor源码, 我clone了仓库, 但是不知道怎么编译. 也不知道怎么用. 看了看makefile 和 readme2 就有点懂了, 但是还是不太一样, 不知道为啥ucb的没有 emulator , 另一个仓库 passlab的有emulator
79+
80+
make的问题:
81+
82+
没有 32位工具链. make sodor还是要32位工具链?
83+
84+
不过我好像有toolchain,应该可以编译一个工具链.
85+
86+
https://github.com/passlab/riscv-sodor 有emulator,个文档比较详细
87+
88+
https://github.com/riscvarchive/riscv-fesvr 废弃了, it has been absorbed into the Spike repository
89+
90+
可以和https://github.com/ucb-bar/chisel.git Build together with Chisel sources,可以If you are a developer of Chisel and are using sodor cores to test your changes to the Chisel repository
91+
92+
https://github.com/chipsalliance/chisel3 这个是chisel 的仓库
93+
94+
rocker chip里面有chisel3, chipyard/tools里也有 ,
95+
96+
https://github.com/riscv/riscv-tests/issues 讲怎么测试
97+
98+
https://github.com/riscvarchive/riscv-fesvr This repository is deprecated; it has been absorbed into the Spike repository
7399

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# 编译riscv32
2+
3+
怎么编译https://blog.csdn.net/l471094842/article/details/108118939
4+
5+
https://www.riscv-mcu.com/article-article-show-id-122.html
6+
7+
https://www.sohu.com/a/394843697_505803
8+
9+
riscv gcc可以编译成以下几个版本
10+
11+
- riscv32-unknown-elf-gcc
12+
- riscv64-unknown-elf-gcc
13+
- riscv32-unknown-linux-gnu-gcc 这个报错 can't link soft-float modules with double-float modules
14+
- riscv64-unknown-linux-gnu-gcc
15+
- riscv64-multilib-elf-gcc 这个据说可以32位
16+
- riscv64-liunx-multilib-gcc
17+
18+
```c
19+
riscv32-unknown-elf-gcc 用这个编译
20+
```
21+
22+
### riscv32-unknown-linux-gnu-gcc
23+
24+
该工具针对riscv32架构的编译器,使用的C运行库为linux中的标准glibc。我也不知道和 -elf有啥区别?
25+
26+
区别: elf-gcc是静态链接,linux-gnu-gcc是动态链接
27+
28+
```c
29+
root@f550c67bf4ea:/opt/riscv/bin# riscv32-unknown-linux-gnu-gcc -v
30+
Using built-in specs.
31+
COLLECT_GCC=riscv32-unknown-linux-gnu-gcc
32+
COLLECT_LTO_WRAPPER=/opt/riscv/libexec/gcc/riscv32-unknown-linux-gnu/10.2.0/lto-wrapper
33+
Target: riscv32-unknown-linux-gnu
34+
Configured with: /riscv-gnu-toolchain/riscv-gcc/configure --target=riscv32-unknown-linux-gnu --prefix=/opt/riscv --with-sysroot=/opt/riscv/sysroot --with-system-zlib --enable-shared --enable-tls --enable-languages=c,c++,fortran --disable-libmudflap --disable-libssp --disable-libquadmath --disable-libsanitizer --disable-nls --disable-bootstrap --src=.././riscv-gcc --disable-multilib --with-abi=ilp32d --with-arch=rv32gc --with-tune=rocket 'CFLAGS_FOR_TARGET=-O2 -mcmodel=medlow' 'CXXFLAGS_FOR_TARGET=-O2 -mcmodel=medlow'
35+
Thread model: posix
36+
Supported LTO compression algorithms: zlib
37+
gcc version 10.2.0 (GCC)
38+
march=rv32imac -mabi=ilp32 -o file file.c
39+
```
40+
41+
报错
42+
43+
/opt/riscv/lib/gcc/riscv32-unknown-linux-gnu/10.2.0/../../../../riscv32-unknown-linux-gnu/bin/ld: /tmp/cc9EwS9A.o: can't link soft-float modules with double-float modules /opt/riscv/lib/gcc/riscv32-unknown-linux-gnu/10.2.0/../../../../riscv32-unknown-linux-gnu/bin/ld: failed to merge target specific data of file /tmp/cc9EwS9A.o collect2: error: ld returned 1 exit status
44+
45+
github有issue: It's because your C library still using hard floating-point instruction, so I would suggest you re-build toolchain with --with-arch=rv32i --with-abi=ilp32 or enable multi-lib via
46+
47+
[can't link double-float modules with soft-float modules riscv compiler](https://stackoverflow.com/questions/65036779/cant-link-double-float-modules-with-soft-float-modules-riscv-compiler)
48+
49+
readelf -h 可以看the exact arch and ABI(应用程序二进制接口)of your library . 看到了abi是 unix-system V. version 0. 但是不知道arch看哪个. 也有一个回答说加参数msoft-float 有用, 但是不知道怎么加. -msoft-float 不行 , mfloat-abi=softfp 也不行
50+
51+
### 尝试2
52+
53+
```c
54+
矩阵相乘代码
55+
#include<stdio.h>
56+
int main(){
57+
printf("hello world!\\n");
58+
}
59+
```
60+
61+
clang好像也不太行,问题是sysroot不存在, 所以缺乏依赖, link时出错
62+
63+
```c
64+
root@77e8d4f6684c:~# clang-9 -v
65+
clang version 9.0.0 ([<https://github.com/llvm/llvm-project.git>](<https://github.com/llvm/llvm-project.git>) 0399d5a9682b3cef71c653373e38890c63c4c365)
66+
Target: riscv32-unknown-unknown-elf
67+
Thread model: posix
68+
InstalledDir: /opt/riscv32-unknown-elf/bin
69+
报错
70+
/usr/riscv32-unknown-elf/bin/riscv32-unknown-elf-ld: cannot find crt0.o: No such file or directory
71+
/usr/riscv32-unknown-elf/bin/riscv32-unknown-elf-ld: cannot find crtbegin.o: No such file or directory
72+
/usr/riscv32-unknown-elf/bin/riscv32-unknown-elf-ld: cannot find -lc
73+
/usr/riscv32-unknown-elf/bin/riscv32-unknown-elf-ld: cannot find -lgloss
74+
clang-9: error: ld command failed with exit code 1 (use -v to see invocation)
75+
```
76+
77+
### 尝试3
78+
79+
clang hello.c -o hello
80+
81+
欸怎么可以了.神奇.c我把编译不出来的部分都删除了.产生可执行的.但是不知道是不是一样
82+
83+
不尝试了, 都做出来了. 是直接用riscv-test自带的makefile 修改了一些option生成的
84+
85+
下了riscv-gnu-toolchain,编译了riscv32-unknown-elf-gcc
86+
87+
接下来就是需要 接口函数, 某些能够通过串口打印出cpu运行状态的函数.原来32位的makefile不考虑那些接口函数的位置, 还得改

0 commit comments

Comments
 (0)