当前位置: 首页 > news >正文

vscode里几种程序调试配置

标题调试python嵌入的c++代码,例如

import torch
from torch.utils.cpp_extension import loadtest_load = load(name='test_load', sources=['test.cpp'],extra_cflags=['-O0', '-g'],#extra_cflags=['-O1'],verbose=True,
)
a = torch.tensor([1, 2, 3])
b = torch.tensor([4, 5, 6])
result = test_load.add(a, b)
print(result)  # Should print tensor([5, 7, 9])
#include <torch/extension.h>// 定义一个简单的加法函数
at::Tensor add(at::Tensor a, at::Tensor b) {int size = a.size(0);int dim = a.dim();printf("size: %d, dim: %d\n", size, dim);return a + b;
}PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {m.def("add", &add, "Add two tensors");
}

launch.json配置

{"version": "0.2.0","configurations": [																																																																																																																																																																																																																																																																																																																																																																																																																		{"name": "(gdb) Launch test","type": "cppdbg","request": "launch","program": "/root/miniconda3/bin/python","args": ["test.py"],"stopAtEntry": false,"cwd": "${workspaceFolder}","environment": [],"externalConsole": false,"MIMode": "gdb","miDebuggerPath": "/usr/bin/gdb","setupCommands": [{"description": "Enable pretty-printing for gdb","text": "-enable-pretty-printing","ignoreFailures": true}]}]
}

或者这种简单配置也行

{// Use IntelliSense to learn about possible attributes.// Hover to view descriptions of existing attributes.// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387"version": "0.2.0","configurations": [{"name": "Python test","type": "cppdbg","request": "launch","program": "/root/miniconda3/bin/python","console": "integratedTerminal","args": ["test.py"],"cwd": "${workspaceFolder}","MIMode": "gdb","env": {"PATH": "/root/miniconda3/bin/:$PATH","LD_LIBRARY_PATH": "$PWD:extensions/aec/lib/:$LD_LIBRARY_PATH","CUDA_VISIBLE_DEVICES": "0,1,2,3,4,5,6,7"}}]
}

标题调试torchrun启动代码

bash启动脚本是这样

#!/bin/bash
. /root/miniconda3/etc/profile.d/conda.sh
conda activate /root/miniconda3
export LD_LIBRARY_PATH=$PWD:extensions/lib/:/myso:$LD_LIBRARY_PATH
export PATH=$PWD:extensions/lib/:$PATH
CUDA_VISIBLE_DEVICES=0,1,2,3 torchrun --nproc_per_node=4 --master_port=25642 debug.py

调试配置需要先配置tasks.json激活环境,然后配置launch.json
launch.json

{"version": "0.2.0","configurations": [{"name": "Python: noise_gen_debug","type": "python","request": "launch","program": "/root/miniconda3/bin/torchrun","args": ["--nproc_per_node=1","--master_port=25642","debug.py"],"console": "integratedTerminal","env": {"LD_LIBRARY_PATH": "${workspaceFolder}:${workspaceFolder}/extensions/lib/:/root/myso:${env:LD_LIBRARY_PATH}","CUDA_VISIBLE_DEVICES": "0"}}]
}

tasks.json 里先激活虚拟环境

{"version": "2.0.0","tasks": [{"label": "setup-conda","type": "shell","command": "source /root/miniconda3/etc/profile.d/conda.sh && conda activate /root/miniconda3"}]
}

标题调试python启动ddp代码

#!/bin/bash
export PATH=/root/miniconda3/bin/:$PATHexport LD_LIBRARY_PATH=$PWD/extensions/lib/:$LD_LIBRARY_PATH
export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
python xspeech/bin/ddp_train_debug.py --train_conf=conf/test.yaml --data_conf=conf/test.cfg --gpus=1
{// Use IntelliSense to learn about possible attributes.// Hover to view descriptions of existing attributes.// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387"version": "0.2.0","configurations": [{"name": "Python: Debug ddp_train_test.py","type": "python","request": "launch","program": "${workspaceFolder}/xspeech/bin/ddp_train_test.py","console": "integratedTerminal","python": "/root/miniconda3/bin/python","args": ["--train_conf=conf/test.yaml", "--data_conf=conf/test.cfg", "--gpus=1"],"justMyCode": false,"env": {"PATH": "/root/miniconda3/bin/:$PATH","LD_LIBRARY_PATH": "$PWD:extensions/lib/:$LD_LIBRARY_PATH","CUDA_VISIBLE_DEVICES": "0,1,2,3,4,5,6,7"}}]
}

标题调试已经编译好的c++程序

{"version": "0.2.0","configurations": [{"name": "(gdb) Launch","type": "cppdbg","request": "launch","program": "${workspaceFolder}/build/test-debug","args": [ "model.pkg", "test.conf", "data/test.lst", "10", "2", "1"],"stopAtEntry": false,"cwd": "${workspaceFolder}","environment": [],"externalConsole": false,"MIMode": "gdb","miDebuggerPath": "/usr/bin/gdb","setupCommands": [{"description": "Enable pretty-printing for gdb","text": "-enable-pretty-printing","ignoreFailures": true}]}]
}

settings.json

{"files.associations": {"thread": "cpp"}
}
http://www.xdnf.cn/news/603127.html

相关文章:

  • WebGL入门:贴图
  • iOS 主要版本发布历史
  • Spark on Yarn 高可用模式部署流程
  • 卷积神经网络(CNN)可视化技术详解:从特征学到演化分析
  • 单点击登录sso实现
  • Android Studio历史版本下载方法
  • SpringBoot3整合WebSocket
  • LIEDNet: A Lightweight Network for Low-light Enhancement and Deblurring论文阅读
  • 探索Dify:开启大语言模型应用开发新时代
  • 怎么判断一个Android APP使用了Cordova这个跨端框架
  • [SWPUCTF 2024 秋季新生赛]ret2libc也阴嘛?(NSSCTF)
  • OpenEuler-Apache服务原理
  • 如何配置jmeter做分布式压测
  • .jsx文件和.tsx文件有什么区别
  • 补题目找规律
  • uni-app/vue2:微信小程序实现文件流的下载及预览
  • Claude MCP协议从入门到精通
  • 【Hexo】2.常用的几个命令
  • MySQL别名规则与应用场景
  • Facebook + AdsPower!用一台设备实现 Facebook 多账号管理
  • Jenkins 构建日志统一上报:企业级 DevOps 管理实践
  • 科学养生:解锁现代健康生活新方式
  • 现代生活下的创新健康养生之道
  • 《计算机组成原理》——第二章-6 总线定时:同步定时(同步通信)
  • Pysnmp使用指南
  • CentOS停止维护了,解决yum不能安装软件的问题
  • 网络通信与传输安全
  • echarts定制化柱状图——条纹柱状图
  • RK3588 Opencv-ffmpeg-rkmpp-rkrga编译与测试
  • 【JAVA】注解基础:元注解与自定义注解(30)