在 Visual Studio Code 中编译、调试和执行 Makefile 工程 llama2.c

在 Visual Studio Code 中编译、调试和执行 Makefile 工程 llama2.c

  • [1. Installing the extension (在 Visual Studio Code 中安装插件)](#1. Installing the extension (在 Visual Studio Code 中安装插件))
    • [1.1. Extensions for Visual Studio Code](#1.1. Extensions for Visual Studio Code)
    • [1.2. C/C++](#1.2. C/C++)
      • [1.2.1. Pre-requisites](#1.2.1. Pre-requisites)
    • [1.3. Makefile Tools](#1.3. Makefile Tools)
  • [2. Configuring your project (配置项目)](#2. Configuring your project (配置项目))
    • [2.1. `/home/yongqiang/llm_work/llama2.c/`](#2.1. /home/yongqiang/llm_work/llama2.c/)
    • [2.2. 创建工作区设置文件 `.vscode/settings.json`](#2.2. 创建工作区设置文件 .vscode/settings.json)
    • [2.3. Makefile: Project Outline](#2.3. Makefile: Project Outline)
  • [3. Debugging and running targets (调试并运行目标)](#3. Debugging and running targets (调试并运行目标))
    • [3.1. 配置 `.vscode/settings.json` 文件中 `binaryArgs` 的运行参数](#3.1. 配置 .vscode/settings.json 文件中 binaryArgs 的运行参数)
  • References

1. Installing the extension (在 Visual Studio Code 中安装插件)

1.1. Extensions for Visual Studio Code

https://marketplace.visualstudio.com/vscode

1.2. C/C++

C/C++ for Visual Studio Code

The C/C++ extension adds language support for C/C++ to Visual Studio Code, including editing (IntelliSense) and debugging features.

1.2.1. Pre-requisites

C++ is a compiled language meaning your program's source code must be translated (compiled) before it can be run on your computer. VS Code is first and foremost an editor, and relies on command-line tools to do much of the development workflow. The C/C++ extension does not include a C++ compiler or debugger. You will need to install these tools or use those already installed on your computer.

  • C++ compiler pre-installed
  • C++ debugger pre-installed

Here is a list of compilers and architectures per platform officially supported by the extension.

Platform Compilers Architectures
Windows MSVC, Clang, GCC x64, x86, arm64, arm
Linux Clang, GCC x64, x86, arm64, arm
macOS Clang, GCC x64, x86, arm64

1.3. Makefile Tools

VS Code Makefile Tools

This extension provides IntelliSense configurations to the VS Code C/C++ Extension for Makefile projects. It also provides convenient commands to build, debug, and run your targets.

2. Configuring your project (配置项目)

2.1. /home/yongqiang/llm_work/llama2.c/

Help -> Welcome -> Open Folder

2.2. 创建工作区设置文件 .vscode/settings.json

Command Palette (Ctrl + Shift + P)

Preferences: Open Workspace Settings (JSON)

/home/yongqiang/llm_work/llama2.c/.vscode/settings.json

2.3. Makefile: Project Outline

  • Configuration: [Default]

Hover over Configuration and select the pencil icon to choose a configuration for your project.

将鼠标悬停在 Configuration 上并选择铅笔图标来为你的项目选择配置。

  • Build target: [rundebug]

Choose a Build target by selecting the pencil icon that appears on hover.

通过选择悬停时出现的铅笔图标来选择构建目标。

  • Launch target: [run]
  • Launch target: [runq]
  • Makefile: [/home/yongqiang/llm_work/llama2.c/Makefile]

在 VS Code 中使用快捷键 Ctrl + Shift + P,输入并选择 Makefile: Configure。

The extension will activate when it finds a Makefile in your ${workspaceFolder}.

  • .vscode/settings.json

    {
    "makefile.launchConfigurations": [
    {
    "cwd": "/home/yongqiang/llm_work/llama2.c",
    "binaryPath": "/home/yongqiang/llm_work/llama2.c/run",
    "binaryArgs": []
    },
    {
    "cwd": "/home/yongqiang/llm_work/llama2.c",
    "binaryPath": "/home/yongqiang/llm_work/llama2.c/runq",
    "binaryArgs": []
    }
    ]
    }

3. Debugging and running targets (调试并运行目标)

After setting the Build target, click the Build icon.

Makefile: Build the current target

Once the Launch target is set, select the Debug icon to start a debugging session.

Makefile: Debug the selected binary target

To run the program without debugging, select the Run in Terminal button.

Makefile: Run the selected binary target in the terminal

If you need to pass additional arguments to your targets, update the makefile.launchConfigurations by adding the binaryArgs property to the configuration.

复制代码
(base) yongqiang@yongqiang:~/llm_work/llama2.c$ "/home/yongqiang/llm_work/llama2.c/run" 
Usage:   run <checkpoint> [options]
Example: run model.bin -n 256 -i "Once upon a time"
Options:
  -t <float>  temperature in [0,inf], default 1.0
  -p <float>  p value in top-p (nucleus) sampling in [0,1] default 0.9
  -s <int>    random seed, default time(NULL)
  -n <int>    number of steps to run for, default 256. 0 = max_seq_len
  -i <string> input prompt
  -z <string> optional path to custom tokenizer
  -m <string> mode: generate|chat, default: generate
  -y <string> (optional) system prompt in chat mode
(base) yongqiang@yongqiang:~/llm_work/llama2.c$ 

3.1. 配置 .vscode/settings.json 文件中 binaryArgs 的运行参数

If you need to pass additional arguments to your targets, update the makefile.launchConfigurations by adding the binaryArgs property to the configuration.

./run stories15M.bin -n 256 -i "Once upon a time"

/home/yongqiang/llm_work/llama2.c/.vscode/settings.json

复制代码
{
    "makefile.launchConfigurations": [
        {
            "cwd": "/home/yongqiang/llm_work/llama2.c",
            "binaryPath": "/home/yongqiang/llm_work/llama2.c/run",
            "binaryArgs": ["stories15M.bin", "-n", "256", "-i", "\"Once upon a time\""]
        },
        {
            "cwd": "/home/yongqiang/llm_work/llama2.c",
            "binaryPath": "/home/yongqiang/llm_work/llama2.c/runq",
            "binaryArgs": []
        }
    ]
}
复制代码
(base) yongqiang@yongqiang:~/llm_work/llama2.c$ "/home/yongqiang/llm_work/llama2.c/run" stories15M.bin -n 256 -i "Once upon a time"
Once upon a time, there was a cute little cat named Fluffy. Fluffy loved to climb trees. One sunny day, Fluffy saw a big tree and wanted to climb it.
Fluffy started to climb the tree. It was not easy, but Fluffy did not give up. Fluffy used its muscles to help get to the top. When Fluffy got to the top, it was so much fun!
Fluffy was very happy. Fluffy learned that when you try and do big things, you can do anything. And that is how Fluffy's love for climbing trees made her very happy.
achieved tok/s: 25.695931
(base) yongqiang@yongqiang:~/llm_work/llama2.c$ 

References

1 Yongqiang Cheng, https://yongqiang.blog.csdn.net/

2 Makefile support in Visual Studio Code!, https://devblogs.microsoft.com/cppblog/now-announcing-makefile-support-in-visual-studio-code/

相关推荐
formulahendry5 天前
在 VS Code 里自由切换 Copilot、Claude、Codex、OpenCode、Pi、Kimi、Qwen:任何 Agent 都能接
visual studio code·vs code·acp
Vex2une11 天前
PowerShell 发展史:从命令行外壳到跨平台自动化引擎
windows·自动化·azure·powershell·vs code·脚本语言·dsc
AI大模型-小华12 天前
AI 编程进入深度开发阶段:什么时候普通方案不够,需要更高算力支持?
人工智能·chatgpt·ai编程·vs code·codex·codex cli
GPU实战笔记15 天前
云端写 Python:JupyterLab 和 VS Code Remote-SSH,按工作方式选
python·vs code·jupyterlab·remote-ssh·远程开发·云端开发
阿钱真强道21 天前
课时00 嵌入式技术应用设计实训 | 开发环境搭建与开发板认识
git·hal库·keil·vs code·开发环境搭建·stm32f103·st-link
漂着的圆木22 天前
模型:VS Code启用HydraFusion编排器配置与限制
vs code·github copilot·hydrafusion·运行时模型编排器·配置排查
狂奔的sherry25 天前
VS Code Remote SSH Markdown 预览白屏排障
markdown·vs code·remote ssh
承渊政道1 个月前
Linux系统学习【进程信号详细解析——认识、产生、保存以及捕捉信号】
linux·学习·ubuntu·ssh·vs code·进程信号
GPU实战笔记1 个月前
云端 Python 开发:JupyterLab 还是 VS Code Remote-SSH?
python·vs code·jupyterlab·remote-ssh·远程开发
formulahendry1 个月前
微信和 VS Code 强强联合!WeChat AHP 来了
visual studio code·vs code