benchmark/benchmark.rb in tensor_stream-opencl-0.2.2 vs benchmark/benchmark.rb in tensor_stream-opencl-0.2.3
- old
+ new
@@ -24,11 +24,11 @@
tf.set_random_seed(seed)
SHAPES = [32, 32]
sess = tf.session(:ruby_evaluator)
-
+large_tensor = tf.constant(sess.run(tf.random_uniform([256, 256])))
a = tf.constant(sess.run(tf.random_uniform(SHAPES)))
a_int = tf.constant([
[1, 2, 3, 4, 4, 1, 4, 8, 3, 4, 1, 1],
[2, 2, 3, 4, 4, 1, 1, 1, 1, 4, 1, 1],
[3, 2, 3, 4, 0, 1, 1, 2, 1, 1, 2, 1],
@@ -47,10 +47,13 @@
c = tf.constant(sess.run(tf.random_uniform(SHAPES)))
d = tf.constant(sess.run(tf.random_uniform(SHAPES)))
+sample_image = tf.constant(sess.run(tf.random_uniform([10, 8, 8, 3])))
+sample_filter = tf.constant(sess.run(tf.random_uniform([2, 2, 3, 3])))
+
p = tf.placeholder('float')
q = tf.placeholder('float')
model = -tf.sin(a.dot(b + p) + c).dot(a) + tf.cos(a.dot(d + q))
single_function_test = (tf.sigmoid(a * p) * tf.sigmoid(b * q)) + c
@@ -59,18 +62,37 @@
matmul = tf.matmul(a, b)
out_of_order = tf.matmul(a, b) + tf.matmul(c, d)
softmax = tf.nn.softmax(a)
add_n = tf.add_n([a,b,c,d])
split = tf.split(a, 4)
+sum = tf.reduce_sum(large_tensor)
+sum_axis_1 = tf.reduce_sum(large_tensor, 1)
+min = tf.min(large_tensor, 1)
+index = large_tensor[0]
+conv2d = tf.nn.conv2d(sample_image, sample_filter, [1, 1, 1, 1], 'SAME')
+conv2d_grad = tf.gradients(conv2d, [sample_image, sample_filter])
+
puts TensorStream::Evaluator.default_evaluators
sess2 = tf.session
puts `cat /proc/cpuinfo | grep "model name" | head -1`
device = TensorStream::Evaluator::OpenclEvaluator.default_device.native_device
puts "OpenCL device #{device.platform.to_s} #{device.name}"
Benchmark.bmbm do |x|
+ x.report("pure ruby conv2d_backprop :") { 100.times do sess.run(conv2d_grad) end }
+ x.report("opencl conv2d_backprop :") { 100.times do sess2.run(conv2d_grad) end }
+ x.report("pure ruby conv2d :") { 100.times do sess.run(conv2d) end }
+ x.report("opencl conv2d :") { 100.times do sess2.run(conv2d) end }
+ x.report("pure ruby arr index :") { 100.times do sess.run(index) end }
+ x.report("opencl arr index :") { 100.times do sess2.run(index) end }
+ x.report("pure ruby min :") { 100.times do sess.run(min) end }
+ x.report("opencl min :") { 100.times do sess2.run(min) end }
+ x.report("pure ruby sum :") { 100.times do sess.run(sum) end }
+ x.report("opencl sum :") { 100.times do sess2.run(sum) end }
+ x.report("pure ruby sum axis 1 :") { 100.times do sess.run(sum_axis_1) end }
+ x.report("opencl sum axis 1 :") { 100.times do sess2.run(sum_axis_1) end }
x.report("pure ruby split :") { 100.times do sess.run(split) end }
x.report("opencl split :") { 100.times do sess2.run(split) end }
x.report("pure ruby add_n :") { 100.times do sess.run(add_n) end }
x.report("opencl add_n :") { 100.times do sess2.run(add_n) end }
x.report("pure ruby ooo matmul :") { 100.times do sess.run(out_of_order) end }
\ No newline at end of file