IMAX3: Amazing Dataflow-Centric CGRA and its Applications
I present this slide to all hungry engineers who are tired of CPU, GPU, FPGA, tensor core, AI core, who want some challenging one with no black box inside, and who want to improve by themselves.
This is the slide for the event of GDSC held on Oct, 13. The main goal of this course is helping the attendees to discover the world of KOTLIN, and preparing the basic for android developement.
My inspiration from reading *C++ Primer*, *Effective C++*, *More Effective C++*, *The C++ Standard Library* and some experience from coding.
Include:
* Debug
* C++ Syntax
* Habit && Optimization
* Trick
* Trap
* Reference
IMAX3: Amazing Dataflow-Centric CGRA and its Applications
I present this slide to all hungry engineers who are tired of CPU, GPU, FPGA, tensor core, AI core, who want some challenging one with no black box inside, and who want to improve by themselves.
This is the slide for the event of GDSC held on Oct, 13. The main goal of this course is helping the attendees to discover the world of KOTLIN, and preparing the basic for android developement.
My inspiration from reading *C++ Primer*, *Effective C++*, *More Effective C++*, *The C++ Standard Library* and some experience from coding.
Include:
* Debug
* C++ Syntax
* Habit && Optimization
* Trick
* Trap
* Reference
smallpt: Global Illumination in 99 lines of C++鍾誠 陳鍾誠
?
This document summarizes Kevin Beason's smallpt, a 99 line path tracer written in C++. It begins with an overview of global illumination and path tracing. It then walks through the key parts of smallpt, including ray and vector classes, sphere intersections, scene description, camera setup, the rendering equation, path tracing algorithm, and functions for diffuse reflection, specular reflection, refraction, and more. The document provides explanations of the algorithms and math concepts used in smallpt.
21. 程式與科學
Eugene Goostman 程式真的通過了圖靈測試嗎? (作者:陈钟诚)
前言
2014 年 6 月 9 日,我看到 inside 網站中有人發布了一個訊息 「電腦首度通過圖靈測試(36kr.com)」。 我的直
覺反應是,這件事情勢必有假,於是一路追了下去。
Inside 的訊息其實是轉貼自 36氪這個來自中國的網站, 36氪網站的文章標是 「计算机首次通过图灵测试」
。
不仔細看文章的人,很可能會被誤導,認為電腦已經可以成功得欺騙人類,讓人以為他是一個真人,而且
比率達到和真人一樣的水準,也就是「人類已經無法正確區分文字交談的對象到底是電腦還是人類了」。
但是、這樣的想法是錯的,文章中所說的 Eugene Goostman 這個軟體其實並沒有達到「完全能欺騙人類」的
水準,因為他們所說的圖靈測試,和我所認知的圖靈測試,根本就是不同的東西。
圖靈測試是甚麼?
36氪文章中所說的 「图灵测试」 ,其實有連結到百度百科。百度百科裏對圖靈測試的描述如下:
图灵测试是测试人在与被测试者(一个人和一台机器)隔开的情况下,通过一些装置(如键盘)向被测
试者随意提问。问过一些问题后,如果被测试者超过30%的答复不能使测试人确认出哪个是人、哪个
是机器的回答,那么这台机器就通过了测试,并被认为具有人类智能。
但是、我所認知的圖靈測試,並不是採用 30% 誤判率為基準的,而是應該達到「和人類被誤判為電腦」一
樣的水準。換句話說,假如程式偽裝的和真人一樣好的話,那麼應該要符合下列的表格要求。
判斷者的決定 交談對象為人類 交談對象為電腦程式
判斷為人 比率為 P (正確判斷) 比率大於或等於為 P (欺騙成功)
判斷為電腦 比率為 1-P (誤判人為電腦) 比率小於或等於為 1-P (欺騙失敗)
因此、對於上述新聞中所說的,「计算机首次通过图灵测试」 這件事情,其實是採用 30% 的欺騙成功
率,這是我們認為該宣稱有問題的關鍵原因。
但是、為甚麼測試單位「英國雷丁大學」要採用 30% 做為圖靈測試是否通過的標準呢?我想原因應該來自
於「圖靈」本人在那篇名為 「COMPUTING MACHINERY AND INTELLIGENCE 」的文章中所提到的一個
預估,原文如下:
I believe that in about fifty years' time it will be possible to programme computers, with a storage capacity of about
10^9, to make them play the imitation game so well that an average interrogator will not have more than 70 percent
chance of making the right identification after five minutes of questioning. … I believe that at the end of the century the
use of words and general educated opinion will have altered so much that one will be able to speak of machines
22. thinking without expecting to be contradicted.
在上文當中「圖靈」預估 50 年後電腦就可以讓不超過 70% 的人做正確的決定。換句話說,就是成功的欺
騙過 30% 的人。於是「英國雷丁大學」就把這個預估當成圖靈測試的基準了。
但是、這只是圖靈的一個預估,並不代表圖靈測試就應該定為成功的欺騙過 30% 的人啊! (而且這也不是
學術界對圖靈測試的一個共識)。
測試單位的英文公告
36氪的 「计算机首次通过图灵测试」 一文中指出了訊息來源為「英國雷丁大學的新聞稿」,連結如下:
TURING TEST SUCCESS MARKS MILESTONE IN COMPUTING HISTORY
該新聞稿提到 Eugene Goostman 這個程式通過圖靈測試的語句如下:
The 65 year-old iconic Turing Test was passed for the very first time by supercomputer Eugene Goostman during
Turing Test 2014 held at the renowned Royal Society in London on Saturday.
但新聞稿的後面有寫出測試方法的描述:
1. Simultaneous tests as specified by Alan Turing
2. Each judge was involved in five parallel tests - so 10 conversations
3. 30 judges took part
4. In total 300 conversations
5. In each five minutes a judge was communicating with both a human and a machine
6. Each of the five machines took part in 30 tests
7. To ensure accuracy of results, Test was independently adjudicated by Professor John Barnden, University of
Birmingham, formerly head of British AI Society
我對這個測試方法的解讀如下:
1. 圖靈測試:電腦程式是否能成功的透過文字交談欺騙人類,偽裝自己是個人。
2. 每個「判斷者」都會分別判斷五組「人+電腦」的配對,也就是總共進行 10 次的對話。
3. 總共有 30 位判斷者參與。
4. 總共有 30*10=300 場的交談。
5. 在五分鐘內,「判斷者」會與一組「人和機器」分別交談。
6. 五組「電腦程式」都會與 30 位「判斷者」談過一次。
7. 為了確認「判斷者」判斷結果為正確或錯誤, John Barnden 教授會監控並確認結果。
問題在哪裡?
我認為「英國雷丁大學發布的新聞稿」用詞有欠妥當,主要是因為下列語句實在是太過強烈:
The 65 year-old iconic Turing Test was passed for the very first time by supercomputer Eugene Goostman during
Turing Test 2014 held at the renowned Royal Society in London on Saturday.
23. 雖然新聞稿後面有交代 Eugene Goostman 程式成功的欺騙過 33% 的判斷者,但是沒有看完全文的人還是很
容易被誤導的。
If a computer is mistaken for a human more than 30% of the time during a series of five minute keyboard
conversations it passes the test. No computer has ever achieved this, until now. Eugene managed to convince 33% of
the human judges (30 judges took part - see more details below) that it was human.
而 36氪網站直接把 「计算机首次通过图灵测试」 拿來當標題,則是進一步的誤導了大家, 雖然 36氪有超
連結指向 百度的圖靈測試定義 ,但是這個定義顯然與一般人的認知不同,應該要強調一下才對,不應該
企圖用聳動性的標題吸引目光。
最後、 inside 的轉載 「電腦首度通過圖靈測試(36kr.com)」 這篇,雖然有指出來源的 36氪網站文章,不過
我想轉貼的人或許沒有仔細想過到底文章中的「通過圖靈測試」到底是甚麼意義,也沒想過這樣可能會誤
導讀者,造成錯誤科學訊息的傳播問題。
以前的程式表現如何?
事實上、能夠成功欺騙人類,讓某些人認為對方是真人的交談程式,在人工智慧的歷史上很早就出現過
了。
遠在 1966 年時,Joseph Weizenbaum 就曾經創造出一個稱為 ELIZA 的程式,該程式採用了非常簡單的字串比
對方法,結果竟然讓不少交談者認為 ELIZA 是個真人,以下是維基百科對 Eliza 程式的描述網址。
http://en.wikipedia.org/wiki/ELIZA
在 2013 年 8 月號的程式人杂誌當中,筆者也在文章中展示了一個自己寫的「中文版 Eliza 聊天程式」,有
興趣的朋友也可以閱讀該文章順便瞭解這種程式是怎麼做的。
JavaScript (8) – 中文版 Eliza 聊天程式
另外、在 2011 年時有一個稱為 Cleverbot 的程式 曾經創造過成功欺騙 60% 判斷者的紀錄,這個紀錄比這次
比賽第一名的 Eugene Goostman 程式還要高。因此我們真的很難用「電腦首度通過圖靈測試」這樣的語句來
描述這次比賽的結果,甚至這次比賽到底是否有創了什麼記錄都是很難確定的。
所以、我真的覺得這樣的訊息是過於聳動了,因此特別寫了這篇文章來提醒大家,避免很多人會被這些訊
息誤導。
我的感想
從這個案例中,我們可以看到在網路訊息發達的今天,要能夠不被誤導,恐怕必須要有很強的判斷力與追
根究柢的精神,但是在這個訊息多如牛毛的世界中,錯誤與聳動的訊息往往傳播的特別快,這恐怕是網路
世界亟待解決的問題之一啊!
最後、我上 g0v 的新聞小幫手 去檢舉了這個新聞,希望能讓誤導的情況稍微降低一下,檢舉網址如下:
http://newshelper.g0v.tw/index/log/1819
參考文獻
24. http://en.wikipedia.org/wiki/ELIZA
JavaScript (8) – 中文版 Eliza 聊天程式
http://en.wikipedia.org/wiki/Cleverbot
36氪網站:「计算机首次通过图灵测试」 -- http://www.36kr.com/p/212680.html
百度百科:「图灵测试」 -- http://baike./view/94296.htm
Inside 網站:「電腦首度通過圖靈測試(36kr.com)」 -- http://share.inside.com.tw/posts/5079
TURING TEST SUCCESS MARKS MILESTONE IN COMPUTING HISTORY
http://en.wikipedia.org/wiki/Turing_test
http://www.wired.com/2014/06/turing-test-not-so-fast/
http://plato.stanford.edu/entries/turing-test/
資訊科學到底算不算是科學呢? -- http://pansci.tw/archives/44422
COMPUTING MACHINERY AND INTELLIGENCE , By A. M. Turing --
http://www.csee.umbc.edu/courses/471/papers/turing.pdf
图灵测试,测的到底是什么? -- http://www.guokr.com/article/438573/
38. 我們曾經在下列文章中設計出了 MCU0 迷你版這個只有六個指令的微控制器,整個實作只有 51 行。
開放電腦計畫 (6) – 一顆只有 51 行 Verilog 程式碼的 16 位元處理器 MCU0
但是、上述程式雖然簡單,但卻是採用流程式的寫法。雖然、筆者不覺得流程式的寫法有甚麼特別的缺
陷,但是對那些習慣採用硬體角度設計 Verilog 程式的人而言,似乎採用「區塊式的設計方式」才是正
統,所以、筆者將於本文中採用「區塊式的方式重新設計」MCU0 迷你版,以便能學習「硬體設計者」的
思考方式。
MCU0 迷你版的指令表
為了方便讀者閱讀,不需要查閱前文,我們再次列出了 MCU0 迷你版的指令表如下:
OP name 格式 意 義
0 LD LD C A = [C]
1 ADD ADD C A = A + [C]
2 JMP JMP C PC = C
3 ST ST C [C] = A
4 CMP CMP C SW = A CMP [C]
5 JEQ JEQ C if SW[30]=Z=1 then PC = C
MCU0 迷你版的區塊設計圖
在MCU0 迷你版裏,總共有三個暫存器,分別是 A, PC 與 SW,一個具有兩組讀取 (i1/d1, i2/d2) 與一組寫入
的記憶體 (wi/wd),還有一個算術邏輯單元 ALU,這個電路的設計圖如下。
39. 圖、MCU0bm 的區塊設計圖
由於筆者不熟悉數位電路設計的繪圖軟體,因此就簡單的用 LibreOffice 的 Impress 繪製了上圖,純粹採用區
塊表達法,並沒有使用標準的數位電路設計圖示。
原始碼
根據上圖,我們設計出了下列 Verilog 程式,您應該可以很清楚的找出程式與圖形之間的對應關係。
module memory(input w, input [11:0] wi, input [15:0] wd, input [11:0] i1
, output [15:0] d1, input [11:0] i2, output [15:0] d2);
integer i;
reg [7:0] m[0:2**12-1];
initial begin
$readmemh("mcu0m.hex", m);
for (i=0; i < 32; i=i+2) begin
$display("%x: %x", i, {m[i], m[i+1]});
end
end
assign d1 = {m[i1], m[i1+1]};
assign d2 = {m[i2], m[i2+1]};
always @(w) begin
if (w) {m[wi], m[wi+1]} = wd;
end
endmodule
40. module adder#(parameter W=16)(input [W-1:0] a, input [W-1:0] b, output [
W-1:0] c);
assign c = a + b;
endmodule
module register#(parameter W=16)(input clock, w, input [W-1:0] ri, outpu
t [W-1:0] ro);
reg [W-1:0] r;
always @(posedge clock) begin
if (w) r = ri;
end
assign ro=r;
endmodule
module alu(input [3:0] op, input [15:0] a, input [15:0] b, output reg [1
5:0] c);
parameter [3:0] ZERO=4'h0, ADD=4'h1, CMP=4'he, APASS=4'hf;
always @(*) begin
case (op)
ADD: c = a+b;
CMP: begin c[15]=(a < b); c[14]=(a==b); c[13:0]=14'h0; end
APASS: c = a;
default: c = 0;
endcase
end
endmodule
module mux#(parameter W=16)(input sel, input [W-1:0] i0, i1, output [W-1
:0] o);
assign o=(sel)?i1:i0;
endmodule
`define OP ir[15:12]
`define C ir[11:0]
`define N SW.r[15]
`define Z SW.r[14]
41. module mcu(input clock);
parameter [3:0] LD=4'h0,ADD=4'h1,JMP=4'h2,ST=4'h3,CMP=4'h4,JEQ=4'h5;
reg mw, aw, pcmux, sww;
reg [3:0] aluop;
wire [11:0] pco, pci, pcnext;
wire [15:0] aluout, ao, swo, ir, mo;
register#(.W(12)) PC(clock, 1, pci, pco);
adder#(.W(12)) adder0(2, pco, pcnext);
memory mem(mw, `C, ao, pco[11:0], ir, `C, mo);
register#(.W(16)) A(~clock, aw, aluout, ao);
register#(.W(16)) SW(~clock, sww, aluout, swo);
alu alu0(aluop, mo, ao, aluout);
mux#(.W(12)) muxpc(pcmux, pcnext, `C, pci);
initial begin
PC.r = 0; SW.r = 0; mw = 0; aw = 0; pcmux=0; sww=0; aluop=alu0.ZERO;
end
always @(ir or mo or A.r) begin
mw = 0;
aw = 0;
sww = 0;
pcmux = 0;
aluop = alu0.ZERO;
case (`OP)
LD: begin aw=1; aluop=alu0.APASS; end // LD C
ST: mw=1; // ST C
JMP: pcmux=1; // JMP C
JEQ: if (`Z) pcmux=1; // JEQ C
CMP: begin sww=1; aluop = alu0.CMP; end // CMP C
ADD: begin aw=1; aluop=alu0.ADD; end // ADD C
endcase
end
endmodule
module main; // 測試程式開始
reg clock; // 時脈 clock 變數
42. mcu mcu0(clock);
initial begin
clock = 0;
$monitor("%4dns pc=%x ir=%x mo=%x sw=%x a=%d mw=%b aluout=%x", $stime,
mcu0.PC.r, mcu0.ir, mcu0.mo, mcu0.SW.r, mcu0.A.r, mcu0.mw, mcu0.aluout);
#1000 $finish;
end
always #5 begin
clock=~clock; // 每隔 5ns 反相,時脈週期為 10ns
end
endmodule
輸入的機器碼 mcu0m.hex
為了測試上述程式,我們同樣採用了計算 SUM=1+2+...+10 的這個程式作為輸入,以下是機器碼與對應的
組合語言程式。
00 16 // 00 LOOP: LD I
40 1A // 02 CMP N
50 12 // 04 JEQ EXIT
10 18 // 06 ADD K1
30 16 // 08 ST I
00 14 // 0A LD SUM
10 16 // 0C ADD I
30 14 // 0E ST SUM
20 00 // 10 JMP LOOP
20 12 // 12 EXIT: JMP EXIT
00 00 // 14 SUM: WORD 0
00 00 // 16 I: WORD 0
00 01 // 18 K1: WORD 1
00 0A // 1A N: WORD 10
執行結果
編寫完成之後,我們就可以測試整個 mcu0bm.v 程式了,其執行結果如下所示。
C:DropboxPublicweboccodemcu0>iverilog mcu0bm.v -o mcu0bm