Skip to content
This repository was archived by the owner on Jun 5, 2022. It is now read-only.

Commit bf80d81

Browse files
Merge pull request aymericdamien#71 from Helw150/master
Fixes for Multi-Gpu_basics No Longer hangs on CPU
2 parents 5ed3296 + 101e0fc commit bf80d81

File tree

2 files changed

+10
-94
lines changed

2 files changed

+10
-94
lines changed

examples/5_MultiGPU/multigpu_basics.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
'''
23
Basic Multi GPU computation example using TensorFlow library.
34
@@ -12,7 +13,7 @@
1213
"/gpu:1": The second GPU of your machine
1314
'''
1415

15-
from __future__ import print_function
16+
1617

1718
import numpy as np
1819
import tensorflow as tf
@@ -31,8 +32,8 @@
3132
* Multi GPU computation time: 0:00:07.131701
3233
'''
3334
# Create random large matrix
34-
A = np.random.rand(1e4, 1e4).astype('float32')
35-
B = np.random.rand(1e4, 1e4).astype('float32')
35+
A = np.random.rand(10000, 10000).astype('float32')
36+
B = np.random.rand(10000, 10000).astype('float32')
3637

3738
# Create a graph to store results
3839
c1 = []
@@ -48,8 +49,8 @@ def matpow(M, n):
4849
Single GPU computing
4950
'''
5051
with tf.device('/gpu:0'):
51-
a = tf.constant(A)
52-
b = tf.constant(B)
52+
a = tf.placeholder(tf.float32, [10000, 10000])
53+
b = tf.placeholder(tf.float32, [10000, 10000])
5354
# Compute A^n and B^n and store results in c1
5455
c1.append(matpow(a, n))
5556
c1.append(matpow(b, n))
@@ -60,7 +61,7 @@ def matpow(M, n):
6061
t1_1 = datetime.datetime.now()
6162
with tf.Session(config=tf.ConfigProto(log_device_placement=log_device_placement)) as sess:
6263
# Run the op.
63-
sess.run(sum)
64+
sess.run(sum, {a:A, b:B})
6465
t2_1 = datetime.datetime.now()
6566

6667

@@ -70,13 +71,13 @@ def matpow(M, n):
7071
# GPU:0 computes A^n
7172
with tf.device('/gpu:0'):
7273
# Compute A^n and store result in c2
73-
a = tf.constant(A)
74+
a = tf.placeholder(tf.float32, [10000, 10000])
7475
c2.append(matpow(a, n))
7576

7677
# GPU:1 computes B^n
7778
with tf.device('/gpu:1'):
7879
# Compute B^n and store result in c2
79-
b = tf.constant(B)
80+
b = tf.placeholder(tf.float32, [10000, 10000])
8081
c2.append(matpow(b, n))
8182

8283
with tf.device('/cpu:0'):
@@ -85,7 +86,7 @@ def matpow(M, n):
8586
t1_2 = datetime.datetime.now()
8687
with tf.Session(config=tf.ConfigProto(log_device_placement=log_device_placement)) as sess:
8788
# Run the op.
88-
sess.run(sum)
89+
sess.run(sum, {a:A, b:B})
8990
t2_2 = datetime.datetime.now()
9091

9192

multigpu_basics.py

-85
This file was deleted.

0 commit comments

Comments
 (0)