@driftengine/texture 4.4.0 → 4.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/dist/tensor/reuse.d.ts +0 -33
- package/dist/tensor/reuse.js +0 -59
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@driftengine/texture",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.1",
|
|
4
4
|
"description": "DriftTexture: a texture as a compiled, sampled field rather than an image",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
],
|
|
28
28
|
"sideEffects": false,
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@driftengine/core": "4.4.
|
|
30
|
+
"@driftengine/core": "4.4.1"
|
|
31
31
|
},
|
|
32
32
|
"author": "Drift Technologies",
|
|
33
33
|
"repository": {
|
package/dist/tensor/reuse.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Which values of a graph may share one buffer, as one rule both sides plan by: the reference
|
|
3
|
-
* evaluator here, and the device's runner in `@driftengine/core`.
|
|
4
|
-
*
|
|
5
|
-
* **A value's buffer is given back after the last node that reads it, and not before** — so a
|
|
6
|
-
* node's output never shares a buffer with any of its own inputs, since the inputs are read while
|
|
7
|
-
* the output is written. What is `held` keeps a buffer of its own for the life of the plan, and so
|
|
8
|
-
* does every output; a value that is neither written by a node nor held is not planned at all,
|
|
9
|
-
* which is how the evaluator leaves weights and inputs in the caller's own arrays.
|
|
10
|
-
*
|
|
11
|
-
* **Two implementations of this would drift**, and the failure is a network that runs, validates
|
|
12
|
-
* and answers wrongly — a value overwritten before its last reader reads it.
|
|
13
|
-
*
|
|
14
|
-
* What it gives up: a free buffer is taken first-come rather than by the size that fits best, so a
|
|
15
|
-
* small value may hold a large buffer while a larger one waits. The transformers this runs repeat a
|
|
16
|
-
* block of identically shaped values, where first-come and best-fit choose the same buffers.
|
|
17
|
-
*/
|
|
18
|
-
export interface BufferReuse {
|
|
19
|
-
/** The buffer each planned value lives in. */
|
|
20
|
-
readonly slotOf: ReadonlyMap<string, number>;
|
|
21
|
-
/** Each buffer's size, in values: the largest value it ever holds. */
|
|
22
|
-
readonly sizes: readonly number[];
|
|
23
|
-
}
|
|
24
|
-
export declare function planReuse(graph: {
|
|
25
|
-
readonly nodes: readonly {
|
|
26
|
-
readonly inputs: readonly string[];
|
|
27
|
-
readonly output: string;
|
|
28
|
-
}[];
|
|
29
|
-
/** Values given a buffer each before any node runs, in this order. */
|
|
30
|
-
readonly held: readonly string[];
|
|
31
|
-
/** Values never given back, claimed where they are written. */
|
|
32
|
-
readonly outputs: readonly string[];
|
|
33
|
-
}, sizeOf: (name: string) => number): BufferReuse;
|
package/dist/tensor/reuse.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Which values of a graph may share one buffer, as one rule both sides plan by: the reference
|
|
3
|
-
* evaluator here, and the device's runner in `@driftengine/core`.
|
|
4
|
-
*
|
|
5
|
-
* **A value's buffer is given back after the last node that reads it, and not before** — so a
|
|
6
|
-
* node's output never shares a buffer with any of its own inputs, since the inputs are read while
|
|
7
|
-
* the output is written. What is `held` keeps a buffer of its own for the life of the plan, and so
|
|
8
|
-
* does every output; a value that is neither written by a node nor held is not planned at all,
|
|
9
|
-
* which is how the evaluator leaves weights and inputs in the caller's own arrays.
|
|
10
|
-
*
|
|
11
|
-
* **Two implementations of this would drift**, and the failure is a network that runs, validates
|
|
12
|
-
* and answers wrongly — a value overwritten before its last reader reads it.
|
|
13
|
-
*
|
|
14
|
-
* What it gives up: a free buffer is taken first-come rather than by the size that fits best, so a
|
|
15
|
-
* small value may hold a large buffer while a larger one waits. The transformers this runs repeat a
|
|
16
|
-
* block of identically shaped values, where first-come and best-fit choose the same buffers.
|
|
17
|
-
*/
|
|
18
|
-
export function planReuse(graph, sizeOf) {
|
|
19
|
-
const slotOf = new Map();
|
|
20
|
-
const sizes = [];
|
|
21
|
-
const pinned = new Set([...graph.held, ...graph.outputs]);
|
|
22
|
-
const claim = (name) => {
|
|
23
|
-
sizes.push(sizeOf(name));
|
|
24
|
-
slotOf.set(name, sizes.length - 1);
|
|
25
|
-
return sizes.length - 1;
|
|
26
|
-
};
|
|
27
|
-
for (const name of graph.held)
|
|
28
|
-
claim(name);
|
|
29
|
-
/* The last node reading each value; a value never read is last read where it is written. */
|
|
30
|
-
const lastRead = new Map();
|
|
31
|
-
graph.nodes.forEach((node, at) => {
|
|
32
|
-
lastRead.set(node.output, at);
|
|
33
|
-
for (const input of node.inputs)
|
|
34
|
-
lastRead.set(input, at);
|
|
35
|
-
});
|
|
36
|
-
const free = [];
|
|
37
|
-
graph.nodes.forEach((node, at) => {
|
|
38
|
-
if (pinned.has(node.output)) {
|
|
39
|
-
claim(node.output);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
const reuse = free.shift();
|
|
43
|
-
if (reuse === undefined)
|
|
44
|
-
claim(node.output);
|
|
45
|
-
else {
|
|
46
|
-
slotOf.set(node.output, reuse);
|
|
47
|
-
sizes[reuse] = Math.max(sizes[reuse], sizeOf(node.output));
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
/* Only after the node has run: its inputs are read while its output is written. */
|
|
51
|
-
for (const value of new Set([...node.inputs, node.output])) {
|
|
52
|
-
const slot = slotOf.get(value);
|
|
53
|
-
if (slot === undefined || pinned.has(value) || lastRead.get(value) !== at)
|
|
54
|
-
continue;
|
|
55
|
-
free.push(slot);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
return { slotOf, sizes };
|
|
59
|
-
}
|