而在 main() 裡面的 part1,則是先取得 CUDA Device 的數量,然後在 part2 時,再透過迴圈把各個 device 的資訊各自取出來並輸出。以 Heresy 工作用的電腦來說,由於有安裝 8800GT 和 8800GTX 兩張顯示卡,所以執行這個程式,他會顯示出下面的資訊:
Number of GPU: 2
=== Device 0 ===
Device name: GeForce 8800 GT
Device memory: 536543232
Memory per-block: 16384
Register per-block: 8192
Warp size: 32
Memory pitch: 262144
Constant Memory: 65536
Max thread per-block: 512
Max thread dim: ( 512, 512, 64 )
Max grid size: ( 65535, 65535, 1 )
Ver: 1.1
Clock: 1512000
textureAlignment: 256
=== Device 1 ===
Device name: GeForce 8800 GTX
Device memory: 805044224
Memory per-block: 16384
Register per-block: 8192
Warp size: 32
Memory pitch: 262144
Constant Memory: 65536
Max thread per-block: 512
Max thread dim: ( 512, 512, 64 )
Max grid size: ( 65535, 65535, 1 )
Ver: 1.0
Clock: 1350000
textureAlignment: 256
這裡也可以發現,兩張卡除了基本的版本、時脈不一樣外,不同的地方,好像也只剩下記憶體大小了!在 CUDA 的一些參數方面,都是完全一樣的~
而 part3 的 cudaSetDevice( 1 ); 則就是設定讓 CUDA driver 去使用第二個 device(第一個是 0)去做 CUDA 程式的運算;如此,在 part4 的其他運算,就不會在主要顯示裝置上計算了~
而由於目前 CUDA 已經有 1.0/1.1 兩個版本了,所以如果要確定裝置支援哪個版本的話,也可以透過 cudaDeviceProp.major、cudaDeviceProp.minor 這兩個變數來做識別。
不過,一般人應該不會有兩張 8 系列顯示卡就是了… ^^"