Compact reference for the public cthreads.gpu surface and related sync entry
points. Narrative guides: README.md.
- Package imports
@Gpu- Launch
- Indexes
- GpuArena
- Probe / lifecycle
- Errors
- Sync barriers
- Kernel language (summary)
from cthreads.gpu import (
Gpu,
gpu,
prepare,
compile,
GpuJob,
GpuArena,
GlobalIdx,
ThreadIdx,
BlockIdx,
BlockDim,
GridDim,
available,
device_name,
init,
shutdown,
)
from cthreads.sync import Barrier, __sync_threads@Gpu
def kernel(...) -> None: ...
@Gpu(log=True)
def kernel_logged(...) -> None: ...- Validates GPU type allowlist and registers the function.
- Requires GPU availability at decorate time.
- Does not launch.
Allowed parameter types: int, float, bool, list[int], list[float],
list[bool]. Return must be None.
Ensure Vulkan is usable and compile registered @Gpu kernels.
Emit / refresh SPIR-V artifacts for registered kernels.
Launch a @Gpu function. Positional args only. Auto-prepares when needed.
| Method | Signature | Notes |
|---|---|---|
join |
join(download: bool = True) -> None |
Wait; download ref lists when download is true |
result |
result() -> None |
Always None |
Markers with .x / .y / .z:
| Name | Meaning |
|---|---|
GlobalIdx |
Global invocation id (prefer for 1D maps) |
ThreadIdx |
Id within workgroup |
BlockIdx |
Workgroup id |
BlockDim |
Workgroup size |
GridDim |
Number of workgroups |
Default workgroup size X: 64. group_count_x defaults to ceil(n / 64) with
n from parameter n or longest list length.
with GpuArena() as arena:
arena.bind(x=x, y=y)
gpu(fn, n, x, y).join(download=False)
arena.sync() # or arena.sync("y")
# arena.release() on exit| Method | Role |
|---|---|
bind(**lists) |
Upload / register lists by keyword slot name |
sync(*names) |
Download slots into Python lists |
release() |
Destroy buffers; clear registrations |
names() |
Bound slot names |
Residency is keyed by list object identity + length.
| Function | Returns | Raises |
|---|---|---|
available() |
bool |
No (soft fail) |
device_name() |
str |
Mapped GPU errors / not built |
init() |
None |
Mapped GPU errors / not built |
shutdown() |
None |
Soft if not built |
CThreadsGPUError and subclasses:
VulkanNotBuiltErrorVulkanLoaderNotFoundVulkanNoDeviceVulkanInitFailedVulkanOutOfMemoryGpuInvalidArgumentGpuUseAfterDestroyGPUNotAvailable
Details: errors.md.
Inside @Gpu only:
__sync_threads()
Barrier.arrive_and_wait()Workgroup scope. Barrier(...) construction inside @Gpu raises TypeError.
Guide: sync.md.
Supported: annotated locals, if/else, while, for i in range(...), early
return, list indexing, arithmetic/comparisons, sqrt / floor / int(...),
barrier calls.
Not supported: list for-in, rich Python types, valued returns, keyword
gpu(...) args, mid-run Python observe.
Full rules: kernels.md.