c++: internal compiler error: Killed (program cc1plus)

编译pytorch时报错如下:

c++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-7/README.Bugs> for instructions.
caffe2/CMakeFiles/torch_cpu.dir/build.make:3724: recipe for target 'caffe2/CMakeFiles/torch_cpu.dir/__/aten/src/ATen/Functions.cpp.o' failed
make[2]: *** [caffe2/CMakeFiles/torch_cpu.dir/__/aten/src/ATen/Functions.cpp.o] Error 4
CMakeFiles/Makefile2:2837: recipe for target 'caffe2/CMakeFiles/torch_cpu.dir/all' failed
make[1]: *** [caffe2/CMakeFiles/torch_cpu.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
Traceback (most recent call last):
  File "setup.py", line 727, in <module>
    build_deps()
  File "setup.py", line 319, in build_deps
    cmake=cmake)
  File "/home/casia/pytorch1.7/pytorch/tools/build_pytorch_libs.py", line 62, in build_caffe2
    cmake.build(my_env)
  File "/home/casia/pytorch1.7/pytorch/tools/setup_helpers/cmake.py", line 346, in build
    self.run(build_args, my_env)
  File "/home/casia/pytorch1.7/pytorch/tools/setup_helpers/cmake.py", line 141, in run
    check_call(command, cwd=self.build_dir, env=env)
  File "/home/casia/.conda/envs/py36/lib/python3.6/subprocess.py", line 291, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--target', 'install', '--config', 'Release', '--', '-j', '1']' returned non-zero exit status 2.

问题解决

这个问题网上解决方案很多,在此总结一些

遇到此类问题,原因是内存不足,也就是交换空间不足

使用指令查看当前内存和交换空间情况:

free -m
              total        used        free      shared  buff/cache   available
Mem:            989         954          12           0          22          14
Swap:          0            0            0

 可以看到我并没有启用swap空间,打开swap就可以解决这个问题

# 创建swap分区文件
sudo dd if=/dev/zero of=/root/swapfile bs=64M count=32
# swapfile格式化为交换分区文件
sudo mkswap /root/swapfile
# 启用交换空间
sudo swapon /root/swapfile
# 关闭交换空间
sudo swapoff /root/swapfile
# 若有需要,也可以删掉交换空间
sudo rm /root/swapfile

在上面的代码中,bs表示块的大小,swap空间的大小为:bs*count

通过上面的操作后,我们重新编译,应该可以成功编译,并且没有报错的!还报错的话,就请加大交换空间

  • 11
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值