- 点击左边的运行/ 或者用快捷键 ctrl+shift+d——添加launch.json
- 在launch.json中添加CUDA_VISIBLE_DEVICES:1
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: 当前文件",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"env":{
"CUDA_VISIBLE_DEVICES":"1"
}
}
]
}
- 结果
可以通过nvidia-smi看现存占用情况