#Import libraries for simulation
import tensorflow as tf
import numpy as np
sess = tf.InteractiveSession()
def make_kernel(a):
"""Transform a 2D array into a convolution kernel"""
a = np.asarray(a)
a = a.reshape(list(a.shape) + [1,1])
return tf.constant(a, dtype=1)
def simple_conv(x, k):
"""A simplified 2D convolution operation"""
x = tf.expand_dims(tf.expand_dims(x, 0), -1)
y = tf.nn.depthwise_conv2d(x, k, [1, 1, 1, 1], padding='SAME')
return y[0, :, :, 0]
def laplace(x):
"""Compute the 2D laplacian of an array"""
laplace_k = make_kernel([[0.5, 1.0, 0.5],
[1.0, -6., 1.0],
[0.5, 1.0, 0.5]])
return simple_conv(x, laplace_k)
# Initial Conditions -- some rain drops hit a pond
N = 500
# Set everything to zero
u_init = np.zeros([N, N], dtype=np.float32)
ut_init = np.zeros([N, N], dtype=np.float32)
# Some rain drops hit a pond at random points
for n in range(40):
a,b = np.random.randint(0, N, 2)
u_init[a,b] = np.random.uniform()
# Parameters:
# eps -- time resolution
# damping -- wave damping
eps = tf.placeholder(tf.float32, shape=())
damping = tf.placeholder(tf.float32, shape=())
# Create variables for simulation state
U = tf.Variable(u_init)
Ut = tf.Variable(ut_init)
# Discretized PDE update rules
U_ = U + eps * Ut
Ut_ = Ut + eps * (laplace(U) - damping * Ut)
# Operation to update the state
step = tf.group(
U.assign(U_),
Ut.assign(Ut_))
# Initialize state to initial conditions
tf.initialize_all_variables().run()
# Run 1000 steps of PDE
nsteps = 1000
for i in range(nsteps):
# Step simulation
step.run({eps: 0.03, damping: 0.04})
# Visualize every 50 steps
if i % 50 == 0:
print("iter = %d, max(U) = %f, min(U) = %f" % \
(i, np.max(U.eval()), np.min(U.eval())))
sess.close()
在我本地计算机上的GPU上,我在step.run({eps: 0.03, damping: 0.04})
I tensorflow / core / common_runtime / gpu / gpu_device.cc:755]创建TensorFlow设备(/ gpu:0) - > (设备:0,名称:GeForce GTX 750 Ti,pci总线ID:0000:01:00.0)
F tensorflow / stream_executor / cuda / cuda_dnn.cc:675]检查失败:status == CUDNN_STATUS_SUCCESS(3 vs. 0)无法找到合适的算法进行前向卷积
中止(核心倾销)
当我使用CPU with tf.device('/cpu:0'):
运行代码时,它可以正常工作。此外,我已经使用GPU运行其他示例了。
这是他们尚未实施的功能吗?或者我在某个地方犯了错误?
系统信息:
操作系统:Ubuntu 14.04 LTS
显卡:GeForce GTX 750 Ti
已安装的CUDA和cuDNN版本:CUDA 7.5,cuNN v5
我通过从GitHub中提取来安装源代码。有关GitHub问题跟踪器的更多信息:https://github.com/tensorflow/tensorflow/issues/2174
答案 0 :(得分:0)
(1)TensorFlow要求(请参阅tensorflow手册)
TensorFlow Python API支持Python 2.7和Python 3.3 +。
GPU版本(仅限Linux)最适合Cuda Toolkit 7.5和cuDNN v4。仅在从源安装时支持其他版本(Cuda toolkit> = 7.0和cuDNN 6.5(v2),7.0(v3),v5)。
(2)Make do
因此 (2-1)删除cuDNN5 (2-2)安装cuDNN4并设置
(2-3-1)卸载tensorflow (2-3-2)安装(gpu)tensorflow