libraries-openly-fused/fusedkernellibrary/fkl-using-the-library
Claude Code and agent skill by libraries-openly-fused/fusedkernellibrary
- community
Checking that the SKILL.md file is still in the repository.
Write user code with the Fused Kernel Library (FKL) — compose fused GPU/CPU pipelines with executeOperations, manage Ptr2D/Tensor data, streams, and runtime parameters. Use when writing an application or library that calls FKL, when porting OpenCV-style image pipelines to fused kernels, or when you need the canonical pipeline patterns (DNN preprocessing, multi-ROI crop, color conversion).
Install
npx vskill@latest install libraries-openly-fused/fusedkernellibrary/fkl-using-the-librarySKILL.md
Using the Fused Kernel Library
Mental model (60 seconds)
FKL fuses a SEQUENCE of operations into ONE kernel at C++ compile time. You write the operations in execution order; intermediates live in registers, never in DRAM:
Rules:
- First IOp must be a complete Read (
PerThreadRead,TensorRead,ReadSet, ...). Last must be a Write (PerThreadWrite,TensorWrite,TensorSplit, ...). - Each op's OutputType must match the next op's InputType. Type errors are compile errors with the offending pair in the message.
- TYPES define the kernel. VALUES (
build()arguments) are runtime parameters: changing a factor or a crop rect does NOT create a new kernel.
The two layers
Operationstructs (e.g.Mul<float3>): staticexec()+ type aliases. Pure compute, no state.InstantiableOperation(IOp) = Operation + its runtime params, created withOp::build(args...). What you pass toexecuteOperations.
Common pipeline patterns (all verified)
DNN preprocessing in one kernel (crop -> resize -> normalize -> planar)
Many ROIs from one image (Horizontal Fusion: pass an array)
Batch of separate same-size images
Color conversion + channel ops
Streams
Stream stream;creates an owning CUDA stream;stream.sync()waits.- Wrap an external stream zero-cost:
Stream s(existingCudaStream);(FKL will NOT destroy it). Use this to interop with torch/cupy streams. - All
executeOperationsoverloads are async on the given stream. Streamis the stream of the default backend (ParArch::GPU_NVIDIAunder nvcc,GPU_AMDunder hipcc,CPU
otherwise). The multithreaded CPU stream is always explicit: Stream_<ParArch::CPU_MULTITHREAD> (see below).
Out-of-bounds reads
Wrap the read with a BorderReader policy BEFORE ops that may sample outside (Crop past the edge, warps). The backIOp is the complete read:
Policies: CONSTANT, REPLICATE, REFLECT, WRAP, REFLECT_101.
Temporal video windows
CircularTensor<T, COLOR_PLANES, BATCH, CircularTensorOrder, ColorPlanes> keeps the last BATCH frames on the GPU; update(stream, readIOp, ops..., writeIOp) preprocesses + inserts + rotates in one Divergent-HF kernel.
CPU backends
The same pipelines run on CPU: executeOperations<TransformDPP<ParArch::CPU>> with Stream_<ParArch::CPU> (single thread, runs before returning). Useful for tests without a GPU.
Multithreaded CPU: ParArch::CPU_MULTITHREAD
Available when FK_CPU_MULTITHREAD_ENABLED is defined (CMake option ENABLE_CPU_MULTITHREAD, ON when the thread-pool submodule is checked out: clone with --recursive). The work runs on fk::cpuThreadPool(), shared by all streams (one worker per hardware thread), with the same results as ParArch::CPU. Every DPP has it except the GPU-only attention DPPs; the filter entry points (executeLinearFilter, executeMorphology, executeBoxFilterQuad, ...) have Stream_<ParArch::CPU_MULTITHREAD>& overloads.
Stream rules (as with a CUDA stream):
- Entry points enqueue and return. The executions of a stream run in order; different streams run concurrently.
sync()waits for the executions enqueued before it, and rethrows the first exception their work threw since the previoussync(). Called on a pool worker (e.g. insidecpuThreadPool().submit(...)), it runs queued work instead of blocking.- A stream holds at most 1024 pending executions; past that, enqueueing waits.
- Copies of a stream share its queue; the last copy to be destroyed waits for the executions (errors nobody synced are lost).
Memory rules:
- Everything an execution reads or writes must stay valid until it has finished (
sync()). TheexecuteOperationsoverloads that takePtr/Tensor/std::array<Ptr2D>arguments, andsetTo, keep those buffers alive. IOps only hold aRawPtr, even whenbuild()got aPtror anImage, so those buffers (and aCircularTensorbeing updated) are NOT kept alive: do not release them, or access them from the host, beforesync(). - Memory must be
HostorHostPinned. On this streamPtr/Imageupload/downloadare ordered no-ops (there is a single buffer), and they andsetTothrowstd::runtime_errorforDevice/DeviceAndPinnedmemory.
Pitfalls (each cost real debugging time)
- Mismatched adjacent types: read the static_assert chain bottom-up; the first frame names the two ops that disagree.
- An array-built op (e.g.
Crop<>::build(std::array<Rect,N>)) enables Horizontal Fusion (batch planes). Just pass the IOps toexecuteOperationsas usual; the executor/BackFuser handles the fusion automatically. Ensure your output is a batched write (e.g.TensorWrite/TensorSplit) that matches the batch size N.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryChecking.github/skills/fkl-using-the-library/SKILL.md
Popularity
- Repository stars
- 58
- Repository forks
- 4
- 7-day trend score
- 20
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/libraries-openly-fused/fusedkernellibrary/fkl-using-the-library)