Skip to content

ci(cuda): limit parallel jobs to avoid OOM during CUDA build#841

Open
doringeman wants to merge 1 commit intomainfrom
llamacpp-cuda-build
Open

ci(cuda): limit parallel jobs to avoid OOM during CUDA build#841
doringeman wants to merge 1 commit intomainfrom
llamacpp-cuda-build

Conversation

@doringeman
Copy link
Copy Markdown
Contributor

No description provided.

Signed-off-by: Dorin Geman <dorin.geman@docker.com>
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • Since cmake --build already parallelizes when using Ninja, consider using CMAKE_BUILD_PARALLEL_LEVEL (or Ninja’s -j via CMAKE_BUILD_TOOL) to limit jobs instead of adding -j here, which can be less portable across generators.
  • The $(nproc --ignore=2) expression assumes GNU coreutils; if these Docker builds may run on non-GNU environments, you might want to guard this or use a simpler $(nproc) with a fixed upper bound to avoid portability issues.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Since `cmake --build` already parallelizes when using Ninja, consider using `CMAKE_BUILD_PARALLEL_LEVEL` (or Ninja’s `-j` via `CMAKE_BUILD_TOOL`) to limit jobs instead of adding `-j` here, which can be less portable across generators.
- The `$(nproc --ignore=2)` expression assumes GNU coreutils; if these Docker builds may run on non-GNU environments, you might want to guard this or use a simpler `$(nproc)` with a fixed upper bound to avoid portability issues.

## Individual Comments

### Comment 1
<location path="llamacpp/native/cuda.Dockerfile" line_range="40" />
<code_context>
     -S ." > cmake-flags
 RUN cmake $(cat cmake-flags)
-RUN cmake --build build --config Release
+RUN cmake --build build --config Release -j$(nproc --ignore=2)
 RUN cmake --install build --config Release --prefix install

</code_context>
<issue_to_address>
**issue:** Guard against `nproc --ignore=2` returning 0 parallel jobs on small-core machines.

On 1–2 core machines, `nproc --ignore=2` can return 0, yielding `-j0`, which some build tools treat as unlimited parallelism or otherwise special-case. To avoid this, ensure a minimum of 1 job, e.g.:

```dockerfile
RUN cmake --build build --config Release -j"$(nproc --ignore=2 || echo 1)"
```

or use a small shell expression to compute `max(1, nproc-2)` explicitly.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

-S ." > cmake-flags
RUN cmake $(cat cmake-flags)
RUN cmake --build build --config Release
RUN cmake --build build --config Release -j$(nproc --ignore=2)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue: Guard against nproc --ignore=2 returning 0 parallel jobs on small-core machines.

On 1–2 core machines, nproc --ignore=2 can return 0, yielding -j0, which some build tools treat as unlimited parallelism or otherwise special-case. To avoid this, ensure a minimum of 1 job, e.g.:

RUN cmake --build build --config Release -j"$(nproc --ignore=2 || echo 1)"

or use a small shell expression to compute max(1, nproc-2) explicitly.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the cuda.Dockerfile to parallelize the CMake build process by utilizing available CPU cores. While this improves build performance, a critical issue was identified regarding the use of nproc --ignore=2, which could return a non-positive value on environments with two or fewer cores and cause the build to fail. A suggestion was provided to ensure at least one build job is always specified using a shell arithmetic check.

-S ." > cmake-flags
RUN cmake $(cat cmake-flags)
RUN cmake --build build --config Release
RUN cmake --build build --config Release -j$(nproc --ignore=2)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

Using nproc --ignore=2 can result in a negative or zero value if the build environment has 2 or fewer cores, causing the build command to fail. It is safer to use a shell arithmetic expansion to ensure a minimum of 1 job.

RUN cmake --build build --config Release -j$(nproc --ignore=2 | awk '{print ($1 < 1 ? 1 : $1)}')

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.

1 participant