sourcelibs/Accel/demos/lookup.xtl
1⍝!/usr/bin/env xetal
2⍝ Lookups: items of a vector at given positions (one, several, a
3⍝ matrix of them), rows of a matrix, columns along the second axis;
4⍝ then an embedding table and a batch of two prompts of three token
5⍝ ids each, the embeddings summed per prompt. On a GPU a lookup is a
6⍝ gather with the table resident and only the ids uploaded. Run with
7⍝ "just demo-lib Accel lookup".
8ᵃᶜ⁼u̲se< "Accel"
9v ← 10 20 30 40 50
102 s̲elect v
112 4 1 s̲elect v
12(2 2 r̲eshape 2 4 1 1) s̲elect v
13m ← 3 2 r̲eshape r̲ange 6
143 1 s̲elect m
152 1 s̲elect₂ m
16t ← 5 4 r̲eshape 0.0 0.1 0.2 0.3 1.0 1.1 1.2 1.3 2.0 2.1 2.2 2.3 3.0 3.1 3.2 3.3 4.0 4.1 4.2 4.3
17ids ← 2 3 r̲eshape 1 5 2 4 4 3
18e ← t ᵃᶜe̲mbed ids
19e
20'+ r̲/₂ e