enable no GPU Fallback

This commit is contained in:
biglyderv 2025-02-02 21:48:24 -05:00
parent a0baee54d5
commit 1079f4a034

38
rank.js
View file

@ -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 {
@ -75,7 +75,7 @@ function rankCalc(result, iterations = 10, main = [], domain_mode = false) {
let h = new URL(unn); let h = new URL(unn);
if (!(h.pathname == '/' || h.pathname == '')) fail *= 0.5; if (!(h.pathname == '/' || h.pathname == '')) fail *= 0.5;
if (!(h.search == '')) fail *= 0.4; if (!(h.search == '')) fail *= 0.4;
if (main.indexOf(unn) != -1) fail = 10; if (main.indexOf(unn) != -1) fail = 10;
} catch (err) { } catch (err) {
} }
@ -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;