MCPcopy Create free account
hub / github.com/apache/tvm / decl_buffer

Function decl_buffer

python/tvm/tirx/buffer.py:513–563  ·  view source on GitHub ↗
(
    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",
)

Source from the content-addressed store, hash-verified

511
512
513def 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")

Callers 13

sparse_reshapeFunction · 0.90
test_deduce_non_supportFunction · 0.90
test_copyFunction · 0.90
test_fillFunction · 0.90
test_gemmFunction · 0.90

Calls 5

PrimTypeClass · 0.90
PointerTypeClass · 0.90
TileLayoutClass · 0.85
tupleFunction · 0.85
VarClass · 0.70

Tested by 11

test_deduce_non_supportFunction · 0.72
test_copyFunction · 0.72
test_fillFunction · 0.72
test_gemmFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…