Skip to content

Instantly share code, notes, and snippets.

@michelp
Created January 24, 2024 20:16
Show Gist options
  • Save michelp/580d1b663c14a082e7db6e91ccf0ee0b to your computer and use it in GitHub Desktop.
Save michelp/580d1b663c14a082e7db6e91ccf0ee0b to your computer and use it in GitHub Desktop.
gb.binary.ss.register_new(
"relu",
"""void relu (int64_t *z, int64_t *x, int64_t *y) {
int64_t v;
v = (*x) + (*y);
v = v < 32 ? v : 32;
(*z) = v < 0 ? 0 : v;
}; """,
gb.dtypes.INT64,
gb.dtypes.INT64,
gb.dtypes.INT64)
gb.semiring.register_new(
"plus_relu",
gb.monoid.plus,
gb.binary.ss.relu)
def dnn(W, B, Y):
for w, b in zip(W, B):
Y << Y @ w
Y << gb.semiring.plus_relu(Y @ b)
Y << Y.select(">", 0)
return Y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment