# 暑假進度報告
###### tags: `Lab` `ppt`
---
## Outline
- AI 課程
- 計算機組織實驗
- ARC Contest
- Code generation
---
## AI 課程
----
### 第一周
- 學習 `python` 環境建立
- TensorFlow, Keras 語法
- ANN 架構,ML 專有名詞
- `Activation function` 種類
- 學習方法 (ex: `back propagation`)
----
### 第二周
- Convolution 基本概念
- cuda & cuDNN 環境架設和使用方法
----
### 第三周
- 深度學習架構 (ex: `VGGNet`, `ResNet`)
- 深度學習遇到的問題 (ex: `gradient vanish`)
---
## 計算機結構實驗
----
## 實驗步驟
1. 搭建 linux 環境, 下載 Qemu、linux kernel
2. 新增虛擬硬體給 Qemu 進行模擬
3. 用 cross compiler 編譯 driver 將其放入模擬環境
4. 掛載 driver 並執行測試程式

---
## ARC Contest
----
### MDFI On Arc
- Obstacle
- Solution
- Outcome
- Todo
----
1. Code Size Overflowed

----
- Optimiation option -Os
<span><!-- .element: class="fragment" data-fragment-index="1" --></span>
- Removing layers which are not used in Lenet (ex: yolo_layer, upsample_layer...)
- Removing detector.c
- Pruning fatfs
<span><!-- .element: class="fragment" data-fragment-index="2" --></span>
<span><!-- .element: class="fragment" data-fragment-index="3" --></span>
Note:
- 最後修剪檔案系統的大小,會有這個想法是因為在看記憶體分佈的時候,發現檔案系統佔了全部的1/3以上。
- 其中 unicode 佔了快 60kb,這個檔案在定義 unicode 的編碼轉換,但我們在讀檔的時候通常只會讀基本的數字,英文,標點符號等等
- 都拉出去之後記憶體大小剩下 153 kb,之後可能會再把拉出去的 layer 放回來,使 MDFI 擁有更高的完整性
----
2. Heap Memory Overflowed
- Convlolution layer

----

----
- Connected layer

----

----
### Outcome

---
## Code Generation
- Generally considered the last phase of compilation.
- Takes parse tree or an abstract syntax tree as input
- Converting input to machine code
---
## Compiler
1. Lexical Analysis (詞彙分析)
2. Syntactic Anaysis (語法分析)
3. Semantic Analysis (語意分析)
4. Code Generation
----
### Lexical Analysis
將一連串的字元轉換成 Token, 並產生 Symbol Table, 轉換後就不會有"換行"、"空白"、"註解"等等

----
### Syntactic Analysis
對照 Symbol Table, 把 code 主換成 Parse Tree

Note:
- `*` 號後面沒有接東西,不能產生 parse tree
- paese tree 就是 code generation 的 input
----
### Semantic Analysus
分析是否有"語意"上的錯誤

Note:
- 像是變數"重複宣告"
- 變數型態不符合
---
## Make a Code Generator
----
### <font color=#3333FF>First</font>
- Choose IR Type
- Be familiar with Target Language
Note:
- 要對 input output 夠熟悉
- 要對硬體提供的 `ISA` 有足夠的了解,有提供什麼指令,register 有多少個等等
----
### <font color=#3333FF>Next...</font>
<font color=#AA1111>Selection of instructions</font>
>One representation can have many ways to convert it, so it becomes the responsibility of the code generator to choose the appropriate instructions wisely.
>
Note:
- 我們要將一段程式瑪轉換成組合語言,他不是一對一的 mapping ,再對指令集夠了解後,我們要選擇用什麼指令集做轉換
- 在轉換的時候還需要考慮每個指令所消耗的時間,做出最有效率的轉換
----
### <font color=#3333FF>Next...</font>
<font color=#AA1111>Register allocation</font>
>Code generator decides what values to keep in registers. Also, it decides the register to be used to keep these values.
>
Note:
- 程式在執行的時候,通常要用到的變數都存在 register 裡面,code generator 再做轉換的時候還要考慮要用哪個 register 去存,還有哪些資料要放到 memory 裡面
----
### <font color=#3333FF>Next...</font>
<font color=#AA1111>Odering of Instructions</font>
>At last, the code generator decides the order in which the instruction will be executed.
>
---
## LLVM
一個自由軟體專案,提供一些編譯器的基礎設施,包含一系列模組化的編譯器元件和工具鏈

Note:
- 一般編譯器分成前、中、後端三部份,三者之間交換資料時都會用到內部私有的 `API` 導致三者密不可分
----
### LLVM IR
LLVM 定義了一個通用的程式中介表示法 (LLVM IR),一種組合語言的簡化版本

----
### 前、中、後端
- Clang
一個C、C++、Objective-C和Objective-C++程式語言的編譯器前端。它採用了LLVM作為其後端
- LLVM pass
- LLVM backend
Note:
- Clang 將 MDFI 轉換成 LLVM IR
- 中間端的部份有很多原的 module 可以拿來用,如果覺得不夠我們也可以參考官方文件自己做我們需要的 module
- 後端也是有官方的文件可以參考,這部份我就還沒細讀
---
## The End
{"metaMigratedAt":"2023-06-14T23:21:11.080Z","metaMigratedFrom":"Content","title":"暑假進度報告","breaks":true,"contributors":"[{\"id\":\"ff4d57f6-b8a6-4265-87df-70e37fc421a0\",\"add\":4710,\"del\":712}]"}