import { v as u } from "./index-DSGwv2Yx.js";
const c = (r) => {
  let t = 1;
  for (let n = 0; n < r.length; n++)
    t *= r[n];
  return t;
};
function m(r, t, n = [1, 1, 1], a = [1, 1, 1]) {
  const [o, i, f] = [
    Math.ceil(c(r.x.map((e) => t[e])) / (n[0] * a[0])),
    r.y ? Math.ceil(c(r.y.map((e) => t[e])) / (n[1] * a[1])) : 1,
    r.z ? Math.ceil(c(r.z.map((e) => t[e])) / (n[2] * a[2])) : 1
  ];
  return [o, i, f];
}
function d(r, t, n, a = !1) {
  const o = [8, 8, 1], i = [4, 4, 1];
  return a || (r <= 8 && (i[1] = 1), t <= 16 && n <= 16 && (o[0] = 4)), { workgroupSize: o, elementsPerThread: i };
}
function p(r, t, n = !1) {
  if (n)
    return [8, 8, 1];
  const a = c(r.x.map((i) => t[i])), o = c(r.y.map((i) => t[i]));
  return a <= 4 ? [4, 16, 1] : o <= 4 ? [16, 4, 1] : [16, 16, 1];
}
function M(r, t, n = !1) {
  if (n)
    return [4, 4, 1];
  const a = c(r.x.map((i) => t[i])), o = c(r.y.map((i) => t[i]));
  return a <= 4 ? [1, 2, 1] : o <= 4 ? [2, 1, 1] : [2, 2, 1];
}
function h(r) {
  return { x: r.map((t, n) => n) };
}
function x(r) {
  if (r === "float32" || r === "int32" || r === "bool" || r === "string" || r === "packedF16")
    return 4;
  if (r === "complex64")
    return 8;
  throw new Error(`Unknown dtype ${r}`);
}
function g() {
  return !!(typeof globalThis < "u" && globalThis.navigator && globalThis.navigator.gpu);
}
function b(r, t) {
  Array.isArray(r) || (r = [r]), r.forEach((n) => {
    n != null && u(n.dtype !== "complex64", () => `${t} does not support complex64 tensors in the WebGPU backend.`);
  });
}
var s;
(function(r) {
  r[r.MatMulReduceProgram = 0] = "MatMulReduceProgram", r[r.MatMulSplitKProgram = 1] = "MatMulSplitKProgram", r[r.MatMulSmallOutputSizeProgram = 2] = "MatMulSmallOutputSizeProgram", r[r.MatMulPackedProgram = 3] = "MatMulPackedProgram", r[r.MatMulMax = 4] = "MatMulMax";
})(s || (s = {}));
export {
  x as G,
  s as M,
  d as a,
  b,
  m as c,
  p as d,
  M as e,
  h as f,
  g as i
};
