Skip to content

Commit

Permalink
Add pl.when function
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 543791101
  • Loading branch information
sharadmv authored and The jax_triton Authors committed Jun 27, 2023
1 parent c3721db commit b6897bc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions jax_triton/pallas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from jax_triton.pallas.primitives import program_id
from jax_triton.pallas.primitives import store
from jax_triton.pallas.primitives import swap
from jax_triton.pallas.utils import when
from jax_triton.utils import cdiv

from jax_triton.pallas import registration
Expand Down
26 changes: 26 additions & 0 deletions jax_triton/pallas/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2023 The jax_triton Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Pallas utility functions."""
from jax import lax


def when(condition):
def _wrapped(f):
if isinstance(condition, bool):
if condition:
f()
else:
lax.cond(condition, f, lambda: None)
return _wrapped

0 comments on commit b6897bc

Please sign in to comment.