how to create ms vs code equivalent of cuda makefile

Viewed 425

Here's a minimal makefile to compile and execute the NVidia sample code 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

I would like to use ms vs code, in Ubuntu. The make file build can have multiple steps, which are compile, link, and execute. How do I make the c_cpp_properties.json and tasks.json to automate the nvcc / gcc (for cpp files) compiling and nvcc linking. The current properties json file is

{
    "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
}

and tasks json file

{
    "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"
}
1 Answers

In the tasks.json add something like:

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

Here you are setting it to the default (so cntl+B should build it). It uses GCC format for errors so you can cntl+click on the errors to go to the error line.

But basically you are telling vs to use the shell and run the command make or make -j10 or make all or whatever your make command is...

Related