In [1]:
import numpy as np
import tensorflow as tf
import datetime
from my_poly import get_polynom

In [2]:
NR = 65536

In [3]:
#get the tensorflow session
sess = tf.Session() #config=tf.ConfigProto(log_device_placement=True))

x = [None]*50
with tf.device('/gpu:0'):
  for i in range(0, 50):
    x[i] = tf.random_uniform([NR, 1], minval=0.0, maxval=1.0, dtype=tf.float32, name="x{}".format(i))

print("x[0]:", x[0])


x[0]: Tensor("x0:0", shape=(65536, 1), dtype=float32, device=/device:GPU:0)

In [4]:
poly_start = datetime.datetime.now()
print("Started to load the polynom at ", poly_start)
#build the sum operation
res = get_polynom(x[0], x[1], x[2], x[3], x[4], x[5], x[6], x[7], x[8], x[9],
                  x[10], x[11], x[12], x[13], x[14], x[15], x[16], x[17], x[18], x[19],
                  x[20], x[21], x[22], x[23], x[24], x[25], x[26], x[27], x[28], x[29],
                  x[30], x[31], x[32], x[33], x[34], x[35], x[36], x[37], x[38], x[39],
                  x[40], x[41], x[42], x[43], x[44], x[45], x[46], x[47], x[48], x[49])
poly_end = datetime.datetime.now()
print("Finished loading the polynom at ", poly_end)
print("That took ", (poly_end-poly_start).total_seconds(), "seconds.")


Started to load the polynom at  2017-06-14 22:56:31.187645
Finished loading the polynom at  2017-06-14 22:58:09.988864
That took  98.801219 seconds.

In [5]:
init_start = datetime.datetime.now()
#initialize all variables
sess.run(tf.global_variables_initializer())
init_end = datetime.datetime.now()
print("Initialization took ", (init_end-init_start).total_seconds(), "seconds.")


Initialization took  8.922306 seconds.

In [6]:
# First iteration is slower than others.
sess.run([res])

NumIter = 100
start = datetime.datetime.now()
print("Started at ", start)
#now run the sum operation
for i in range (0, NumIter):
  ppx = sess.run([res])
  if i % 10 == 0:
    print("i={}, ppx[0][0][0]={}".format(i, ppx[0][0][0]))
end = datetime.datetime.now()
print("Finished at ", end)
print("Total time: ", (end-start).total_seconds(), "seconds")
print("Per iteration: ", (end-start).total_seconds()/NumIter, "seconds")

#print the result
#print(ppx)


Started at  2017-06-14 22:58:32.148853
i=0, ppx[0][0][0]=49.80255889892578
i=10, ppx[0][0][0]=59.26311492919922
i=20, ppx[0][0][0]=45.799468994140625
i=30, ppx[0][0][0]=4.098703384399414
i=40, ppx[0][0][0]=76.356201171875
i=50, ppx[0][0][0]=11.672137260437012
i=60, ppx[0][0][0]=10.378355026245117
i=70, ppx[0][0][0]=11.437309265136719
i=80, ppx[0][0][0]=56.3490104675293
i=90, ppx[0][0][0]=5.472430229187012
Finished at  2017-06-14 23:00:25.936660
Total time:  113.787807 seconds
Per iteration:  1.13787807 seconds

In [7]:
print(ppx[0][0])


[ 3.26279593]

In [8]:
x0x1 = sess.run(x[0]*x[1])
x0x2 = sess.run(x[0]*x[1])
#x0x1m = sess.run(tf.multiply(x[0], x[1]))
print(x0x1)
print(x0x2)


[[ 0.07227628]
 [ 0.00313414]
 [ 0.15028499]
 ..., 
 [ 0.25584871]
 [ 0.00903096]
 [ 0.02874264]]
[[ 0.52578342]
 [ 0.00306612]
 [ 0.05576322]
 ..., 
 [ 0.09704245]
 [ 0.03446794]
 [ 0.19207746]]

In [ ]: