| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | # SPDX-FileCopyrightText: Songlin Yang, Yu Zhang |
| 4 | # |
| 5 | # This file contains code copied from the flash-linear-attention project. |
| 6 | # The original source code was licensed under the MIT license and included |
| 7 | # the following copyright notice: |
| 8 | # Copyright (c) 2023-2025, Songlin Yang, Yu Zhang |
| 9 | |
| 10 | import os |
| 11 | |
| 12 | from vllm.triton_utils import tl, tldevice, triton |
| 13 | |
| 14 | from .utils import is_gather_supported |
| 15 | |
| 16 | if os.environ.get("FLA_USE_FAST_OPS", "0") == "1": |
| 17 | exp = tldevice.fast_expf |
| 18 | exp2 = tl.exp2 |
| 19 | log = tldevice.fast_logf |
| 20 | log2 = tldevice.fast_log2f |
| 21 | else: |
| 22 | exp = tl.exp |
| 23 | exp2 = tl.exp2 |
| 24 | log = tl.log |
| 25 | log2 = tl.log2 |
| 26 | |
| 27 | |
| 28 | if not is_gather_supported: |
| 29 | |
| 30 | @triton.jit |
| 31 | def gather(src, index, axis, _builder=None): |
| 32 | """ |
| 33 | Gather operation that works when tl.gather is not supported. |
| 34 | This is a fallback implementation that returns None. |
| 35 | Just to make triton compiler happy. |
| 36 | """ |
| 37 | return None |
| 38 | else: |
| 39 | gather = tl.gather |
| 40 | |
| 41 | if hasattr(triton.language, "_experimental_make_tensor_descriptor"): |
| 42 | # For Triton 3.3.x |
| 43 | make_tensor_descriptor = triton.language._experimental_make_tensor_descriptor |
| 44 | elif hasattr(triton.language, "make_tensor_descriptor"): |
| 45 | # For Triton 3.4.x and later |
| 46 | make_tensor_descriptor = triton.language.make_tensor_descriptor |
| 47 | else: |
| 48 | """ |
| 49 | Fallback implementation when TMA is not supported. |
| 50 | Returns None to indicate TMA descriptors are unavailable. |
| 51 | Just make triton compiler happy. |
| 52 | """ |
| 53 | |
| 54 | @triton.jit |
| 55 | def make_tensor_descriptor( |
| 56 | base, |
| 57 | shape, |
| 58 | strides, |
| 59 | block_shape, |
| 60 | _builder=None, |
| 61 | ): |
| 62 | return None |