// bend-blas, the JS twins: plain loops, correct and slow, for the // interpreter and the tests. An Array is a JS array of numbers. // A failure is io_fail(code): the runtime's message for a code is not // this library's, so the code is the contract on this lane. function bend_fresh(n) { let slots = 1; while (slots < n) slots *= 2; return new Array(slots).fill(0); } function bend_copy(src, n) { const c = bend_fresh(n); for (let i = 0; i < n; i++) c[i] = src[i]; return c; } function bend_short(a, n) { return n > 0x7fffffff || a.length < n; } function bend_gemm(ta, tb, m, n, k, alpha, a, b, beta, c) { const out = bend_copy(c, m * n); for (let i = 0; i < m; i++) for (let j = 0; j < n; j++) { let acc = 0; for (let l = 0; l < k; l++) acc += (ta ? a[l * m + i] : a[i * k + l]) * (tb ? b[j * k + l] : b[l * n + j]); out[i * n + j] = alpha * acc + beta * out[i * n + j]; } return out; } // the device buffer table of the JS twins: host arrays if (typeof globalThis.bend_devs === "undefined") globalThis.bend_devs = []; function cublas_upload(n, a) { if (bend_short(a, n)) return io_fail(2); globalThis.bend_devs.push(bend_copy(a, n)); return io_done(globalThis.bend_devs.length - 1); } io_eff(CID(Cublas.upload), cublas_upload);