1818import tensorflow as tf
1919import datetime
2020
21- #Processing Units logs
21+ # Processing Units logs
2222log_device_placement = True
2323
24- #num of multiplications to perform
24+ # Num of multiplications to perform
2525n = 10
2626
2727'''
3030 * Single GPU computation time: 0:00:11.277449
3131 * Multi GPU computation time: 0:00:07.131701
3232'''
33- #Create random large matrix
33+ # Create random large matrix
3434A = np .random .rand (1e4 , 1e4 ).astype ('float32' )
3535B = np .random .rand (1e4 , 1e4 ).astype ('float32' )
3636
37- # Creates a graph to store results
37+ # Create a graph to store results
3838c1 = []
3939c2 = []
4040
@@ -50,7 +50,7 @@ def matpow(M, n):
5050with tf .device ('/gpu:0' ):
5151 a = tf .constant (A )
5252 b = tf .constant (B )
53- #compute A^n and B^n and store results in c1
53+ # Compute A^n and B^n and store results in c1
5454 c1 .append (matpow (a , n ))
5555 c1 .append (matpow (b , n ))
5656
@@ -59,23 +59,23 @@ def matpow(M, n):
5959
6060t1_1 = datetime .datetime .now ()
6161with tf .Session (config = tf .ConfigProto (log_device_placement = log_device_placement )) as sess :
62- # Runs the op.
62+ # Run the op.
6363 sess .run (sum )
6464t2_1 = datetime .datetime .now ()
6565
6666
6767'''
6868Multi GPU computing
6969'''
70- #GPU:0 computes A^n
70+ # GPU:0 computes A^n
7171with tf .device ('/gpu:0' ):
72- #compute A^n and store result in c2
72+ # Compute A^n and store result in c2
7373 a = tf .constant (A )
7474 c2 .append (matpow (a , n ))
7575
76- #GPU:1 computes B^n
76+ # GPU:1 computes B^n
7777with tf .device ('/gpu:1' ):
78- #compute B^n and store result in c2
78+ # Compute B^n and store result in c2
7979 b = tf .constant (B )
8080 c2 .append (matpow (b , n ))
8181
@@ -84,7 +84,7 @@ def matpow(M, n):
8484
8585t1_2 = datetime .datetime .now ()
8686with tf .Session (config = tf .ConfigProto (log_device_placement = log_device_placement )) as sess :
87- # Runs the op.
87+ # Run the op.
8888 sess .run (sum )
8989t2_2 = datetime .datetime .now ()
9090
0 commit comments