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])
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.")
In [ ]:
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.")
In [ ]:
# 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)
In [ ]:
print(ppx[0][0])
In [ ]:
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)
In [ ]: