PART I: COMPUTER ARCHITECTURE
1. (25 pts) The advance of computer architecture is enabling big data analytics, machine learning and new smart applications. Please read the following article before answering the questions:
Nvidia Announces New Drive PX 2 'Supercomputer in A Lunchbox' For Self-Driving Cars (Source: techcrunch.com, 2016/01/04)
Following last year's Drive CX, Nvidia just announced an updated version of its computing platform for self-driving cars, the Drive PX 2. Compared to last year's model, this is a much more powerful beast, able to process data from 12 video cameras and other sensors in real time to make educated driving decisions. The company calls it a supercomputer, and it's the size of a lunchbox.
Behind the scene, the Drive PX 2 features 12 different cores representing 8 teraflops of calculation power, 24 deep learning tera operations per second. The company is using a 16nm architecture, and it's a hungry beast as it requires 250W of power. Finally, Nvidia is using a liquid-cooling system. Because the PX 2 will be used in cars, that's not too much of a problem and Nvidia argues that car manufacturers will just plug the device into their existing cooling solutions.
Nvidia co-founder and CEO Jen-Hsun Huang said that the PX 2 was as powerful as 150 MacBook Pros. The company is certainly comparing GPU power with the 13-inch MacBook Pro, which currently sports an Intel Iris Graphics 6100 chip. The PX 2 features two next-gen Tegra processors, as well as a Pascal-based GPU. In total, the system can push up to 8 teraflops and recognize up to 2,800 images per second using the AlexNet neural network-based deep learning algorithm.
The company also announced Nvidia Drivenet, its own deep neural network. It has the equivalent of 37 million neurons and was trained 120 million objects so far. Like other deep neural networks, it gets better over time. Companies will be able to leverage this network, but Nvidia also insisted in saying that car makers would want to control their own neural network. The company is promoting a platform approach, meaning that it wants to work with as many car makers as possible to kickstart their self-driving efforts. Volvo is going to be the first partner shipping Drive PX 2 in about 100 upcoming test cars. Nvidia has also partnered with Audi, Daimler, BMW and Ford to develop and test the PX 2.
As Huang showed during today's keynote, all of this power is needed to enable self-driving cars to know enough about their environment — and interpret it — to safely drive in traffic. In one demo, Nvidia showed a new dashboard that can use this data to show drivers whether there are other cars around them at any given time. Thanks to this, "we soon won't need rear-view mirrors anymore," Huang joked. As Nvidia clearly noted, though, identifying objects and planning basic paths is only the beginning. Looking ahead, making self-driving cars work in the real world also means that cars can recognize circumstances as well. Not every truck is the same, after all — some are ambulances, for example, and you better make space for those.
Please answer the following questions:
(a) [2 pts] Nvidia is famous for making Graphics Processing Units (GPU's). Can GPU's be used for general purpose computing? How?
(b) [2 pts] Which category does this PX 2 platform belongs: desktop, server, embedded, or supercomputer?
(c) [2 pts] What is the power efficiency of the PX 2 platform, in terms of teraflops/watt?
(d) [2 pts] Nvidia said that the PX 2 was as powerful as 150 MacBook Pros. Why don't we use it to make desktop computers? (In addition to answering yes/now, please give an explanation).
The PX 2 is designed to accelerate "deep learning" or "deep neural network" algorithms with GPU's. The following figure is an example of deep neural network, where data are received by the input layer from the left, processed through 3 hidden layers, and finally delivered to the output layer to produce the results. Each circle represents a functional node which receives multiple input data from the previous layer, computes a result with a function, and deliver the result to the nodes in the next layer.
(原題附圖:全連接的 deep neural network——input layer、hidden layer 1、2、3、output layer,共 5 層,相鄰兩層的每個 node 兩兩相連)
(e) [2 pts] Please explain why GPU may be useful for accelerating such an algorithm?
(f) [2 pts] Can the deep neural network shown above be implemented by a pipelined datapath? Draw a picture to show how the pipelined data path works.
(g) [2 pts] How would pipelining affect the performance, in terms of throughput and latency?
(h) [2 pts] As opposed to Nvidia's GPU approach, do you think it is a good idea to design a chip entirely for deep learning? What would be the advantages and disadvantages?
(i) [2 pts] For a very large deep neural network, we may want to accelerate it with multiple machines by partitioning the input data. Suppose we have two machines connected with Ethernet, and each machine receives half of the input data. For simplicity, assume every layer has N nodes and each node sends its output data (1 floating point number) to every node in the next layer. How many floating point numbers need to be exchanged between the two machines for one set of input data?
(j) [2 pts] Following the previous question, suppose each node takes A nanoseconds to complete its function, each machine has Q processor cores, and the Ethernet has 10Gbps duplex bandwidth (i.e. each direction can transfer at 10Gbits/sec). Please estimate the speedup of the execution time with two machines. (Ignore the network delay and the other overhead in this case).
(k) [2 pts] Following the previous question, if we have P machines instead of 2 machines, please estimate the limit of speedup of the execution time, as P approaches infinity.
(l) [3 pts] Based on the above, please discuss how you would design system architectures for small, medium, and large deep neural network for best cost-performance? You may use CPUs, GPU, custom-designed chips, FPGA, clusters, etc.
(a) 可以(GPGPU):把一般計算寫成 kernel(CUDA/OpenCL),由成千上萬個 thread 同時在 GPU 的 SIMD/SIMT 核心上跑;適合資料彼此獨立、每筆做同樣運算的工作(矩陣運算、影像處理、科學模擬)
可以,用 CUDA/OpenCL 把 data-parallel 的計算寫成 kernel 丟給 GPU
(b) 裝在車內、為特定的即時任務服務,是 embedded(不是通用的 desktop/server,也不是集中的 supercomputer)
embedded
(c) \(\dfrac{8\ \text{TFLOPS}}{250\ \text{W}}=0.032\ \text{TFLOPS/W}\)
\(0.032\) TFLOPS/W = 32 GFLOPS/W
(d) 不適合:
① 「150 台 MacBook Pro」比的是特定的 deep-learning/GPU 吞吐量;desktop 常見的工作(網頁、辦公、編譯)是循序、少平行,用不到那麼多 GPU 核心,加速不成比例
② 250 W、要液冷:desktop 用空冷、要安靜,電源與散熱的成本與體積都撐不住
③ 價格高;而且軟體生態(x86/Windows 應用程式)、顯示輸出與周邊介面都和 desktop 不同
No:加速只對 deep learning 這類高度平行的負載成立,加上功耗 250 W、需液冷、成本高、軟體生態不同
(e) 同一層的每個 node 做的是「對上一層的輸出做乘加」(內積+激活函數),各 node 之間互相獨立、運算完全相同 → data-level parallelism;整層就是矩陣乘以向量(或多筆輸入時是矩陣乘矩陣)。GPU 有上千個簡單核心與高記憶體頻寬,剛好同時算完一整層
每層的 node 運算相同又互相獨立(矩陣乘法),GPU 的大量核心與高頻寬能同時算完
(f) 可以:每一層當成一個 pipeline stage,stage 之間放 register;上一筆資料進到下一層時,下一筆資料就能進入這一層
| t1 | t2 | t3 | t4 | t5 | t6 | t7 | |
|---|---|---|---|---|---|---|---|
| 資料 1 | L1 | L2 | L3 | L4 | L5 | ||
| 資料 2 | L1 | L2 | L3 | L4 | L5 | ||
| 資料 3 | L1 | L2 | L3 | L4 | L5 |
可以:每層一個 stage,之間用 register 隔開;填滿後 5 筆資料同時在 5 層中
(g) throughput 提高:填滿 pipeline 後每個 stage 時間就產生一筆輸出,最多接近 stage 數倍(受最慢的 stage 限制)。latency(單筆資料從進入到出來)不會變短:仍要走過全部 5 層,加上 pipeline register 的延遲,還會稍微變長
throughput 上升,單筆 latency 不變或略增
(h) 值得(DNN 這類固定、規則的運算量大到有規模):
優點:專用的矩陣乘法單元、低精度(8/16 bit)、把權重放在 on-chip memory,拿掉圖形用不到的電路 → performance per watt 與 throughput 都比 GPU 高、延遲低、可做成車內小型低功耗晶片
缺點:設計與製造成本(NRE)很高,要有夠大的量才攤得回來;演算法一變(新的網路結構、運算)就不好適應,彈性低;軟體工具與生態系要自己建
可以:換到 performance per watt;代價是高 NRE、彈性差、軟體生態
(i) 每台 machine 負責每層 \(N/2\) 個 node(接收一半的輸入資料)
相鄰兩層之間,一台 machine 上的 \(N/2\) 個 node 各要傳 1 個數給對面 machine 的 \(N/2\) 個 node:\(\dfrac N2\cdot\dfrac N2=\dfrac{N^2}{4}\) 個;兩個方向合計 \(\dfrac{N^2}2\)
圖有 5 層 → 相鄰層之間 4 組:\(4\times\dfrac{N^2}2\)
\(2N^2\) 個 floating point numbers(每組相鄰層 \(N^2/2\),每個方向 \(N^2/4\))
(j) 假設 floating point 是 32 bit、層與層之間依序進行、計算與傳輸不重疊
單機:5 層 \(\times\) 每層 \(N\) 個 node \(\times A\) ns,由 \(Q\) 核分攤:\(T_1=\dfrac{5AN}{Q}\)
兩台:每台每層只算 \(N/2\) 個:計算 \(\dfrac{5AN}{2Q}\)
傳輸:每組相鄰層每個方向 \(N^2/4\) 個 \(\times32\) bit \(=8N^2\) bit;duplex 兩個方向同時走,各 10 Gbit/s = 10 bit/ns → \(0.8N^2\) ns;4 組依序 → \(3.2N^2\) ns
\(T_2=\dfrac{5AN}{2Q}+3.2N^2\)
\(\text{speedup}=\dfrac{T_1}{T_2}=\dfrac{5AN/Q}{5AN/(2Q)+3.2N^2}=\dfrac{2}{1+1.28\,NQ/A}\)
要大於 1 需要 \(A\gt1.28\,NQ\),也就是每個 node 的計算時間要遠大於「核心數 \(\times\) 每層 node 數」那麼多 ns,否則用 Ethernet 把網路拆到兩台反而比較慢
(k) \(P\) 台共用同一條 Ethernet:每台每層 \(N/P\) 個 node,計算 \(\dfrac{5AN}{PQ}\);跨 machine 的 node 配對有 \(N^2(1-\tfrac1P)\) 個(每組相鄰層),全部經過同一條 Ethernet(兩個方向合計 20 Gbit/s,用 \(P=2\) 時同樣的算法):每組 \(\dfrac{32N^2(1-1/P)}{20}=1.6N^2(1-\tfrac1P)\) ns,4 組共 \(6.4N^2(1-\tfrac1P)\)
\(T_P=\dfrac{5AN}{PQ}+6.4N^2\Big(1-\dfrac1P\Big)\)(\(P=2\) 代入得 \(\dfrac{5AN}{2Q}+3.2N^2\),與 (j) 相同)
\(P\to\infty\):計算項 \(\to0\),傳輸項 \(\to6.4N^2\),不再下降
\(\text{speedup}\to\dfrac{5AN/Q}{6.4N^2}=\dfrac{25A}{32\,NQ}\approx0.78\dfrac{A}{NQ}\)
如果每台 machine 都有自己的 10 Gbit/s link、經非阻塞 switch 連接,每台的傳輸量也隨 \(1/P\) 下降,這個上限就不存在;這裡照題目的「the Ethernet」當成共用的一條
(l) 由 (j)(k):網路傳輸的量是 \(N^2\),計算量是 \(AN/Q\);只有計算遠大於傳輸時,拆到多台機器才划算,而且 Ethernet 的頻寬很快變成瓶頸
| 規模 | 建議 | 理由 |
|---|---|---|
| small | 一顆 CPU(或手機等級的 GPU) | 運算量小,單機放得下;不需要特別的硬體,成本最低 |
| medium | 一張(或數張)GPU;網路固定、要低延遲低功耗時用 FPGA | GPU 的 throughput 與成本比最好、軟體成熟;FPGA 可針對固定網路客製、效率較高 |
| large | 多 GPU 伺服器叢集,用高速互連(NVLink、InfiniBand 等);量夠大且模型穩定時,用客製 ASIC | 單機放不下或要縮短訓練時間;Ethernet 太慢,要靠高速互連;ASIC 的高 NRE 要用大量使用才攤得回來 |
small:CPU;medium:GPU(固定網路可用 FPGA);large:GPU 叢集+高速互連,量大且穩定時用客製 ASIC