import { a } from "../../index-DSGwv2Yx.js";
import { u as s, C as i } from "../../kernel_funcs_utils-DGqzNlHT.js";
const t = 0.7978845608028654, r = 0.044715, c = i + `
    float x3 = x * x * x;
    float inner = x + ${r} * x3;
    inner = ${t} * inner;
    inner = abs(inner) > 15.0 ? sign(inner) : tanh(inner);
    inner = 0.5 * (1.0 + inner);
    inner = x * inner;
    return inner;
`, d = s({ opSnippet: c }), x = {
  kernelName: "Gelu",
  backendName: "webgl",
  kernelFunc: d
};
a(x);
class f {
  // Inputs: dy, x
  variableNames = ["dy", "x"];
  outputShape;
  userCode;
  constructor(n) {
    this.outputShape = n, this.userCode = `
            void main() {
                float dy = getDyAtOutCoords();
                float x  = getXAtOutCoords();
                float x2 = x * x;
                float x3 = x2 * x;
                float u  = ${t} * (x + ${r} * x3);
                float t = abs(u) > 15.0 ? sign(u) : tanh(u);
                float sech2 = 1.0 - t * t;
                float du_dx = ${t} * (1.0 + 3.0 * ${r} * x2);
                float dgelu = 0.5 * (1.0 + t) + 0.5 * x * sech2 * du_dx;
                setOutput(dy * dgelu);
            }`;
  }
}
function g(e) {
  const { dy: n, x: o } = e.inputs, u = e.backend, l = new f(o.shape);
  return u.runWebGLProgram(l, [n, o], "float32");
}
const p = {
  kernelName: "GeluGrad",
  backendName: "webgl",
  kernelFunc: g
};
a(p);
export {
  d as gelu
};
