Skip to content

How to run VSCode Python Debugger with TensileLite

KKyang edited this page May 19, 2025 · 2 revisions

There are two options to run the Python debugger with TensileLite. The first one is to run TensileLite with CMake and Tensile.sh once to build the rocisa Python module, then run the debugger directly with Python Tensile. The second one is to run the debugger directly using Tensile.sh.

Make sure you have debugpy installed under your environment. debugpy does not support multi-process debugging, so make sure you set CpuThreads to 0.

Option 1: Run the Debugger with Python File Tensile (By @Serge45)

Step 1: Run TensileLite Once to Generate the rocisa Module

We assume our working directory is under hipBLASLt/tensilelite/build

cd hipBLASLt/tensilelite
mkdir build
cd build
cmake -DDEVELOP_MODE=ON -DCMAKE_PREFIX_PATH=/opt/rocm ..
./Tensile.sh <path-to-yaml> .

Step 2: Write the launch.json

Create a launch.json and put it under .vscode

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python Debugger",
            "type": "debugpy",
            "request": "launch",
            "program": "${workspaceFolder}/tensilelite/Tensile/bin/Tensile",
            "console": "integratedTerminal",
            "args": ["<path-to-the-yaml>", "<working-dir>"],
            "env": {
               "PYTHONPATH": "${workspaceFolder}/tensilelite/build/lib" 
            }
        }
    ]
}

Option 2: Run the Debugger Directly with Tensile.sh

This method requires a tasks.json and a launch.json. The VSCode is in the host and TensileLite is executed in the docker. If both VSCode and TensileLite are in the docker, then you'll have to make some changes in tasks.json.

Step 1: Run CMake

We assume our working directory is under hipBLASLt/tensilelite/build

cd hipBLASLt/tensilelite
mkdir build
cd build
cmake -DDEVELOP_MODE=ON -DCMAKE_PREFIX_PATH=/opt/rocm ..

Step 2: Write tasks.json

If VSCode is also connected into the docker, you can execute the Tensile.sh directly and have the DEBUGPY_ENABLE=1 set with env after args.

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Run Shell Script from Docker",
            "type": "shell",
            "command": "docker",
            "args": [
                "exec",
                "-e",
                "DEBUGPY_ENABLE=1",
                <your-container-id>,
                "${workspaceFolder}/hipBLASLt/tensilelite/build/Tensile.sh",
                "<path-to-yaml>",
                "<working-dir>"
            ],
            "problemMatcher": [
                {
                    "pattern": [
                        {
                            "regexp": "===DEBUGPY_READY===",
                            "file": 1,
                            "location": 2,
                            "message": 3
                        }
                    ],
                    "background": {
                        "activeOnStart": true,
                        "beginsPattern": "===DEBUGPY_READY===",
                        "endsPattern": "===DEBUGPY_READY==="
                    }
                }
            ],
            "isBackground": true,
        }
    ]
}

Step 3: Write launch.json

Noted that here should be attach not launch. The pathMappings is the path in your host (local) and the docker (remote).

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Attach to Python via debugpy",
            "type": "debugpy",
            "request": "attach",
            "connect": {
                "host": "localhost",
                "port": 5678
            }, // Use lsof -i :5678 to find the zombie process and kill with kill -9 <PID>
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "${workspaceFolder}"
                }
            ],
            "preLaunchTask": "Run Shell Script from Docker"
        }
    ]
}

Note: when using option 2, you may get the port been occupied by a zombie process if something goes wrong with the VSCode setup. When this happens, you can use lsof to find the zombie process and kill it.

lsof -i :5678
kill -9 <PID>