pycuda和tensorflow可以一起工作吗?

时间:2018-05-02 01:24:18

标签: python tensorflow pycuda

一旦张量流量激活。即使我使用sess.close() ...

,它也会使每个cuda代码崩溃

错误消息是:

  

pycuda._driver.LogicError:cuFuncSetBlockShape失败:无效   资源处理

下面的代码是一个简单的示例cuda代码由pycuda运行:
我添加sess = tf.Session()后。我的cuda代码崩溃了。没有sess = tf.Session(),它可以正常工作。

import tensorflow as tf
import pycuda.autoinit
import pycuda.driver as drv
import numpy
from pycuda.compiler import SourceModule
mod = SourceModule("""
__global__ void multiply_them(float *dest, float *a, float *b)
{
  const int i = threadIdx.x;
  dest[i] = a[i] * b[i];
}
""")

## tensorflow will make any other cuda code crash............
sess = tf.Session()
sess.close()
## tensorflow will make any other cuda code crash............

multiply_them = mod.get_function("multiply_them")
a = numpy.random.randn(400).astype(numpy.float32)
b = numpy.random.randn(400).astype(numpy.float32)
dest = numpy.zeros_like(a)
multiply_them(drv.Out(dest), drv.In(a), drv.In(b), block=(400,1,1), grid=(1,1))
print (dest-a*b)
print("finish")

有什么建议吗?感谢~~~

0 个答案:

没有答案