pytorch - RuntimeError: CUDA error: invalid argument torch tensor.cuda() 在执行编译的 C++ cuda 函数后引发错误
问题描述
我所有的运营商都是:
.cu
在文件中写一个函数。- 编译
.cu
使用nvcc xxx.cu -o xxx.so -shared -Xcompiler -fPIC
- 加载它
ctypes.cdll
错误发生在:
lib = ctypes.cdll.load('xxx.so')
tmp = torch.ones((1, 1)).cuda()
a = np.ones((1, 1))
b = lib.xxx(a)
tmp = torch.ones((1, 1)).cuda()
执行第二个时出错tensor.cuda()
RuntimeError: CUDA error: invalid argument
但即使发生错误,torch.cuda.is_available()
仍然是 True。
如果我从不将张量加载到 gpu,错误就会消失,即:
lib = ctypes.cdll.load('xxx.so')
tmp = torch.ones((1, 1))
a = np.ones((1, 1))
b = lib.xxx(a)
tmp = torch.ones((1, 1)).cuda()
运行没有错误。
我想找到一种在.so
任何地方执行该功能的方法。
解决方案
推荐阅读
- variables - 在 JuMP 中我们如何使用 VariableRef 来映射值?
- javascript - 读取 Promise 结果变量
- mysql - 捕获 mysql CRUD 命令并将其保存在表中?
- floating-point - 对双倍的 ULP 错误得到不正确的答案
- python - Python,如何为 jsonPayload 设置日志格式
- angular - html表中的ngFor不适用于jsPDF自动表
- c++ - 动态数组(std::vector)如何在 C++ 中工作?
- vuejs3 - vuejs 3:将密钥注入子组件?
- reactjs - 如何将数据从 firebase 解析到 MUI DataGrid?
- python - 如何实现一个高效的 WordFinder?