graphwise 1.8.1 → 1.9.0
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/dist/{adjacency-map-D-Ul7V1r.js → adjacency-map-BtKzcuJq.js} +1 -1
- package/dist/{adjacency-map-D-Ul7V1r.js.map → adjacency-map-BtKzcuJq.js.map} +1 -1
- package/dist/{adjacency-map-B6wPtmaq.cjs → adjacency-map-JqBnMNkF.cjs} +1 -1
- package/dist/{adjacency-map-B6wPtmaq.cjs.map → adjacency-map-JqBnMNkF.cjs.map} +1 -1
- package/dist/async/index.cjs +2 -2
- package/dist/async/index.js +2 -2
- package/dist/expansion/index.cjs +1 -1
- package/dist/expansion/index.js +1 -1
- package/dist/{expansion-sldRognt.js → expansion-ClDhlMK8.js} +4 -4
- package/dist/{expansion-sldRognt.js.map → expansion-ClDhlMK8.js.map} +1 -1
- package/dist/{expansion-FkmEYlrQ.cjs → expansion-DaTroIyv.cjs} +4 -4
- package/dist/{expansion-FkmEYlrQ.cjs.map → expansion-DaTroIyv.cjs.map} +1 -1
- package/dist/extraction/index.cjs +1 -1
- package/dist/extraction/index.js +1 -1
- package/dist/gpu/csr.d.ts +29 -30
- package/dist/gpu/csr.d.ts.map +1 -1
- package/dist/gpu/dispatch.d.ts +31 -0
- package/dist/gpu/dispatch.d.ts.map +1 -0
- package/dist/gpu/dispatch.unit.test.d.ts +5 -0
- package/dist/gpu/dispatch.unit.test.d.ts.map +1 -0
- package/dist/gpu/index.cjs +15 -410
- package/dist/gpu/index.d.ts +3 -1
- package/dist/gpu/index.d.ts.map +1 -1
- package/dist/gpu/index.js +2 -400
- package/dist/gpu/kernels/bfs/kernel.d.ts +59 -0
- package/dist/gpu/kernels/bfs/kernel.d.ts.map +1 -0
- package/dist/gpu/kernels/bfs/logic.d.ts +47 -0
- package/dist/gpu/kernels/bfs/logic.d.ts.map +1 -0
- package/dist/gpu/kernels/bfs/logic.unit.test.d.ts +2 -0
- package/dist/gpu/kernels/bfs/logic.unit.test.d.ts.map +1 -0
- package/dist/gpu/kernels/degree-histogram/kernel.d.ts +32 -0
- package/dist/gpu/kernels/degree-histogram/kernel.d.ts.map +1 -0
- package/dist/gpu/kernels/degree-histogram/logic.d.ts +45 -0
- package/dist/gpu/kernels/degree-histogram/logic.d.ts.map +1 -0
- package/dist/gpu/kernels/degree-histogram/logic.unit.test.d.ts +2 -0
- package/dist/gpu/kernels/degree-histogram/logic.unit.test.d.ts.map +1 -0
- package/dist/gpu/kernels/jaccard/kernel.d.ts +40 -0
- package/dist/gpu/kernels/jaccard/kernel.d.ts.map +1 -0
- package/dist/gpu/kernels/jaccard/logic.d.ts +43 -0
- package/dist/gpu/kernels/jaccard/logic.d.ts.map +1 -0
- package/dist/gpu/kernels/jaccard/logic.unit.test.d.ts +2 -0
- package/dist/gpu/kernels/jaccard/logic.unit.test.d.ts.map +1 -0
- package/dist/gpu/kernels/pagerank/kernel.d.ts +44 -0
- package/dist/gpu/kernels/pagerank/kernel.d.ts.map +1 -0
- package/dist/gpu/kernels/pagerank/logic.d.ts +50 -0
- package/dist/gpu/kernels/pagerank/logic.d.ts.map +1 -0
- package/dist/gpu/kernels/pagerank/logic.unit.test.d.ts +2 -0
- package/dist/gpu/kernels/pagerank/logic.unit.test.d.ts.map +1 -0
- package/dist/gpu/kernels/spmv/kernel.d.ts +43 -0
- package/dist/gpu/kernels/spmv/kernel.d.ts.map +1 -0
- package/dist/gpu/kernels/spmv/logic.d.ts +31 -0
- package/dist/gpu/kernels/spmv/logic.d.ts.map +1 -0
- package/dist/gpu/kernels/spmv/logic.unit.test.d.ts +2 -0
- package/dist/gpu/kernels/spmv/logic.unit.test.d.ts.map +1 -0
- package/dist/gpu/operations.d.ts +76 -0
- package/dist/gpu/operations.d.ts.map +1 -0
- package/dist/gpu/operations.unit.test.d.ts +5 -0
- package/dist/gpu/operations.unit.test.d.ts.map +1 -0
- package/dist/gpu/root.d.ts +53 -0
- package/dist/gpu/root.d.ts.map +1 -0
- package/dist/gpu/root.unit.test.d.ts +2 -0
- package/dist/gpu/root.unit.test.d.ts.map +1 -0
- package/dist/gpu/types.d.ts +3 -8
- package/dist/gpu/types.d.ts.map +1 -1
- package/dist/gpu-CHiCN0wa.js +16945 -0
- package/dist/gpu-CHiCN0wa.js.map +1 -0
- package/dist/gpu-Y6owRVMi.cjs +17028 -0
- package/dist/gpu-Y6owRVMi.cjs.map +1 -0
- package/dist/graph/index.cjs +1 -1
- package/dist/graph/index.js +1 -1
- package/dist/index/index.cjs +18 -15
- package/dist/index/index.js +10 -10
- package/dist/{jaccard-Yddrtt5D.js → jaccard-3rCdilwm.js} +2 -2
- package/dist/{jaccard-Yddrtt5D.js.map → jaccard-3rCdilwm.js.map} +1 -1
- package/dist/{jaccard-Bmd1IEFO.cjs → jaccard-Bys9_dGW.cjs} +2 -2
- package/dist/{jaccard-Bmd1IEFO.cjs.map → jaccard-Bys9_dGW.cjs.map} +1 -1
- package/dist/{kmeans-D3yX5QFs.cjs → kmeans-B8x9D1kt.cjs} +1 -1
- package/dist/{kmeans-D3yX5QFs.cjs.map → kmeans-B8x9D1kt.cjs.map} +1 -1
- package/dist/{kmeans-DVCe61Me.js → kmeans-DKkL9rAN.js} +1 -1
- package/dist/{kmeans-DVCe61Me.js.map → kmeans-DKkL9rAN.js.map} +1 -1
- package/dist/{ops-4nmI-pwk.cjs → ops-djAsQQSh.cjs} +2 -2
- package/dist/{ops-4nmI-pwk.cjs.map → ops-djAsQQSh.cjs.map} +1 -1
- package/dist/{ops-Zsu4ecEG.js → ops-upIi6JIi.js} +2 -2
- package/dist/{ops-Zsu4ecEG.js.map → ops-upIi6JIi.js.map} +1 -1
- package/dist/{priority-queue-ChVLoG6T.cjs → priority-queue-BIiD1L0k.cjs} +1 -1
- package/dist/{priority-queue-ChVLoG6T.cjs.map → priority-queue-BIiD1L0k.cjs.map} +1 -1
- package/dist/{priority-queue-DqCuFTR8.js → priority-queue-CFDd5cBg.js} +1 -1
- package/dist/{priority-queue-DqCuFTR8.js.map → priority-queue-CFDd5cBg.js.map} +1 -1
- package/dist/ranking/index.cjs +2 -2
- package/dist/ranking/index.js +2 -2
- package/dist/ranking/mi/index.cjs +2 -2
- package/dist/ranking/mi/index.js +2 -2
- package/dist/{ranking-mUm9rV-C.js → ranking-3ez5m67U.js} +2 -2
- package/dist/{ranking-mUm9rV-C.js.map → ranking-3ez5m67U.js.map} +1 -1
- package/dist/{ranking-riRrEVAR.cjs → ranking-DVvajgUZ.cjs} +2 -2
- package/dist/{ranking-riRrEVAR.cjs.map → ranking-DVvajgUZ.cjs.map} +1 -1
- package/dist/seeds/index.cjs +1 -1
- package/dist/seeds/index.js +1 -1
- package/dist/structures/index.cjs +1 -1
- package/dist/structures/index.js +1 -1
- package/dist/utils/index.cjs +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/{utils-CcIrKAEb.js → utils-BodeE2Mo.js} +1 -1
- package/dist/{utils-CcIrKAEb.js.map → utils-BodeE2Mo.js.map} +1 -1
- package/dist/{utils-CpyzmzIF.cjs → utils-CDtCcsyF.cjs} +1 -1
- package/dist/{utils-CpyzmzIF.cjs.map → utils-CDtCcsyF.cjs.map} +1 -1
- package/package.json +3 -1
- package/dist/gpu/context.d.ts +0 -118
- package/dist/gpu/context.d.ts.map +0 -1
- package/dist/gpu/context.unit.test.d.ts +0 -2
- package/dist/gpu/context.unit.test.d.ts.map +0 -1
- package/dist/gpu/index.cjs.map +0 -1
- package/dist/gpu/index.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_adjacency_map = require("../adjacency-map-
|
|
2
|
+
const require_adjacency_map = require("../adjacency-map-JqBnMNkF.cjs");
|
|
3
3
|
//#region src/extraction/ego-network.ts
|
|
4
4
|
/**
|
|
5
5
|
* Extract the ego-network (k-hop neighbourhood) of a centre node.
|
package/dist/extraction/index.js
CHANGED
package/dist/gpu/csr.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { d, StorageFlag, TgpuBuffer } from 'typegpu';
|
|
1
2
|
import { NodeId, Direction, NodeData, EdgeData } from '../graph/types';
|
|
2
3
|
import { ReadableGraph } from '../graph';
|
|
4
|
+
import { GraphwiseGPURoot } from './root';
|
|
3
5
|
/**
|
|
4
6
|
* CSR matrix representation of a graph adjacency structure.
|
|
5
7
|
*
|
|
@@ -39,17 +41,18 @@ export interface CSRGraph {
|
|
|
39
41
|
readonly indexMap: CSRIndexMap;
|
|
40
42
|
}
|
|
41
43
|
/**
|
|
42
|
-
* Group of
|
|
44
|
+
* Group of TypeGPU typed buffers holding a CSR matrix.
|
|
43
45
|
*
|
|
44
|
-
*
|
|
46
|
+
* Uses TypeGPU's typed buffer API for type-safe GPU computation.
|
|
47
|
+
* Buffers are created with storage usage for compute operations.
|
|
45
48
|
*/
|
|
46
|
-
export interface
|
|
47
|
-
/** Buffer containing rowOffsets data */
|
|
48
|
-
readonly rowOffsets:
|
|
49
|
-
/** Buffer containing colIndices data */
|
|
50
|
-
readonly colIndices:
|
|
51
|
-
/** Buffer containing values data (optional) */
|
|
52
|
-
readonly values?:
|
|
49
|
+
export interface TypedBufferGroup {
|
|
50
|
+
/** Buffer containing rowOffsets data (u32 array) */
|
|
51
|
+
readonly rowOffsets: TgpuBuffer<ReturnType<typeof d.arrayOf<typeof d.u32>>> & StorageFlag;
|
|
52
|
+
/** Buffer containing colIndices data (u32 array) */
|
|
53
|
+
readonly colIndices: TgpuBuffer<ReturnType<typeof d.arrayOf<typeof d.u32>>> & StorageFlag;
|
|
54
|
+
/** Buffer containing values data (f32 array, optional) */
|
|
55
|
+
readonly values?: TgpuBuffer<ReturnType<typeof d.arrayOf<typeof d.f32>>> & StorageFlag;
|
|
53
56
|
/** Number of nodes */
|
|
54
57
|
readonly nodeCount: number;
|
|
55
58
|
/** Number of edges */
|
|
@@ -67,31 +70,27 @@ export interface GPUBufferGroup {
|
|
|
67
70
|
*/
|
|
68
71
|
export declare function graphToCSR<N extends NodeData, E extends EdgeData>(graph: ReadableGraph<N, E>, direction?: Direction): CSRGraph;
|
|
69
72
|
/**
|
|
70
|
-
* Create
|
|
73
|
+
* Create TypeGPU typed buffers from a CSR matrix.
|
|
71
74
|
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* - values: STORAGE | COPY_DST (if present)
|
|
75
|
+
* Uses TypeGPU's typed buffer API for type-safe GPU computation.
|
|
76
|
+
* Buffers are created with storage usage for compute operations.
|
|
75
77
|
*
|
|
76
|
-
* @param
|
|
78
|
+
* @param root - TypeGPU root instance
|
|
77
79
|
* @param csr - CSR matrix to upload
|
|
78
|
-
* @returns
|
|
79
|
-
*/
|
|
80
|
-
export declare function csrToGPUBuffers(device: GPUDevice, csr: CSRMatrix): GPUBufferGroup;
|
|
81
|
-
/**
|
|
82
|
-
* Create a result buffer for reading compute output.
|
|
80
|
+
* @returns Typed buffer group
|
|
83
81
|
*
|
|
84
|
-
* @
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* import { initGPU, csrToTypedBuffers, graphToCSR } from "graphwise/gpu";
|
|
85
|
+
*
|
|
86
|
+
* const root = await initGPU();
|
|
87
|
+
* const { csr } = graphToCSR(graph);
|
|
88
|
+
* const buffers = csrToTypedBuffers(root, csr);
|
|
91
89
|
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
90
|
+
* // Read data back to CPU
|
|
91
|
+
* const rowOffsets = await buffers.rowOffsets.read();
|
|
92
|
+
* console.log(rowOffsets); // Uint32Array
|
|
93
|
+
* ```
|
|
95
94
|
*/
|
|
96
|
-
export declare function
|
|
95
|
+
export declare function csrToTypedBuffers(root: GraphwiseGPURoot, csr: CSRMatrix): TypedBufferGroup;
|
|
97
96
|
//# sourceMappingURL=csr.d.ts.map
|
package/dist/g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
|
+
* Options for backend dispatch.
|
|
5
|
+
*/
|
|
6
|
+
export interface DispatchOptions {
|
|
7
|
+
/** Backend selection: 'auto', 'gpu', or 'cpu' */
|
|
8
|
+
readonly backend?: ComputeBackend | undefined;
|
|
9
|
+
/** Optional pre-initialised TypeGPU root */
|
|
10
|
+
readonly root?: GraphwiseGPURoot | undefined;
|
|
11
|
+
/** Optional abort signal for cancellation */
|
|
12
|
+
readonly signal?: AbortSignal | undefined;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* CPU compute function type.
|
|
16
|
+
*/
|
|
17
|
+
export type CPUFunction<T> = () => T;
|
|
18
|
+
/**
|
|
19
|
+
* GPU compute function type.
|
|
20
|
+
*/
|
|
21
|
+
export type GPUFunction<T> = (root: GraphwiseGPURoot) => Promise<T> | T;
|
|
22
|
+
/**
|
|
23
|
+
* Execute a compute operation with automatic backend selection.
|
|
24
|
+
*
|
|
25
|
+
* @param options - Backend selection and cancellation options
|
|
26
|
+
* @param cpuFn - CPU fallback implementation
|
|
27
|
+
* @param gpuFn - GPU implementation (receives TypeGPU root)
|
|
28
|
+
* @returns Compute result with backend used and timing
|
|
29
|
+
*/
|
|
30
|
+
export declare function withBackend<T>(options: DispatchOptions, cpuFn: CPUFunction<T>, gpuFn: GPUFunction<T>): Promise<ComputeResult<T>>;
|
|
31
|
+
//# sourceMappingURL=dispatch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../../src/gpu/dispatch.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAEN,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B,iDAAiD;IACjD,QAAQ,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,SAAS,CAAC;IAC9C,4CAA4C;IAC5C,QAAQ,CAAC,IAAI,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAC;IAC7C,6CAA6C;IAC7C,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;CAC1C;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC;AAErC;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,gBAAgB,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAExE;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAClC,OAAO,EAAE,eAAe,EACxB,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,EACrB,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CA6D3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatch.unit.test.d.ts","sourceRoot":"","sources":["../../src/gpu/dispatch.unit.test.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
package/dist/gpu/index.cjs
CHANGED
|
@@ -1,411 +1,16 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* For undirected graphs, each edge is stored twice (once in each direction).
|
|
18
|
-
* For directed graphs, edges are stored in the out-direction by default.
|
|
19
|
-
*
|
|
20
|
-
* @param graph - The graph to convert
|
|
21
|
-
* @param direction - Edge direction to include (default: 'out' for directed, 'both' for undirected)
|
|
22
|
-
* @returns CSR representation with index mapping
|
|
23
|
-
*/
|
|
24
|
-
function graphToCSR(graph, direction = graph.directed ? "out" : "both") {
|
|
25
|
-
const nodeToIndex = /* @__PURE__ */ new Map();
|
|
26
|
-
const indexToNode = [];
|
|
27
|
-
for (const nodeId of graph.nodeIds()) {
|
|
28
|
-
const index = indexToNode.length;
|
|
29
|
-
nodeToIndex.set(nodeId, index);
|
|
30
|
-
indexToNode.push(nodeId);
|
|
31
|
-
}
|
|
32
|
-
const nodeCount = indexToNode.length;
|
|
33
|
-
const degrees = new Uint32Array(nodeCount);
|
|
34
|
-
for (const nodeId of graph.nodeIds()) {
|
|
35
|
-
const srcIndex = nodeToIndex.get(nodeId);
|
|
36
|
-
if (srcIndex === void 0) continue;
|
|
37
|
-
degrees[srcIndex] = graph.degree(nodeId, direction);
|
|
38
|
-
}
|
|
39
|
-
let totalEdges = 0;
|
|
40
|
-
for (let i = 0; i < nodeCount; i++) totalEdges += degrees[i] ?? 0;
|
|
41
|
-
const rowOffsets = new Uint32Array(nodeCount + 1);
|
|
42
|
-
for (let i = 0; i < nodeCount; i++) rowOffsets[i + 1] = (rowOffsets[i] ?? 0) + (degrees[i] ?? 0);
|
|
43
|
-
const colIndices = new Uint32Array(totalEdges);
|
|
44
|
-
const values = new Float32Array(totalEdges);
|
|
45
|
-
for (const nodeId of graph.nodeIds()) {
|
|
46
|
-
const srcIndex = nodeToIndex.get(nodeId);
|
|
47
|
-
if (srcIndex === void 0) continue;
|
|
48
|
-
const baseOffset = rowOffsets[srcIndex] ?? 0;
|
|
49
|
-
let localOffset = 0;
|
|
50
|
-
for (const neighbourId of graph.neighbours(nodeId, direction)) {
|
|
51
|
-
const dstIndex = nodeToIndex.get(neighbourId);
|
|
52
|
-
if (dstIndex === void 0) continue;
|
|
53
|
-
const edgeIdx = baseOffset + localOffset;
|
|
54
|
-
colIndices[edgeIdx] = dstIndex;
|
|
55
|
-
values[edgeIdx] = graph.getEdge(nodeId, neighbourId)?.weight ?? 1;
|
|
56
|
-
localOffset++;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
csr: {
|
|
61
|
-
rowOffsets,
|
|
62
|
-
colIndices,
|
|
63
|
-
values,
|
|
64
|
-
nodeCount,
|
|
65
|
-
edgeCount: graph.directed ? graph.edgeCount : graph.edgeCount * 2
|
|
66
|
-
},
|
|
67
|
-
indexMap: {
|
|
68
|
-
nodeToIndex,
|
|
69
|
-
indexToNode
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Create GPU buffers from a CSR matrix.
|
|
75
|
-
*
|
|
76
|
-
* Buffers are created with:
|
|
77
|
-
* - rowOffsets/colIndices: STORAGE | COPY_DST
|
|
78
|
-
* - values: STORAGE | COPY_DST (if present)
|
|
79
|
-
*
|
|
80
|
-
* @param device - GPU device to create buffers on
|
|
81
|
-
* @param csr - CSR matrix to upload
|
|
82
|
-
* @returns GPU buffer group
|
|
83
|
-
*/
|
|
84
|
-
function csrToGPUBuffers(device, csr) {
|
|
85
|
-
const rowOffsetsBuffer = device.createBuffer({
|
|
86
|
-
size: csr.rowOffsets.byteLength,
|
|
87
|
-
usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST,
|
|
88
|
-
mappedAtCreation: false
|
|
89
|
-
});
|
|
90
|
-
device.queue.writeBuffer(rowOffsetsBuffer, 0, csr.rowOffsets);
|
|
91
|
-
const colIndicesBuffer = device.createBuffer({
|
|
92
|
-
size: csr.colIndices.byteLength,
|
|
93
|
-
usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST,
|
|
94
|
-
mappedAtCreation: false
|
|
95
|
-
});
|
|
96
|
-
device.queue.writeBuffer(colIndicesBuffer, 0, csr.colIndices);
|
|
97
|
-
let valuesBuffer;
|
|
98
|
-
if (csr.values !== void 0) {
|
|
99
|
-
valuesBuffer = device.createBuffer({
|
|
100
|
-
size: csr.values.byteLength,
|
|
101
|
-
usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST,
|
|
102
|
-
mappedAtCreation: false
|
|
103
|
-
});
|
|
104
|
-
device.queue.writeBuffer(valuesBuffer, 0, csr.values);
|
|
105
|
-
}
|
|
106
|
-
if (valuesBuffer !== void 0) return {
|
|
107
|
-
rowOffsets: rowOffsetsBuffer,
|
|
108
|
-
colIndices: colIndicesBuffer,
|
|
109
|
-
values: valuesBuffer,
|
|
110
|
-
nodeCount: csr.nodeCount,
|
|
111
|
-
edgeCount: csr.edgeCount
|
|
112
|
-
};
|
|
113
|
-
return {
|
|
114
|
-
rowOffsets: rowOffsetsBuffer,
|
|
115
|
-
colIndices: colIndicesBuffer,
|
|
116
|
-
nodeCount: csr.nodeCount,
|
|
117
|
-
edgeCount: csr.edgeCount
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Create a result buffer for reading compute output.
|
|
122
|
-
*
|
|
123
|
-
* @param device - GPU device
|
|
124
|
-
* @param byteLength - Size of the buffer in bytes
|
|
125
|
-
* @returns GPU buffer configured for map reading
|
|
126
|
-
*/
|
|
127
|
-
function createResultBuffer(device, byteLength) {
|
|
128
|
-
return device.createBuffer({
|
|
129
|
-
size: byteLength,
|
|
130
|
-
usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC | GPUBufferUsage.MAP_READ
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Read data from a GPU buffer to CPU.
|
|
135
|
-
*
|
|
136
|
-
* @param device - GPU device
|
|
137
|
-
* @param buffer - Buffer to read from
|
|
138
|
-
* @returns ArrayBuffer containing the buffer data
|
|
139
|
-
*/
|
|
140
|
-
async function readBufferToCPU(device, buffer) {
|
|
141
|
-
await buffer.mapAsync(GPUMapMode.READ);
|
|
142
|
-
const data = buffer.getMappedRange().slice(0);
|
|
143
|
-
buffer.unmap();
|
|
144
|
-
return data;
|
|
145
|
-
}
|
|
146
|
-
//#endregion
|
|
147
|
-
//#region src/gpu/detect.ts
|
|
148
|
-
/**
|
|
149
|
-
* Detect WebGPU availability in the current environment.
|
|
150
|
-
*
|
|
151
|
-
* Checks for:
|
|
152
|
-
* - Browser: navigator.gpu
|
|
153
|
-
* - Node.js: global GPU constructor (Node.js 21+ with --experimental-webgpu)
|
|
154
|
-
* - Deno: global GPU constructor
|
|
155
|
-
*
|
|
156
|
-
* @returns Detection result with availability status and reason
|
|
157
|
-
*/
|
|
158
|
-
function detectWebGPU() {
|
|
159
|
-
if (typeof navigator !== "undefined" && "gpu" in navigator) return { available: true };
|
|
160
|
-
if (typeof globalThis !== "undefined" && "GPU" in globalThis) return { available: true };
|
|
161
|
-
const reasons = [];
|
|
162
|
-
if (typeof navigator === "undefined" && typeof globalThis === "undefined") reasons.push("no global scope detected");
|
|
163
|
-
else if (typeof navigator !== "undefined" && !("gpu" in navigator)) reasons.push("navigator.gpu not present (browser may not support WebGPU)");
|
|
164
|
-
else if (typeof globalThis !== "undefined" && !("GPU" in globalThis)) reasons.push("global GPU not present (Node.js requires v21+ with --experimental-webgpu flag)");
|
|
165
|
-
return {
|
|
166
|
-
available: false,
|
|
167
|
-
reason: reasons.length > 0 ? reasons.join("; ") : "unknown environment"
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Check if WebGPU is available (convenience function).
|
|
172
|
-
*
|
|
173
|
-
* @returns true if WebGPU is available, false otherwise
|
|
174
|
-
*/
|
|
175
|
-
function isWebGPUAvailable() {
|
|
176
|
-
return detectWebGPU().available;
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Assert that WebGPU is available, throwing an error if not.
|
|
180
|
-
*
|
|
181
|
-
* @throws Error if WebGPU is not available
|
|
182
|
-
*/
|
|
183
|
-
function assertWebGPUAvailable() {
|
|
184
|
-
const result = detectWebGPU();
|
|
185
|
-
if (!result.available) throw new Error(`WebGPU required but not available: ${result.reason ?? "unknown reason"}`);
|
|
186
|
-
}
|
|
187
|
-
//#endregion
|
|
188
|
-
//#region src/gpu/context.ts
|
|
189
|
-
/**
|
|
190
|
-
* GPU context management for WebGPU compute operations.
|
|
191
|
-
*
|
|
192
|
-
* Provides device acquisition, buffer pooling, and shader compilation
|
|
193
|
-
* with caching for efficient GPU resource management.
|
|
194
|
-
*/
|
|
195
|
-
/**
|
|
196
|
-
* Type guard to check if an object has a WebGPU-compatible requestAdapter method.
|
|
197
|
-
*/
|
|
198
|
-
function hasRequestAdapter(obj) {
|
|
199
|
-
if (typeof obj !== "object" || obj === null) return false;
|
|
200
|
-
if (!("requestAdapter" in obj)) return false;
|
|
201
|
-
const descriptor = Object.getOwnPropertyDescriptor(obj, "requestAdapter");
|
|
202
|
-
return descriptor !== void 0 && typeof descriptor.value === "function";
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Manages GPU device, buffers, and compiled shaders.
|
|
206
|
-
*
|
|
207
|
-
* Use the singleton pattern via getGPUContext() for most use cases,
|
|
208
|
-
* or create separate contexts for isolated GPU resource pools.
|
|
209
|
-
*/
|
|
210
|
-
var GPUContext = class {
|
|
211
|
-
device = null;
|
|
212
|
-
shaderCache = /* @__PURE__ */ new Map();
|
|
213
|
-
bufferPool = [];
|
|
214
|
-
destroyedBuffers = /* @__PURE__ */ new WeakSet();
|
|
215
|
-
/**
|
|
216
|
-
* Check if this context has an acquired GPU device.
|
|
217
|
-
*/
|
|
218
|
-
get isReady() {
|
|
219
|
-
return this.device !== null;
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Get the GPU device, throwing if not acquired.
|
|
223
|
-
*/
|
|
224
|
-
getDevice() {
|
|
225
|
-
if (this.device === null) throw new Error("GPUContext not initialised. Call acquireDevice() first.");
|
|
226
|
-
return this.device;
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Acquire a GPU device from the adapter.
|
|
230
|
-
*
|
|
231
|
-
* @param options - Context creation options
|
|
232
|
-
* @returns true if device was acquired successfully
|
|
233
|
-
* @throws Error if WebGPU is unavailable or device request fails
|
|
234
|
-
*/
|
|
235
|
-
async acquireDevice(options = {}) {
|
|
236
|
-
const detection = detectWebGPU();
|
|
237
|
-
if (!detection.available) throw new Error(`WebGPU unavailable: ${detection.reason ?? "unknown reason"}`);
|
|
238
|
-
let adapter = null;
|
|
239
|
-
const adapterOpts = options.powerPreference !== void 0 ? { powerPreference: options.powerPreference } : {};
|
|
240
|
-
if (typeof navigator !== "undefined" && "gpu" in navigator) adapter = await navigator.gpu.requestAdapter(adapterOpts);
|
|
241
|
-
if (adapter === null && typeof globalThis !== "undefined" && "GPU" in globalThis) {
|
|
242
|
-
const gpuDescriptor = Object.getOwnPropertyDescriptor(globalThis, "gpu");
|
|
243
|
-
if (gpuDescriptor !== void 0 && hasRequestAdapter(gpuDescriptor.value)) adapter = await gpuDescriptor.value.requestAdapter(adapterOpts);
|
|
244
|
-
}
|
|
245
|
-
if (adapter === null) throw new Error("No GPU adapter found");
|
|
246
|
-
this.device = await adapter.requestDevice();
|
|
247
|
-
this.device.lost.then((info) => {
|
|
248
|
-
console.error(`GPU device lost: ${info.message}`);
|
|
249
|
-
this.device = null;
|
|
250
|
-
this.clearCache();
|
|
251
|
-
});
|
|
252
|
-
return true;
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* Compile a WGSL shader, using cache if available.
|
|
256
|
-
*
|
|
257
|
-
* @param code - WGSL shader code
|
|
258
|
-
* @param key - Optional cache key (defaults to code hash)
|
|
259
|
-
* @returns Compiled shader module
|
|
260
|
-
*/
|
|
261
|
-
compileShader(code, key) {
|
|
262
|
-
const cacheKey = key ?? this.hashCode(code);
|
|
263
|
-
const cached = this.shaderCache.get(cacheKey);
|
|
264
|
-
if (cached?.code === code) return cached.module;
|
|
265
|
-
const module = this.getDevice().createShaderModule({ code });
|
|
266
|
-
this.shaderCache.set(cacheKey, {
|
|
267
|
-
module,
|
|
268
|
-
code
|
|
269
|
-
});
|
|
270
|
-
return module;
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* Create a GPU buffer, optionally reusing from pool.
|
|
274
|
-
*
|
|
275
|
-
* @param size - Buffer size in bytes
|
|
276
|
-
* @param usage - Buffer usage flags
|
|
277
|
-
* @returns GPU buffer
|
|
278
|
-
*/
|
|
279
|
-
createBuffer(size, usage) {
|
|
280
|
-
for (let i = 0; i < this.bufferPool.length; i++) {
|
|
281
|
-
const buffer = this.bufferPool[i];
|
|
282
|
-
if (buffer !== void 0 && !this.destroyedBuffers.has(buffer) && buffer.size >= size && (buffer.usage & usage) === usage) {
|
|
283
|
-
this.bufferPool.splice(i, 1);
|
|
284
|
-
return buffer;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
return this.getDevice().createBuffer({
|
|
288
|
-
size,
|
|
289
|
-
usage
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Return a buffer to the pool for reuse.
|
|
294
|
-
*
|
|
295
|
-
* @param buffer - Buffer to recycle
|
|
296
|
-
*/
|
|
297
|
-
recycleBuffer(buffer) {
|
|
298
|
-
if (!this.destroyedBuffers.has(buffer)) this.bufferPool.push(buffer);
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* Mark a buffer as destroyed (call before GPUBuffer.destroy()).
|
|
302
|
-
*
|
|
303
|
-
* @param buffer - Buffer to mark as destroyed
|
|
304
|
-
*/
|
|
305
|
-
markDestroyed(buffer) {
|
|
306
|
-
this.destroyedBuffers.add(buffer);
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* Create a compute pipeline from shader code.
|
|
310
|
-
*
|
|
311
|
-
* @param code - WGSL compute shader code
|
|
312
|
-
* @param entryPoint - Entry point function name
|
|
313
|
-
* @returns Compute pipeline
|
|
314
|
-
*/
|
|
315
|
-
createComputePipeline(code, entryPoint = "main") {
|
|
316
|
-
const device = this.getDevice();
|
|
317
|
-
const module = this.compileShader(code);
|
|
318
|
-
return device.createComputePipeline({
|
|
319
|
-
layout: "auto",
|
|
320
|
-
compute: {
|
|
321
|
-
module,
|
|
322
|
-
entryPoint
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
* Create a compute pipeline asynchronously (preferred for performance).
|
|
328
|
-
*
|
|
329
|
-
* @param code - WGSL compute shader code
|
|
330
|
-
* @param entryPoint - Entry point function name
|
|
331
|
-
* @returns Promise resolving to compute pipeline
|
|
332
|
-
*/
|
|
333
|
-
async createComputePipelineAsync(code, entryPoint = "main") {
|
|
334
|
-
const device = this.getDevice();
|
|
335
|
-
const module = this.compileShader(code);
|
|
336
|
-
return device.createComputePipelineAsync({
|
|
337
|
-
layout: "auto",
|
|
338
|
-
compute: {
|
|
339
|
-
module,
|
|
340
|
-
entryPoint
|
|
341
|
-
}
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* Clear all cached resources.
|
|
346
|
-
*/
|
|
347
|
-
clearCache() {
|
|
348
|
-
this.shaderCache.clear();
|
|
349
|
-
for (const buffer of this.bufferPool) buffer.destroy();
|
|
350
|
-
this.bufferPool.length = 0;
|
|
351
|
-
}
|
|
352
|
-
/**
|
|
353
|
-
* Destroy the context and release all resources.
|
|
354
|
-
*/
|
|
355
|
-
destroy() {
|
|
356
|
-
this.clearCache();
|
|
357
|
-
if (this.device !== null) {
|
|
358
|
-
this.device.destroy();
|
|
359
|
-
this.device = null;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* Simple string hash for cache keys.
|
|
364
|
-
*/
|
|
365
|
-
hashCode(str) {
|
|
366
|
-
let hash = 0;
|
|
367
|
-
for (let i = 0; i < str.length; i++) {
|
|
368
|
-
const char = str.charCodeAt(i);
|
|
369
|
-
hash = (hash << 5) - hash + char | 0;
|
|
370
|
-
}
|
|
371
|
-
return hash.toString(16);
|
|
372
|
-
}
|
|
373
|
-
};
|
|
374
|
-
var defaultContext = null;
|
|
375
|
-
/**
|
|
376
|
-
* Get or create the default GPU context.
|
|
377
|
-
*
|
|
378
|
-
* This is a lazy singleton - the device is not acquired until
|
|
379
|
-
* acquireDevice() is called.
|
|
380
|
-
*
|
|
381
|
-
* @param options - Context creation options
|
|
382
|
-
* @returns GPU context instance
|
|
383
|
-
*/
|
|
384
|
-
function getGPUContext(options) {
|
|
385
|
-
if (defaultContext === null || (options?.forceNew ?? false)) defaultContext = new GPUContext();
|
|
386
|
-
return defaultContext;
|
|
387
|
-
}
|
|
388
|
-
/**
|
|
389
|
-
* Create a new isolated GPU context.
|
|
390
|
-
*
|
|
391
|
-
* Use this when you need separate resource pools or device management.
|
|
392
|
-
*
|
|
393
|
-
* @returns New GPU context instance
|
|
394
|
-
*/
|
|
395
|
-
function createGPUContext() {
|
|
396
|
-
return new GPUContext();
|
|
397
|
-
}
|
|
398
|
-
//#endregion
|
|
399
|
-
exports.GPUContext = GPUContext;
|
|
400
|
-
exports.GPUNotAvailableError = GPUNotAvailableError;
|
|
401
|
-
exports.assertWebGPUAvailable = assertWebGPUAvailable;
|
|
402
|
-
exports.createGPUContext = createGPUContext;
|
|
403
|
-
exports.createResultBuffer = createResultBuffer;
|
|
404
|
-
exports.csrToGPUBuffers = csrToGPUBuffers;
|
|
405
|
-
exports.detectWebGPU = detectWebGPU;
|
|
406
|
-
exports.getGPUContext = getGPUContext;
|
|
407
|
-
exports.graphToCSR = graphToCSR;
|
|
408
|
-
exports.isWebGPUAvailable = isWebGPUAvailable;
|
|
409
|
-
exports.readBufferToCPU = readBufferToCPU;
|
|
410
|
-
|
|
411
|
-
//# sourceMappingURL=index.cjs.map
|
|
2
|
+
const require_gpu = require("../gpu-Y6owRVMi.cjs");
|
|
3
|
+
exports.GPUNotAvailableError = require_gpu.GPUNotAvailableError;
|
|
4
|
+
exports.assertWebGPUAvailable = require_gpu.assertWebGPUAvailable;
|
|
5
|
+
exports.csrToTypedBuffers = require_gpu.csrToTypedBuffers;
|
|
6
|
+
exports.detectWebGPU = require_gpu.detectWebGPU;
|
|
7
|
+
exports.gpuBfsLevels = require_gpu.gpuBfsLevels;
|
|
8
|
+
exports.gpuDegreeHistogram = require_gpu.gpuDegreeHistogram;
|
|
9
|
+
exports.gpuJaccardBatch = require_gpu.gpuJaccardBatch;
|
|
10
|
+
exports.gpuPageRank = require_gpu.gpuPageRank;
|
|
11
|
+
exports.gpuSpmv = require_gpu.gpuSpmv;
|
|
12
|
+
exports.graphToCSR = require_gpu.graphToCSR;
|
|
13
|
+
exports.initGPU = require_gpu.initGPU;
|
|
14
|
+
exports.initGPUFromDevice = require_gpu.initGPUFromDevice;
|
|
15
|
+
exports.isWebGPUAvailable = require_gpu.isWebGPUAvailable;
|
|
16
|
+
exports.withBackend = require_gpu.withBackend;
|
package/dist/gpu/index.d.ts
CHANGED
package/dist/gpu/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/gpu/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/gpu/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
|