我目前正在使用cuda 9.0运行tensorflow-gpu 1.8 . 当我训练下面的模型时,我注意到我的CPU使用率为99%,但我的特斯拉M60使用率为0% .
导入张量流为tf
tf.test.gpu_device_name()
def train(tfidf_matrix, num_clusters):
# Convert sparse matrix to dense matrix
points = tfidf_matrix.todense()
tf.device('/gpu:0')
def input_fn():
return tf.train.limit_epochs(tf.convert_to_tensor(points, dtype=tf.float32), num_epochs=1)
kmeans = tf.contrib.factorization.KMeansClustering(num_clusters=num_clusters, use_mini_batch=False)
num_iterations = 100
kmeans.train(input_fn=input_fn, steps=num_iterations)
print('score:', kmeans.score(input_fn))
# map the input points to their clusters
cluster_indices = list(kmeans.predict_cluster_index(input_fn))
return kmeans, cluster_indices
我似乎无法让模型在gpu上运行 . 我试过这样做:
with tf.device('/gpu:0'):
kmeans.train(input_fn)
但它仍然在cpu上运行 . 当我运行tf.test.gpu_device_name()时,我得到了这个
`2018-07-18 15:28:47.105452:我c:\ users \ user \ source \ repos \ tensorflow \ tensorflow \ core \ common_runtime \ gpu \ gpu_device.cc:1392]找到具有属性的设备0:名称:Tesla M60 major:5 minor:2 memoryClockRate(GHz):1.1775 pciBusID:0000:00:1e.0 totalMemory:7.44GiB freeMemory:7.12GiB 2018-07-18 15:28:47.105846:我c:\ users \ user \ source \ repos \ tensorflow \ tensorflow \ core \ common_runtime \ gpu \ gpu_device.cc:1471]添加可见的gpu设备:0 2018-07-18 15:28:47.852029:我c:\ users \ user \ source \ repos \ tensorflow \ tensorflow \ core \ common_runtime \ gpu \ gpu_device.cc:952]具有强度1边缘矩阵的设备互连StreamExecutor:2018-07-18 15:28:47.852268:我c:\ users \ user \ source \ repos \ tensorflow \ tensorflow \ core \ common_runtime \ gpu \ gpu_device.cc:958] 0 2018-07-18 15:28:47.852440:我c:\ users \ user \ source \ repos \ tensorflow \ tensorflow \ core \ common_runtime \ gpu \ gpu_device.cc:971 ] 0:N 2018-07-18 15:28:47.852859:我c:\ users \ user \ source \ repos \ tensorflow \ tensorflow \ core \ common_runtime \ gpu \ gpu_device.cc:1084] Crea Ted TensorFlow设备(/设备:GPU:0,内存为6874 MB) - >物理GPU(设备:0,名称:Tesla M60,pci总线ID:0000:00:1e.0,计算能力:5.2