# GPU math in Python: CuPy and nvmath-python (CUDA-X)

> Exact signatures, GPU-verified pitfalls and a static checker for CuPy and nvmath-python, so GPU math code is right before it runs.

GPU math in Python: CuPy and nvmath-python (CUDA-X) is a free AI agent skill on Agensi by Jarno Rantala, in LLM Ops. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: Free
- Creator: [Jarno Rantala](https://www.agensi.io/creators/jarski)
- Category: [LLM Ops](https://www.agensi.io/skills/llm-ops)
- Uses: 2
- Version: 1.0
- Last updated: 2026-10-20
- Security: scan passed (2026-10-19); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/gpu-math-in-python-cupy-and-nvmath-python-cuda-x
- Tags: llm-ops, ai-agents, code-review, cupy, cuda, python, gpu-computing, scipy

## About this skill

GPU numerical code in Python fails in ways that look fine on screen: a NumPy name that doesn't exist in CuPy, a keyword from an older SciPy, a submodule that `import cupy` never loaded, an nvmath inverse FFT that comes back scaled by *n*. None of it shows up until the code runs on a GPU. This skill replaces guessing with lookup: exact signatures, known pitfalls, GPU-verified examples and a static checker, all generated from the library sources at pinned versions.

### What it does
- **Exact signatures** for 275 functions and classes of CuPy 14.2.0 and nvmath-python 1.0.0, the Python front ends of cuBLAS, cuFFT, cuSOLVER, cuSPARSE, cuDSS and cuTENSOR.
- **Pitfalls that look right and fail on the GPU**, on 43 curated cards: dense linear algebra, FFTs, sparse solvers, nvmath matmul epilogs and the cuDSS direct solver.
- **39 examples verified on a Tesla T4**, each a complete, runnable snippet whose asserts passed there.
- **A static checker** that finds functions that don't exist, wrong or positional-only keywords, missing arguments and submodules that were never imported, and suggests the real name. It needs no GPU.

### How it works
1. Find the function in the index (one line per function, curated ones marked).
2. Read its card: signature, the import it really needs, pitfalls, verified example.
3. Skim the pitfalls for your area.
4. Write the code, then run `scripts/check_gpu_code.py` on it and fix every error it reports.

If the mathlib-mcp MCP server is connected, the skill uses its tools instead of the files.

### Measured, not promised
This skill was measured on a benchmark of 26 GPU tasks run on a Tesla T4, three samples per task. Claude Haiku 4.5 solved 100% of the tasks with it, against 51% without help, 87% with the full documentation in the prompt and 96% with the same knowledge served as MCP tools; none of its final solutions contained a hallucinated API (36% did without help). Claude Sonnet 5.5 went from 94% to 99%. The checker raised no false alarms on 407 passing attempts and flagged 36 of the 41 that failed with an API error. Full results, transcripts and code: github.com/jarski/mathlib-mcp (MIT).

### Use cases
- Porting NumPy or SciPy pipelines to the GPU without the trial-and-error round trips.
- Batched linear solves, eigenvalues, SVD and least squares on stacked matrices.
- FFT-based filtering and convolution, including nvmath-python's unnormalized inverse transforms.
- Sparse iterative and direct solvers (cuSPARSE, cuDSS) with the right keywords and matrix formats.
- Fused matrix multiplication with epilogs (bias, ReLU, GELU) through cuBLASLt.

### Requirements and limits
Python 3.12+ and uv or pip for the checker; no GPU needed to use the skill. Covers `cupy`, `cupy.linalg`, `cupy.fft`, `cupy.cublas`, `cupyx.scipy.linalg`, `cupyx.scipy.fft`, `cupyx.scipy.sparse` and the `nvmath` linalg, fft, sparse and tensor modules. Not covered: custom CUDA kernels, `cupyx.jit`, `cupy.testing`. The checker is static: it verifies names, arguments and imports, not shapes, dtypes, memory or numerical results.

## Requires

- Python 3.12+
- uv (Python tool runner)
- Git

## Known limitations

Covers specific pinned versions of CuPy and nvmath-python. Does not verify array shapes, dtypes, or memory limits. Excludes custom kernels and JIT.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the GPU math in Python: CuPy and nvmath-python (CUDA-X) skill from Agensi" and describe your task.
3. Your agent loads the skill from Agensi when it needs it. Nothing is downloaded.

## Frequently asked questions

### How does this skill prevent common errors when writing GPU-accelerated Python code?

This skill solves the common problem of API hallucination, where AI models mistakenly apply NumPy syntax to CuPy. It provides a static checker and verified signatures to ensure your GPU-accelerated math code runs correctly without runtime crashes.

### What specific assets are included in the 'cupy nvmath gpu math' skill?

The package includes an API index of 275 functions, 43 verified code snippets tested on Tesla T4 GPUs, a domain-specific pitfall guide, and a Python-based static analysis checker script.

### Which library versions and AI environments is this skill compatible with?

This skill is optimized for environments running Python 3.12+, CuPy 14.2.0, and nvmath-python 1.0.0. It is designed to work seamlessly with AI agents that support external tool integration and uses 'uv' for rapid static checking.

### Can this skill help me debug custom CUDA kernels or memory overflow issues?

While the skill excels at verifying API signatures for libraries like cuBLAS and cuFFT, it does not support custom CUDA C++ kernels, JIT compilation, or runtime validation of array shapes and memory limits.

### How do I use the static analysis feature to validate my math code?

The skill provides a dedicated Python checker script; you simply run this script against your source files to identify non-existent functions or incorrect arguments before deploying to your GPU cluster.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
