User Guide

  • 2021.2
  • 04/12/2021
  • Public Content

Developing a Visual Studio Code Project

Explore Samples Using Visual Studio Code*

Before running samples, you must first set the oneAPI environment. This can be accomplished by running
setvars
as explained below, or by installing the Environment and Launch Configurator Extension and running Set oneAPI Environment.
To run
setvars
for Linux*:
  1. Navigate to the install directory and source
    setvars.sh
    .
    source <install_dir>/setvars.sh
    The command above assumes you installed to the default folder. If you customized the installation folder,
    setvars.sh
    is in your custom folder. See here for more information on setvars.sh.
  2. Launch VS Code:
    code
To run
setvars
for Windows*:
  1. From a terminal window, run
    setvars.bat
    .
    "C:\Program Files (x86)\Intel\oneAPI\setvars.bat"
    The command above assumes you installed to the default folder. If you customized the installation folder,
    setvars.bat
    is in your custom folder.
  2. From the same terminal window, launch VS Code:
    "C:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\Code.exe"
Open the Samples Extension:
  1. Click on the oneAPI button on the left navigation to view samples. If you do not have the extension installed, search the Extensions Marketplace for "Samples Browser for Intel oneAPI".
  2. A list of available samples will open in the left navigation.
  3. To view the readme for the sample, click the next to the sample. If you choose to build and run the sample, the readme will also be downloaded with the sample.
  4. To build and run a sample, click the
    +
    to the right of the sample name.
  5. Create a new folder for the sample. The sample will load in a new window:
  6. Click README.md to view instructions for the sample.
Not all oneAPI sample projects use CMake. The
README.md
file for each sample specifies how to build the sample. We recommend that you check out the CMake extension for VS Code that is maintained by Microsoft.

Create a Blank Project

  1. Click
    File
    New File
    to open a blank file in Visual Studio Code (VS Code).
  2. Once you have completed writing code, you can save it as a file or save it as a workspace. For more information on workspaces, see the Visual Studio Code Get Started Guide.
  3. To run the code, click
    Run
    Run without Debugging
    .
  4. Select C++ as the language. The code will run.

Import an Existing Project

  1. Click
    File
    Open File
    or
    File
    Open Workspace
    to open an existing project in Visual Studio Code (VS Code).
  2. Once you have completed writing code, you can save it as a file or save it as a workspace. For more information on workspaces, see the Visual Studio Code Get Started Guide.
  3. To run the code, click
    Run
    Run without Debugging
    .
  4. Select C++ as the language. The code will run.

Try Debugging (CPU Only) (Preview)

Intel® Distribution for GDB* does not currently support VS Code. You can use upstream gdb to debug.
This section assumes that you can build your sample and have installed the Microsoft VS Code C/C++ Extension. The C/C++ extension is required to configure the oneAPI C/C++ debugger.
The Intel
®
oneAPI Base Toolkit
includes a special version of GNU* GDB (
gdb-oneapi
) designed to support oneAPI C/C++ applications. To debug your DPC++ application using this special debugger, you will need to make changes to the
.vscode/launch.json
configuration file.
  1. Go to
    Debug
    Open Configurations
    , and open the
    launch.json
    configuration settings.
    If you are prompted to select a debug environment, choose
    C++ (GDB/LLDB)
    .
    Screenshot showing command pallet prompting for debugger
  2. Copy the code shown below into your
    launch.json
    file, and replace the
    "program":
    property's value with the path to your project's executable (that is, the application that you are going to debug).
    If VS Code doesn't recognize the application name, you may have to insert the full path and file name into the
    launch.json
    file's
    "program":
    property.
  3. Add
    gdb-oneapi
    to your
    launch.json
    configuration's
    "miDebuggerPath":
    property.
    The
    gdb-oneapi
    application should have been added to your path when you ran
    setvars.sh
    to configure the oneAPI development environment, prior to starting VS Code. If you prefer, you can specify the full path and filename to the
    gdb-oneapi
    application in your
    launch.json
    file.
  4. In some configurations, GDB may not be compatible with VS Code. If this happens, add the environment variable to disable `gdb-oneapi` support for GPU autolaunch. This can either be done in the environment prior to launching VS Code, or within the launch.json:
    export INTELGT_AUTO_ATTACH_DISABLE=1
    { "version":"0.2.0", "configurations":[ { "name":"(gdb) Launch", "type":"cppdbg", "request":"launch", "program":"${workspaceFolder}/build/array-transform", "args":[ "cpu" ], "stopAtEntry":false, "cwd":"${workspaceFolder}", "environment":[ { "name":"INTELGT_AUTO_ATTACH_DISABLE", "value":"1" } ], "externalConsole":false, "MIMode":"gdb", "miDebuggerPath":"gdb-oneapi", "setupCommands":[ { "description":"Enable pretty-printing for gdb", "text":"-enable-pretty-printing", "ignoreFailures":true } ] } ] }
  5. Bring up the debug view by selecting the
    Run
    icon in the
    Activity Bar
    . You can also use the keyboard shortcut (
    Ctrl+Shift+D
    ).
  6. Start the run and debug session by clicking the green
    DEBUG AND RUN
    icon, or go to
    Run
    Start Debugging
    (
    F5
    ).
    Screenshot showing VS Code recommended extension installation popup

Product and Performance Information

1

Performance varies by use, configuration and other factors. Learn more at www.Intel.com/PerformanceIndex.