콘텐츠로 이동

타입

타입

Legato eDSL에서 텐서와 scalar에 어노테이션을 붙일 때 쓰는 타입 생성자입니다.

텐서를 특정 compute model의 메모리 공간에 binding할 때는 다음 예처럼 활성 compute model이 제공하는 모델 전용 생성자를 쓰십시오.

1
legato.get_model().tensor_type(legato.types.float("float32"), [16, 32], "shared_dram")

tensor

1
tensor(dtype: Value, shape: Value, memory: Value | None = None, layout: Value | None = None) -> Callable

Create a tensor type.

Creates a Legato tensor type of the given type and shape.

Parameters:

  • dtype (Value): Interpreted type of the tensor.
  • shape (Value): Interpreted shape of the tensor. (List of constexpr Integer, or Index)
  • memory (Value | None): Interpreted memory of the tensor. (Memory type) Default: None.
  • layout (Value | None): Interpreted layout of the tensor. (Layout type) Default: None.

Returns:

  • (Callable): Constexpr value representing the tensor type.

float

1
float(kind: Value) -> Callable

Create a floating-point type.

Creates a Legato floating-point scalar type of the given kind.

Parameters:

  • kind (Value): Interpreted string specifying the float kind. Supported kinds include: "float16" ("half"), "float32" ("float"), "float64" ("double"), "float8", "float4", "bfloat16".

Returns:

  • (Callable): Constexpr value representing the floating-point type.

Example:

1
2
3
@legato.compile(backend=get_backend)
def fn(x: legato.types.tensor(legato.types.float("float32"), [10, 10])):
    return

integer

1
integer(kind: Value) -> Callable

Create an integer type.

Creates a Legato integer scalar type of the given kind.

Parameters:

  • kind (Value): Interpreted string specifying the integer kind. Supported kinds include: "bool", "int4", "int8", "int16", "int32", "int64".

Returns:

  • (Callable): Constexpr value representing the integer type.

Example:

1
2
3
4
@legato.compile(backend=get_backend)
def fn(a: legato.types.integer("int64"), b: legato.types.integer("int64")):
    with legato.get_context().get_device().get_core(0):
        c = a + b

bool

1
bool() -> Callable

Create a bool type.

Returns the Legato boolean scalar type.

Returns:

  • (Callable): Constexpr value representing the boolean type.

Example:

1
t_bool = legato.types.bool()

index

1
index() -> Callable

Create an index type.

Returns the Legato index scalar type, commonly used for loop indices and shapes.

Returns:

  • (Callable): Constexpr value representing the index type.

Example:

1
t_index = legato.types.index()

tuple

1
tuple(types: Value) -> Callable

Create a tuple type.

Creates a Legato tuple type of the given types.

Parameters:

  • types (Value): List of constexpr values representing the types of the tuple.

Returns:

  • (Callable): Constexpr value representing the tuple type.

list

1
list(list_dtype: Value) -> Callable

Create a list type.

Creates a Legato list type of the given type.

Parameters:

  • list_dtype (Value): Constexpr value representing the type of the list.

Returns:

  • (Callable): Constexpr value representing the list type.

constexpr

1
constexpr(input_type: Value) -> Callable

Create a constexpr type.

Marks value assigned with this type will be marked as constexpr.

Parameters:

  • input_type (Value): Constexpr value representing the type of the constexpr.

Returns:

  • (Callable): Constexpr value representing the constexpr type.

Note :

constexpr marker itself is not a part of the type, but kind of metadata attached to a value inside the type, that indicates whether value is constant. In other words, constexpr is property of the value, not the type.

Example :

1
2
3
@legato.compile(backend=get_backend)
def fn(a: legato.types.constexpr(legato.types.integer("int64"))): # Indicates function to expect a to be constexpr.
    result = a + 3 # result is constexpr, since both a and 3 are constexpr.