Skip to content

How to debug SYCLomatic —— use VSCode

Tang Jiajun edited this page Jun 26, 2023 · 5 revisions

Step 1: Download some necessary extensions.

  • .NET Install Tool for Extension Authors
  • CMake Language Support
  • clangd
  • CodeLLDB

Step 2: Add “launch.json” and “tasks.json” in “.vscode” folder, create new folders named “vscode-build” (to put the build progress files).

syclomatic_home
|-- .vscode
   |-- launch.json
   |-- tasks.json
|-- vscode-build
|-- SYCLomatic

launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "dpct",
            "type": "lldb",
            "request": "launch",
            "program": "${workspaceFolder}/vscode-build/bin/dpct",
            "args": [
                "--out-root=${workspaceFolder}/test/out",
                "--no-incremental-migration",
                "${workspaceFolder}/test/test.cu",
                "--format-range=none"
            ],
            "preLaunchTask": "install-dpct"
        },
        {
            "name": "dpct-pkg",
            "type": "lldb",
            "request": "launch",
            "program": "${workspaceFolder}/vscode-build/bin/dpct",
            "args": [
                "--in-root=${workspaceFolder}/pkg_test",
                "--out-root=${workspaceFolder}/pkg_test_out",
                "--no-incremental-migration",
                "--process-all",
                "--format-range=none",
                "--use-pure-sycl"
            ],
            "cwd": "${workspaceFolder}",
            "preLaunchTask": "install-dpct",
        },
        {
            "name": "clang-ast",
            "type": "lldb",
            "request": "launch",
            "program": "${workspaceFolder}/vscode-build/bin/clang",
            "args": [
                "-Xclang",
                "-ast-dump",
                "-fsyntax-only",
                "${workspaceFolder}/test/test.cpp",
                "-nocudalib"
            ],
            "cwd": "${workspaceFolder}",
            "preLaunchTask": "install-clang",
        }
    ]
}

tasks.json:

{
    "tasks": [
        {
            "type": "shell",
            "label": "cmake",
            "command": "cmake",
            "args": [
                "-G",
                "Ninja",
                "-DCMAKE_INSTALL_PREFIX=${workspaceFolder}/vscode-build/c2s_install",
                "-DCMAKE_BUILD_TYPE=Debug",
                "-DLLVM_ENABLE_PROJECTS=\"clang\"",
                "-DLLVM_TARGETS_TO_BUILD=\"X86;NVPTX\"",
                "${workspaceFolder}/SYCLomatic/llvm/"
            ],
            "options": {
                "cwd": "${workspaceFolder}/vscode-build"
            }
        },
        {
            "label": "install-dpct",
            "command": "ninja",
            "args": [
                "-j",
                "16",
                "install-dpct"
            ],
            "options": {
                "cwd": "${workspaceFolder}/vscode-build"
            },
            "dependsOn": [
                "cmake"
            ]
        },
        {
            "label": "install-clang",
            "command": "ninja",
            "args": [
                "-j",
                "16",
                "install-clang"
            ],
            "options": {
                "cwd": "${workspaceFolder}/vscode-build"
            },
            "dependsOn": [
                "cmake"
            ]
        }
    ],
    "version": "2.0.0"
}

Step 3: Chose "dpct" and click the green "start" button to start debug. Set the "clangd" when need auto complete:

  • Clangd: Arguments
--compile-commands-dir=${workspaceFolder}/vscode-build
  • Clangd: Fallback Flags
-std=c++17
--cuda-path=/path-to-cuda/ (make sure has a version.txt file)
--cuda-gpu-arch=sm_70