Reputation: 417
So I am training a NN in tensorflow and in the same time I am monitoring my GPU load.
From the screenshot I see that Tensorflow basically uses only the GPU memory, is this normal ? I thought they utilize all my cuda cores to perform some computations and etc.
Is there are someone who knows this stuff in detal ?
Thanks in advance!
Here comes the code ...
import tensorflow as tf
tf.logging.set_verbosity(tf.logging.INFO)
# ... some file reading here
def train_input_fn(features, labels, batch_size):
return tf.estimator.inputs.pandas_input_fn(
x = features,
y = labels,
num_epochs = 1,
shuffle = True,
batch_size = batch_size)
def eval_input_fn(features, labels):
return tf.estimator.inputs.pandas_input_fn(
x = features,
y = labels,
num_epochs = 1,
shuffle = True)
def pred_input_fn(features):
return tf.estimator.inputs.pandas_input_fn(
x = features,
num_epochs = 1,
shuffle = False)
model_dir = './DNN_Linear_Combined_Regressor'
file_writer = tf.summary.FileWriter(model_dir)
estimator = tf.estimator.DNNLinearCombinedRegressor(
model_dir = model_dir,
linear_feature_columns = wide_columns,
dnn_feature_columns = deep_columns,
dnn_optimizer = tf.train.AdamOptimizer(learning_rate=0.001),
dnn_hidden_units = [64,64,64,8],
batch_norm = True,
dnn_dropout = 0.1
)
train_spec = tf.estimator.TrainSpec(input_fn = train_input_fn(train, y_train, batch_size=5000))
eval_spec = tf.estimator.EvalSpec(input_fn = eval_input_fn(valid, y_valid))
tf.estimator.train_and_evaluate(estimator, train_spec, eval_spec)
Upvotes: 1
Views: 841
Reputation: 2012
According to TensorFlow docs here, TensorFlow will use as much as your GPU memory by default.
Also, you can check which tensor calculation is using which device in terminal with following code:
# Creates an estimator with log_device_placement set to True.
sess_config = tf.ConfigProto(log_device_placement=True)
run_config = tf.estimator.RunConfig(session_config = sess_config)
your_classifier = tf.estimator.Estimator(config=run_config)
You'll see something like this:
Device mapping:
/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: Tesla K40c, pci bus
id: 0000:05:00.0
b: /job:localhost/replica:0/task:0/device:GPU:0
a: /job:localhost/replica:0/task:0/device:GPU:0
MatMul: /job:localhost/replica:0/task:0/device:GPU:0
where GPU:0
is your default GPU.
Upvotes: 2
Reputation: 143
Cuda is a platform which allows you to run C/C++ code on the GPU. Cuda cores are part of GPU. So it is using Cuda cores for computation.
It is normal for Tensorflow to use GPU. Special operations like Matrix addition, multiplication, etc can be executed quite efficiently on a GPU as compared to a CPU (because of parallelism and hardware acceleration).
Upvotes: 1