Docsv0.5.1Ask AIGet started

Standard library / gpu

gpu.alloc

Starts allocating GPU memory in the background and returns right away. Await the result before you use it.

func alloc(_ size: Int) -> Memory

Parameters

size
Int
Number of elements to allocate

Returns

Memory you await before use

Example

allocateAndFill.emma
1
2
3
4
5
6
7
8
9
kernel func allocateAndFill(with constant: Float) {
    // The allocation will begin in the background
    let mem = gpu.alloc(1024)

    // do other stuff

    // If the allocation is not complete, pause here until it is
    await gpu.fill(await mem, constant)
}

See also