Skip to content

test: Add comprehensive CUDA and GPU validation test script#117

Open
ggoklani wants to merge 1 commit intolinux-system-roles:mainfrom
ggoklani:feat/add-cuda-gpu-validation-tests
Open

test: Add comprehensive CUDA and GPU validation test script#117
ggoklani wants to merge 1 commit intolinux-system-roles:mainfrom
ggoklani:feat/add-cuda-gpu-validation-tests

Conversation

@ggoklani
Copy link
Copy Markdown
Collaborator

@ggoklani ggoklani commented Apr 2, 2026

Add test-cuda-gpu.sh to validate CUDA toolkit and GPU functionality on HPC nodes. This addresses high-priority gap in GPU computing validation.

Features:

  • CUDA driver installation verification
  • CUDA toolkit version check (12.9)
  • nvidia-smi validation
  • GPU memory test
  • CUDA compiler (nvcc) availability and functionality
  • CUDA libraries verification
  • NVIDIA driver and persistence daemon checks
  • GPU properties validation (count, compute capability, memory)

The script follows project conventions:

  • Matches style of test-diagnostics.sh and test-nvidia-docker.sh
  • Supports verbose mode (-v) for detailed output
  • Gracefully skips on non-GPU systems (exit code 77)
  • Exits with proper status codes (0=pass, 1=fail, 77=skip)

Deployed to: {{ __hpc_azure_tests_dir }}/test-cuda-gpu.sh

🤖 Generated with Claude Code

Issue Tracker Tickets (Jira or BZ if any):https://redhat.atlassian.net/browse/RHELHPC-197

Summary by Sourcery

Add a new CUDA and GPU validation test script and ensure it is installed on HPC nodes.

New Features:

  • Introduce a comprehensive test-cuda-gpu.sh script to validate CUDA toolkit installation, environment configuration, and NVIDIA GPU hardware/driver state on HPC systems.

Tests:

  • Install the CUDA/GPU validation script via Ansible so it is deployed with the existing HPC Azure test suite.

Add test-cuda-gpu.sh to validate CUDA toolkit and GPU functionality
on HPC nodes. This addresses high-priority gap in GPU computing
validation.

Features:
- CUDA driver installation verification
- CUDA toolkit version check (12.9)
- nvidia-smi validation
- GPU memory test
- CUDA compiler (nvcc) availability and functionality
- CUDA libraries verification
- NVIDIA driver and persistence daemon checks
- GPU properties validation (count, compute capability, memory)

The script follows project conventions:
- Matches style of test-diagnostics.sh and test-nvidia-docker.sh
- Supports verbose mode (-v) for detailed output
- Gracefully skips on non-GPU systems (exit code 77)
- Exits with proper status codes (0=pass, 1=fail, 77=skip)

Deployed to: {{ __hpc_azure_tests_dir }}/test-cuda-gpu.sh

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Gaurav Goklani <ggoklani@redhat.com>
@ggoklani ggoklani requested review from richm and spetrosi as code owners April 2, 2026 10:38
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Apr 2, 2026

Reviewer's Guide

Adds a new CUDA/GPU validation bash test script and wires it into the Ansible role so it is deployed to the HPC Azure tests directory, providing comprehensive checks for CUDA installation, nvcc, NVIDIA drivers, persistence daemon, GPU hardware, and environment configuration with proper exit codes and verbose mode support.

Sequence diagram for CUDA/GPU validation script execution

