opencl
OpenCL SDK (Khronos Group) for cross-platform GPU/CPU parallel computing in C and C++. Use when writing OpenCL kernels, managing devices/contexts/queues, allocating and transferring buffers or images, building and executing programs, or using the C++ wrapper (opencl.hpp / cl::CommandQueue, cl::Buffer, cl::KernelFunctor). Covers OpenCL C API, C++ bindings, and SDK utility libraries (OpenCLUtils, OpenCLSDK).
Best use case
opencl is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
OpenCL SDK (Khronos Group) for cross-platform GPU/CPU parallel computing in C and C++. Use when writing OpenCL kernels, managing devices/contexts/queues, allocating and transferring buffers or images, building and executing programs, or using the C++ wrapper (opencl.hpp / cl::CommandQueue, cl::Buffer, cl::KernelFunctor). Covers OpenCL C API, C++ bindings, and SDK utility libraries (OpenCLUtils, OpenCLSDK).
Teams using opencl should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/opencl/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How opencl Compares
| Feature / Agent | opencl | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
OpenCL SDK (Khronos Group) for cross-platform GPU/CPU parallel computing in C and C++. Use when writing OpenCL kernels, managing devices/contexts/queues, allocating and transferring buffers or images, building and executing programs, or using the C++ wrapper (opencl.hpp / cl::CommandQueue, cl::Buffer, cl::KernelFunctor). Covers OpenCL C API, C++ bindings, and SDK utility libraries (OpenCLUtils, OpenCLSDK).
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# OpenCL SDK
**Version:** v2025.07.23 (Khronos Group OpenCL-SDK)
**Language:** C (OpenCL 1.0–3.0) / C++ (opencl.hpp wrapper)
**License:** Apache-2.0
**Repo:** https://github.com/KhronosGroup/OpenCL-SDK
## Overview
OpenCL (Open Computing Language) is a framework for parallel programming across heterogeneous platforms — GPUs, CPUs, FPGAs, and DSPs — from a single API. The SDK bundles:
- **OpenCL-Headers** — C headers (`<CL/cl.h>`, `<CL/cl_ext.h>`)
- **OpenCL-CLHPP** — C++ wrapper (`<CL/opencl.hpp>`)
- **OpenCL-ICD-Loader** — runtime dispatch to installed platform drivers
- **OpenCLUtils / OpenCLSDK** — utility libraries (`<CL/Utils/>`, `<CL/SDK/>`)
## Quick Start (C)
Kernel file `saxpy.cl`:
```c
__kernel void saxpy(float a, __global float *x, __global float *y) {
int i = get_global_id(0);
y[i] = fma(a, x[i], y[i]);
}
```
Host:
```c
#include <CL/cl.h>
cl_platform_id plat; cl_device_id dev;
clGetPlatformIDs(1, &plat, NULL);
clGetDeviceIDs(plat, CL_DEVICE_TYPE_DEFAULT, 1, &dev, NULL);
cl_context ctx = clCreateContext(NULL, 1, &dev, NULL, NULL, &err);
cl_command_queue q = clCreateCommandQueueWithProperties(ctx, dev, NULL, &err);
// ... load source, clCreateProgramWithSource, clBuildProgram,
// clCreateKernel, clSetKernelArg, clEnqueueNDRangeKernel,
// clEnqueueReadBuffer, clReleaseXxx ...
```
## Quick Start (C++)
```cpp
#define CL_HPP_ENABLE_EXCEPTIONS
#define CL_HPP_TARGET_OPENCL_VERSION 200
#include <CL/opencl.hpp>
cl::Context ctx{CL_DEVICE_TYPE_DEFAULT};
cl::Device dev = ctx.getInfo<CL_CONTEXT_DEVICES>()[0];
cl::CommandQueue queue{ctx, dev};
cl::Program prog{ctx, source_string};
prog.build(dev);
auto saxpy = cl::KernelFunctor<cl_float, cl::Buffer, cl::Buffer>(prog, "saxpy");
saxpy(cl::EnqueueArgs{queue, cl::NDRange{N}}, a, buf_x, buf_y);
```
## Core Concepts
- **Work-item** — one parallel execution unit; maps to one GPU thread
- **Work-group** — block of work-items sharing local memory and barriers
- **NDRange** — N-dimensional index space (up to 3D); defines total parallelism
- **Context** — owns devices, memory objects, programs, and queues
- **Command Queue** — ordered or OOO stream of commands to one device
- **Memory object** — buffer (linear) or image (typed, sampled); device-side
- **Kernel** — a `__kernel` function compiled from OpenCL C source or SPIR-V
- **Event** — synchronization token returned by every enqueue command
- **Address spaces** — `__global` (buffers), `__local` (shared), `__constant` (read-only), `__private` (per-item)
## API Reference
| Domain | Reference File | Key Functions / Types |
|---|---|---|
| Platform & Device | `references/api-platform-device.md` | `clGetPlatformIDs`, `clGetDeviceIDs`, `clGetDeviceInfo`, `clCreateSubDevices`, timer APIs |
| Context & Queue | `references/api-context-queue.md` | `clCreateContext`, `clCreateCommandQueueWithProperties`, `clFlush`, `clFinish`, destructor callbacks |
| Memory Objects | `references/api-memory.md` | `clCreateBuffer`, `clCreateImage`, enqueue read/write/copy/fill, map/unmap, pipes, samplers, SVM |
| Programs & Kernels | `references/api-program-kernel.md` | `clCreateProgramWithSource`, `clBuildProgram`, `clCompileProgram`, `clLinkProgram`, `clCreateKernel`, sub-group queries |
| Execution & Events | `references/api-execution.md` | `clEnqueueNDRangeKernel`, `clWaitForEvents`, `clSetEventCallback`, profiling, extension access |
| C++ Wrapper | `references/api-cpp-wrapper.md` | `cl::Context`, `cl::Buffer`, `cl::Pipe`, `cl::Sampler`, `cl::KernelFunctor`, `cl::SVMAllocator`, exceptions |
| Workflows | `references/workflows.md` | Quick-start, vector add, image blur, async events, binary caching, error handling |
## Common Workflows
See `references/workflows.md` for complete, runnable examples:
- **Vector add (C)** — minimal host+kernel from scratch
- **SAXPY (C++)** — `KernelFunctor` pattern with RAII
- **Device enumeration** — iterate all platforms and devices
- **Image blur** — 2D image creation, `read_imageui` / `write_imageui`
- **Async events** — non-blocking enqueue chains
- **Binary caching** — save/restore compiled programs
- **Error handling** — C goto pattern vs. C++ exceptions
## SDK Utility Libraries
Include `<CL/Utils/Utils.h>` (C) or `<CL/Utils/Utils.hpp>` (C++) and link `OpenCLUtils` / `OpenCLUtilsCpp`.
| Header | API |
|---|---|
| `<CL/Utils/Context.h>` | `cl_util_get_device`, `cl_util_get_context`, `cl_util_print_device_info` |
| `<CL/Utils/File.h>` | `cl_util_read_text_file`, `cl_util_read_exe_relative_text_file`, `cl_util_write_binaries` |
| `<CL/Utils/Error.h>` | `OCLERROR_RET`, `OCLERROR_PAR`, `MEM_CHECK` macros, `cl_util_print_error` |
| `<CL/Utils/Event.h>` | `cl_util_get_event_duration` |
| `<CL/Utils/Device.hpp>` | `cl::util::supports_extension`, `cl::util::supports_feature` |
SDK Library (samples only, not installed): `<CL/SDK/CLI.h>`, `<CL/SDK/Random.h>`, `<CL/SDK/Image.h>`.
## Key Considerations
**Release everything:** Every `clCreate*` call must be paired with the corresponding `clRelease*`. Leak buffers or kernels and you exhaust device memory silently.
**Blocking vs. non-blocking transfers:** `clEnqueueReadBuffer(..., CL_TRUE, ...)` blocks the CPU. Use `CL_FALSE` + events for overlap. Always `clFlush` before blocking on an event from another thread.
**Local work-group size:** Must evenly divide global work size in each dimension. Query `CL_KERNEL_WORK_GROUP_SIZE` for the max; `CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE` for optimal alignment. Passing `NULL` lets the runtime choose (portable, not always optimal).
**Build log on failure:** `clBuildProgram` returns `CL_BUILD_PROGRAM_FAILURE` — always query `CL_PROGRAM_BUILD_LOG` to get the compiler error message. The SDK's `cl_util_build_program` does this automatically.
**Image format validation:** Not all `cl_image_format` combinations are supported on every device. Call `clGetSupportedImageFormats` before creating images.
**Event callbacks must not block:** Callbacks registered via `clSetEventCallback` are invoked from a runtime thread. Never call `clFinish` or `clWaitForEvents` inside a callback.
**C++ exceptions:** Enable with `#define CL_HPP_ENABLE_EXCEPTIONS` before including `<CL/opencl.hpp>`. Without it, check `cl_int` error parameters manually.
**OpenCL version targeting:** Set `CL_HPP_TARGET_OPENCL_VERSION` (e.g., `300`, `200`, `120`) to control which API surface is available in the C++ wrapper. OpenCL 1.x deprecated `clCreateCommandQueue`; use `clCreateCommandQueueWithProperties` for 2.0+.
**SVM requires OpenCL 2.0+:** Shared Virtual Memory (`clSVMAlloc`) requires device support for `CL_DEVICE_SVM_CAPABILITIES`. Check before use.Related Skills
rocm
AMD ROCm GPU computing stack for HIP kernel development and GPU-accelerated library usage. Use when: writing HIP kernels (.hip files), using rocBLAS/rocFFT/rocRAND/rocSOLVER/rocSPARSE/hipBLAS/hipBLASLt/hipTensor/hipSPARSELt/rocALUTION compute libraries, profiling with rocProfiler or rocprof, porting CUDA code to HIP, building CMake/Makefile projects targeting AMD GPUs, using HIP Graphs for low-overhead kernel replay, or debugging GPU code with rocGDB.
powergridmodel
Python library for steady-state distribution power system analysis (power flow, state estimation, short-circuit calculations). Use when working with the power-grid-model library to: (1) perform load flow or Newton-Raphson/iterative calculations on electrical grids, (2) run state estimation with sensor data, (3) compute IEC 60909 short-circuit currents, (4) execute batch/time-series or N-1 contingency simulations, or (5) work with grid component types (node, line, transformer, source, sym_load, etc.) and numpy structured arrays.
pandapower
Power systems analysis and optimization library (pandapower v3.4.0). Use when working with electric power networks: building network models (buses, lines, transformers, loads, generators), running AC/DC power flow, optimal power flow (OPF), short circuit calculations (IEC 60909), state estimation, time series simulations, network topology analysis, or visualizing power grids in Python.
ollama
Run and manage local LLMs via Ollama REST API — text generation, chat completions, embeddings, tool calling, structured output, and model management. Use when code imports ollama, references localhost:11434, or user asks about local LLM inference.
llamacpp
Complete llama.cpp C/C++ API reference covering model loading, inference, text generation, embeddings, chat, tokenization, sampling, batching, KV cache, LoRA adapters, and state management. Triggers on: llama.cpp questions, LLM inference code, GGUF models, local AI/ML inference, C/C++ LLM integration, "how do I use llama.cpp", API function lookups, implementation questions, troubleshooting llama.cpp issues, and any llama-cpp or ggerganov/llama.cpp mentions.
greycat
Build, run, and edit GreyCat projects. GreyCat is a statically-typed language plus runtime for graph-persistent, time-series-aware applications. Use when reading or writing `.gcl` source, when the user mentions GreyCat / project.gcl / nodeTime / nodeList / nodeIndex / nodeGeo / @expose / @library, or when the task involves running `greycat <command>`, deploying a project, or reasoning about gcdata/, lib/, files/, webroot/.
greycat-c
GreyCat C API and GCL Standard Library reference. Use for: (1) Native C development with gc_machine_t context, tensors, objects, memory management, crypto, I/O; (2) GCL Standard Library modules - std::core (Date/Time/Tuple/geospatial types), std::runtime (Scheduler/Task/Logger/User/Security/System/OpenAPI/MCP), std::io (CSV/JSON/XML/HTTP/Email/FileWalker), std::util (Queue/Stack/SlidingWindow/Gaussian/Histogram/Quantizers/Random/Plot); (3) Plugin development patterns - lifecycle hooks, type configuration, nativegen, module-level and type-level function linking, global state, thread safety, conditional logging. Keywords: GreyCat, GCL, native functions, tensors, task automation, scheduler, plugin development.
ggml
C tensor computation library for ML inference and training. Use when working with ggml graphs, GGUF model files, backend scheduling, quantization, or implementing low-level ML ops in C/C++.
cuda
NVIDIA CUDA parallel computing platform — use when writing .cu kernels, using cuBLAS/cuDNN/cuFFT/cuSPARSE/cuRAND/cuSolver, Thrust, or Cooperative Groups for GPU-accelerated computing
blas_lapack
Complete CBLAS and LAPACKE C API reference (LAPACK v3.12.1) covering 1284 functions for numerical linear algebra: BLAS Level 1/2/3 vector and matrix operations, linear system solvers (LU, Cholesky, LDL), eigenvalue/eigenvector computation, singular value decomposition, least squares, QR/LQ factorizations, and auxiliary routines. Triggers on: BLAS/LAPACK questions, CBLAS/LAPACKE code, linear algebra in C/C++, matrix operations, numerical computing, scientific computing, HPC, linking BLAS/LAPACK.
skill-creator
Guide for creating effective skills. This skill should be used when users want to create a new skill (or update an existing skill) that extends Claude's capabilities with specialized knowledge, workflows, or tool integrations.
openclaw-config-guard
Audit and safely repair OpenClaw configuration with deterministic validation, backups, rollback, and change reporting. Use when asked to review or modify `openclaw.json`, check whether OpenClaw can still start, safely fix startup-blocking config errors, or audit OpenClaw config before deciding on changes.