|
15 | 15 | from typing import Sequence, Tuple, Union |
16 | 16 |
|
17 | 17 | from nvtripy import export |
18 | | -from nvtripy.common.shape_bounds import ShapeBounds |
| 18 | +from nvtripy.common.shape_bounds import ShapeBounds, ValueBounds |
19 | 19 | from nvtripy.frontend.dimension_size import DimensionSize |
20 | 20 | from nvtripy.types import IntLike |
21 | 21 | from nvtripy.utils import json as json_utils |
@@ -57,7 +57,6 @@ def __init__( |
57 | 57 | """ |
58 | 58 | is_int_like = lambda arg: any(isinstance(arg, typ) for typ in {int, DimensionSize}) |
59 | 59 |
|
60 | | - # TODO (#252): Allow `shape` to be a shape tensor |
61 | 60 | min_shape = [] |
62 | 61 | opt_shape = [] |
63 | 62 | max_shape = [] |
@@ -100,3 +99,44 @@ def decode_input_info(input_info_dict): |
100 | 99 | input_info = InputInfo(shape=[], dtype=input_info_dict["dtype"]) |
101 | 100 | input_info.shape_bounds = input_info_dict["shape_bounds"] |
102 | 101 | return input_info |
| 102 | + |
| 103 | +@export.public_api(document_under="compiling_code") |
| 104 | +class DimensionInputInfo: |
| 105 | + """ |
| 106 | + Captures information about a dimension size input to a compiled function. |
| 107 | + """ |
| 108 | + |
| 109 | + def __init__(self, value_bounds: Tuple[IntLike, IntLike, IntLike]) -> None: |
| 110 | + """ |
| 111 | + Args: |
| 112 | + value_bounds: The value bound of the dimension size input, consisting of minimum, optimum, and maximum values. |
| 113 | +
|
| 114 | + .. code-block:: python |
| 115 | + :linenos: |
| 116 | + :caption: Dynamic Dimensions |
| 117 | +
|
| 118 | + # The dimension size will support values in the range [1, 3], |
| 119 | + # optimizing for a size of 2. |
| 120 | + dim_inp = tp.DimensionInputInfo((1, 2, 3)) |
| 121 | + assert dim_inp.min == 1 |
| 122 | + assert dim_inp.opt == 2 |
| 123 | + assert dim_inp.max == 3 |
| 124 | + """ |
| 125 | + self.value_bounds = ValueBounds(min=tuple(value_bounds[0]), opt=tuple(value_bounds[1]), max=tuple(value_bounds[2])) |
| 126 | + |
| 127 | + def __str__(self) -> str: |
| 128 | + return ( |
| 129 | + f"DimensionInputInfo(min={self.value_bounds.min}, opt={self.value_bounds.opt}, max={self.value_bounds.max})" |
| 130 | + ) |
| 131 | + |
| 132 | +@json_utils.Encoder.register(DimensionInputInfo) |
| 133 | +def encode_input_info(dim_input_info): |
| 134 | + return { |
| 135 | + "value_bounds": dim_input_info.value_bounds, |
| 136 | + } |
| 137 | + |
| 138 | + |
| 139 | +@json_utils.Decoder.register(DimensionInputInfo) |
| 140 | +def decode_input_info(dim_input_info_dict): |
| 141 | + dim_input_info_dict.value_bounds = dim_input_info_dict["value_bounds"] |
| 142 | + return dim_input_info_dict |
0 commit comments