-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpu-time-test.py
More file actions
25 lines (20 loc) · 780 Bytes
/
gpu-time-test.py
File metadata and controls
25 lines (20 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"""
A simple test which measures time taken while taking the dot product of
a random matrix with itself.
"""
import numpy as np
import tensorflow as tf
from datetime import datetime
device_name = '/gpu:0' # /gpu:0 or /cpu:0
shape = (10000, 10000)
with tf.device(device_name):
random_matrix = tf.random_uniform(shape=shape, minval=0, maxval=1)
dot_operation = tf.matmul(random_matrix, tf.transpose(random_matrix))
sum_operation = tf.reduce_sum(dot_operation)
start_time = datetime.now()
with tf.Session(config=tf.ConfigProto(log_device_placement=True,
allow_soft_placement = True)) as session:
result = session.run(sum_operation)
print(result)
print("Time taken:", datetime.now() - startTime)
print("Shape:", shape, "Device:", device_name)