FK

Handles GPU memory allocation and data structure wrapping for FKL pipelines.

Install

mkdir -p .claude/skills/fkl-data-structures && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/19361" && unzip -o skill.zip -d .claude/skills/fkl-data-structures && rm skill.zip

Installs to .claude/skills/fkl-data-structures

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

FKL data structures — Ptr2D, Tensor, TensorT, RawPtr, PtrDims, MemType, constructors and memory layouts (packed, planar CHW, transposed T3D). Use when allocating or wrapping GPU memory for FKL pipelines, when interfacing external pointers (torch/cupy buffers), or when a Tensor/TensorT constructor or pitch issue appears.
321 chars✓ has a “when” triggerlonger than Claude Code's old 250-char listing cap (fine on current versions)
Advanced

Key capabilities

  • Allocate GPU memory for FKL pipelines
  • Wrap external pointers from torch or cupy
  • Manage memory layouts including packed and planar CHW
  • Define memory types for FKL data structures
  • Perform zero-copy interop with external frameworks

How it works

It provides a hierarchy of data structures like RawPtr and Tensor to manage GPU memory layouts. It allows wrapping external pointers without copying by specifying memory types and pitch parameters.

Inputs & outputs

You give it
Memory dimensions and framework pointers
You get back
FKL-compatible data structure or wrapped buffer

When to use fkl-data-structures

  • Allocating GPU memory for image processing
  • Wrapping external buffers from torch or cupy
  • Handling pitched memory layouts for 3D tensors
  • Defining memory types for FKL pipelines

About this skill

FKL data structures

The hierarchy

  • RawPtr<ND, T> — POD: data pointer + PtrDims<ND>. What kernels see.
  • Ptr<ND, T> — ref-counted owner/wrapper around a RawPtr.
  • Convenience classes: Ptr1D, Ptr2D, Ptr3D, Tensor, TensorT.
  • .ptr() returns the RawPtr; Op::build(container) extracts what it needs. Copies of Ptr objects are SHALLOW (shared refcount).

Dimensionalities (ND)

NDlayoutuse
_1Dwflat arrays
_2Dw x h (pitched)images
_3Dw x h x planes x color_planesbatched images / planar CHW
T3Dtransposed: color_planes outermostNCHW-like DNN ingest

Constructors that matter (and their traps)

// allocating
Ptr2D<uchar3> img(width, height);                       // device by default
Tensor<float> t(width, height, planes, color_planes);   // 3D batch

// wrapping EXTERNAL memory (zero-copy interop):
Ptr2D<float> wrap(devPtr, width, height, pitchBytes, MemType::Device);
Tensor<float> wrapT(devPtr, width, height, planes, color_planes, MemType::Device);

TRAPS (verified the hard way):

  1. Tensor has NO PtrDims-taking constructor — pass the dimension list.
  2. Tensor's semantics for batch+channels: planes = batch (thread.z), color_planes = channels. TensorSplit writes channel c of plane z at offset z * plane_pitch * color_planes + c * plane_pitch.
  3. TensorT(data, ...) and the 4-arg PtrDims<T3D> constructor leave pitches at ZERO (they are filled on allocation). When wrapping an external pointer for T3D, build the PtrDims and set pitch, plane_pitch, color_planes_pitch manually, then construct the RawPtr<T3D> and pass it to TensorTSplit<T>::build(rawPtr).
  4. Pitch is in BYTES. For tightly-packed external buffers, pitch = width * sizeof(T).

MemType

Device, Host, HostPinned, DeviceAndPinned (mirrored pair with .upload(stream) / .download(stream)). GPU pipelines require Device or DeviceAndPinned memory — CircularTensor enforces this at runtime.

Layout cheat-sheet for DNN interop

wantuseoutput shape
packed HWC batchTensorWrite<T>(batch, H, W, C-packed-in-T)
planar CHW per imageTensorSplit<T>(batch, C, H, W)
planar, C outermostTensorTSplit<T> into TensorT(C, batch, H, W)
read planar back as packedTensorPack<T> / TensorTPack<T>

Vector pixel types

Channels are encoded in the TYPE: uchar3, float4, etc.

  • VBase<T> = scalar base, cn<T> = channels, VectorType_t<base, n>.
  • Per-channel arithmetic operators are predefined (vector_utils.h).
  • 16-bit types (ushort3, short2) work like the 8/32-bit ones.

External-framework interop (what bindings do)

A torch/cupy CUDA tensor is wrapped without copying:

Ptr2D<float> in((float*)cuda_ptr, w, h, w * sizeof(float), MemType::Device);
Stream s(reinterpret_cast<cudaStream_t>(framework_stream));  // non-owning

Contiguity is the caller's responsibility (require C-contiguous or read strides into the pitch argument).

When not to use it

  • When using non-GPU memory for FKL pipelines
  • When attempting to use Tensor constructors without dimension lists

Prerequisites

CUDA-compatible environmentExternal framework buffers (torch/cupy)

Limitations

  • Pitch must be calculated in bytes
  • Tensor constructors require explicit dimension lists

How it compares

This approach provides explicit control over memory layout and pitch for GPU kernels compared to generic framework-level tensor abstractions.

Compared to similar skills

fkl-data-structures side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
fkl-data-structures (this skill)015dNo flagsAdvanced
mlir-development16moReviewAdvanced
compiler-development16moNo flagsAdvanced
add-cuda-kernel13moReviewAdvanced

Try saying

Example prompts that trigger this skill in your AI assistant.

Search skills

Search the agent skills registry