macbookpro2014midでchainerを使ってみる。

# スペック
MacBook Pro (Retina, 15-inch, Mid 2014)
2.5 GHz Intel Core i7
16 GB 1600 MHz DDR3
NVIDIA GeForce GT 750M 2048 MB

Python 3.5.2 :: Anaconda 4.1.1 (x86_64)

# 実験

pfnet/chainer/examples/mnist/train_mnist.py をターミナルから実行

```--gpu=-1(cpu)
pfnet/chainer/examples/mnist/train_mnist.py 
GPU: -1
# unit: 1000
# Minibatch-size: 100
# epoch: 20

epoch       main/loss   validation/main/loss  main/accuracy  validation/main/accuracy  elapsed_time
1           0.192781    0.126955              0.941067       0.9583                    13.6592       
2           0.0735274   0.0879777             0.97775        0.9732                    28.9926       
3           0.0496319   0.0733552             0.984617       0.978                     47.763        
4           0.0330894   0.0751933             0.989267       0.9793                    65.5131       
5           0.0301927   0.0743176             0.990133       0.9789                    83.9239       
6           0.0228305   0.075348              0.992733       0.9812                    103.67        
7           0.0201278   0.0727324             0.993517       0.9811                    120.459       
8           0.0174357   0.0826239             0.994367       0.9808                    137.905       
9           0.0167024   0.0843307             0.994383       0.9812                    156.301       
10          0.0163925   0.0814977             0.994967       0.9799                    174.836       
11          0.0128264   0.115372              0.995733       0.9748                    193.53        
12          0.0149023   0.084797              0.994933       0.9822                    214.294       
13          0.00920458  0.0975131             0.99695        0.9789                    235.031       
14          0.0141595   0.0831671             0.995567       0.9831                    254.675       
15          0.00896259  0.090519              0.997367       0.9839                    276.319       
16          0.00998607  0.106729              0.996817       0.9814                    296.651       
17          0.0113792   0.09336               0.996717       0.9803                    317.971       
18          0.0102693   0.0951749             0.99665        0.9845                    340.063       
19          0.00888105  0.114466              0.997583       0.9805                    362.947       
20          0.00705615  0.0936531             0.9979         0.983                     385.006       
```

```--gpu=0
pfnet/chainer/examples/mnist/train_mnist.py --gpu=0
GPU: 0
# unit: 1000
# Minibatch-size: 100
# epoch: 20

epoch       main/loss   validation/main/loss  main/accuracy  validation/main/accuracy  elapsed_time
1           0.187818    0.0950646             0.9439         0.97                      22.2375       
2           0.0731585   0.0821572             0.977266       0.9762                    28.4661       
3           0.0491227   0.0861518             0.984366       0.9753                    34.4956       
4           0.0349865   0.0808704             0.988582       0.9747                    40.6497       
5           0.0305819   0.0709175             0.990065       0.9807                    46.6325       
6           0.0234635   0.0756805             0.992382       0.9811                    52.9139       
7           0.0173655   0.090005              0.994298       0.9784                    59.3054       
8           0.0209338   0.0881618             0.993198       0.9783                    65.3685       
9           0.0163699   0.0870689             0.994365       0.9818                    71.4204       
10          0.013596    0.0856411             0.995899       0.9828                    77.5482       
11          0.0127105   0.0961925             0.995632       0.9802                    83.6669       
12          0.0137413   0.0942255             0.995615       0.9817                    89.8108       
13          0.0131813   0.082361              0.996015       0.9824                    96.327        
14          0.00963876  0.100076              0.997182       0.9814                    102.652       
15          0.0104344   0.129419              0.996616       0.9786                    108.762       
16          0.0144244   0.0982004             0.995599       0.982                     114.887       
17          0.00632741  0.0944044             0.997849       0.9832                    120.928       
18          0.0106704   0.0848241             0.996599       0.9843                    127.147       
19          0.0100163   0.111707              0.997316       0.982                     133.411       
20          0.00694956  0.105781              0.997766       0.9836                    139.521       
```

```--gpu=1は無い
pfnet/chainer/examples/mnist/train_mnist.py --gpu=1
GPU: 1
# unit: 1000
# Minibatch-size: 100
# epoch: 20
（略）
cupy.cuda.runtime.CUDARuntimeError: cudaErrorInvalidDevice: invalid device ordinal
```

# 結論
- chainerでgpu使うと計算時間は140/385=0.36倍になる。2.7倍gpuの方が速い。
- gpuはオプションで「0」で指定できる。