Skip to content

compute.aug ​

GPU workers · Source and specification

Files in this project

Code ​

aug
// aug-spec: "compute.aug.md" explains this file. Read it before changes; refresh with aug spec.
import Device and Buffer and openDevice and upload and add and download from "https://github.com/GreenPandaStudios/aug-gpu#ebc288b8d88b30213715bdbcd3d4647ff81a5462"
/** Add two lists on a GPU and return copied values. GPU resources stay local. */
calculate(List<float> left, List<float> right) returns List<float>:
    own Device device = openDevice()
    own Buffer first = upload(device, values=left)
    own Buffer second = upload(device, values=right)
    own Buffer result = add(left=first, right=second)
    return download(buffer=result)
test calculate:
    when "native":
        it "copies_the_GPU_result":
            List<float> result = calculate(left=[1.0, 2.0, 3.0], right=[4.0, 5.0, 6.0])
            assert(result.length() == 3)
            assert(result.get(index=0) == 5.0)
            assert(result.get(index=1) == 7.0)
            assert(result.get(index=2) == 9.0)
aug
// aug-spec: "compute.aug.md" explains this file. Read it before changes; refresh with aug spec.
import Device and Buffer and openDevice and upload and add and download from "https://github.com/GreenPandaStudios/aug-gpu#ebc288b8d88b30213715bdbcd3d4647ff81a5462"
/** Add two lists on a GPU and return copied values. GPU resources stay local. */
calculate(List<float> left, List<float> right) returns List<float> {
    own Device device = openDevice()
    own Buffer first = upload(device, values=left)
    own Buffer second = upload(device, values=right)
    own Buffer result = add(left=first, right=second)
    return download(buffer=result)
}
test calculate {
    when "native" {
        it "copies_the_GPU_result" {
            List<float> result = calculate(left=[1.0, 2.0, 3.0], right=[4.0, 5.0, 6.0])
            assert(result.length() == 3)
            assert(result.get(index=0) == 5.0)
            assert(result.get(index=1) == 7.0)
            assert(result.get(index=2) == 9.0)
        }
    }
}

Compiled specification ​

Interactions and sequences

calculate · source ​

Add two lists on a GPU and return copied values. GPU resources stay local. It takes left and right as List<float>. Failures can raise GpuError.

It calls openDevice and stores the result in owned device (Device). It calls upload with device and values from left and stores the result in owned first (Buffer). It calls upload with device and values from right and stores the result in owned second (Buffer). It calls add with left from first and right from second and stores the result in owned result (Buffer). source

It returns download with buffer from result. source

Checked interface
text
calculate(List<float> left, List<float> right) returns List<float> unless GpuError

It takes left and right as List<float>. Failures can raise GpuError.

test calculate · source ​

Tests calculate. Each case gets fresh setup and dependencies.

native ​

copies_the_GPU_result · source ​

It sets result of type List<float> to calculate with left from a list containing 1.0, 2.0, 3.0 and right from a list containing 4.0, 5.0, 6.0. The test requires the number of elements in result equals 3. The test requires the item at index 0 in result equals 5.0. The test requires the item at index 1 in result equals 7.0. source

The test requires the item at index 2 in result equals 9.0. source

Dependencies ​

It uses add, download, openDevice, upload, Buffer, and Device from https://github.com/GreenPandaStudios/aug-gpu#ebc288b8d88b30213715bdbcd3d4647ff81a5462. It uses GpuError.

Built-in operations follow the language reference.

Last updated:

The world runs on language