(
shape,
dtype=None,
name="buffer",
data=None,
strides=None,
elem_offset=None,
scope="",
data_alignment=-1,
offset_factor=0,
buffer_type="",
axis_separators=None,
span=None,
layout="default",
)
| 511 | |
| 512 | |
| 513 | def decl_buffer( |
| 514 | shape, |
| 515 | dtype=None, |
| 516 | name="buffer", |
| 517 | data=None, |
| 518 | strides=None, |
| 519 | elem_offset=None, |
| 520 | scope="", |
| 521 | data_alignment=-1, |
| 522 | offset_factor=0, |
| 523 | buffer_type="", |
| 524 | axis_separators=None, |
| 525 | span=None, |
| 526 | layout="default", |
| 527 | ): |
| 528 | # pylint: disable=import-outside-toplevel |
| 529 | from .expr import Var |
| 530 | from .layout import S, TileLayout |
| 531 | |
| 532 | shape = (shape,) if isinstance(shape, PrimExpr | Integral) else shape |
| 533 | dtype = "float32" if dtype is None else dtype |
| 534 | strides = () if strides is None else strides |
| 535 | |
| 536 | if axis_separators is None: |
| 537 | axis_separators = [] |
| 538 | |
| 539 | if layout == "default": |
| 540 | layout = TileLayout(S[tuple(shape)]) if shape else None |
| 541 | |
| 542 | if offset_factor != 0 and elem_offset is None: |
| 543 | shape_dtype = shape[0].dtype if shape and hasattr(shape[0], "dtype") else "int32" |
| 544 | elem_offset = Var(f"{name}_elem_offset", shape_dtype) |
| 545 | if data is None: |
| 546 | # Bool is represented as uint1 in the IR, but stored as int8 |
| 547 | storage_type = PrimType(dtype) |
| 548 | storage_type = PrimType("int8") if storage_type.dtype == "bool" else storage_type |
| 549 | data = Var(name, PointerType(storage_type, scope), span) |
| 550 | return _ffi_api.Buffer( # type: ignore |
| 551 | data, |
| 552 | dtype, |
| 553 | shape, |
| 554 | strides, |
| 555 | elem_offset, |
| 556 | name, |
| 557 | data_alignment, |
| 558 | offset_factor, |
| 559 | buffer_type, |
| 560 | axis_separators, |
| 561 | span, |
| 562 | layout, |
| 563 | ) |
| 564 | |
| 565 | |
| 566 | @tvm_ffi.register_object("tirx.DataProducer") |
searching dependent graphs…