State
State representation and feature extraction for MLIR operations.
This module provides data structures for representing benchmark and operation states, including features like loops, memory accesses, and operation types. It also provides functionality for extracting these features from MLIR AST using the AstDumper tool.
OperationType
Bases: Enum
Enumeration of operation types for MLIR operations.
Attributes:
| Name | Type | Description |
|---|---|---|
Generic |
Generic operation type. |
|
Matmul |
Matrix multiplication operation type. |
|
Conv |
Convolutional operation type. |
|
Pooling |
Pooling operation type. |
|
Add |
Add operation type. |
|
unknown |
Unknown operation type. |
IteratorType
Bases: Enum
Enumeration of iterator types for loop dimensions.
Attributes:
| Name | Type | Description |
|---|---|---|
Parallel |
Parallel iterator type. |
|
Reduction |
Reduction iterator type. |
NestedLoopFeatures(arg, lower_bound, upper_bound, step, iterator_type)
dataclass
Dataclass to store the nested loops features data.
Attributes:
| Name | Type | Description |
|---|---|---|
arg |
str
|
The argument representing the loop iterator. |
lower_bound |
int
|
The lower bound of the loop. |
upper_bound |
int
|
The upper bound of the loop. |
step |
int
|
The loop step. |
iterator_type |
IteratorType
|
The type of the loop iterator. |
copy()
OperationFeatures(operation_name, operation_type, op_count, load_data, store_data, nested_loops, producers, consumers, vectorizable, pre_actions)
dataclass
Dataclass to store the operation features data.
Attributes:
| Name | Type | Description |
|---|---|---|
operation_name |
str
|
The name of the mlir operation. |
operation_type |
OperationType
|
The type of the operation. |
op_count |
dict[str, int]
|
Number of arithmetic operations in the operation. |
load_data |
list[list[str]]
|
List of load accesses where each load is represented by the list of access arguments. |
store_data |
list[list[str]]
|
List of store accesses where each store is represented by the list of access arguments. |
nested_loops |
list[NestedLoopFeatures]
|
List of nested loops where each loop is represented by the NestedLoopFeatures dataclass. |
producers |
list[tuple[str, int]]
|
List of tags of operations that are consumed by the current operation along with their operand indices. |
consumers |
list[tuple[str, int]]
|
List of tags of operations that consume the current operation. |
vectorizable |
bool
|
Flag to indicate if the operation is vectorizable. |
pre_actions |
list[Action]
|
List actions that are already applied the current operatiom. |
copy()
Copy the current OperationFeatures object.
Returns:
| Type | Description |
|---|---|
OperationFeatures
|
The copy. |
Source code in mlir_rl_artifact/state.py
BenchmarkFeatures(bench_name, code, operation_tags, operations, root_exec_time)
dataclass
Dataclass to store the benchmark features data.
Attributes:
| Name | Type | Description |
|---|---|---|
bench_name |
str
|
The name of the benchmark. |
code |
str
|
The MLIR code of the benchmark. |
operation_tags |
list[str]
|
List of operation tags. |
operations |
dict[str, OperationFeatures]
|
List of operations where each operation is represented by the OperationFeatures dataclass. |
root_exec_time |
int
|
Execution time of the benchmark in nanoseconds without any transformation. |
copy()
Copy the current BenchmarkFeatures object.
Returns:
| Type | Description |
|---|---|
BenchmarkFeatures
|
The copy. |
Source code in mlir_rl_artifact/state.py
OperationState(bench_idx, bench_name, operation_tag, original_operation_features, operation_features, producer_tag, producer_operand_idx, producer_features, transformation_history, terminal)
dataclass
Dataclass to store the operation state data.
Attributes:
| Name | Type | Description |
|---|---|---|
bench_idx |
int
|
The index of the benchmark. |
bench_name |
str
|
The name of the benchmark. |
operation_tag |
str
|
The tag of the operation. |
original_operation_features |
OperationFeatures
|
The features of the operation that will be kept always unchanged. |
operation_features |
OperationFeatures
|
The features of the operation. |
producer_tag |
str | None
|
The tag of the selected producer. |
producer_operand_idx |
int | None
|
The index of the producer's operand. |
producer_features |
OperationFeatures | None
|
The features of the selected producer. |
transformation_history |
list[list[Action]]
|
List of transformations with their parameters applied to the operation. |
terminal |
bool
|
Flag to indicate if the state is terminal. |
current_history
property
step_count
property
Get the number of steps in the current transformation sequence.
Returns:
| Type | Description |
|---|---|
int
|
The number of steps. |
latest_action
property
Get the latest action in the current transformation sequence.
Returns:
| Type | Description |
|---|---|
Action | None
|
The latest action. |
has_incomplete_action
property
Check if the latest action is incomplete.
Returns:
| Type | Description |
|---|---|
bool
|
True if the latest action is incomplete, False otherwise. |
record_action(action)
Record an action in the current transformation sequence.
Note
If the latest action is incomplete, it will be replaced by the new action,
and all the past incomplete actions will be kept in sub_actions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
Action
|
The action to record. |
required |
Source code in mlir_rl_artifact/state.py
copy()
Copy the current OperationState object.
Returns:
| Type | Description |
|---|---|
OperationState
|
The copy. |
Source code in mlir_rl_artifact/state.py
extract_bench_features_from_code(bench_name, code, root_execution_time)
Extract benchmark features from the given code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bench_name
|
str
|
the benchmark name |
required |
code
|
str
|
the code to extract features from |
required |
root_execution_time
|
int
|
the root execution time |
required |
Returns:
| Type | Description |
|---|---|
BenchmarkFeatures
|
the extracted benchmark features |
Source code in mlir_rl_artifact/state.py
extract_bench_features_from_file(bench_name, file_path, root_execution_time)
Extract benchmark features from the code in the file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bench_name
|
str
|
the benchmark name |
required |
file_path
|
str
|
the file path |
required |
root_execution_time
|
int
|
the root execution time |
required |
Returns:
| Type | Description |
|---|---|
BenchmarkFeatures
|
the extracted benchmark features |
Source code in mlir_rl_artifact/state.py
__extract_bench_features_from_ast_result(bench_name, raw_ast_info, root_execution_time)
Extracts benchmark features from the code's AST result and execution time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bench_name
|
str
|
the benchmark name |
required |
raw_ast_info
|
str
|
the raw AST information |
required |
root_execution_time
|
int
|
the root execution time |
required |
Returns:
| Type | Description |
|---|---|
BenchmarkFeatures
|
extracted benchmark features |
Source code in mlir_rl_artifact/state.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 | |
__get_operation_type(operation_name)
Get the operation type from the operation name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operation_name
|
str
|
The operation name. |
required |
Returns:
| Type | Description |
|---|---|
OperationType
|
The operation type or None if not found. |