import { a as k, a6 as N } from "../../index-DSGwv2Yx.js";
import { createReduceInfo as w, reduce as S } from "./utils/reductions.js";
import { isPackedTensor as d } from "../../utilities/packed.js";
import { p as f } from "../../pack16-WlOSOuZA.js";
import b from "./normRMS16_program.js";
import z from "./normRMS32_program.js";
import G from "./utils/deviceInfo.js";
function u(t) {
  const { x: e, gamma: o } = t.inputs, m = t.backend, c = G(m), p = d(e), i = o ? d(o) : !1, n = p || i, r = !n || n ? e : f(e), a = !n || !o ? o : f(o), h = a ? [r, a] : [r], s = w(h, -1), l = n ? new b(c, s, !!o) : new z(c, s, !!o);
  if (a && N(a.shape, [r.shape[r.shape.length - 1]], "Error in RMSNorm: "), e.shape.length !== 3)
    throw new Error(`rmsNormGPU: input rank ${e.shape.length} not supported, only rank 3 is supported`);
  if (s.inSize !== r.shape[r.shape.length - 1])
    throw new Error(
      `rmsNormGPU: reduction size ${s.inSize} does not match expected size ${r.shape[r.shape.length - 1]}`
    );
  if (s.batchSize !== e.shape[0] * e.shape[1])
    throw new Error(
      `rmsNormGPU: batch size ${s.batchSize} does not match expected size ${e.shape[0] * e.shape[1]}`
    );
  const g = S(l, h, m);
  return n && !p && r.dispose(), n && !i && a && a.dispose(), g;
}
const P = {
  kernelName: "RMSNorm",
  backendName: "webgpu",
  kernelFunc: u
};
k(P);
const M = {
  kernelName: "RMSNormNoGamma",
  backendName: "webgpu",
  kernelFunc: u
};
k(M);
