首页 > 其他分享 >Hello Cuda(三)——VSCODE&LibTorch

Hello Cuda(三)——VSCODE&LibTorch

时间:2023-08-26 10:34:24浏览次数:30  
标签:cmake shiyanshi VSCODE Hello LibTorch gdb home include example

CMAKELists

cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(example)

set(CMAKE_PREFIX_PATH /home/xuliangyu/libtorch)
set(Torch_DIR /home/shiyanshi/libtorch/share/cmake/) 
# 修改这里为自己的libtorch cmake路径,也可以用pytorch安装时编译的pkg里的cmake
find_package(Torch REQUIRED)
#find_package(CUDA REQUIRED)

INCLUDE_DIRECTORIES(
    "/home/shiyanshi/libtorch/include"
    "/home/shiyanshi/liborch/include/csrc/api/include"
)

add_executable(example example.cpp)
target_link_libraries(example "${TORCH_LIBRARIES}")
set_property(TARGET example PROPERTY CXX_STANDARD 14)

Tasks.json

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "cppbuild",
			"label": "cmake build",
			"command": "cmake", // 这里要写cmake编译指令 可以写在command 也可以拆开来写
			"args": [
				"-D",
				"CMAKE_PREFIX_PATH=/home/shiyanshi/libtorch/share/cmake",
				"..",
				"&&",
				"make",
				"-j"
			],
			"options": {
				"cwd": "/home/shiyanshi/Cuda_Lib/cuda_2/build"  // 工作路径,表示要编译的文件目录
			},
			"problemMatcher": [
				"$gcc"
			],
			"group": {
				"kind": "build",
				"isDefault": true
			},
			"detail": "compiler: /usr/bin/g++"
		}
	]
}

Launch.json

{
    // 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": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build/example", // 用于指定要进行调试的程序路径
            "args": [],
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}", // 表示当前workspace文件夹路径
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "cmake build",
            "miDebuggerArgs": "/usr/bin/gdb"
        }
    ]
}

测试C++文件

#include <torch/script.h>
#include <iostream>

int main() {
  torch::Tensor foo = torch::arange(25).reshape({5, 5});
  torch::Tensor bar  = torch::einsum("ii", foo);

  std::cout << "==> matrix is:\n " << foo << std::endl;
  std::cout << "==> trace of it is:\n " << bar << std::endl;
}

标签:cmake,shiyanshi,VSCODE,Hello,LibTorch,gdb,home,include,example
From: https://www.cnblogs.com/XL2COWARD/p/MyCuda_3.html

相关文章

  • VSCode使用JavaScript刷LeetCode配置教程(亲试可以!)
    账号秘密都对,但是缺登录不成功的问题诀窍可能是:在属性设置中把LeetCode版本改成cn。点击LeetCode配置,修改Endpoint配置项,改成leetcode-cn,再次尝试登陆即可。  大家可移步原博文:https://blog.csdn.net/qq_37263248/article/details/124304402......
  • vscode reference代码提示怎么关闭
     ......
  • 编程真好玩Python_2.1你的第一个程序HelloWorld
    一、作业效果。(1)程序首先显示信息:“你好,世界!”(2)询问你的名字(3)输入后,屏幕显示“你好,×××!”二、完成(1)新建文件夹,保存-命名(2)运行代码print("Hello,World!")person=input("Whatisyourname?\n")print("Hello,",person)(3)在编辑窗口中,选择Run-RunModule,运行程序......
  • vscode 中 Markdown 粘贴图片的位置
    背景自从typora开始收费后,不少人开始寻找其他的Markdown编辑器,我觉得vscode就是一个很不错的选择虽然不能像typora在Markdown预览中编辑,但是左右布局对于一个前端工程师来说已是习以为常PS:自从github被微软收购后,github开始使用网页版的vscode编辑器......
  • VScode settings.json默认配置文件路径
    LinuxUbuntu:/home/${用户名}/.config/Code/User/settings.jsonWindows:C:\Users\用户名\AppData\Roaming\Code\User来源、参考:https://blog.csdn.net/cyqzy/article/details/130011314......
  • vscode 配置
    {"workbench.colorTheme":"VisualStudioDark","editor.fontSize":16,"workbench.startupEditor":"none","editor.formatOnType":true,"workbench.settings.openDefaultSett......
  • Hello Cuda(二)——向量加法
    #include<stdio.h>#include<stdlib.h>#include<cuda.h>#include<math.h>#include<cuda_runtime.h>#include<device_launch_parameters.h>typedeffloatFLOAT;doubleget_time();voidwarm_up();voidvec_add_host(FLOA......
  • Hello Cuda(一)——GPU设备检测
    #include"device_launch_parameters.h"#include<iostream>intmain(intargc,char*argv[]){intdeviceCount;//设备数目cudaGetDeviceCount(&deviceCount);for(inti=0;i<deviceCount;i++){cudaDeviceProp......
  • 1001:Hello,World!
    1001:Hello,World!时间限制:1000ms      内存限制:65536KB提交数:345055   通过数:168663【题目描述】编写一个能够输出“Hello,World!”的程序,这个程序常常作为一个初学者接触一门新的编程语言所写的第一个程序,也经常用来测试开发、编译环境是否能够正常......
  • VScode调试F5 调试操作介绍
    继续(F5):按下F5键启动调试后,程序会在断点处停止执行。当你希望程序继续执行至下一个断点或完整地运行结束时,可以选择"继续"。可以使用F5键或点击调试工具栏中的"继续"按钮。单步跳过(F10):单步跳过是在调试过程中逐行执行代码,但是对于遇到的函数或方法调用,不会进入其内部进行调试......