ggml_custom_inplace: In-Place Custom Operation Node

View source: R/custom_ops.R

ggml_custom_inplaceR Documentation

In-Place Custom Operation Node

Description

Creates a custom-op node that writes into a view of a rather than into a freshly allocated tensor. The output has the shape and type of a, and a itself is the node's first source; tensors in args follow it, so the kernel sees a as dst->src[0] and the first extra argument as dst->src[1].

Usage

ggml_custom_inplace(ctx, a, name, args = NULL, n_tasks = GGML_N_TASKS_MAX)

Arguments

ctx

GGML context

a

Tensor to write into

name

Name of a registered custom op (character scalar)

args

List of additional input tensors, or NULL for none. At most 8 tensors, one fewer than ggml_custom because a occupies the first source slot.

n_tasks

Number of threads the kernel may be split across, or GGML_N_TASKS_MAX (-1). Use 1 for a kernel that is not thread-safe.

Details

See ggml_custom for how kernels are registered and for the CPU-only backend restriction, which applies here too.

Value

Tensor pointer for the custom node (a view of a)

See Also

ggml_custom, ggml_custom_ops

Examples

# "clip_inplace" takes its bounds as a 2-element tensor, since a custom node
# carries no scalar parameters of its own.
ggml_set_n_threads(1L)
ctx <- ggml_init(16 * 1024 * 1024)
x <- ggml_new_tensor_1d(ctx, GGML_TYPE_F32, 5)
ggml_set_f32(x, c(-3, -1, 0, 1, 3))

bounds <- ggml_new_tensor_1d(ctx, GGML_TYPE_F32, 2)
ggml_set_f32(bounds, c(-1, 1))

y <- ggml_custom_inplace(ctx, x, "clip_inplace", args = list(bounds))
graph <- ggml_build_forward_expand(ctx, y)
ggml_graph_compute(ctx, graph)
ggml_get_f32(y)   # -1, -1, 0, 1, 1
ggml_free(ctx)

ggmlR documentation built on Oct. 23, 2026, 1:07 a.m.