import { a as q } from "../../index-DSGwv2Yx.js";
import { r as o } from "../../reshape-BIN71H3p.js";
import { s as x } from "../../split-BN9LkEgS.js";
function v(p) {
  const { x: c, kernel: K } = p.inputs, { heads: n, packed: C } = p.attrs;
  if (C)
    throw new Error("QKV CPU implementation does not support packed tensors.");
  const [s, e, t] = c.shape, a = o(c, [s * e, t]), i = a.dot(K);
  a.dispose();
  const d = o(i, [s, e, 3 * t]);
  i.dispose();
  const [k, l, m] = x(d, 3, -1);
  d.dispose();
  const r = t / n, f = o(k, [s, e, n, r]);
  k.dispose();
  const w = f.transpose([0, 2, 1, 3]);
  f.dispose();
  const h = o(l, [s, e, n, r]);
  l.dispose();
  const N = h.transpose([0, 2, 1, 3]);
  h.dispose();
  const u = o(m, [s, e, n, r]);
  m.dispose();
  const T = u.transpose([0, 2, 1, 3]);
  return u.dispose(), [w, N, T];
}
const F = {
  kernelName: "QKV",
  backendName: "cpu",
  kernelFunc: v
};
q(F);
const Q = {
  kernelName: "QKV",
  backendName: "tensorflow",
  kernelFunc: v
};
q(Q);
export {
  v as qkvCPU
};
