“对等访问”一起使用pycuda和tensorflow时失败 [英] "Peer access" failed when using pycuda and tensorflow together

查看:103
本文介绍了“对等访问”一起使用pycuda和tensorflow时失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在python3中有一些这样的代码:

I have some codes in python3 like this:

import numpy as np
import pycuda.driver as cuda
from pycuda.compiler import SourceModule, compile
import tensorflow as tf

# create device and context
cudadevice=cuda.Device(gpuid1)
cudacontext=cudadevice.make_context()

config = tf.ConfigProto()
config.gpu_options.visible_device_list={}.format(gpuid2)
sess = tf.Session(config=config)



# compile from a .cu file
cuda_mod = SourceModule(cudaCode, include_dirs = [dir_path], no_extern_c = True, options = ['-O0'])
# in the .cu code a texture named "map" is defined as:
# texture<float4, cudaTextureType2D, cudaReadModeElementType> map;
texRef = cuda_mod.get_texref('map')

# tex is a np.ndarray with shape 256*256*4, and it is the output of a tensorflow's graph by calling sess.run()
tex = np.ascontiguousarray(tex).astype(np.float32)
tex_gpu = cuda.make_multichannel_2d_array(tex, 'C') 

# error here!!!!!
texRef.set_array(tex_gpu)

并显示错误消息:

pycuda._driver.LogicError:cuTexRefSetArray失败:未启用对等访问

当以下情况出现对等访问错误也使用了 tensorflow (即使gpuid1和gpuid2相同),但是如果没有 tensorflow ,一切都会进行。
我发现对等访问与GPU(设备)之间的通信有关。但是我在这里所做的只是将一个 numpy 数组设置为GPU内存的纹理,因此我认为这与在不同GPU之间传输数据无关。那怎么了谢谢!

The peer access error appeared when tensorflow is also on use (even if gpuid1 and gpuid2 are same), but everything goes right without tensorflow. I found that "peer access" has something to do with communicating between GPUs (devices). But what I'm doing here is just setting a numpy array to GPU memory as texture, so I think it has nothing to do with transferring data between different GPUs. So what's wrong with it? Thanks!

推荐答案

似乎我找到了解决方案。将texRef.set_array(tex_gpu)插入cudadevice.cudacontext.push()和cudadevice.cudacontext.pop()之间以显式切换cuda上下文时,一切正常。

It seems I have found the solution. When texRef.set_array(tex_gpu) is inserted between cudadevice.cudacontext.push() and cudadevice.cudacontext.pop() to explicitly switch the cuda context, everything goes okay.

这篇关于“对等访问”一起使用pycuda和tensorflow时失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