Skip to content

dev container for OpenMP backend#8

Open
science-enthusiast wants to merge 1 commit into
mainfrom
kokkos-dev-container
Open

dev container for OpenMP backend#8
science-enthusiast wants to merge 1 commit into
mainfrom
kokkos-dev-container

Conversation

@science-enthusiast
Copy link
Copy Markdown
Member

Dev container for IDEs like VSCode for Kokkos OpenMP backend.

More details in the README.md file.

@tretre91 tretre91 self-requested a review April 15, 2026 10:06
Copy link
Copy Markdown
Member

@tretre91 tretre91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could get the dev container to work with both docker and podman on a desktop with

  • Fedora 43
  • docker 29.4.3
  • podman 5.8.2
  • vscode 1.119.0

}
}
},
"postStartCommand": "cmake -DKokkos_ROOT=/opt/kokkos-install -DKokkos_ENABLE_OPENMP=ON -B build"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to repeat Kokkos_ENABLE_OPENMP here.
Using CMAKE_EXPORT_COMPILE_COMMANDS=ON will tell CMake to produce a compile_commands.json file, which can then be used by the C++ extension (or any other language server protocol extension) to get the info about the include path and the flags

Suggested change
"postStartCommand": "cmake -DKokkos_ROOT=/opt/kokkos-install -DKokkos_ENABLE_OPENMP=ON -B build"
"postStartCommand": "cmake -DKokkos_ROOT=/opt/kokkos-install -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -B build"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why -DKokkos_ENABLE_OPENMP=ON was added here. It should go.

"settings": {
"C_Cpp.default.includePath": [
"/opt/kokkos-install/include/"
]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the setting used by the C++ extension to locate the compile_commands.json, cmake puts it in the build directory.
Using this, Kokkos symbols are correctly recognized by Intellisense, it also removes the need for the export CPATH=...

Suggested change
]
],
"C_Cpp.default.compileCommands": [
"./build/compile_commands.json"
]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. Nice to know.

@@ -0,0 +1,22 @@
FROM mcr.microsoft.com/vscode/devcontainers/cpp:ubuntu-22.04

# Install C++ development tools, Git and CMake
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing space

Suggested change
# Install C++ development tools, Git and CMake
# Install C++ development tools, Git and CMake

"ms-vscode.cpptools-extension-pack",
"ms-azuretools.vscode-docker"
],
"settings": {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing space

Suggested change
"settings": {
"settings": {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your time, Trévis.

I am curious to know what approach you take to identify trailing white spaces in a file.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My editor is configured to show spaces at the end of a line as visible characters (see the list and listchars options in vim)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will look into those vim options.

cmake

RUN git clone https://github.com/kokkos/kokkos.git \
--branch release-candidate-4.6.01 --depth=1 /opt/kokkos && \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use a more recent kokkos version (and the release-candidate-4.6.01 branch doesn't exist anymore)

Suggested change
--branch release-candidate-4.6.01 --depth=1 /opt/kokkos && \
--branch 5.1.1 --depth=1 /opt/kokkos && \


There is a simple C++ project that links with [Kokkos](https://cexa-project.org/news/2025-03-19-ninth-kokkos-tea-time/) to be built and run in `devc_hellow`. One can see in the `CMakeLists.txt` file that CMake expects Kokkos to be installed, in order to build the project. The container image takes care of this requirement.

In `devcontainer.json`, one can specify a "postStartCommand". For e.g., it is defined as "cmake -DKokkos_ROOT=/opt/kokkos-install -DKokkos_ENABLE_OPENMP=ON -B build" in our case. This ensures that a `build` directory is generated by CMake. See below for some observations with Docker and Podman regarding "postStartCommand".
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In `devcontainer.json`, one can specify a "postStartCommand". For e.g., it is defined as "cmake -DKokkos_ROOT=/opt/kokkos-install -DKokkos_ENABLE_OPENMP=ON -B build" in our case. This ensures that a `build` directory is generated by CMake. See below for some observations with Docker and Podman regarding "postStartCommand".
In `devcontainer.json`, one can specify a "postStartCommand". For e.g., it is defined as "cmake -DKokkos_ROOT=/opt/kokkos-install -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -B build" in our case. This ensures that a `build` directory is generated by CMake, and that compile commands are exported (helpful for getting Intellisense to work). See below for some observations with Docker and Podman regarding "postStartCommand".

Comment on lines +69 to +76
* Currently, "postStartCommand" works only with Docker and not with Podman. One gets an error like the following with Podman:

Error: error parsing environment variables: name "\afbfa9712-93dc-4bca-8ecc-99ffb315ae27\x1b]0;vscode@mdlspc111.extra.cea.fr: cat /proc/self/environ\aREMOTE_CONTAINERS_IPC" has white spaces, poorly formatted name
[147463 ms] postStartCommand from devcontainer.json failed with exit code 125. Skipping any further user-provided commands.
* Podman takes more time to build and run the container. Probably, it takes more time to restart a container also.
* With Podman, VS Code disconnects and reconnects to the container from time to time.

Probably, these issues with Podman can be resolved by using a more recent version of Podman. For example, VS Code recommends version 5+. However, Podman offers much better support for Red Hat distributions like Fedora.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that I did not get any issue using podman, but as you mention it might be because I have a fairly recent version (5.8.2)


#### Some technical points
* In order to enable networking while building the container, define `"build"` as `"build": { …, "options": ["--network=host"], …}`. This may be needed in order to `git clone` the Kokkos repository. Also, note that `“runArgs”: [“--network=host”]` is for enabling network connection while running the container.
* Setting the environment variable `CPATH` as `CPATH="/opt/kokkos-install/include:$CPATH"` helps with IntelliSense recognizing Kokkos header files.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Setting the environment variable `CPATH` as `CPATH="/opt/kokkos-install/include:$CPATH"` helps with IntelliSense recognizing Kokkos header files.

* In the Command Palette enter ">Dev Containers: Rebuild Without Cache and Reopen in Container" whenever you need to rebuild the container after making changes to either `devcontainer.json` or `Dockerfile`.

#### To explore further
* Kokkos functions are incorrectly flagged by IntelliSense.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed by the compile_commands thing

Suggested change
* Kokkos functions are incorrectly flagged by IntelliSense.

Comment on lines +87 to +88
* Try installing the following extensions in VS Code to check for a better experience with Podman.
* "Container Tools" and "Pod Manager". Note: These extensions have been released relatively recently.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only needed to install the dev container extension for it to work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants