//clika-runtime/io.clika.runtime/Tensors/fromBlob
fromBlob
[common]
fun fromBlob(buffer: <Error class: unknown class>, shape: LongArray, dtype: DType = DType.FLOAT32, where: Placement? = null, deleter: VoidCallback? = null): Tensor
Wrap memory the application owns, without copying: buffer must be a DIRECT ByteBuffer (allocateDirect, the one JVM buffer with a stable native address) holding shape elements of dtype in row-major order from its position 0. With no deleter the tensor BORROWS the buffer, which the returned tensor keeps referenced while it lives (a view derived from it does not: keep the buffer alive for as long as any view is in use); with a deleter the tensor ADOPTS it, and the deleter runs exactly once, when the last reference drops (on whichever thread that happens). Writes through the buffer are visible through the tensor: it is the same memory. A buffer smaller than the shape needs is refused.
val buf = ByteBuffer.allocateDirect(8 * 4).order(ByteOrder.nativeOrder())
val view = Tensors.fromBlob(buf, longArrayOf(8)) // borrowed
val owned = Tensors.fromBlob(buf, longArrayOf(8), deleter = VoidCallback {
println("released") // adopted
})