sequenceDiagram
    actor Admin
    participant HPCNode
    participant TestScript as test_cuda_gpu_sh
    participant OS as System_tools
    participant GPU as GPU_hardware

    Admin->>HPCNode: ssh to node
    Admin->>TestScript: execute test-cuda-gpu.sh [options]

    TestScript->>TestScript: parse_arguments
    TestScript->>OS: check_nvidia_smi
    OS-->>TestScript: nvidia_smi_status
    alt nvidia_smi_not_found_or_no_gpu
        TestScript-->>Admin: exit 77 (skip non GPU system)
    else gpu_detected
        TestScript->>OS: check_cuda_driver_and_toolkit
        OS-->>TestScript: cuda_versions

        TestScript->>OS: check_nvcc_compiler
        OS-->>TestScript: nvcc_status

        TestScript->>OS: validate_cuda_libraries
        OS-->>TestScript: library_status

        TestScript->>OS: check_nvidia_driver_and_persistence
        OS-->>TestScript: driver_daemon_status

        TestScript->>GPU: query_gpu_properties
        GPU-->>TestScript: count_compute_capability_memory

        alt all_checks_pass
            TestScript-->>Admin: exit 0 (all validations passed)
        else any_check_fails
            TestScript-->>Admin: exit 1 (validation failed)
        end
    end
Loading

Flow diagram for CUDA/GPU validation logic in test-cuda-gpu.sh

flowchart TD
    A[Start] --> B[Parse CLI arguments
    support verbose flag]
    B --> C[Check nvidia_smi presence
    and query GPUs]

    C -->|nvidia_smi missing or no GPUs| D[Exit 77
    skip non GPU system]
    C -->|GPU detected| E[Check CUDA driver and toolkit
    verify expected version 12_9]

    E --> F[Check nvcc compiler
    availability and simple compile]
    F --> G[Verify CUDA libraries
    required shared libs present]
    G --> H[Check NVIDIA driver version
    and persistence daemon]
    H --> I[Validate GPU properties
    count compute capability memory]

    I --> J{Any check failed}
    J -->|yes| K[Print failure details
    set appropriate error messages]
    K --> L[Exit 1
    validation failed]

    J -->|no| M[Print success summary]
    M --> N[Exit 0
    all validations passed]
Loading

File-Level Changes

Change Details Files
Deploy a CUDA/GPU validation test script via Ansible
  • Add an Ansible task to copy test-cuda-gpu.sh into the configured HPC Azure tests directory
  • Set file ownership to root:root and mark the script as executable (0755)
tasks/main.yml
Introduce comprehensive CUDA and GPU validation bash script
  • Implement argument parsing for verbose/help flags and consistent logging helpers
  • Add tests for CUDA driver and toolkit presence, including package and PATH/LD_LIBRARY_PATH validation
  • Verify nvcc availability, expected CUDA version (12.9), and ability to compile a minimal CUDA program
  • Check presence of key CUDA libraries via ldconfig
  • Detect GPU hardware and nvidia-smi, tracking whether a GPU is present
  • Validate NVIDIA driver, kernel module, and nvidia-persistenced systemd service state
  • Inspect GPU properties (count, compute capability, and minimum memory threshold) and handle non-GPU or non-CUDA systems via exit code 77
  • Enforce strict bash options and structured main() flow with aggregated pass counter and clear success/skip/fail exits
files/test-cuda-gpu.sh

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@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 left some high level feedback:

  • The CUDA version is hard-coded in multiple places (EXPECTED_CUDA_VERSION, /usr/local/cuda-12.9, and the cuda-toolkit-12-9 package name); consider centralizing this in a single variable or making it configurable so future version bumps only require one change.
  • The script mixes privilege models by calling sudo within a test script that is likely already run as root via automation; consider removing the internal sudo calls and assuming the script is invoked with appropriate privileges to avoid unexpected prompts or failures.
  • The temporary directory used for the nvcc compilation test is only cleaned up on the success path; add a trap to ensure rm -rf "$TEMP_DIR" runs on exit or failure to avoid leaking temp directories.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The CUDA version is hard-coded in multiple places (EXPECTED_CUDA_VERSION, /usr/local/cuda-12.9, and the cuda-toolkit-12-9 package name); consider centralizing this in a single variable or making it configurable so future version bumps only require one change.
- The script mixes privilege models by calling `sudo` within a test script that is likely already run as root via automation; consider removing the internal `sudo` calls and assuming the script is invoked with appropriate privileges to avoid unexpected prompts or failures.
- The temporary directory used for the nvcc compilation test is only cleaned up on the success path; add a `trap` to ensure `rm -rf "$TEMP_DIR"` runs on exit or failure to avoid leaking temp directories.

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.

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