如何创建相当于 cuda makefile 的 MS VS 代码

how to create ms vs code equivalent of cuda makefile

这是一个用于编译和执行 NVidia 示例代码的最小 makefile jpegNPP.cpp

CC=g++
NVCC=nvcc
CXXFLAGS= -m64    -gencode arch=compute_30,code=compute_30
CUDAFLAGS= -ccbin
LIBS= -lnppisu -lnppicom -lnppig -lnppc -lfreeimage
LIBDIRS=-L/usr/local/cuda-10.2/lib64 \
    -L/usr/local/cuda-10.2/samples/7_CUDALibraries/common/FreeImage/lib/x64 \
    -L/usr/local/cuda-10.2/samples/7_CUDALibraries/common/FreeImage/lib/linux \
    -L/usr/local/cuda-10.2/samples/7_CUDALibraries/common/FreeImage/lib/linux/aarch64 
INCDIRS=-I/usr/local/cuda-10.2/include \
    -I/usr/local/cuda-10.2/samples/7_CUDALibraries/common/UtilNPP/ \
    -I/usr/local/cuda-10.2/samples/common/inc/ 

all: jpegNPP
    ./jpegNPP -input=../Data/1.jpg -output=tmp.jpg -scale=.5
    xdg-open tmp.jpg 
    xdg-open  ../Data/1.jpg 

jpegNPP.o: jpegNPP.cpp
    $(NVCC) $(CUDAFLAGS) $(CC) $(INCDIRS) $(CXXFLAGS) -o jpegNPP.o -c jpegNPP.cpp

jpegNPP: jpegNPP.o
    $(NVCC) $(CUDAFLAGS) $(CC) $(CXXFLAGS) -o jpegNPP jpegNPP.o $(LIBDIRS) $(LIBS)
 
clean:
    rm -rf jpegNPP *.o *.jpg

我想在 Ubuntu 中使用 ms vs code。 make文件构建可以有多个步骤,分别是编译、link、执行。如何使 c_cpp_properties.json 和 tasks.json 自动执行 nvcc / gcc(对于 cpp 文件)编译和 nvcc linking。当前属性 json 文件是

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/local/cuda-10.2/samples/7_CUDALibraries/common/UtilNPP/",
                "/usr/local/cuda-10.2/samples/common/inc/"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "gnu11",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "linux-gcc-arm64"
        }
    ],
    "version": 4
}

和任务json文件

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++-7 build active file",
            "command": "nvcc -ccbin g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}.o"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger and modified for nvcc"
        }
    ],
    "version": "2.0.0"
}

在 tasks.json 中添加如下内容:

        {
            "label": "make",
            "type": "shell",
            "command": "make -j10",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": [
                "$gcc"
            ]
        },

此处您将其设置为默认值(因此 cntl+B 应该构建它)。它对错误使用 GCC 格式,因此您可以 cntl+单击错误以转到错误行。

但基本上你是在告诉 vs 使用 shell 和 运行 命令 makemake -j10make all 或任何你的 make 命令...