enable no GPU Fallback
This commit is contained in:
parent
a0baee54d5
commit
1079f4a034
1 changed files with 28 additions and 10 deletions
36
rank.js
36
rank.js
|
@ -1,7 +1,7 @@
|
||||||
import { GPU, input, Input } from "gpu.js";
|
import { GPU, input, Input } from "gpu.js";
|
||||||
|
|
||||||
// derived from https://git.dervland.net/biglyderv/new-bigly-chat/src/branch/master/docs/stats.php
|
// derived from https://git.dervland.net/biglyderv/new-bigly-chat/src/branch/master/docs/stats.php
|
||||||
function rankCalc(result, iterations = 10, main = [], domain_mode = false) {
|
function rankCalc(result, iterations = 10, main = [], domainMode = false) {
|
||||||
|
|
||||||
let fng = {};
|
let fng = {};
|
||||||
let fnc = {};
|
let fnc = {};
|
||||||
|
@ -19,7 +19,7 @@ function rankCalc(result, iterations = 10, main = [], domain_mode = false) {
|
||||||
let keys = Object.keys(result);
|
let keys = Object.keys(result);
|
||||||
for (let unn in result) {
|
for (let unn in result) {
|
||||||
let v = true;
|
let v = true;
|
||||||
if (domain_mode) {
|
if (domainMode) {
|
||||||
v = false;
|
v = false;
|
||||||
try {
|
try {
|
||||||
let test = new URL(unn);
|
let test = new URL(unn);
|
||||||
|
@ -36,7 +36,7 @@ function rankCalc(result, iterations = 10, main = [], domain_mode = false) {
|
||||||
fng[unn] = result[unn].following || [];
|
fng[unn] = result[unn].following || [];
|
||||||
|
|
||||||
let lf = Object.keys(fng[unn]).length;
|
let lf = Object.keys(fng[unn]).length;
|
||||||
if (domain_mode) {
|
if (domainMode) {
|
||||||
let domains = [];
|
let domains = [];
|
||||||
for (let x of fng[unn]) {
|
for (let x of fng[unn]) {
|
||||||
try {
|
try {
|
||||||
|
@ -90,13 +90,31 @@ function rankCalc(result, iterations = 10, main = [], domain_mode = false) {
|
||||||
let mm = (iterations);
|
let mm = (iterations);
|
||||||
|
|
||||||
let gpu = new GPU();
|
let gpu = new GPU();
|
||||||
const multiplyMatrix = gpu.createKernel(function (a, b, c) {
|
let isGpu = process.env.isGpu;
|
||||||
let sum = 0;
|
let multiplyMatrix;
|
||||||
for (let i = 0; i < c; i++) {
|
|
||||||
sum += a[(this.thread.x % c) * c + i] * b[i * c + this.thread.x / c];
|
if (isGpu) {
|
||||||
|
multiplyMatrix = gpu.createKernel(function (a, b, c) {
|
||||||
|
let sum = 0;
|
||||||
|
for (let i = 0; i < c; i++) {
|
||||||
|
sum += a[(this.thread.x % c) * c + i] * b[i * c + this.thread.x / c];
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}).setOutput([keys.length ** 2, 1]);
|
||||||
|
} else {
|
||||||
|
console.warn(`GPU mode not enabled. Using CPU multiplication...`)
|
||||||
|
multiplyMatrix = function (a, b, c) {
|
||||||
|
let outMatrix = new Float32Array(keys.length ** 2);
|
||||||
|
for (let i in outMatrix) {
|
||||||
|
let sum = 0;
|
||||||
|
for (let j = 0; j < c; j++) {
|
||||||
|
sum += a[(i % c) * c + j] * b[j * c + Math.floor(i / c)];
|
||||||
|
}
|
||||||
|
outMatrix[i] = sum;
|
||||||
|
}
|
||||||
|
return [outMatrix];
|
||||||
}
|
}
|
||||||
return sum;
|
}
|
||||||
}).setOutput([keys.length ** 2, 1]);
|
|
||||||
|
|
||||||
for (let i = 0; i < mm; i++) {
|
for (let i = 0; i < mm; i++) {
|
||||||
let prold = pr;
|
let prold = pr;
|
||||||
|
|
Loading…
Reference in a new issue