Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ported a few changes to FragmentArray by cperivol@ #23568

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion jax/experimental/mosaic/gpu/fragmented_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ def _pointwise(self, op, *other):
other_arrs = []
for o in other:
if not isinstance(o, FragmentedArray):
if not isinstance(o, ir.Value):
if isinstance(o, (float, int)):
o = utils.c(o, self.mlir_dtype)
elif not isinstance(o, ir.Value):
raise NotImplementedError(o)

o = FragmentedArray.splat(o, shape=self.shape, layout=self.layout)
Expand All @@ -267,6 +269,14 @@ def _pointwise(self, op, *other):
new_regs[idx] = op(reg, *(o.registers[idx] for o in other_arrs))
return FragmentedArray(_registers=new_regs, _layout=self.layout)

def __neg__(self):
if ir.FloatType.isinstance(self.mlir_dtype):
return self._pointwise(arith.negf)
elif ir.IntegerType.isinstance(self.mlir_dtype):
return self._pointwise(arith.negsi)
else:
raise NotImplementedError(self.mlir_dtype)

def __add__(self, other):
if ir.FloatType.isinstance(self.mlir_dtype):
return self._pointwise(arith.addf, other)
Expand Down
2 changes: 2 additions & 0 deletions tests/mosaic/gpu_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,8 @@ def kernel(ctx, dst, _):
(lambda x: mgpu.FragmentedArray.cos(x, approx=True), np.cos, True),
(lambda x: mgpu.FragmentedArray.rsqrt(x), jax.lax.rsqrt, False),
(lambda x: mgpu.FragmentedArray.rsqrt(x, approx=True), jax.lax.rsqrt, True),
(lambda x: -x, jax.lax.neg, False),
(lambda x: x + 42.0, lambda x: x + 42.0, False),
),
m=(64, 128),
n=(8, 16, 32, 64, 80, 128, 256),
Expand Down
Loading