From 995003dda721e4234121d691bb19bcf71cbfd565 Mon Sep 17 00:00:00 2001 From: Erika Hunhoff Date: Fri, 22 Nov 2024 14:56:55 -0700 Subject: [PATCH] Rename `TensorTile` to `TensorAccessPattern` (#1941) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../basic/dma_transpose/aie2.py | 6 +- .../basic/dma_transpose/aie2_alt.py | 6 +- .../matrix_multiplication/whole_array/aie2.py | 48 +-- .../whole_array/aie2_tiler.py | 53 ++- .../mat_mul_whole_array_visualization.ipynb | 24 +- .../basic/matrix_scalar_add/aie2.py | 6 +- .../basic/matrix_scalar_add/aie2_alt.py | 6 +- .../passthrough_pykernel.ipynb | 3 +- .../basic/row_wise_bias_add/aie2.py | 8 +- .../basic/row_wise_bias_add/aie2_alt.py | 10 +- .../basic/tiling_exploration/README.md | 4 +- .../tiling_exploration/introduction/Makefile | 6 +- .../tiling_exploration/introduction/README.md | 2 +- .../{tilerhelper.ipynb => taplib.ipynb} | 121 +++--- .../tiling_exploration/per_tile/README.md | 4 +- .../basic/tiling_exploration/per_tile/aie2.py | 4 +- .../basic/tiling_exploration/per_tile/test.py | 4 +- .../tiling_exploration/tile_group/README.md | 4 +- .../tiling_exploration/tile_group/aie2.py | 4 +- .../tiling_exploration/tile_group/test.py | 4 +- .../section-2/section-2g/README.md | 5 +- python/CMakeLists.txt | 2 +- python/dialects/aiex.py | 44 +- python/helpers/taplib/__init__.py | 5 + .../tensortile.py => taplib/tap.py} | 100 +++-- python/helpers/taplib/tas.py | 287 +++++++++++++ .../{tensortiler => taplib}/tensortiler2d.py | 14 +- .../helpers/{tensortiler => taplib}/utils.py | 8 +- .../visualization2d.py | 4 +- python/helpers/tensortiler/__init__.py | 5 - .../helpers/tensortiler/tensortilesequence.py | 255 ------------ .../{tensortiler => taplib}/group_tiler.py | 126 +++--- .../group_tiler_partial.py | 362 ++++++++-------- .../matmul_matrix_vector_tiling_sweep.py | 46 +- .../matmul_whole_array_tiling_sweep.py | 24 +- .../rectangular_tiler.py | 6 +- .../rectangular_tiler2.py | 6 +- .../rectangular_tiler_col_major_tensor.py | 6 +- ...ngular_tiler_col_major_tensor_and_tiler.py | 6 +- .../{tensortiler => taplib}/simple_tiler.py | 58 ++- .../sizes_strides_clean.py | 4 +- .../{tensortiler => taplib}/square_tiler.py | 6 +- .../{tensortiler => taplib}/square_tiler2.py | 6 +- ...col_major_tensor_and_tile_tile_grouping.py | 6 +- ...e_grouping_rectangular_col_major_groups.py | 6 +- .../square_tiler_col_major_tile.py | 6 +- .../square_tiler_tile_grouping.py | 6 +- ...re_tiler_tile_grouping_col_major_groups.py | 6 +- .../{tensortiler => taplib}/step_tiler.py | 120 +++--- .../step_tiler_partial.py | 394 +++++++++--------- .../tensor_tile_same_height.py | 6 +- .../{tensortiler => taplib}/tensortile.py | 36 +- .../tensortilesequence.py | 48 ++- .../tile_repeat_suite.py | 42 +- test/python/{tensortiler => taplib}/util.py | 0 55 files changed, 1243 insertions(+), 1145 deletions(-) rename programming_examples/basic/tiling_exploration/introduction/{tilerhelper.ipynb => taplib.ipynb} (68%) create mode 100644 python/helpers/taplib/__init__.py rename python/helpers/{tensortiler/tensortile.py => taplib/tap.py} (56%) create mode 100644 python/helpers/taplib/tas.py rename python/helpers/{tensortiler => taplib}/tensortiler2d.py (98%) rename python/helpers/{tensortiler => taplib}/utils.py (92%) rename python/helpers/{tensortiler => taplib}/visualization2d.py (98%) delete mode 100644 python/helpers/tensortiler/__init__.py delete mode 100644 python/helpers/tensortiler/tensortilesequence.py rename test/python/{tensortiler => taplib}/group_tiler.py (94%) rename test/python/{tensortiler => taplib}/group_tiler_partial.py (68%) rename test/python/{tensortiler => taplib}/matmul_matrix_vector_tiling_sweep.py (64%) rename test/python/{tensortiler => taplib}/matmul_whole_array_tiling_sweep.py (93%) rename test/python/{tensortiler => taplib}/rectangular_tiler.py (93%) rename test/python/{tensortiler => taplib}/rectangular_tiler2.py (92%) rename test/python/{tensortiler => taplib}/rectangular_tiler_col_major_tensor.py (92%) rename test/python/{tensortiler => taplib}/rectangular_tiler_col_major_tensor_and_tiler.py (93%) rename test/python/{tensortiler => taplib}/simple_tiler.py (82%) rename test/python/{tensortiler => taplib}/sizes_strides_clean.py (94%) rename test/python/{tensortiler => taplib}/square_tiler.py (98%) rename test/python/{tensortiler => taplib}/square_tiler2.py (98%) rename test/python/{tensortiler => taplib}/square_tiler_col_major_tensor_and_tile_tile_grouping.py (97%) rename test/python/{tensortiler => taplib}/square_tiler_col_major_tensor_tile_grouping_rectangular_col_major_groups.py (95%) rename test/python/{tensortiler => taplib}/square_tiler_col_major_tile.py (98%) rename test/python/{tensortiler => taplib}/square_tiler_tile_grouping.py (97%) rename test/python/{tensortiler => taplib}/square_tiler_tile_grouping_col_major_groups.py (97%) rename test/python/{tensortiler => taplib}/step_tiler.py (97%) rename test/python/{tensortiler => taplib}/step_tiler_partial.py (74%) rename test/python/{tensortiler => taplib}/tensor_tile_same_height.py (91%) rename test/python/{tensortiler => taplib}/tensortile.py (67%) rename test/python/{tensortiler => taplib}/tensortilesequence.py (70%) rename test/python/{tensortiler => taplib}/tile_repeat_suite.py (94%) rename test/python/{tensortiler => taplib}/util.py (100%) diff --git a/programming_examples/basic/dma_transpose/aie2.py b/programming_examples/basic/dma_transpose/aie2.py index 3f1636b928..aa0bac1ca7 100644 --- a/programming_examples/basic/dma_transpose/aie2.py +++ b/programming_examples/basic/dma_transpose/aie2.py @@ -13,12 +13,12 @@ from aie.dialects.aiex import * from aie.extras.context import mlir_mod_ctx from aie.helpers.dialects.ext.scf import _for as range_ -from aie.helpers.tensortiler import TensorTile +from aie.helpers.taplib import TensorAccessPattern def my_passthrough(M, K, N, generate_access_map=False): tensor_ty = np.ndarray[(M, K), np.dtype[np.int32]] - data_transform = TensorTile( + data_transform = TensorAccessPattern( (M, K), offset=0, sizes=[1, 1, K, M], strides=[1, 1, 1, K] ) if generate_access_map: @@ -57,7 +57,7 @@ def sequence(A, B, C): metadata=of_in, bd_id=1, mem=A, - tensor_tile=data_transform, + tap=data_transform, issue_token=True, ) npu_dma_memcpy_nd(metadata=of_out, bd_id=0, mem=C, sizes=[1, 1, 1, N]) diff --git a/programming_examples/basic/dma_transpose/aie2_alt.py b/programming_examples/basic/dma_transpose/aie2_alt.py index ad0d64f22d..e7261c0423 100644 --- a/programming_examples/basic/dma_transpose/aie2_alt.py +++ b/programming_examples/basic/dma_transpose/aie2_alt.py @@ -13,12 +13,12 @@ from aie.dialects.aiex import * from aie.extras.context import mlir_mod_ctx from aie.helpers.dialects.ext.scf import _for as range_ -from aie.helpers.tensortiler import TensorTile +from aie.helpers.taplib import TensorAccessPattern def my_passthrough(M, K, N, generate_access_map=False): tensor_ty = np.ndarray[(M, K), np.dtype[np.int32]] - data_transform = TensorTile( + data_transform = TensorAccessPattern( (M, K), offset=0, sizes=[1, 1, K, M], strides=[1, 1, 1, K] ) if generate_access_map: @@ -54,7 +54,7 @@ def sequence(A, B, C): # The strides below are configured to read across all rows in the same column # Stride of K in dim/wrap 2 skips an entire row to read a full column in_task = shim_dma_single_bd_task( - of_in, A, tensor_tile=data_transform, issue_token=True + of_in, A, tap=data_transform, issue_token=True ) out_task = shim_dma_single_bd_task( of_out, C, sizes=[1, 1, 1, N], issue_token=True diff --git a/programming_examples/basic/matrix_multiplication/whole_array/aie2.py b/programming_examples/basic/matrix_multiplication/whole_array/aie2.py index 6d56ba8a81..0689894e7a 100644 --- a/programming_examples/basic/matrix_multiplication/whole_array/aie2.py +++ b/programming_examples/basic/matrix_multiplication/whole_array/aie2.py @@ -14,7 +14,7 @@ from aie.dialects.aie import * from aie.dialects.aiex import * from aie.helpers.dialects.ext.scf import _for as range_ -from aie.helpers.tensortiler import TensorTile, TensorTileSequence +from aie.helpers.taplib import TensorAccessPattern, TensorAccessSequence dtype_map = { "bf16": bfloat16, @@ -49,14 +49,14 @@ def main(): ) argparser.add_argument("--trace_size", type=int, default=0) argparser.add_argument( - "--generate-tiles", + "--generate-taps", action="store_true", - help="Generate TensorTiles, a Python object to represent each data transfer" + help="Generate TensorAccessPatterns, a Python object to represent each data transfer" "of the input/output matrices. These objects can be used for visualization.", ) args = argparser.parse_args() with mlir_mod_ctx() as ctx: - maybe_tiles = my_matmul( + maybe_taps = my_matmul( args.M, args.K, args.N, @@ -68,13 +68,13 @@ def main(): args.dtype_out, args.b_col_maj, args.trace_size, - args.generate_tiles, + args.generate_taps, ) # print(ctx.module.operation.verify()) print(ctx.module) - if args.generate_tiles: - return maybe_tiles + if args.generate_taps: + return maybe_taps def ceildiv(a, b): @@ -93,7 +93,7 @@ def my_matmul( dtype_out_str, b_col_maj, trace_size, - generate_tiles=False, + generate_taps=False, ): n_aie_rows = 4 n_aie_cores = n_aie_rows * n_aie_cols @@ -169,11 +169,11 @@ def my_matmul( elif n_aie_cols == 4: dev = AIEDevice.npu1_4col - # These will hold TensorTile objects that represent the runtime - # npu_dma_memcpy_nd operations of this design. They are only used if generate_tiles is true - A_tensor_tiles = [] - B_tensor_tiles = [] - C_tensor_tiles = [] + # These will hold TensorAccessPattern objects that represent the runtime + # npu_dma_memcpy_nd operations of this design. They are only used if generate_taps is true + A_taps = [] + B_taps = [] + C_taps = [] @device(dev) def device_body(): @@ -415,8 +415,8 @@ def sequence(A, B, C): # Use the calculated sizes/strides/offsets to record the data movement # caused by the above call to npu_dma_memcpy_nd. # This line does not change MLIR output at all. - C_tensor_tiles.append( - TensorTile( + C_taps.append( + TensorAccessPattern( (M, N), offset=C_offset, sizes=C_sizes, @@ -469,8 +469,8 @@ def sequence(A, B, C): # Use the calculated sizes/strides/offsets to record the data movement # caused by the above call to npu_dma_memcpy_nd. # This line does not change MLIR output at all. - A_tensor_tiles.append( - TensorTile( + A_taps.append( + TensorAccessPattern( (M, K), offset=A_offset, sizes=A_sizes, @@ -515,8 +515,8 @@ def sequence(A, B, C): # Use the calculated sizes/strides/offsets to record the data movement # caused by the above call to npu_dma_memcpy_nd. # This line does not change MLIR output at all. - B_tensor_tiles.append( - TensorTile( + B_taps.append( + TensorAccessPattern( (K, N), offset=B_col_offset, sizes=B_sizes, @@ -527,13 +527,13 @@ def sequence(A, B, C): dma_wait(*C_l2l3_fifos) dma_wait(*C_l2l3_fifos) - if generate_tiles: - # If generate tiles is true, return a representation of tensor tiles + if generate_taps: + # If generate_taps is true, return a representation of tensor tiles # representing all the npu_dma_memcpy_nd runtime sequence operations per input/ouput tensor. return ( - TensorTileSequence.from_tiles(A_tensor_tiles), - TensorTileSequence.from_tiles(B_tensor_tiles), - TensorTileSequence.from_tiles(C_tensor_tiles), + TensorAccessSequence.from_taps(A_taps), + TensorAccessSequence.from_taps(B_taps), + TensorAccessSequence.from_taps(C_taps), ) diff --git a/programming_examples/basic/matrix_multiplication/whole_array/aie2_tiler.py b/programming_examples/basic/matrix_multiplication/whole_array/aie2_tiler.py index 764907de6f..a850ad2982 100644 --- a/programming_examples/basic/matrix_multiplication/whole_array/aie2_tiler.py +++ b/programming_examples/basic/matrix_multiplication/whole_array/aie2_tiler.py @@ -14,7 +14,7 @@ from aie.dialects.aie import * from aie.dialects.aiex import * from aie.helpers.dialects.ext.scf import _for as range_ -from aie.helpers.tensortiler import TensorTiler2D, TensorTileSequence +from aie.helpers.taplib import TensorTiler2D, TensorAccessSequence dtype_map = { "bf16": bfloat16, @@ -49,14 +49,14 @@ def main(): ) argparser.add_argument("--trace_size", type=int, default=0) argparser.add_argument( - "--generate-tiles", + "--generate-taps", action="store_true", - help="Generate TensorTiles, a Python object to represent each data transfer" + help="Generate TensorAccessPatterns, a Python object to represent each data transfer" "of the input/output matrices. These objects can be used for visualization.", ) args = argparser.parse_args() with mlir_mod_ctx() as ctx: - maybe_tiles = my_matmul( + maybe_taps = my_matmul( args.M, args.K, args.N, @@ -68,13 +68,13 @@ def main(): args.dtype_out, args.b_col_maj, args.trace_size, - args.generate_tiles, + args.generate_taps, ) # print(ctx.module.operation.verify()) print(ctx.module) - if args.generate_tiles: - return maybe_tiles + if args.generate_taps: + return maybe_taps def ceildiv(a, b): @@ -93,7 +93,7 @@ def my_matmul( dtype_out_str, b_col_maj, trace_size, - generate_tiles=False, + generate_taps=False, ): n_aie_rows = 4 n_aie_cores = n_aie_rows * n_aie_cols @@ -169,11 +169,11 @@ def my_matmul( elif n_aie_cols == 4: dev = AIEDevice.npu1_4col - # These will hold TensorTile objects that represent the runtime - # npu_dma_memcpy_nd operations of this design. They are only used if generate_tiles is true - A_tensor_tiles = [] - B_tensor_tiles = [] - C_tensor_tiles = [] + # These will hold TensorAccessPattern objects that represent the runtime + # npu_dma_memcpy_nd operations of this design. They are only used if generate_taps is true + A_taps = [] + B_taps = [] + C_taps = [] @device(dev) def device_body(): @@ -433,7 +433,7 @@ def sequence(A, B, C): for col in range(n_aie_cols): # This line does not change MLIR output at all - it's just for recording data movement - C_tensor_tiles.append(C_tiles[c_index]) + C_taps.append(C_tiles[c_index]) # C Output Transfer: # The smallest transfer unit is a (m*n_aie_rows)-x-(n)-sized sub-tile of the matrix. @@ -457,16 +457,11 @@ def sequence(A, B, C): c_task = shim_dma_single_bd_task( C_l2l3_fifos[col], C, - tensor_tile=C_tiles[c_index], + tap=C_tiles[c_index], issue_token=True, ) dma_start_task(c_task) out_tasks.append(c_task) - - # Use the calculated sizes/strides/offsets to record the data movement - # caused by the above call to npu_dma_memcpy_nd. - # This line does not change MLIR output at all. - C_tensor_tiles.append(C_tiles[c_index]) c_index += 1 for tile_row in range(current_tb_n_rows): @@ -495,14 +490,13 @@ def sequence(A, B, C): a_task = shim_dma_single_bd_task( A_l3l2_fifos[col], A, - tensor_tile=A_tiles[tile_offset], + tap=A_tiles[tile_offset], ) dma_start_task(a_task) in_tasks.append(a_task) # Use the calculated sizes/strides/offsets to record the data movement # caused by the above call to npu_dma_memcpy_nd. # This line does not change MLIR output at all. - A_tensor_tiles.append(A_tiles[tile_offset]) # B input transfer: # Transfer the first a (n)-wide block of columns of B, @@ -525,13 +519,14 @@ def sequence(A, B, C): b_task = shim_dma_single_bd_task( B_l3l2_fifos[col], B, - tensor_tile=B_tiles[col], + tap=B_tiles[col], ) dma_start_task(b_task) in_tasks.append(b_task) # These lines do not change MLIR output at all - they are just for recording data movement - B_tensor_tiles.append(B_tiles[col]) + A_taps.append(A_tiles[tile_offset]) + B_taps.append(B_tiles[col]) if tb > 0 or (tb == 0 and pingpong > 0): dma_await_task(*out_tasks) out_tasks = [] @@ -542,13 +537,13 @@ def sequence(A, B, C): if len(in_tasks) > 0: dma_free_task(*in_tasks) - if generate_tiles: - # If generate tiles is true, return a representation of tensor tiles + if generate_taps: + # If generate taps is true, return a representation of tensor access patterns # representing all the npu_dma_memcpy_nd runtime sequence operations per input/ouput tensor. return ( - TensorTileSequence.from_tiles(A_tensor_tiles), - TensorTileSequence.from_tiles(B_tensor_tiles), - TensorTileSequence.from_tiles(C_tensor_tiles), + TensorAccessSequence.from_taps(A_taps), + TensorAccessSequence.from_taps(B_taps), + TensorAccessSequence.from_taps(C_taps), ) diff --git a/programming_examples/basic/matrix_multiplication/whole_array/mat_mul_whole_array_visualization.ipynb b/programming_examples/basic/matrix_multiplication/whole_array/mat_mul_whole_array_visualization.ipynb index 0386936b5c..864a496b7d 100644 --- a/programming_examples/basic/matrix_multiplication/whole_array/mat_mul_whole_array_visualization.ipynb +++ b/programming_examples/basic/matrix_multiplication/whole_array/mat_mul_whole_array_visualization.ipynb @@ -21,7 +21,7 @@ "id": "2", "metadata": {}, "source": [ - "The purpose of this notebook is to visually describe how the A, B, and C matrices are tiled and transformed in the matrix multiply whole array design. To do this, we use some of the tiling helper tools included in IRON." + "The purpose of this notebook is to visually describe how the A, B, and C matrices are tiled and transformed in the matrix multiply whole array design. To do this, we use some of the taplib (Tensor Access Pattern Library) tools included in IRON." ] }, { @@ -55,7 +55,7 @@ "metadata": {}, "outputs": [], "source": [ - "# Call the mat mul function with generate_tiles=True\n", + "# Call the mat mul function with generate_taps=True\n", "M = 640\n", "K = 896\n", "N = 768\n", @@ -67,7 +67,7 @@ "b_col_maj = False\n", "\n", "with mlir_mod_ctx() as ctx:\n", - " A_tiles, B_tiles, C_tiles = my_matmul(\n", + " A_taps, B_taps, C_taps = my_matmul(\n", " M=M,\n", " K=K,\n", " N=N,\n", @@ -79,7 +79,7 @@ " dtype_out_str=\"i32\",\n", " b_col_maj=b_col_maj,\n", " trace_size=0,\n", - " generate_tiles=True,\n", + " generate_taps=True,\n", " )" ] }, @@ -114,7 +114,7 @@ "metadata": {}, "outputs": [], "source": [ - "A_tiles.visualize(plot_access_count=True)" + "A_taps.visualize(plot_access_count=True)" ] }, { @@ -132,7 +132,7 @@ "metadata": {}, "outputs": [], "source": [ - "B_tiles.visualize(plot_access_count=True)" + "B_taps.visualize(plot_access_count=True)" ] }, { @@ -150,7 +150,7 @@ "metadata": {}, "outputs": [], "source": [ - "C_tiles.visualize(plot_access_count=True)" + "C_taps.visualize(plot_access_count=True)" ] }, { @@ -178,7 +178,7 @@ "metadata": {}, "outputs": [], "source": [ - "a_anim = A_tiles.animate()\n", + "a_anim = A_taps.animate()\n", "HTML(a_anim.to_jshtml())" ] }, @@ -197,7 +197,7 @@ "metadata": {}, "outputs": [], "source": [ - "b_anim = B_tiles.animate()\n", + "b_anim = B_taps.animate()\n", "HTML(b_anim.to_jshtml())" ] }, @@ -216,16 +216,16 @@ "metadata": {}, "outputs": [], "source": [ - "c_anim = C_tiles.animate()\n", + "c_anim = C_taps.animate()\n", "HTML(c_anim.to_jshtml())" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "ironenv", "language": "python", - "name": "python3" + "name": "ironenv" }, "language_info": { "codemirror_mode": { diff --git a/programming_examples/basic/matrix_scalar_add/aie2.py b/programming_examples/basic/matrix_scalar_add/aie2.py index 93168e1930..d20ba12340 100644 --- a/programming_examples/basic/matrix_scalar_add/aie2.py +++ b/programming_examples/basic/matrix_scalar_add/aie2.py @@ -12,7 +12,7 @@ from aie.dialects.aiex import * from aie.extras.context import mlir_mod_ctx from aie.helpers.dialects.ext.scf import _for as range_ -from aie.helpers.tensortiler import TensorTiler2D +from aie.helpers.taplib import TensorTiler2D # Size of the entire image IMAGE_HEIGHT = 16 @@ -79,7 +79,7 @@ def sequence(inTensor, notUsed, outTensor): metadata=of_in1, bd_id=1, mem=inTensor, - tensor_tile=tiler[0], + tap=tiler[0], issue_token=True, ) @@ -87,7 +87,7 @@ def sequence(inTensor, notUsed, outTensor): metadata=of_out1, bd_id=0, mem=outTensor, - tensor_tile=tiler[0], + tap=tiler[0], ) dma_wait(of_in1, of_out1) diff --git a/programming_examples/basic/matrix_scalar_add/aie2_alt.py b/programming_examples/basic/matrix_scalar_add/aie2_alt.py index bd62a148cf..8cf8e73fa9 100644 --- a/programming_examples/basic/matrix_scalar_add/aie2_alt.py +++ b/programming_examples/basic/matrix_scalar_add/aie2_alt.py @@ -12,7 +12,7 @@ from aie.dialects.aiex import * from aie.extras.context import mlir_mod_ctx from aie.helpers.dialects.ext.scf import _for as range_ -from aie.helpers.tensortiler import TensorTiler2D +from aie.helpers.taplib import TensorTiler2D # Size of the entire image IMAGE_HEIGHT = 16 @@ -76,10 +76,10 @@ def core_body(): @runtime_sequence(tile_ty, tile_ty, tile_ty) def sequence(inTensor, notUsed, outTensor): in_task = shim_dma_single_bd_task( - of_in1, inTensor, tensor_tile=tiler[0], issue_token=True + of_in1, inTensor, tap=tiler[0], issue_token=True ) out_task = shim_dma_single_bd_task( - of_out1, outTensor, tensor_tile=tiler[0], issue_token=True + of_out1, outTensor, tap=tiler[0], issue_token=True ) dma_start_task(in_task, out_task) diff --git a/programming_examples/basic/passthrough_pykernel/passthrough_pykernel.ipynb b/programming_examples/basic/passthrough_pykernel/passthrough_pykernel.ipynb index 40995879bf..f39f56ecba 100644 --- a/programming_examples/basic/passthrough_pykernel/passthrough_pykernel.ipynb +++ b/programming_examples/basic/passthrough_pykernel/passthrough_pykernel.ipynb @@ -224,7 +224,8 @@ "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython3" + "pygments_lexer": "ipython3", + "version": "3.10.12" } }, "nbformat": 4, diff --git a/programming_examples/basic/row_wise_bias_add/aie2.py b/programming_examples/basic/row_wise_bias_add/aie2.py index bfcea0fec0..46e792ac48 100644 --- a/programming_examples/basic/row_wise_bias_add/aie2.py +++ b/programming_examples/basic/row_wise_bias_add/aie2.py @@ -11,7 +11,7 @@ from aie.dialects.aiex import * from aie.extras.context import mlir_mod_ctx from aie.helpers.dialects.ext.scf import _for as range_ -from aie.helpers.tensortiler import TensorTiler2D +from aie.helpers.taplib import TensorTiler2D def row_wise_bias_add(M, N, m, n): @@ -60,19 +60,19 @@ def sequence(inp, bias, out): metadata=in_fifo, bd_id=0, mem=inp, - tensor_tile=tiler[0], + tap=tiler[0], ) npu_dma_memcpy_nd( metadata=bias_fifo, bd_id=1, mem=bias, - tensor_tile=bias_tiler[0], + tap=bias_tiler[0], ) npu_dma_memcpy_nd( metadata=out_fifo, bd_id=2, mem=out, - tensor_tile=tiler[0], + tap=tiler[0], ) # of_out will only complete after of_in completes, so we just wait on of_out instead of both dma_wait(out_fifo) diff --git a/programming_examples/basic/row_wise_bias_add/aie2_alt.py b/programming_examples/basic/row_wise_bias_add/aie2_alt.py index da974d37f8..16b0b08628 100644 --- a/programming_examples/basic/row_wise_bias_add/aie2_alt.py +++ b/programming_examples/basic/row_wise_bias_add/aie2_alt.py @@ -11,7 +11,7 @@ from aie.dialects.aiex import * from aie.extras.context import mlir_mod_ctx from aie.helpers.dialects.ext.scf import _for as range_ -from aie.helpers.tensortiler import TensorTiler2D +from aie.helpers.taplib import TensorTiler2D def row_wise_bias_add(M, N, m, n): @@ -56,12 +56,10 @@ def core_body(): @runtime_sequence(tensor_ty, bias_ty, tensor_ty) def sequence(inp, bias, out): - in_task = shim_dma_single_bd_task(in_fifo, inp, tensor_tile=tiler[0]) - bias_task = shim_dma_single_bd_task( - bias_fifo, bias, tensor_tile=bias_tiler[0] - ) + in_task = shim_dma_single_bd_task(in_fifo, inp, tap=tiler[0]) + bias_task = shim_dma_single_bd_task(bias_fifo, bias, tap=bias_tiler[0]) out_task = shim_dma_single_bd_task( - out_fifo, out, tensor_tile=tiler[0], issue_token=True + out_fifo, out, tap=tiler[0], issue_token=True ) dma_start_task(in_task, bias_task, out_task) diff --git a/programming_examples/basic/tiling_exploration/README.md b/programming_examples/basic/tiling_exploration/README.md index 4b4dcbced8..30ab06ffb2 100644 --- a/programming_examples/basic/tiling_exploration/README.md +++ b/programming_examples/basic/tiling_exploration/README.md @@ -2,7 +2,7 @@ ## Overview -This directory contains resources to explore tiling on AIEs with IRON: -* [introduction](introduction): an IPython notebook that introduces the tiling tools included with IRON +This directory contains resources to Tiling Access Pattern library (`taplib`) on AIEs with IRON: +* [introduction](introduction): an IPython notebook that introduces the `taplib` * [per_tile](per_tile): an example design illustrating the order elements are accessed when tiling * [tile_group](tile_group): an example design illustrating how to access elements when grouping tiles with a single DMA operation \ No newline at end of file diff --git a/programming_examples/basic/tiling_exploration/introduction/Makefile b/programming_examples/basic/tiling_exploration/introduction/Makefile index 5766fa7108..098090f6b4 100644 --- a/programming_examples/basic/tiling_exploration/introduction/Makefile +++ b/programming_examples/basic/tiling_exploration/introduction/Makefile @@ -9,10 +9,10 @@ srcdir := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) all: run -run: ${srcdir}/tilerhelper.ipynb +run: ${srcdir}/taplib.ipynb mkdir -p build - cd build && jupyter nbconvert --to script ${srcdir}/tilerhelper.ipynb --output-dir . - cd build && ipython tilerhelper.py + cd build && jupyter nbconvert --to script ${srcdir}/taplib.ipynb --output-dir . + cd build && ipython taplib.py clean: rm -rf build \ No newline at end of file diff --git a/programming_examples/basic/tiling_exploration/introduction/README.md b/programming_examples/basic/tiling_exploration/introduction/README.md index cc23116e03..626ef444b8 100644 --- a/programming_examples/basic/tiling_exploration/introduction/README.md +++ b/programming_examples/basic/tiling_exploration/introduction/README.md @@ -11,7 +11,7 @@ * In your browser, navigate to the URL (which includes a token) which is found in the output of the above command. * Navigate to `programming_examples/basic/tiling_exploration/introduction` -* Double click `tilerhelper.ipynb` to start the notebook; choose the ipykernel called `ironenv`. +* Double click `taplib.ipynb` to start the notebook; choose the ipykernel called `ironenv`. * You should now be good to go! #### Run the Notebook as a Script diff --git a/programming_examples/basic/tiling_exploration/introduction/tilerhelper.ipynb b/programming_examples/basic/tiling_exploration/introduction/taplib.ipynb similarity index 68% rename from programming_examples/basic/tiling_exploration/introduction/tilerhelper.ipynb rename to programming_examples/basic/tiling_exploration/introduction/taplib.ipynb index 97a6fa34b3..eace21ed28 100644 --- a/programming_examples/basic/tiling_exploration/introduction/tilerhelper.ipynb +++ b/programming_examples/basic/tiling_exploration/introduction/taplib.ipynb @@ -5,7 +5,7 @@ "id": "0", "metadata": {}, "source": [ - "# IRON Tools for Data Movements and Tiling" + "# Tensor Access Pattern Library (`taplib`): An IRON Tool for Data Movements and Tiling" ] }, { @@ -27,11 +27,11 @@ "source": [ "## Introduction\n", "\n", - "Components of *AI Engines* (AIEs) have *Data Movement Accelerators* (DMAs) which are capable of expressing pretty complex on-the-fly data movement transformations.\n", + "Components of *AI Engines* (AIEs) have *Data Movement Accelerators* (DMAs) which are capable of expressing complex on-the-fly data transformations.\n", "\n", - "A common type of transformation is known as *tiling*, where a larger *image* or *tensor* of data is broken up into smaller *tiles*. This can be done to encourage smooth streaming behavior, to better conserver resources at specific areas of the memory hierarchy, or because applications or vectorized instructions require data to be structured in a specific way.\n", + "The primary purpose of `taplib` is to provide building blocks for expressing *Tensor Access Patterns* (*taps*) used in DMA transformations. To provide a useful utility (and show the usefulness of `taplib`), `taplib` contains a `TensorTiler2D` class which acts as a factory for generating taps for common tiling patterns.\n", "\n", - "IRON provides some tools to help with tiling data." + "*tiling* is a common type of transformation whereby a larger *image* or *tensor* of data is broken up into smaller *tiles* or groups of tiles. This can be done to encourage smooth streaming behavior, to better conserver resources at specific areas of the memory hierarchy, or because applications or vectorized instructions require data to be structured in a specific way. `TensorTiler2D` provides several methods to generate taps for common tiling patterns." ] }, { @@ -41,9 +41,9 @@ "source": [ "## Data Transformations in MLIR\n", "\n", - "Internally, the mlir-aie dialect represents data movements as a combination of an *offset* into a region of data, a set of *strides*, and a set of *sizes*. Most of the DMA components take either 4 dimensions of offsets/sizes/strides or 3 dimensions + a repeat count with a repeat step (which is, for the most part, functionally equivalent to 4 dimensions of sizes/strides).\n", + "Internally, the `mlir-aie` dialect represents tensor access patterns as a combination of an *offset* into a region of data, a set of *strides*, and a set of *sizes*. Most of the DMAs take either 4 dimensions of offsets/sizes/strides or 3 dimensions + a repeat count with a repeat step (which is, for the most part, functionally equivalent to 4 dimensions of sizes/strides).\n", "\n", - "It takes practice to successfully think about data movements in offsets/sizes/strides; that is why IRON provides some tools to help reason about data transformations." + "It takes practice to successfully think about data movements in offsets/sizes/strides; that is why `taplib` provides some tools to help reason about tensor access patterns." ] }, { @@ -51,7 +51,7 @@ "id": "4", "metadata": {}, "source": [ - "## IRON Tools for Tiling" + "## `taplib`" ] }, { @@ -69,7 +69,7 @@ "metadata": {}, "outputs": [], "source": [ - "from aie.helpers.tensortiler import TensorTile, TensorTileSequence, TensorTiler2D" + "from aie.helpers.taplib import TensorAccessPattern, TensorAccessSequence, TensorTiler2D" ] }, { @@ -77,9 +77,9 @@ "id": "7", "metadata": {}, "source": [ - "### TensorTile\n", + "### `TensorAccessPattern` (`tap`)\n", "\n", - "A TensorTile is a way to representing a single set of offset/sizes/strides on a tensor of a particular shape. Let's look at some examples of what you can do with a TensorTile." + "A `TensorAccessPattern` represents a single set of offset/sizes/strides on a tensor of a particular shape. Let's look at some examples of what you can do with a `TensorAccessPattern`." ] }, { @@ -89,12 +89,12 @@ "metadata": {}, "outputs": [], "source": [ - "# Create a TensorTile\n", + "# Create a TensorAccessPattern\n", "tensor_dims = (2, 3)\n", "offset = 4\n", "sizes = [1, 2]\n", "strides = [0, 1]\n", - "tile = TensorTile((2, 3), offset=offset, sizes=[1, 2], strides=[0, 1])" + "tap = TensorAccessPattern((2, 3), offset=offset, sizes=[1, 2], strides=[0, 1])" ] }, { @@ -102,9 +102,9 @@ "id": "9", "metadata": {}, "source": [ - "The TensorTile can be visualized in two ways:\n", + "The `TensorAccessPattern` can be visualized in two ways:\n", "- as a heatmap showing the order that elements are accessed\n", - "- as a heatmap showing the number of times each element in the tensor is accessed by the TensorTile" + "- as a heatmap showing the number of times each element in the tensor is accessed by the `TensorAccessPattern`" ] }, { @@ -114,8 +114,8 @@ "metadata": {}, "outputs": [], "source": [ - "# We can visualize the TensorTile\n", - "tile.visualize(show_arrows=False)" + "# We can visualize the TensorAccessPattern\n", + "tap.visualize(show_arrows=False)" ] }, { @@ -126,7 +126,7 @@ "outputs": [], "source": [ "# We can add some arrows to the visualization, and optionally plot the access count.\n", - "tile.visualize(show_arrows=True, plot_access_count=True)" + "tap.visualize(show_arrows=True, plot_access_count=True)" ] }, { @@ -144,7 +144,7 @@ "metadata": {}, "outputs": [], "source": [ - "access_order, access_count = tile.access_tensors()\n", + "access_order, access_count = tap.accesses()\n", "access_order, access_count" ] }, @@ -152,6 +152,25 @@ "cell_type": "markdown", "id": "14", "metadata": {}, + "source": [ + "There are also methods to get just one of the access tensors, if desired. For larger tensors, it's useful to only calculate what you need to reduce program memory/computation." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "15", + "metadata": {}, + "outputs": [], + "source": [ + "access_order = tap.access_order()\n", + "access_count = tap.access_count()" + ] + }, + { + "cell_type": "markdown", + "id": "16", + "metadata": {}, "source": [ "### TensorTileSequence\n", "\n", @@ -161,76 +180,76 @@ { "cell_type": "code", "execution_count": null, - "id": "15", + "id": "17", "metadata": {}, "outputs": [], "source": [ - "t0 = TensorTile((8, 8), offset=0, sizes=[1, 1, 4, 4], strides=[0, 0, 8, 1])\n", - "t1 = TensorTile((8, 8), offset=4, sizes=[1, 1, 4, 4], strides=[0, 0, 8, 1])\n", - "t2 = TensorTile((8, 8), offset=32, sizes=[1, 1, 4, 4], strides=[0, 0, 8, 1])\n", + "t0 = TensorAccessPattern((8, 8), offset=0, sizes=[1, 1, 4, 4], strides=[0, 0, 8, 1])\n", + "t1 = TensorAccessPattern((8, 8), offset=4, sizes=[1, 1, 4, 4], strides=[0, 0, 8, 1])\n", + "t2 = TensorAccessPattern((8, 8), offset=32, sizes=[1, 1, 4, 4], strides=[0, 0, 8, 1])\n", "\n", "# Create a TensorTileSequence from a list of tiles\n", - "tiles = TensorTileSequence.from_tiles([t0, t1, t2])" + "taps = TensorAccessSequence.from_taps([t0, t1, t2])" ] }, { "cell_type": "code", "execution_count": null, - "id": "16", + "id": "18", "metadata": {}, "outputs": [], "source": [ - "# You can treat the TensorTileSequence like a normal python list, for the most part\n", - "print(tiles[0])\n", + "# You can treat the TensorAccessSequence like a normal python list for common operations\n", + "print(taps[0])\n", "\n", - "print(len(tiles))\n", - "t3 = TensorTile((8, 8), offset=36, sizes=[1, 1, 4, 4], strides=[0, 0, 8, 1])\n", - "tiles.append(t3)\n", - "print(len(tiles))\n", - "print(tiles[3])\n", + "print(len(taps))\n", + "t3 = TensorAccessPattern((8, 8), offset=36, sizes=[1, 1, 4, 4], strides=[0, 0, 8, 1])\n", + "taps.append(t3)\n", + "print(len(taps))\n", + "print(taps[3])\n", "\n", - "for t in tiles:\n", + "for t in taps:\n", " t.visualize()" ] }, { "cell_type": "code", "execution_count": null, - "id": "17", + "id": "19", "metadata": {}, "outputs": [], "source": [ "# But you can also do some neat things to visualize the tiles in a sequence in one graph\n", - "tiles.visualize(plot_access_count=True)" + "taps.visualize(plot_access_count=True)" ] }, { "cell_type": "code", "execution_count": null, - "id": "18", + "id": "20", "metadata": {}, "outputs": [], "source": [ "# Or you can visualize the tiles in a sequence in an animation, where each frame of the animation represents a tile in the sequence.\n", - "anim = tiles.animate()\n", + "anim = taps.animate()\n", "HTML(anim.to_jshtml())" ] }, { "cell_type": "markdown", - "id": "19", + "id": "21", "metadata": {}, "source": [ "### TensorTiler2D\n", "\n", - "While the TensorTileSequence is useful for working with collections of tiles, it can still be a bit arduous to create the TensorTiles in the first place.\n", - "The TensorTiler2D class is meant to help automate the creation of TensorTileSequences process for common tiling patterns." + "While the `TensorAccessSequence` is useful for working with collections of taps, it can still be a bit arduous to create the `TensorAccessPatterns` in the first place.\n", + "`TensorTiler2D` is designed to automate the creation of `TensorAccessSequences` for common tiling patterns." ] }, { "cell_type": "code", "execution_count": null, - "id": "20", + "id": "22", "metadata": {}, "outputs": [], "source": [ @@ -245,7 +264,7 @@ { "cell_type": "code", "execution_count": null, - "id": "21", + "id": "23", "metadata": {}, "outputs": [], "source": [ @@ -256,7 +275,7 @@ { "cell_type": "code", "execution_count": null, - "id": "22", + "id": "24", "metadata": {}, "outputs": [], "source": [ @@ -268,7 +287,7 @@ { "cell_type": "code", "execution_count": null, - "id": "23", + "id": "25", "metadata": {}, "outputs": [], "source": [ @@ -284,7 +303,7 @@ { "cell_type": "code", "execution_count": null, - "id": "24", + "id": "26", "metadata": {}, "outputs": [], "source": [ @@ -295,7 +314,7 @@ { "cell_type": "code", "execution_count": null, - "id": "25", + "id": "27", "metadata": {}, "outputs": [], "source": [ @@ -307,7 +326,7 @@ { "cell_type": "code", "execution_count": null, - "id": "26", + "id": "28", "metadata": {}, "outputs": [], "source": [ @@ -326,7 +345,7 @@ { "cell_type": "code", "execution_count": null, - "id": "27", + "id": "29", "metadata": {}, "outputs": [], "source": [ @@ -337,7 +356,7 @@ { "cell_type": "code", "execution_count": null, - "id": "28", + "id": "30", "metadata": {}, "outputs": [], "source": [ @@ -348,16 +367,16 @@ }, { "cell_type": "markdown", - "id": "29", + "id": "31", "metadata": {}, "source": [ - "That concludes the introduction to IRON tiling tools!" + "That concludes the introduction to `taplib`!" ] }, { "cell_type": "code", "execution_count": null, - "id": "30", + "id": "32", "metadata": {}, "outputs": [], "source": [ diff --git a/programming_examples/basic/tiling_exploration/per_tile/README.md b/programming_examples/basic/tiling_exploration/per_tile/README.md index b7fd130f07..9efe4848fd 100644 --- a/programming_examples/basic/tiling_exploration/per_tile/README.md +++ b/programming_examples/basic/tiling_exploration/per_tile/README.md @@ -14,13 +14,13 @@ This IRON design flow example, called "Tiling Exploration: Per Tile", demonstrat ## Source Files Overview -1. `aie2.py`: A Python script that defines the AIE array structural design using MLIR-AIE operations and the `TensorTiler` to specify 'tiles' of data to be transferred out of the design. The file generates MLIR that is then compiled using `aiecc.py` to produce design binaries (ie. XCLBIN and inst.txt for the NPU in Ryzen™ AI). +1. `aie2.py`: A Python script that defines the AIE array structural design using MLIR-AIE operations and the `TensorTiler2D` to specify `TensorAccessPatterns` (*taps*) of data to be transferred out of the design. The file generates MLIR that is then compiled using `aiecc.py` to produce design binaries (ie. XCLBIN and inst.txt for the NPU in Ryzen™ AI). 1. `test.py`: This Python code is responsible for loading the compiled XCLBIN file, configuring the AIE module, providing input data, and executing the AIE design on the NPU. After executing, the script verifies the results against expected output. ## Design Overview -This design has no inputs; it produces a single output tensor. The single core used in this design touches each element in the output tensor seemingly sequentially. However, due to the data transformation (via `TensorTile`s) in the `runtime_sequence`, the output data is in 'tiled' order, as seen in the picture below. +This design has no inputs; it produces a single output tensor. The single core used in this design touches each element in the output tensor seemingly sequentially. However, due to the data transformation (via `TensorAccessPattern`s) in the `runtime_sequence`, the output data is in 'tiled' order, as seen in the picture below.

1: diff --git a/python/helpers/taplib/__init__.py b/python/helpers/taplib/__init__.py new file mode 100644 index 0000000000..b8fce198c0 --- /dev/null +++ b/python/helpers/taplib/__init__.py @@ -0,0 +1,5 @@ +from .tap import TensorAccessPattern +from .tas import ( + TensorAccessSequence, +) +from .tensortiler2d import TensorTiler2D diff --git a/python/helpers/tensortiler/tensortile.py b/python/helpers/taplib/tap.py similarity index 56% rename from python/helpers/tensortiler/tensortile.py rename to python/helpers/taplib/tap.py index c6782cc1eb..2e08e2ede6 100644 --- a/python/helpers/tensortiler/tensortile.py +++ b/python/helpers/taplib/tap.py @@ -10,10 +10,10 @@ validate_offset, validate_tensor_dims, ) -from .visualization2d import visualize_from_access_tensors +from .visualization2d import visualize_from_accesses -class TensorTile: +class TensorAccessPattern: _DTYPE = np.int32 def __init__( @@ -24,11 +24,7 @@ def __init__( strides: Sequence[int], ): self._tensor_dims = validate_tensor_dims(tensor_dims) - self._offset = validate_offset(offset) - if self._offset >= np.prod(tensor_dims): - raise ValueError( - f"Offset too large: {self._offset}. Max value allowed for tensor: {np.prod(tensor_dims)}" - ) + self._offset = validate_offset(offset, tensor_dims) self._sizes, self._strides = validate_and_clean_sizes_strides(sizes, strides) @property @@ -54,24 +50,51 @@ def strides(self) -> Sequence[int]: def transformation_dims(self) -> Sequence[tuple[int, int]]: return list(zip(self._sizes, self._strides)) - def access_tensors(self) -> tuple[np.ndarray, np.ndarray]: + def accesses(self) -> tuple[np.ndarray, np.ndarray]: + return self._calculate_accesses(calc_order=True, calc_count=True) + + def access_order(self) -> np.ndarray: + access_order_tensor, _ = self._calculate_accesses( + calc_order=True, calc_count=False + ) + return access_order_tensor + + def access_count(self) -> np.ndarray: + _, access_count_tensor = self._calculate_accesses( + calc_order=False, calc_count=True + ) + return access_count_tensor + + def _calculate_accesses( + self, calc_order: bool, calc_count: bool + ) -> tuple[np.ndarray, np.ndarray]: # TODO: should access order be a list of lists instead of generate two separate tensors? # TODO: for performance, should cache and return copies? Or just cache? + if not calc_order and not calc_count: + raise ValueError("Must select calc_order, calc_count, or both") # Initialize access order and count maps total_elems = np.prod(self._tensor_dims) - access_order_tensor = np.full(total_elems, -1, dtype=self._DTYPE) - access_count_tensor = np.full(total_elems, 0, dtype=self._DTYPE) + access_order_tensor = None + if calc_order: + access_order_tensor = np.full(total_elems, -1, dtype=self._DTYPE) + access_count = 0 + access_count_tensor = None + if calc_count: + access_count_tensor = np.full(total_elems, 0, dtype=self._DTYPE) access_idx_generator = self.access_generator() - access_count = 0 for access_idx in access_idx_generator: - access_count_tensor[access_idx] += 1 - access_order_tensor[access_idx] = access_count - access_count += 1 - - access_order_tensor = access_order_tensor.reshape(self._tensor_dims) - access_count_tensor = access_count_tensor.reshape(self._tensor_dims) + if calc_count: + access_count_tensor[access_idx] += 1 + if calc_order: + access_order_tensor[access_idx] = access_count + access_count += 1 + + if calc_order: + access_order_tensor = access_order_tensor.reshape(self._tensor_dims) + if calc_count: + access_count_tensor = access_count_tensor.reshape(self._tensor_dims) return access_order_tensor, access_count_tensor def access_generator(self): @@ -83,9 +106,13 @@ def access_generator(self): self._offset + np.sum(np.multiply(dims, self._strides)) ) % total_elems - def compare_access_orders(self, other: TensorTile) -> bool: - if not isinstance(other, TensorTile): - raise ValueError("Can only compare access order against another TensorTile") + def compare_access_orders(self, other: TensorAccessPattern) -> bool: + # This function compares using access generators, which is more performant + # than actually generating the access order or access count tensors. + if not isinstance(other, TensorAccessPattern): + raise ValueError( + "Can only compare access order against another TensorAccessPattern" + ) my_generator = self.access_generator() other_generator = other.access_generator() return all( @@ -103,27 +130,28 @@ def visualize( show_plot: bool = True, plot_access_count: bool = False, ) -> None: - access_order, access_count = self.access_tensors() - if title is None: - title = str(self) - if not plot_access_count: - access_count = None - if len(self._tensor_dims) == 2: - visualize_from_access_tensors( - access_order, - access_count, - title=title, - show_arrows=show_arrows, - file_path=file_path, - show_plot=show_plot, - ) - else: + if len(self._tensor_dims) != 2: raise NotImplementedError( "Visualization is only currently supported for 1- or 2-dimensional tensors" ) + if plot_access_count: + access_order, access_count = self.accesses() + else: + access_count = None + access_order = self.access_order() + if title is None: + title = str(self) + visualize_from_accesses( + access_order, + access_count, + title=title, + show_arrows=show_arrows, + file_path=file_path, + show_plot=show_plot, + ) def __str__(self) -> str: - return f"TensorTile(offset={self._offset}, sizes={self._sizes}, strides={self._strides})" + return f"TensorAccessPattern({self.tensor_dims} offset={self._offset}, sizes={self._sizes}, strides={self._strides})" def __eq__(self, other): if isinstance(other, self.__class__): diff --git a/python/helpers/taplib/tas.py b/python/helpers/taplib/tas.py new file mode 100644 index 0000000000..cac818864b --- /dev/null +++ b/python/helpers/taplib/tas.py @@ -0,0 +1,287 @@ +from __future__ import annotations +from collections import abc +from copy import deepcopy +import matplotlib.animation as animation +import numpy as np +from typing import Callable, Sequence + +from .tap import TensorAccessPattern +from .utils import ( + validate_and_clean_sizes_strides, + validate_offset, + validate_tensor_dims, +) +from .visualization2d import animate_from_accesses, visualize_from_accesses + + +class TensorAccessSequence(abc.MutableSequence, abc.Iterable): + """ + TensorAccessSequence is a MutableSequence and an Iterable which is a thin wrapper around a list[TensorAccessPattern]. + """ + + def __init__( + self, + tensor_dims: Sequence[int], + num_steps: int, + offset: int | None = None, + sizes: Sequence[int] | None = None, + strides: Sequence[int] | None = None, + offset_fn: Callable[[int, int], int] | None = None, + sizes_fn: Callable[[int, Sequence[int]], Sequence[int]] | None = None, + strides_fn: Callable[[int, Sequence[int]], Sequence[int]] | None = None, + ): + self._current_step = 0 + + # Check tensor dims, offset, sizes, strides + self._tensor_dims = validate_tensor_dims(tensor_dims) + if not (offset is None): + offset = validate_offset(offset, self._tensor_dims) + sizes, strides = validate_and_clean_sizes_strides( + sizes, strides, allow_none=True + ) + + # Validate and set num steps + if num_steps < 0: + raise ValueError(f"Number of steps must be positive (but is {num_steps})") + + if num_steps == 0: + if ( + offset != None + or sizes != None + or strides != None + or offset_fn != None + or sizes_fn != None + or strides_fn != None + ): + raise ValueError( + f"If num_steps=0, no sizes/strides/offset information may be specified" + ) + self._taps = [] + else: + # Make sure values or not None if iteration functions are None; also set default iter fn + if offset_fn is None: + if offset is None: + raise ValueError("Offset must be provided if offset_fn is None") + offset_fn = lambda _step, _prev_offset: offset + else: + offset_fn = offset_fn + if sizes_fn is None: + if sizes is None: + raise ValueError("Sizes must be provided if size_fn is None") + sizes_fn = lambda _step, _prev_sizes: sizes + else: + sizes_fn = sizes_fn + if strides_fn is None: + if strides is None: + raise ValueError("Strides must be provided if stride_fn is None") + strides_fn = lambda _step, _prev_strides: strides + else: + strides_fn = strides_fn + + # Pre-calculate taps, because better for error handling up-front (and for visualizing full iter) + # This is somewhat against the mentality behind iterations, but should be okay at the scale this + # class will be used for (e.g., no scalability concerns with keeping all taps in mem) + self._taps = [] + for step in range(num_steps): + offset = offset_fn(step, offset) + sizes = sizes_fn(step, sizes) + strides = strides_fn(step, strides) + + self._taps.append( + TensorAccessPattern( + self._tensor_dims, + offset, + sizes, + strides, + ) + ) + + @classmethod + def from_taps(cls, taps: Sequence[TensorAccessPattern]) -> TensorAccessSequence: + if len(taps) < 1: + raise ValueError( + "Received no TensorAccessPatterns; must have at least one TensorAccessPatterns to create a TensorAccessSequence." + ) + tensor_dims = taps[0].tensor_dims + for t in taps: + if t.tensor_dims != tensor_dims: + raise ValueError( + f"TensorAccessPatterns have multiple tensor dimensions (found {tensor_dims} and {t.tensor_dims})" + ) + tas = cls( + tensor_dims, + num_steps=1, + offset=taps[0].offset, + sizes=taps[0].sizes, + strides=taps[0].strides, + ) + for t in taps[1:]: + tas.append(t) + return tas + + def accesses(self) -> tuple[np.ndarray, np.ndarray]: + return self._calc_accesses(True, True) + + def access_order(self) -> np.ndarray: + access_order, _ = self._calc_accesses(calc_order=True, calc_count=False) + return access_order + + def access_count(self) -> np.ndarray: + _, access_count = self._calc_accesses(calc_order=False, calc_count=True) + return access_count + + def _calc_accesses( + self, calc_order: bool, calc_count: bool + ) -> tuple[np.ndarray, np.ndarray]: + if not calc_order and not calc_count: + raise ValueError("Must select calc_order, calc_count, or both") + + total_elems = np.prod(self._tensor_dims) + combined_access_order_tensor = None + combined_access_count_tensor = None + + if calc_order: + combined_access_order_tensor = np.full( + total_elems, 0, TensorAccessPattern._DTYPE + ).reshape(self._tensor_dims) + highest_count = 0 + if calc_count: + combined_access_count_tensor = np.full( + total_elems, 0, TensorAccessPattern._DTYPE + ).reshape(self._tensor_dims) + for t in self._taps: + if calc_order and calc_count: + t_access_order, t_access_count = t.accesses() + elif calc_order: + t_access_order = t.access_order() + else: + t_access_count = t.access_count() + + if calc_order: + t_access_order[t_access_order != -1] += 1 + highest_count + t_access_order[t_access_order == -1] = 0 + combined_access_order_tensor += t_access_order + highest_count = np.max(combined_access_order_tensor) + if calc_count: + combined_access_count_tensor += t_access_count + + if calc_order: + combined_access_order_tensor -= 1 + return (combined_access_order_tensor, combined_access_count_tensor) + + def animate( + self, title: str = None, animate_access_count: bool = False + ) -> animation.FuncAnimation: + if len(self._tensor_dims) != 2: + raise NotImplementedError( + "Visualization is only currently supported for 1- or 2-dimensional tensors" + ) + + if title is None: + title = "TensorAccessSequence Animation" + total_elems = np.prod(self._tensor_dims) + + animate_order_frames = [ + np.full(total_elems, -1, TensorAccessPattern._DTYPE).reshape( + self._tensor_dims + ) + ] + + animate_count_frames = None + if animate_access_count: + animate_count_frames = [ + np.full(total_elems, 0, TensorAccessPattern._DTYPE).reshape( + self._tensor_dims + ) + ] + + for t in self._taps: + if animate_access_count: + t_access_order, t_access_count = t.accesses() + animate_count_frames.append(t_access_count) + else: + t_access_order = t.access_order() + animate_order_frames.append(t_access_order) + + return animate_from_accesses( + animate_order_frames, + animate_count_frames, + title=title, + ) + + def visualize( + self, + title: str = None, + file_path: str | None = None, + show_plot: bool = True, + plot_access_count: bool = False, + ) -> None: + if len(self._tensor_dims) != 2: + raise NotImplementedError( + "Visualization is only currently supported for 1- or 2-dimensional tensors" + ) + + if title is None: + title = "TensorAccessSequence" + if plot_access_count: + access_order_tensor, access_count_tensor = self.accesses() + else: + access_order_tensor = self.access_order() + access_count_tensor = None + + visualize_from_accesses( + access_order_tensor, + access_count_tensor, + title=title, + show_arrows=False, + file_path=file_path, + show_plot=show_plot, + ) + + def compare_access_orders(self, other: TensorAccessSequence) -> bool: + if len(self._taps) != len(other._taps): + return False + for my_tap, other_tap in zip(self._taps, other._taps): + if not my_tap.compare_access_orders(other_tap): + return False + return True + + def __contains__(self, tap: TensorAccessPattern): + return tap in self._taps + + def __iter__(self): + return iter(self._taps) + + def __len__(self) -> int: + return len(self._taps) + + def __getitem__(self, idx: int) -> TensorAccessPattern: + return self._taps[idx] + + def __setitem__(self, idx: int, tap: TensorAccessPattern): + if self._tensor_dims != tap.tensor_dims: + raise ValueError( + f"Cannot add TensorAccessPattern with tensor dims {tap.tensor_dims} to TensorAccessSequence with tensor dims {self._tensor_dims}" + ) + self._taps[idx] = deepcopy(tap) + + def __delitem__(self, idx: int): + del self._taps[idx] + + def insert(self, idx: int, tap: TensorAccessPattern): + if self._tensor_dims != tap.tensor_dims: + raise ValueError( + f"Cannot add TensorAccessPattern with tensor dims {tap.tensor_dims} to TensorAccessSequence with tensor dims {self._tensor_dims}" + ) + self._taps.insert(idx, tap) + + def __eq__(self, other): + if isinstance(other, self.__class__): + return ( + self._taps == other._taps and self._current_step == other._current_step + ) + else: + return False + + def __ne__(self, other): + return not self.__eq__(other) diff --git a/python/helpers/tensortiler/tensortiler2d.py b/python/helpers/taplib/tensortiler2d.py similarity index 98% rename from python/helpers/tensortiler/tensortiler2d.py rename to python/helpers/taplib/tensortiler2d.py index 0df5de8d61..b2afc896b3 100644 --- a/python/helpers/tensortiler/tensortiler2d.py +++ b/python/helpers/taplib/tensortiler2d.py @@ -3,13 +3,13 @@ import numpy as np from typing import Sequence -from .tensortilesequence import TensorTileSequence +from .tas import TensorAccessSequence from .utils import ceildiv, validate_and_clean_sizes_strides, validate_tensor_dims class TensorTiler2D: """ - This is a generator (similar to factory pattern) class which produces TensorTileSequence + This is a generator (similar to factory pattern) class which produces TensorAccessSequence objects for common 2-dimensional tiling patterns. """ @@ -18,7 +18,7 @@ class TensorTiler2D: def __init__(self): raise Exception( - f"{self.__class__} cannot be instantiated. Use it as a factory/generator of TensorTileSequences." + f"{self.__class__} cannot be instantiated. Use it as a factory/generator of TensorAccessSequences." ) @classmethod @@ -29,7 +29,7 @@ def simple_tiler( tile_col_major: bool = False, iter_col_major: bool = False, pattern_repeat: int = 1, - ) -> TensorTileSequence: + ) -> TensorAccessSequence: if tile_dims is None: tile_dims = deepcopy(tensor_dims) # Special case of group_tiler @@ -52,7 +52,7 @@ def group_tiler( iter_col_major: bool = False, pattern_repeat: int = 1, allow_partial: bool = False, - ) -> TensorTileSequence: + ) -> TensorAccessSequence: if tile_group_dims is None: tile_group_dims = (1,) * cls._NUM_DIMS # Special case of step_tiler @@ -79,7 +79,7 @@ def step_tiler( iter_col_major: bool = False, allow_partial: bool = False, pattern_repeat: int = 1, - ) -> TensorTileSequence: + ) -> TensorAccessSequence: if tile_group_steps is None: tile_group_steps = (1,) * cls._NUM_DIMS tensor_dims = validate_tensor_dims(tensor_dims, expected_dims=cls._NUM_DIMS) @@ -177,7 +177,7 @@ def sizes_or_strides_fn(step_num, _prev_sizes, is_sizes): sizes_fn = partial(sizes_or_strides_fn, is_sizes=True) strides_fn = partial(sizes_or_strides_fn, is_sizes=False) - return TensorTileSequence( + return TensorAccessSequence( tensor_dims, num_steps, sizes_fn=sizes_fn, diff --git a/python/helpers/tensortiler/utils.py b/python/helpers/taplib/utils.py similarity index 92% rename from python/helpers/tensortiler/utils.py rename to python/helpers/taplib/utils.py index 4b567d2d5c..eeff3af862 100644 --- a/python/helpers/tensortiler/utils.py +++ b/python/helpers/taplib/utils.py @@ -1,4 +1,5 @@ from copy import deepcopy +import numpy as np from typing import Sequence @@ -109,7 +110,12 @@ def validate_tensor_dims( return tensor_dims -def validate_offset(offset: int): +def validate_offset(offset: int, tensor_dims: Sequence[int] | None): if offset < 0: raise ValueError(f"Offset must be >= 0 (offset={offset})") + if tensor_dims: + if offset >= np.prod(tensor_dims): + raise ValueError( + f"Offset too large: {offset}. Max value allowed for tensor: {np.prod(tensor_dims)}" + ) return offset diff --git a/python/helpers/tensortiler/visualization2d.py b/python/helpers/taplib/visualization2d.py similarity index 98% rename from python/helpers/tensortiler/visualization2d.py rename to python/helpers/taplib/visualization2d.py index 7244475f8e..d767e14a6e 100644 --- a/python/helpers/tensortiler/visualization2d.py +++ b/python/helpers/taplib/visualization2d.py @@ -8,7 +8,7 @@ from .utils import ceildiv -def animate_from_access_tensors( +def animate_from_accesses( access_order_tensors: list[np.ndarray], access_count_tensors: list[np.ndarray] | None, title: str = "Animated Access Visualization", @@ -78,7 +78,7 @@ def animate_order(i): return _animation -def visualize_from_access_tensors( +def visualize_from_accesses( access_order_tensor: np.ndarray, access_count_tensor: np.ndarray | None, title: str = "Access Visualization", diff --git a/python/helpers/tensortiler/__init__.py b/python/helpers/tensortiler/__init__.py deleted file mode 100644 index 5641295b7f..0000000000 --- a/python/helpers/tensortiler/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -from .tensortile import TensorTile -from .tensortilesequence import ( - TensorTileSequence, -) -from .tensortiler2d import TensorTiler2D diff --git a/python/helpers/tensortiler/tensortilesequence.py b/python/helpers/tensortiler/tensortilesequence.py deleted file mode 100644 index 6a40f9cb23..0000000000 --- a/python/helpers/tensortiler/tensortilesequence.py +++ /dev/null @@ -1,255 +0,0 @@ -from __future__ import annotations -from collections import abc -from copy import deepcopy -import matplotlib.animation as animation -import numpy as np -from typing import Callable, Sequence - -from .tensortile import TensorTile -from .utils import ( - validate_and_clean_sizes_strides, - validate_offset, - validate_tensor_dims, -) -from .visualization2d import animate_from_access_tensors, visualize_from_access_tensors - - -class TensorTileSequence(abc.MutableSequence, abc.Iterable): - """ - TensorTileSequence is a MutableSequence and an Iterable which is a thin wrapper around a list[TensorTiles]. - """ - - def __init__( - self, - tensor_dims: Sequence[int], - num_steps: int, - offset: int | None = None, - sizes: Sequence[int] | None = None, - strides: Sequence[int] | None = None, - offset_fn: Callable[[int, int], int] | None = None, - sizes_fn: Callable[[int, Sequence[int]], Sequence[int]] | None = None, - strides_fn: Callable[[int, Sequence[int]], Sequence[int]] | None = None, - ): - self._current_step = 0 - - # Check tensor dims, offset, sizes, strides - self._tensor_dims = validate_tensor_dims(tensor_dims) - if not (offset is None): - offset = validate_offset(offset) - sizes, strides = validate_and_clean_sizes_strides( - sizes, strides, allow_none=True - ) - - # Validate and set num steps - if num_steps < 0: - raise ValueError(f"Number of steps must be positive (but is {num_steps})") - - if num_steps == 0: - if ( - offset != None - or sizes != None - or strides != None - or offset_fn != None - or sizes_fn != None - or strides_fn != None - ): - raise ValueError( - f"If num_steps=0, no sizes/strides/offset information may be specified" - ) - self._tiles = [] - else: - # Make sure values or not None if iteration functions are None; also set default iter fn - if offset_fn is None: - if offset is None: - raise ValueError("Offset must be provided if offset_fn is None") - offset_fn = lambda _step, _prev_offset: offset - else: - offset_fn = offset_fn - if sizes_fn is None: - if sizes is None: - raise ValueError("Sizes must be provided if size_fn is None") - sizes_fn = lambda _step, _prev_sizes: sizes - else: - sizes_fn = sizes_fn - if strides_fn is None: - if strides is None: - raise ValueError("Strides must be provided if stride_fn is None") - strides_fn = lambda _step, _prev_strides: strides - else: - strides_fn = strides_fn - - # Pre-calculate tiles, because better for error handling up-front (and for visualizing full iter) - # This is somewhat against the mentality behind iterations, but should be okay at the scale this - # class will be used for (e.g., no scalability concerns with keeping all tiles in mem) - self._tiles = [] - for step in range(num_steps): - offset = offset_fn(step, offset) - sizes = sizes_fn(step, sizes) - strides = strides_fn(step, strides) - - self._tiles.append( - TensorTile( - self._tensor_dims, - offset, - sizes, - strides, - ) - ) - - @classmethod - def from_tiles(cls, tiles: Sequence[TensorTile]) -> TensorTileSequence: - if len(tiles) < 1: - raise ValueError( - "Received no tiles; must have at least one tile to create a tile sequence." - ) - tensor_dims = tiles[0].tensor_dims - for t in tiles: - if t.tensor_dims != tensor_dims: - raise ValueError( - f"Tiles have multiple tensor dimensions (found {tensor_dims} and {t.tensor_dims})" - ) - tileseq = cls( - tensor_dims, - num_steps=1, - offset=tiles[0].offset, - sizes=tiles[0].sizes, - strides=tiles[0].strides, - ) - for t in tiles[1:]: - tileseq.append(t) - return tileseq - - def access_tensors(self) -> tuple[np.ndarray, np.ndarray]: - total_elems = np.prod(self._tensor_dims) - - combined_access_order_tensor = np.full( - total_elems, 0, TensorTile._DTYPE - ).reshape(self._tensor_dims) - combined_access_count_tensor = np.full( - total_elems, 0, TensorTile._DTYPE - ).reshape(self._tensor_dims) - highest_count = 0 - for t in self._tiles: - t_access_order, t_access_count = t.access_tensors() - t_access_order[t_access_order != -1] += 1 + highest_count - t_access_order[t_access_order == -1] = 0 - combined_access_order_tensor += t_access_order - highest_count = np.max(combined_access_order_tensor) - - combined_access_count_tensor += t_access_count - - combined_access_order_tensor -= 1 - return (combined_access_order_tensor, combined_access_count_tensor) - - def animate( - self, title: str = None, animate_access_count: bool = False - ) -> animation.FuncAnimation: - if title is None: - title = "TensorTileSequence Animation" - if len(self._tensor_dims) == 2: - total_elems = np.prod(self._tensor_dims) - - animate_order_frames = [ - np.full(total_elems, -1, TensorTile._DTYPE).reshape(self._tensor_dims) - ] - if animate_access_count: - animate_count_frames = [ - np.full(total_elems, 0, TensorTile._DTYPE).reshape( - self._tensor_dims - ) - ] - else: - animate_count_frames = None - - for t in self._tiles: - t_access_order, t_access_count = t.access_tensors() - animate_order_frames.append(t_access_order) - if animate_access_count: - animate_count_frames.append(t_access_count) - - return animate_from_access_tensors( - animate_order_frames, - animate_count_frames, - title=title, - ) - - else: - raise NotImplementedError( - "Visualization is only currently supported for 1- or 2-dimensional tensors" - ) - - def visualize( - self, - title: str = None, - file_path: str | None = None, - show_plot: bool = True, - plot_access_count: bool = False, - ) -> None: - if len(self._tensor_dims) != 2: - raise NotImplementedError( - "Visualization is only currently supported for 1- or 2-dimensional tensors" - ) - - if title is None: - title = "TensorTileSequence" - access_order_tensor, access_count_tensor = self.access_tensors() - if not plot_access_count: - access_count_tensor = None - - visualize_from_access_tensors( - access_order_tensor, - access_count_tensor, - title=title, - show_arrows=False, - file_path=file_path, - show_plot=show_plot, - ) - - def compare_tile_access_orders(self, other: TensorTileSequence) -> bool: - if len(self._tiles) != len(other._tiles): - return False - for my_tile, other_tile in zip(self._tiles, other._tiles): - if not my_tile.compare_access_orders(other_tile): - return False - return True - - def __contains__(self, tile: TensorTile): - return tile in self._tiles - - def __iter__(self): - return iter(deepcopy(self._tiles)) - - def __len__(self) -> int: - return len(self._tiles) - - def __getitem__(self, idx: int) -> TensorTile: - return self._tiles[idx] - - def __setitem__(self, idx: int, tile: TensorTile): - if self._tensor_dims != tile.tensor_dims: - raise ValueError( - f"Cannot add tile with tensor dims {tile.tensor_dims} to sequence of tiles with tensor dims {self._tensor_dims}" - ) - self._tiles[idx] = deepcopy(tile) - - def __delitem__(self, idx: int): - del self._tiles[idx] - - def insert(self, idx: int, tile: TensorTile): - if self._tensor_dims != tile.tensor_dims: - raise ValueError( - f"Cannot add tile with tensor dims {tile.tensor_dims} to sequence of tiles with tensor dims {self._tensor_dims}" - ) - self._tiles.insert(idx, tile) - - def __eq__(self, other): - if isinstance(other, self.__class__): - return ( - self._tiles == other._tiles - and self._current_step == other._current_step - ) - else: - return False - - def __ne__(self, other): - return not self.__eq__(other) diff --git a/test/python/tensortiler/group_tiler.py b/test/python/taplib/group_tiler.py similarity index 94% rename from test/python/tensortiler/group_tiler.py rename to test/python/taplib/group_tiler.py index 527ce8397e..ef2c349699 100644 --- a/test/python/tensortiler/group_tiler.py +++ b/test/python/taplib/group_tiler.py @@ -1,6 +1,6 @@ import numpy as np -from aie.helpers.tensortiler import TensorTile, TensorTiler2D +from aie.helpers.taplib import TensorAccessPattern, TensorTiler2D from util import construct_test # RUN: %python %s | FileCheck %s @@ -10,8 +10,8 @@ @construct_test def group_tiler(): # Default tile group dims - tiles = TensorTiler2D.group_tiler((3 * 5, 2 * 7), tile_dims=(3, 2)) - assert len(tiles) == 5 * 7 + taps = TensorTiler2D.group_tiler((3 * 5, 2 * 7), tile_dims=(3, 2)) + assert len(taps) == 5 * 7 # fmt: off ref_access_order_tensor = np.array([ [ 0, 1, 6, 7, 12, 13, 18, 19, 24, 25, 30, 31, 36, 37], @@ -30,26 +30,26 @@ def group_tiler(): [170, 171, 176, 177, 182, 183, 188, 189, 194, 195, 200, 201, 206, 207], [172, 173, 178, 179, 184, 185, 190, 191, 196, 197, 202, 203, 208, 209]]) # fmt: on - access_order, access_count = tiles.access_tensors() + access_order, access_count = taps.accesses() assert (access_order == ref_access_order_tensor).all() assert (access_count == 1).all() - tiles = TensorTiler2D.group_tiler( + taps = TensorTiler2D.group_tiler( (3 * 5 * 3, 2 * 7 * 2), tile_dims=(3, 2), tile_group_dims=(5, 7) ) - assert len(tiles) == 3 * 2 - tile0_0 = TensorTile( + assert len(taps) == 3 * 2 + tile0_0 = TensorAccessPattern( (3 * 5 * 3, 2 * 7 * 2), offset=0, sizes=[5, 7, 3, 2], strides=[84, 2, 28, 1] ) - assert tiles[0] == tile0_0 - tile0_1 = TensorTile( + assert taps[0] == tile0_0 + tile0_1 = TensorAccessPattern( (3 * 5 * 3, 2 * 7 * 2), offset=14, sizes=[5, 7, 3, 2], strides=[84, 2, 28, 1] ) - assert tiles[1] == tile0_1 - tile1_0 = TensorTile( + assert taps[1] == tile0_1 + tile1_0 = TensorAccessPattern( (3 * 5 * 3, 2 * 7 * 2), offset=420, sizes=[5, 7, 3, 2], strides=[84, 2, 28, 1] ) - assert tiles[2] == tile1_0 + assert taps[2] == tile1_0 # fmt: off ref_access_order_tensor = np.array([ @@ -99,20 +99,20 @@ def group_tiler(): [1010, 1011, 1016, 1017, 1022, 1023, 1028, 1029, 1034, 1035, 1040, 1041, 1046, 1047, 1220, 1221, 1226, 1227, 1232, 1233, 1238, 1239, 1244, 1245, 1250, 1251, 1256, 1257], [1012, 1013, 1018, 1019, 1024, 1025, 1030, 1031, 1036, 1037, 1042, 1043, 1048, 1049, 1222, 1223, 1228, 1229, 1234, 1235, 1240, 1241, 1246, 1247, 1252, 1253, 1258, 1259]]) # fmt: on - access_order, access_count = tiles.access_tensors() + access_order, access_count = taps.accesses() assert (access_order == ref_access_order_tensor).all() assert (access_count == 1).all() # iter_col_major - tiles_col_iter = TensorTiler2D.group_tiler( + taps_col_iter = TensorTiler2D.group_tiler( (3 * 5 * 3, 2 * 7 * 2), tile_dims=(3, 2), tile_group_dims=(5, 7), iter_col_major=True, ) - assert tiles_col_iter[0] == tile0_0 - assert tiles_col_iter[1] == tile1_0 - assert tiles_col_iter[3] == tile0_1 + assert taps_col_iter[0] == tile0_0 + assert taps_col_iter[1] == tile1_0 + assert taps_col_iter[3] == tile0_1 # fmt: off ref_access_order_tensor = np.array([ @@ -162,29 +162,29 @@ def group_tiler(): [ 590, 591, 596, 597, 602, 603, 608, 609, 614, 615, 620, 621, 626, 627, 1220, 1221, 1226, 1227, 1232, 1233, 1238, 1239, 1244, 1245, 1250, 1251, 1256, 1257], [ 592, 593, 598, 599, 604, 605, 610, 611, 616, 617, 622, 623, 628, 629, 1222, 1223, 1228, 1229, 1234, 1235, 1240, 1241, 1246, 1247, 1252, 1253, 1258, 1259]]) # fmt: on - access_order, access_count = tiles_col_iter.access_tensors() + access_order, access_count = taps_col_iter.accesses() assert (access_order == ref_access_order_tensor).all() assert (access_count == 1).all() # tile_col_major - tiles_tile_col_major = TensorTiler2D.group_tiler( + taps_tile_col_major = TensorTiler2D.group_tiler( (3 * 5 * 3, 2 * 7 * 2), tile_dims=(3, 2), tile_group_dims=(5, 7), tile_col_major=True, ) - tile0_0 = TensorTile( + tile0_0 = TensorAccessPattern( (3 * 5 * 3, 2 * 7 * 2), offset=0, sizes=[1, 5, 14, 3], strides=[0, 84, 1, 28] ) - assert tiles_tile_col_major[0] == tile0_0 - tile0_1 = TensorTile( + assert taps_tile_col_major[0] == tile0_0 + tile0_1 = TensorAccessPattern( (3 * 5 * 3, 2 * 7 * 2), offset=14, sizes=[1, 5, 14, 3], strides=[0, 84, 1, 28] ) - assert tiles_tile_col_major[1] == tile0_1 - tile1_0 = TensorTile( + assert taps_tile_col_major[1] == tile0_1 + tile1_0 = TensorAccessPattern( (3 * 5 * 3, 2 * 7 * 2), offset=420, sizes=[1, 5, 14, 3], strides=[0, 84, 1, 28] ) - assert tiles_tile_col_major[2] == tile1_0 + assert taps_tile_col_major[2] == tile1_0 # fmt: off ref_access_order_tensor = np.array([ @@ -234,31 +234,31 @@ def group_tiler(): [1009, 1012, 1015, 1018, 1021, 1024, 1027, 1030, 1033, 1036, 1039, 1042, 1045, 1048, 1219, 1222, 1225, 1228, 1231, 1234, 1237, 1240, 1243, 1246, 1249, 1252, 1255, 1258], [1010, 1013, 1016, 1019, 1022, 1025, 1028, 1031, 1034, 1037, 1040, 1043, 1046, 1049, 1220, 1223, 1226, 1229, 1232, 1235, 1238, 1241, 1244, 1247, 1250, 1253, 1256, 1259]]) # fmt: on - access_order, access_count = tiles_tile_col_major.access_tensors() + access_order, access_count = taps_tile_col_major.accesses() assert (access_order == ref_access_order_tensor).all() assert (access_count == 1).all() # iter_col_major and tile_col_major - tiles_tile_col_major_col_iter = TensorTiler2D.group_tiler( + taps_tile_col_major_col_iter = TensorTiler2D.group_tiler( (3 * 5 * 3, 2 * 7 * 2), tile_dims=(3, 2), tile_group_dims=(5, 7), iter_col_major=True, tile_col_major=True, ) - assert tiles_tile_col_major_col_iter[0] == tile0_0 - assert tiles_tile_col_major_col_iter[1] == tile1_0 - assert tiles_tile_col_major_col_iter[3] == tile0_1 + assert taps_tile_col_major_col_iter[0] == tile0_0 + assert taps_tile_col_major_col_iter[1] == tile1_0 + assert taps_tile_col_major_col_iter[3] == tile0_1 # tile_col_major and pattern_repeat - tiles_tile_col_major_pattern_repeat = TensorTiler2D.group_tiler( + taps_tile_col_major_pattern_repeat = TensorTiler2D.group_tiler( (3 * 5 * 3, 2 * 7 * 2), tile_dims=(3, 2), tile_group_dims=(5, 7), tile_col_major=True, pattern_repeat=2, ) - assert tiles_tile_col_major_pattern_repeat[0] == TensorTile( + assert taps_tile_col_major_pattern_repeat[0] == TensorAccessPattern( (3 * 5 * 3, 2 * 7 * 2), offset=0, sizes=[2, 5, 14, 3], strides=[0, 84, 1, 28] ) @@ -310,29 +310,29 @@ def group_tiler(): [2059, 2062, 2065, 2068, 2071, 2074, 2077, 2080, 2083, 2086, 2089, 2092, 2095, 2098, 2479, 2482, 2485, 2488, 2491, 2494, 2497, 2500, 2503, 2506, 2509, 2512, 2515, 2518], [2060, 2063, 2066, 2069, 2072, 2075, 2078, 2081, 2084, 2087, 2090, 2093, 2096, 2099, 2480, 2483, 2486, 2489, 2492, 2495, 2498, 2501, 2504, 2507, 2510, 2513, 2516, 2519]]) # fmt: on - access_order, access_count = tiles_tile_col_major_pattern_repeat.access_tensors() + access_order, access_count = taps_tile_col_major_pattern_repeat.accesses() assert (access_order == ref_access_order_tensor).all() assert (access_count == 2).all() # tile_group_col_major - tiles_group_col_major = TensorTiler2D.group_tiler( + taps_group_col_major = TensorTiler2D.group_tiler( (3 * 5 * 3, 2 * 7 * 2), tile_dims=(3, 2), tile_group_dims=(5, 7), tile_group_col_major=True, ) - tile0_0 = TensorTile( + tile0_0 = TensorAccessPattern( (3 * 5 * 3, 2 * 7 * 2), offset=0, sizes=[1, 7, 15, 2], strides=[0, 2, 28, 1] ) - assert tiles_group_col_major[0] == tile0_0 - tile0_1 = TensorTile( + assert taps_group_col_major[0] == tile0_0 + tile0_1 = TensorAccessPattern( (3 * 5 * 3, 2 * 7 * 2), offset=14, sizes=[1, 7, 15, 2], strides=[0, 2, 28, 1] ) - assert tiles_group_col_major[1] == tile0_1 - tile1_0 = TensorTile( + assert taps_group_col_major[1] == tile0_1 + tile1_0 = TensorAccessPattern( (3 * 5 * 3, 2 * 7 * 2), offset=420, sizes=[1, 7, 15, 2], strides=[0, 2, 28, 1] ) - assert tiles_group_col_major[2] == tile1_0 + assert taps_group_col_major[2] == tile1_0 # fmt: off ref_access_order_tensor = np.array([ @@ -382,30 +382,30 @@ def group_tiler(): [ 866, 867, 896, 897, 926, 927, 956, 957, 986, 987, 1016, 1017, 1046, 1047, 1076, 1077, 1106, 1107, 1136, 1137, 1166, 1167, 1196, 1197, 1226, 1227, 1256, 1257], [ 868, 869, 898, 899, 928, 929, 958, 959, 988, 989, 1018, 1019, 1048, 1049, 1078, 1079, 1108, 1109, 1138, 1139, 1168, 1169, 1198, 1199, 1228, 1229, 1258, 1259]]) # fmt: on - access_order, access_count = tiles_group_col_major.access_tensors() + access_order, access_count = taps_group_col_major.accesses() assert (access_order == ref_access_order_tensor).all() assert (access_count == 1).all() # tile_group_col_major and tile_col_major - tiles_group_col_major = TensorTiler2D.group_tiler( + taps_group_col_major = TensorTiler2D.group_tiler( (3 * 5 * 3, 2 * 7 * 2), tile_dims=(3, 2), tile_group_dims=(5, 7), tile_col_major=True, tile_group_col_major=True, ) - tile0_0 = TensorTile( + tile0_0 = TensorAccessPattern( (3 * 5 * 3, 2 * 7 * 2), offset=0, sizes=[7, 5, 2, 3], strides=[2, 84, 1, 28] ) - assert tiles_group_col_major[0] == tile0_0 - tile0_1 = TensorTile( + assert taps_group_col_major[0] == tile0_0 + tile0_1 = TensorAccessPattern( (3 * 5 * 3, 2 * 7 * 2), offset=14, sizes=[7, 5, 2, 3], strides=[2, 84, 1, 28] ) - assert tiles_group_col_major[1] == tile0_1 - tile1_0 = TensorTile( + assert taps_group_col_major[1] == tile0_1 + tile1_0 = TensorAccessPattern( (3 * 5 * 3, 2 * 7 * 2), offset=420, sizes=[7, 5, 2, 3], strides=[2, 84, 1, 28] ) - assert tiles_group_col_major[2] == tile1_0 + assert taps_group_col_major[2] == tile1_0 # fmt: off ref_access_order_tensor = np.array([ @@ -455,7 +455,7 @@ def group_tiler(): [ 865, 868, 895, 898, 925, 928, 955, 958, 985, 988, 1015, 1018, 1045, 1048, 1075, 1078, 1105, 1108, 1135, 1138, 1165, 1168, 1195, 1198, 1225, 1228, 1255, 1258], [ 866, 869, 896, 899, 926, 929, 956, 959, 986, 989, 1016, 1019, 1046, 1049, 1076, 1079, 1106, 1109, 1136, 1139, 1166, 1169, 1196, 1199, 1226, 1229, 1256, 1259]]) # fmt: on - access_order, access_count = tiles_group_col_major.access_tensors() + access_order, access_count = taps_group_col_major.accesses() assert (access_order == ref_access_order_tensor).all() assert (access_count == 1).all() @@ -467,7 +467,7 @@ def group_tiler(): @construct_test def group_tiler_invalid(): try: - tiles = TensorTiler2D.group_tiler( + taps = TensorTiler2D.group_tiler( (), (3, 2), (1, 1), tile_col_major=True, pattern_repeat=5 ) raise ValueError("Bad tensor dims, should fail.") @@ -475,7 +475,7 @@ def group_tiler_invalid(): # good pass try: - tiles = TensorTiler2D.group_tiler( + taps = TensorTiler2D.group_tiler( (10, 9, 4), (3, 2), (1, 1), tile_col_major=True, pattern_repeat=5 ) raise ValueError("Too many tensor dims, should fail.") @@ -483,7 +483,7 @@ def group_tiler_invalid(): # good pass try: - tiles = TensorTiler2D.group_tiler( + taps = TensorTiler2D.group_tiler( (9, 4), (3, -1), (1, 1), tile_col_major=True, pattern_repeat=5 ) raise ValueError("Bad tile dims, should fail.") @@ -491,7 +491,7 @@ def group_tiler_invalid(): # good pass try: - tiles = TensorTiler2D.group_tiler( + taps = TensorTiler2D.group_tiler( (9, 4), (3,), (1, 1), tile_col_major=True, pattern_repeat=5 ) raise ValueError("Too few tile dims, should fail.") @@ -499,7 +499,7 @@ def group_tiler_invalid(): # good pass try: - tiles = TensorTiler2D.group_tiler( + taps = TensorTiler2D.group_tiler( (9, 4), (1, 1, 1), (1, 1), tile_col_major=True, pattern_repeat=5 ) raise ValueError("Too many tile dims, should fail.") @@ -507,7 +507,7 @@ def group_tiler_invalid(): # good pass try: - tiles = TensorTiler2D.group_tiler( + taps = TensorTiler2D.group_tiler( (9, 4), (3, 2), (1, 1), tile_col_major=True, pattern_repeat=0 ) raise ValueError("Invalid repeat.") @@ -515,7 +515,7 @@ def group_tiler_invalid(): # good pass try: - tiles = TensorTiler2D.group_tiler( + taps = TensorTiler2D.group_tiler( (9, 4), (4, 2), (1, 1), tile_col_major=True, pattern_repeat=5 ) raise ValueError("Indivisible tile (height)") @@ -523,7 +523,7 @@ def group_tiler_invalid(): # good pass try: - tiles = TensorTiler2D.group_tiler( + taps = TensorTiler2D.group_tiler( (9, 4), (3, 3), (1, 1), tile_col_major=True, pattern_repeat=5 ) raise ValueError("Indivisible tile (width)") @@ -532,7 +532,7 @@ def group_tiler_invalid(): pass try: - tiles = TensorTiler2D.group_tiler( + taps = TensorTiler2D.group_tiler( (9, 4), (3, 2), (1,), tile_col_major=True, pattern_repeat=5 ) raise ValueError("Too few tile group dims, should fail.") @@ -540,7 +540,7 @@ def group_tiler_invalid(): # good pass try: - tiles = TensorTiler2D.group_tiler( + taps = TensorTiler2D.group_tiler( (9, 4), (3, 2), (1, -1), tile_col_major=True, pattern_repeat=5 ) raise ValueError("Bad tile group dims, should fail.") @@ -548,15 +548,13 @@ def group_tiler_invalid(): # good pass try: - tiles = TensorTiler2D.group_tiler( - (9, 4), (3, 2), (1, 1, 1), tile_col_major=True - ) + taps = TensorTiler2D.group_tiler((9, 4), (3, 2), (1, 1, 1), tile_col_major=True) raise ValueError("Too many tile group dims, should fail.") except ValueError: # good pass try: - tiles = TensorTiler2D.group_tiler((18, 8), (3, 2), (2, 3), tile_col_major=True) + taps = TensorTiler2D.group_tiler((18, 8), (3, 2), (2, 3), tile_col_major=True) raise ValueError( "Indivisible by tile repeat width (but without allow_partial)." ) @@ -564,7 +562,7 @@ def group_tiler_invalid(): # good pass try: - tiles = TensorTiler2D.group_tiler((18, 8), (3, 2), (4, 2), tile_col_major=True) + taps = TensorTiler2D.group_tiler((18, 8), (3, 2), (4, 2), tile_col_major=True) raise ValueError( "Indivisible by tile repeat height (but without allow_partial)." ) diff --git a/test/python/tensortiler/group_tiler_partial.py b/test/python/taplib/group_tiler_partial.py similarity index 68% rename from test/python/tensortiler/group_tiler_partial.py rename to test/python/taplib/group_tiler_partial.py index 22963bf053..3c619edd69 100644 --- a/test/python/tensortiler/group_tiler_partial.py +++ b/test/python/taplib/group_tiler_partial.py @@ -1,4 +1,4 @@ -from aie.helpers.tensortiler import TensorTile, TensorTileSequence, TensorTiler2D +from aie.helpers.taplib import TensorAccessPattern, TensorAccessSequence, TensorTiler2D from util import construct_test # RUN: %python %s | FileCheck %s @@ -11,135 +11,135 @@ def group_tiler_partial_row(): tensor_dims = (3 * 5 * 3, 2 * 6 * 2) # All row major - tiles = TensorTiler2D.group_tiler( + taps = TensorTiler2D.group_tiler( tensor_dims, tile_dims=(3, 2), tile_group_dims=(5, 7), allow_partial=True ) - reference_tiles = TensorTileSequence.from_tiles( + reference_taps = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[5, 7, 3, 2], strides=[72, 2, 24, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=14, sizes=[5, 5, 3, 2], strides=[72, 2, 24, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=360, sizes=[5, 7, 3, 2], strides=[72, 2, 24, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=374, sizes=[5, 5, 3, 2], strides=[72, 2, 24, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=720, sizes=[5, 7, 3, 2], strides=[72, 2, 24, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=734, sizes=[5, 5, 3, 2], strides=[72, 2, 24, 1] ), ] ) - assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert taps == reference_taps + assert taps.compare_access_orders(reference_taps) # Tile col major - tiles = TensorTiler2D.group_tiler( + taps = TensorTiler2D.group_tiler( tensor_dims, tile_dims=(3, 2), tile_group_dims=(5, 7), tile_col_major=True, allow_partial=True, ) - reference_tiles = TensorTileSequence.from_tiles( + reference_taps = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[1, 5, 14, 3], strides=[0, 72, 1, 24] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=14, sizes=[1, 5, 10, 3], strides=[0, 72, 1, 24] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=360, sizes=[1, 5, 14, 3], strides=[0, 72, 1, 24] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=374, sizes=[1, 5, 10, 3], strides=[0, 72, 1, 24] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=720, sizes=[1, 5, 14, 3], strides=[0, 72, 1, 24] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=734, sizes=[1, 5, 10, 3], strides=[0, 72, 1, 24] ), ] ) - assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert taps == reference_taps + assert taps.compare_access_orders(reference_taps) # Tile group col major - tiles = TensorTiler2D.group_tiler( + taps = TensorTiler2D.group_tiler( tensor_dims, tile_dims=(3, 2), tile_group_dims=(5, 7), tile_group_col_major=True, allow_partial=True, ) - reference_tiles = TensorTileSequence.from_tiles( + reference_taps = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[1, 7, 15, 2], strides=[0, 2, 24, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=14, sizes=[1, 5, 15, 2], strides=[0, 2, 24, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=360, sizes=[1, 7, 15, 2], strides=[0, 2, 24, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=374, sizes=[1, 5, 15, 2], strides=[0, 2, 24, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=720, sizes=[1, 7, 15, 2], strides=[0, 2, 24, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=734, sizes=[1, 5, 15, 2], strides=[0, 2, 24, 1] ), ] ) - assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert taps == reference_taps + assert taps.compare_access_orders(reference_taps) # iter col major - tiles = TensorTiler2D.group_tiler( + taps = TensorTiler2D.group_tiler( tensor_dims, tile_dims=(3, 2), tile_group_dims=(5, 7), iter_col_major=True, allow_partial=True, ) - reference_tiles = TensorTileSequence.from_tiles( + reference_taps = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[5, 7, 3, 2], strides=[72, 2, 24, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=360, sizes=[5, 7, 3, 2], strides=[72, 2, 24, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=720, sizes=[5, 7, 3, 2], strides=[72, 2, 24, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=14, sizes=[5, 5, 3, 2], strides=[72, 2, 24, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=374, sizes=[5, 5, 3, 2], strides=[72, 2, 24, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=734, sizes=[5, 5, 3, 2], strides=[72, 2, 24, 1] ), ] ) - assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert taps == reference_taps + assert taps.compare_access_orders(reference_taps) # all col major - tiles = TensorTiler2D.group_tiler( + taps = TensorTiler2D.group_tiler( tensor_dims, tile_dims=(3, 2), tile_group_dims=(5, 7), @@ -148,33 +148,33 @@ def group_tiler_partial_row(): iter_col_major=True, allow_partial=True, ) - reference_tiles = TensorTileSequence.from_tiles( + reference_taps = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[7, 5, 2, 3], strides=[2, 72, 1, 24] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=360, sizes=[7, 5, 2, 3], strides=[2, 72, 1, 24] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=720, sizes=[7, 5, 2, 3], strides=[2, 72, 1, 24] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=14, sizes=[5, 5, 2, 3], strides=[2, 72, 1, 24] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=374, sizes=[5, 5, 2, 3], strides=[2, 72, 1, 24] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=734, sizes=[5, 5, 2, 3], strides=[2, 72, 1, 24] ), ] ) - assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert taps == reference_taps + assert taps.compare_access_orders(reference_taps) # pattern repeat - tiles = TensorTiler2D.group_tiler( + taps = TensorTiler2D.group_tiler( tensor_dims, tile_dims=(3, 2), tile_group_dims=(5, 7), @@ -182,30 +182,30 @@ def group_tiler_partial_row(): allow_partial=True, pattern_repeat=4, ) - reference_tiles = TensorTileSequence.from_tiles( + reference_taps = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[4, 5, 14, 3], strides=[0, 72, 1, 24] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=14, sizes=[4, 5, 10, 3], strides=[0, 72, 1, 24] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=360, sizes=[4, 5, 14, 3], strides=[0, 72, 1, 24] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=374, sizes=[4, 5, 10, 3], strides=[0, 72, 1, 24] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=720, sizes=[4, 5, 14, 3], strides=[0, 72, 1, 24] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=734, sizes=[4, 5, 10, 3], strides=[0, 72, 1, 24] ), ] ) - assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert taps == reference_taps + assert taps.compare_access_orders(reference_taps) # CHECK: Pass! print("Pass!") @@ -217,135 +217,135 @@ def group_tiler_partial_col(): # All row major tensor_dims = (3 * 4 * 3, 2 * 7 * 2) - tiles = TensorTiler2D.group_tiler( + taps = TensorTiler2D.group_tiler( tensor_dims, tile_dims=(3, 2), tile_group_dims=(5, 7), allow_partial=True ) - reference_tiles = TensorTileSequence.from_tiles( + reference_taps = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[5, 7, 3, 2], strides=[84, 2, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=14, sizes=[5, 7, 3, 2], strides=[84, 2, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=420, sizes=[5, 7, 3, 2], strides=[84, 2, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=434, sizes=[5, 7, 3, 2], strides=[84, 2, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=840, sizes=[2, 7, 3, 2], strides=[84, 2, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=854, sizes=[2, 7, 3, 2], strides=[84, 2, 28, 1] ), ] ) - assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert taps == reference_taps + assert taps.compare_access_orders(reference_taps) # Tile col major - tiles = TensorTiler2D.group_tiler( + taps = TensorTiler2D.group_tiler( tensor_dims, tile_dims=(3, 2), tile_group_dims=(5, 7), tile_col_major=True, allow_partial=True, ) - reference_tiles = TensorTileSequence.from_tiles( + reference_taps = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[1, 5, 14, 3], strides=[0, 84, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=14, sizes=[1, 5, 14, 3], strides=[0, 84, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=420, sizes=[1, 5, 14, 3], strides=[0, 84, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=434, sizes=[1, 5, 14, 3], strides=[0, 84, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=840, sizes=[1, 2, 14, 3], strides=[0, 84, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=854, sizes=[1, 2, 14, 3], strides=[0, 84, 1, 28] ), ] ) - assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert taps == reference_taps + assert taps.compare_access_orders(reference_taps) # Tile group col major - tiles = TensorTiler2D.group_tiler( + taps = TensorTiler2D.group_tiler( tensor_dims, tile_dims=(3, 2), tile_group_dims=(5, 7), tile_group_col_major=True, allow_partial=True, ) - reference_tiles = TensorTileSequence.from_tiles( + reference_taps = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[1, 7, 15, 2], strides=[0, 2, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=14, sizes=[1, 7, 15, 2], strides=[0, 2, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=420, sizes=[1, 7, 15, 2], strides=[0, 2, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=434, sizes=[1, 7, 15, 2], strides=[0, 2, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=840, sizes=[1, 7, 6, 2], strides=[0, 2, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=854, sizes=[1, 7, 6, 2], strides=[0, 2, 28, 1] ), ] ) - assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert taps == reference_taps + assert taps.compare_access_orders(reference_taps) # iter col major - tiles = TensorTiler2D.group_tiler( + taps = TensorTiler2D.group_tiler( tensor_dims, tile_dims=(3, 2), tile_group_dims=(5, 7), iter_col_major=True, allow_partial=True, ) - reference_tiles = TensorTileSequence.from_tiles( + reference_taps = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[5, 7, 3, 2], strides=[84, 2, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=420, sizes=[5, 7, 3, 2], strides=[84, 2, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=840, sizes=[2, 7, 3, 2], strides=[84, 2, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=14, sizes=[5, 7, 3, 2], strides=[84, 2, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=434, sizes=[5, 7, 3, 2], strides=[84, 2, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=854, sizes=[2, 7, 3, 2], strides=[84, 2, 28, 1] ), ] ) - assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert taps == reference_taps + assert taps.compare_access_orders(reference_taps) # all col major - tiles = TensorTiler2D.group_tiler( + taps = TensorTiler2D.group_tiler( tensor_dims, tile_dims=(3, 2), tile_group_dims=(5, 7), @@ -354,33 +354,33 @@ def group_tiler_partial_col(): iter_col_major=True, allow_partial=True, ) - reference_tiles = TensorTileSequence.from_tiles( + reference_taps = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[7, 5, 2, 3], strides=[2, 84, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=420, sizes=[7, 5, 2, 3], strides=[2, 84, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=840, sizes=[7, 2, 2, 3], strides=[2, 84, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=14, sizes=[7, 5, 2, 3], strides=[2, 84, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=434, sizes=[7, 5, 2, 3], strides=[2, 84, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=854, sizes=[7, 2, 2, 3], strides=[2, 84, 1, 28] ), ] ) - assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert taps == reference_taps + assert taps.compare_access_orders(reference_taps) # pattern repeat - tiles = TensorTiler2D.group_tiler( + taps = TensorTiler2D.group_tiler( tensor_dims, tile_dims=(3, 2), tile_group_dims=(5, 7), @@ -388,30 +388,30 @@ def group_tiler_partial_col(): allow_partial=True, pattern_repeat=3, ) - reference_tiles = TensorTileSequence.from_tiles( + reference_taps = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[3, 5, 14, 3], strides=[0, 84, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=14, sizes=[3, 5, 14, 3], strides=[0, 84, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=420, sizes=[3, 5, 14, 3], strides=[0, 84, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=434, sizes=[3, 5, 14, 3], strides=[0, 84, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=840, sizes=[3, 2, 14, 3], strides=[0, 84, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=854, sizes=[3, 2, 14, 3], strides=[0, 84, 1, 28] ), ] ) - assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert taps == reference_taps + assert taps.compare_access_orders(reference_taps) # CHECK: Pass! print("Pass!") @@ -423,40 +423,40 @@ def group_tiler_partial_both(): # All row major tensor_dims = (3 * 4 * 3, 2 * 6 * 2) - tiles = TensorTiler2D.group_tiler( + taps = TensorTiler2D.group_tiler( tensor_dims, tile_dims=(3, 2), tile_group_dims=(5, 7), allow_partial=True, ) - reference_tiles = TensorTileSequence.from_tiles( + reference_taps = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[5, 7, 3, 2], strides=[72, 2, 24, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=14, sizes=[5, 5, 3, 2], strides=[72, 2, 24, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=360, sizes=[5, 7, 3, 2], strides=[72, 2, 24, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=374, sizes=[5, 5, 3, 2], strides=[72, 2, 24, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=720, sizes=[2, 7, 3, 2], strides=[72, 2, 24, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=734, sizes=[2, 5, 3, 2], strides=[72, 2, 24, 1] ), ] ) - assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert taps == reference_taps + assert taps.compare_access_orders(reference_taps) # Tile col major - tiles = TensorTiler2D.group_tiler( + taps = TensorTiler2D.group_tiler( tensor_dims, tile_dims=(3, 2), tile_group_dims=(5, 7), @@ -464,33 +464,33 @@ def group_tiler_partial_both(): allow_partial=True, ) - reference_tiles = TensorTileSequence.from_tiles( + reference_taps = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[1, 5, 14, 3], strides=[0, 72, 1, 24] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=14, sizes=[1, 5, 10, 3], strides=[0, 72, 1, 24] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=360, sizes=[1, 5, 14, 3], strides=[0, 72, 1, 24] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=374, sizes=[1, 5, 10, 3], strides=[0, 72, 1, 24] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=720, sizes=[1, 2, 14, 3], strides=[0, 72, 1, 24] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=734, sizes=[1, 2, 10, 3], strides=[0, 72, 1, 24] ), ] ) - assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert taps == reference_taps + assert taps.compare_access_orders(reference_taps) # Tile group col major - tiles = TensorTiler2D.group_tiler( + taps = TensorTiler2D.group_tiler( tensor_dims, tile_dims=(3, 2), tile_group_dims=(5, 7), @@ -498,33 +498,33 @@ def group_tiler_partial_both(): allow_partial=True, ) - reference_tiles = TensorTileSequence.from_tiles( + reference_taps = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[1, 7, 15, 2], strides=[0, 2, 24, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=14, sizes=[1, 5, 15, 2], strides=[0, 2, 24, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=360, sizes=[1, 7, 15, 2], strides=[0, 2, 24, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=374, sizes=[1, 5, 15, 2], strides=[0, 2, 24, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=720, sizes=[1, 7, 6, 2], strides=[0, 2, 24, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=734, sizes=[1, 5, 6, 2], strides=[0, 2, 24, 1] ), ] ) - assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert taps == reference_taps + assert taps.compare_access_orders(reference_taps) # iter col major - tiles = TensorTiler2D.group_tiler( + taps = TensorTiler2D.group_tiler( tensor_dims, tile_dims=(3, 2), tile_group_dims=(5, 7), @@ -532,33 +532,33 @@ def group_tiler_partial_both(): allow_partial=True, ) - reference_tiles = TensorTileSequence.from_tiles( + reference_taps = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[5, 7, 3, 2], strides=[72, 2, 24, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=360, sizes=[5, 7, 3, 2], strides=[72, 2, 24, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=720, sizes=[2, 7, 3, 2], strides=[72, 2, 24, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=14, sizes=[5, 5, 3, 2], strides=[72, 2, 24, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=374, sizes=[5, 5, 3, 2], strides=[72, 2, 24, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=734, sizes=[2, 5, 3, 2], strides=[72, 2, 24, 1] ), ] ) - assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert taps == reference_taps + assert taps.compare_access_orders(reference_taps) # all col major - tiles = TensorTiler2D.group_tiler( + taps = TensorTiler2D.group_tiler( tensor_dims, tile_dims=(3, 2), tile_group_dims=(5, 7), @@ -568,33 +568,33 @@ def group_tiler_partial_both(): allow_partial=True, ) - reference_tiles = TensorTileSequence.from_tiles( + reference_taps = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[7, 5, 2, 3], strides=[2, 72, 1, 24] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=360, sizes=[7, 5, 2, 3], strides=[2, 72, 1, 24] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=720, sizes=[7, 2, 2, 3], strides=[2, 72, 1, 24] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=14, sizes=[5, 5, 2, 3], strides=[2, 72, 1, 24] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=374, sizes=[5, 5, 2, 3], strides=[2, 72, 1, 24] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=734, sizes=[5, 2, 2, 3], strides=[2, 72, 1, 24] ), ] ) - assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert taps == reference_taps + assert taps.compare_access_orders(reference_taps) # pattern repeat - tiles = TensorTiler2D.group_tiler( + taps = TensorTiler2D.group_tiler( tensor_dims, tile_dims=(3, 2), tile_group_dims=(5, 7), @@ -603,30 +603,30 @@ def group_tiler_partial_both(): pattern_repeat=2, ) - reference_tiles = TensorTileSequence.from_tiles( + reference_taps = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[2, 5, 14, 3], strides=[0, 72, 1, 24] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=14, sizes=[2, 5, 10, 3], strides=[0, 72, 1, 24] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=360, sizes=[2, 5, 14, 3], strides=[0, 72, 1, 24] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=374, sizes=[2, 5, 10, 3], strides=[0, 72, 1, 24] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=720, sizes=[2, 2, 14, 3], strides=[0, 72, 1, 24] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=734, sizes=[2, 2, 10, 3], strides=[0, 72, 1, 24] ), ] ) - assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert taps == reference_taps + assert taps.compare_access_orders(reference_taps) # CHECK: Pass! print("Pass!") diff --git a/test/python/tensortiler/matmul_matrix_vector_tiling_sweep.py b/test/python/taplib/matmul_matrix_vector_tiling_sweep.py similarity index 64% rename from test/python/tensortiler/matmul_matrix_vector_tiling_sweep.py rename to test/python/taplib/matmul_matrix_vector_tiling_sweep.py index 4f4174d39f..df72010720 100644 --- a/test/python/tensortiler/matmul_matrix_vector_tiling_sweep.py +++ b/test/python/taplib/matmul_matrix_vector_tiling_sweep.py @@ -1,4 +1,4 @@ -from aie.helpers.tensortiler import TensorTile, TensorTiler2D +from aie.helpers.taplib import TensorAccessPattern, TensorTiler2D from util import construct_test # RUN: %python %s | FileCheck %s @@ -28,7 +28,7 @@ def matrix_vector_tiling_sweep(): (M, K), (m, k), (M_div_m_div_n_cores, K // k) ) ) - B_tile = TensorTiler2D.simple_tiler( + B_tap = TensorTiler2D.simple_tiler( (1, K), (1, K), pattern_repeat=M_div_m_div_n_cores )[0] C_iter = iter( @@ -37,13 +37,13 @@ def matrix_vector_tiling_sweep(): B_sizes = [M_div_m_div_n_cores, 1, 1, K] B_strides = [0, 0, 0, 1] - if B_sizes != B_tile.sizes or B_strides != B_tile.strides: - B_tile_ref = TensorTile( + if B_sizes != B_tap.sizes or B_strides != B_tap.strides: + B_tap_ref = TensorAccessPattern( (1, K), offset=0, sizes=B_sizes, strides=B_strides ) - assert B_tile.compare_access_orders( - B_tile_ref - ), f"B tile {B_tile} and ref tile {B_tile_ref} are not functionally equivalent." + assert B_tap.compare_access_orders( + B_tap_ref + ), f"B tile {B_tap} and ref tile {B_tap_ref} are not functionally equivalent." for i in range(n_cores): # Current way of calculting sizes/strides/offsets @@ -52,19 +52,19 @@ def matrix_vector_tiling_sweep(): A_strides = [m_x_K, k, K, 1] # Tile iter way to calculating sizes/strides/offsets - A_tile = next(A_iter) + A_tap = next(A_iter) if ( - A_sizes != A_tile.sizes - or A_offset != A_tile.offset - or A_strides != A_tile.strides + A_sizes != A_tap.sizes + or A_offset != A_tap.offset + or A_strides != A_tap.strides ): # There may be different but equivalent transformations - A_tile_ref = TensorTile( + A_tap_ref = TensorAccessPattern( (M, K), offset=A_offset, sizes=A_sizes, strides=A_strides ) - assert A_tile.compare_access_orders( - A_tile_ref - ), f"A tile {A_tile} and ref tile {A_tile_ref} are not functionally equivalent." + assert A_tap.compare_access_orders( + A_tap_ref + ), f"A tile {A_tap} and ref tile {A_tap_ref} are not functionally equivalent." # Current way of calculting sizes/strides/offsets C_offset = i * M_div_m_div_n_cores * m @@ -72,19 +72,19 @@ def matrix_vector_tiling_sweep(): C_strides = [0, 0, 0, 1] # Tile iter way to calculating sizes/strides/offsets - C_tile = next(C_iter) + C_tap = next(C_iter) if ( - C_sizes != C_tile.sizes - or C_offset != C_tile.offset - or C_strides != C_tile.strides + C_sizes != C_tap.sizes + or C_offset != C_tap.offset + or C_strides != C_tap.strides ): # There may be different but equivalent transformations - C_tile_ref = TensorTile( + C_tap_ref = TensorAccessPattern( (1, C_sz), offset=C_offset, sizes=C_sizes, strides=C_strides ) - assert C_tile.compare_access_orders( - C_tile_ref - ), f"C tile {C_tile} and ref tile {C_tile_ref} are not functionally equivalent." + assert C_tap.compare_access_orders( + C_tap_ref + ), f"C tile {C_tap} and ref tile {C_tap_ref} are not functionally equivalent." # CHECK: Pass! print("Pass!") diff --git a/test/python/tensortiler/matmul_whole_array_tiling_sweep.py b/test/python/taplib/matmul_whole_array_tiling_sweep.py similarity index 93% rename from test/python/tensortiler/matmul_whole_array_tiling_sweep.py rename to test/python/taplib/matmul_whole_array_tiling_sweep.py index e79cc9c8d5..603378d652 100644 --- a/test/python/tensortiler/matmul_whole_array_tiling_sweep.py +++ b/test/python/taplib/matmul_whole_array_tiling_sweep.py @@ -6,8 +6,8 @@ # (c) Copyright 2023 AMD Inc. import random -from aie.helpers.tensortiler import TensorTile, TensorTileSequence, TensorTiler2D -from aie.helpers.tensortiler.utils import ceildiv +from aie.helpers.taplib import TensorAccessPattern, TensorAccessSequence, TensorTiler2D +from aie.helpers.taplib.utils import ceildiv from util import construct_test # RUN: %python %s | FileCheck %s @@ -103,9 +103,9 @@ def matmul_tiler_helper(M, K, N, m, k, n, n_aie_cols, b_col_maj, n_aie_rows): A_ordered_tiles.append(A_tiles[tile_offset]) B_ordered_tiles.append(B_tiles[col]) - A_ordered_tiles = TensorTileSequence.from_tiles(A_ordered_tiles) - B_ordered_tiles = TensorTileSequence.from_tiles(B_ordered_tiles) - C_ordered_tiles = TensorTileSequence.from_tiles(C_ordered_tiles) + A_ordered_tiles = TensorAccessSequence.from_taps(A_ordered_tiles) + B_ordered_tiles = TensorAccessSequence.from_taps(B_ordered_tiles) + C_ordered_tiles = TensorAccessSequence.from_taps(C_ordered_tiles) return A_ordered_tiles, B_ordered_tiles, C_ordered_tiles @@ -146,7 +146,9 @@ def matmul_reference(M, K, N, m, k, n, n_aie_cols, b_col_maj, n_aie_rows): C_offset = C_col_offset + C_row_offset C_sizes = [tb_n_rows, N // n // n_aie_cols, m * n_aie_rows, n] C_strides = [m * n_aie_rows * N, n * n_aie_cols, N, 1] - c_tile = TensorTile((M, N), C_offset, sizes=C_sizes, strides=C_strides) + c_tile = TensorAccessPattern( + (M, N), C_offset, sizes=C_sizes, strides=C_strides + ) C_tiles.append(c_tile) for tile_row in range(tb_n_rows): @@ -165,7 +167,7 @@ def matmul_reference(M, K, N, m, k, n, n_aie_cols, b_col_maj, n_aie_rows): k, ] A_strides = [0, k, K, 1] - a_tile = TensorTile( + a_tile = TensorAccessPattern( (M, K), A_offset, sizes=A_sizes, strides=A_strides ) A_tiles.append(a_tile) @@ -181,14 +183,14 @@ def matmul_reference(M, K, N, m, k, n, n_aie_cols, b_col_maj, n_aie_rows): if not b_col_maj else [n * n_aie_cols * K, k, K, 1] ) - b_tile = TensorTile( + b_tile = TensorAccessPattern( (K, N), B_col_offset, sizes=B_sizes, strides=B_strides ) B_tiles.append(b_tile) - A_tiles = TensorTileSequence.from_tiles(A_tiles) - B_tiles = TensorTileSequence.from_tiles(B_tiles) - C_tiles = TensorTileSequence.from_tiles(C_tiles) + A_tiles = TensorAccessSequence.from_taps(A_tiles) + B_tiles = TensorAccessSequence.from_taps(B_tiles) + C_tiles = TensorAccessSequence.from_taps(C_tiles) return A_tiles, B_tiles, C_tiles diff --git a/test/python/tensortiler/rectangular_tiler.py b/test/python/taplib/rectangular_tiler.py similarity index 93% rename from test/python/tensortiler/rectangular_tiler.py rename to test/python/taplib/rectangular_tiler.py index ca054bf9ef..fb7b20b0ba 100644 --- a/test/python/tensortiler/rectangular_tiler.py +++ b/test/python/taplib/rectangular_tiler.py @@ -1,6 +1,6 @@ import numpy as np -from aie.helpers.tensortiler import TensorTiler2D +from aie.helpers.taplib import TensorTiler2D from util import construct_test # RUN: %python %s | FileCheck %s @@ -10,7 +10,7 @@ @construct_test def rectangular_tiler(): tiler = TensorTiler2D.simple_tiler((16, 8), (4, 4)) - access_order, access_count = tiler.access_tensors() + access_order, access_count = tiler.accesses() reference_access = np.array( # fmt: off [ @@ -62,7 +62,7 @@ def rectangular_tiler(): tile_count = 0 for t in tiler: if tile_count == 6: - tile_access_order, _ = t.access_tensors() + tile_access_order = t.access_order() assert (tile_access_order == tile1_reference_order).all() tile_count += 1 assert tile_count == (16 // 4) * (8 // 4) diff --git a/test/python/tensortiler/rectangular_tiler2.py b/test/python/taplib/rectangular_tiler2.py similarity index 92% rename from test/python/tensortiler/rectangular_tiler2.py rename to test/python/taplib/rectangular_tiler2.py index e1b5280147..83142a88f2 100644 --- a/test/python/tensortiler/rectangular_tiler2.py +++ b/test/python/taplib/rectangular_tiler2.py @@ -1,6 +1,6 @@ import numpy as np -from aie.helpers.tensortiler import TensorTiler2D +from aie.helpers.taplib import TensorTiler2D from util import construct_test # RUN: %python %s | FileCheck %s @@ -10,7 +10,7 @@ @construct_test def rectangular_tiler2(): tiler = TensorTiler2D.simple_tiler((12, 8), (3, 2)) - access_order, access_count = tiler.access_tensors() + access_order, access_count = tiler.accesses() reference_access = np.array( # fmt: off [ @@ -54,7 +54,7 @@ def rectangular_tiler2(): tile_count = 0 for t in tiler: if tile_count == 12: - tile_access_order, _ = t.access_tensors() + tile_access_order = t.access_order() assert (tile_access_order == tile1_reference_order).all() tile_count += 1 assert tile_count == (12 // 3) * (8 // 2) diff --git a/test/python/tensortiler/rectangular_tiler_col_major_tensor.py b/test/python/taplib/rectangular_tiler_col_major_tensor.py similarity index 92% rename from test/python/tensortiler/rectangular_tiler_col_major_tensor.py rename to test/python/taplib/rectangular_tiler_col_major_tensor.py index ec24d6ff95..57e2668493 100644 --- a/test/python/tensortiler/rectangular_tiler_col_major_tensor.py +++ b/test/python/taplib/rectangular_tiler_col_major_tensor.py @@ -1,6 +1,6 @@ import numpy as np -from aie.helpers.tensortiler.tensortiler2d import TensorTiler2D +from aie.helpers.taplib import TensorTiler2D from util import construct_test # RUN: %python %s | FileCheck %s @@ -10,7 +10,7 @@ @construct_test def rectangular_tiler_col_major_tensor(): tiler = TensorTiler2D.simple_tiler((8, 16), (4, 2), iter_col_major=True) - access_order, access_count = tiler.access_tensors() + access_order, access_count = tiler.accesses() reference_access = np.array( # fmt: off [ @@ -46,7 +46,7 @@ def rectangular_tiler_col_major_tensor(): tile_count = 0 for t in tiler: if tile_count == 4: - tile_access_order, _ = t.access_tensors() + tile_access_order = t.access_order() assert (tile_access_order == tile1_reference_order).all() tile_count += 1 assert tile_count == (8 // 4) * (16 // 2) diff --git a/test/python/tensortiler/rectangular_tiler_col_major_tensor_and_tiler.py b/test/python/taplib/rectangular_tiler_col_major_tensor_and_tiler.py similarity index 93% rename from test/python/tensortiler/rectangular_tiler_col_major_tensor_and_tiler.py rename to test/python/taplib/rectangular_tiler_col_major_tensor_and_tiler.py index eb44244fa0..8b2f92275d 100644 --- a/test/python/tensortiler/rectangular_tiler_col_major_tensor_and_tiler.py +++ b/test/python/taplib/rectangular_tiler_col_major_tensor_and_tiler.py @@ -1,6 +1,6 @@ import numpy as np -from aie.helpers.tensortiler import TensorTiler2D +from aie.helpers.taplib import TensorTiler2D from util import construct_test # RUN: %python %s | FileCheck %s @@ -12,7 +12,7 @@ def rectangular_tiler_col_major_tensor_and_tile(): tiler = TensorTiler2D.simple_tiler( (16, 8), (4, 2), iter_col_major=True, tile_col_major=True ) - access_order, access_count = tiler.access_tensors() + access_order, access_count = tiler.accesses() reference_access = np.array( # fmt: off [ @@ -64,7 +64,7 @@ def rectangular_tiler_col_major_tensor_and_tile(): tile_count = 0 for t in tiler: if tile_count == 2: - tile_access_order, _ = t.access_tensors() + tile_access_order = t.access_order() assert (tile_access_order == tile1_reference_order).all() tile_count += 1 assert tile_count == (16 // 4) * (8 // 2) diff --git a/test/python/tensortiler/simple_tiler.py b/test/python/taplib/simple_tiler.py similarity index 82% rename from test/python/tensortiler/simple_tiler.py rename to test/python/taplib/simple_tiler.py index 8763233c9f..fad58009d0 100644 --- a/test/python/tensortiler/simple_tiler.py +++ b/test/python/taplib/simple_tiler.py @@ -1,6 +1,6 @@ import numpy as np -from aie.helpers.tensortiler import TensorTile, TensorTileSequence, TensorTiler2D +from aie.helpers.taplib import TensorAccessPattern, TensorAccessSequence, TensorTiler2D from util import construct_test # RUN: %python %s | FileCheck %s @@ -11,7 +11,9 @@ def simple_tiler(): single_tile = TensorTiler2D.simple_tiler((3, 5)) assert len(single_tile) == 1 - ref_tile = TensorTile((3, 5), offset=0, sizes=[1, 1, 3, 5], strides=[0, 0, 5, 1]) + ref_tile = TensorAccessPattern( + (3, 5), offset=0, sizes=[1, 1, 3, 5], strides=[0, 0, 5, 1] + ) assert single_tile[0] == ref_tile tiles = TensorTiler2D.simple_tiler((9, 4), (3, 2)) @@ -28,7 +30,7 @@ def simple_tiler(): [26, 27, 32, 33], [28, 29, 34, 35]]) # fmt: on - access_order, access_count = tiles.access_tensors() + access_order, access_count = tiles.accesses() assert (access_order == ref_access_order_tensor).all() assert (access_count == 1).all() @@ -36,7 +38,7 @@ def offset_fn(step, _prev_offset): offsets = [0, 2, 12, 14, 24, 26] return offsets[step] - tiles2 = TensorTileSequence( + tiles2 = TensorAccessSequence( (9, 4), num_steps=6, sizes=[1, 1, 3, 2], @@ -45,17 +47,25 @@ def offset_fn(step, _prev_offset): ) assert tiles == tiles2 - tile0_0 = TensorTile((9, 4), offset=0, sizes=[1, 1, 3, 2], strides=[0, 0, 4, 1]) - tile0_1 = TensorTile((9, 4), offset=2, sizes=[1, 1, 3, 2], strides=[0, 0, 4, 1]) - tile1_0 = TensorTile((9, 4), offset=12, sizes=[1, 1, 3, 2], strides=[0, 0, 4, 1]) - tile1_1 = TensorTile((9, 4), offset=14, sizes=[1, 1, 3, 2], strides=[0, 0, 4, 1]) + tile0_0 = TensorAccessPattern( + (9, 4), offset=0, sizes=[1, 1, 3, 2], strides=[0, 0, 4, 1] + ) + tile0_1 = TensorAccessPattern( + (9, 4), offset=2, sizes=[1, 1, 3, 2], strides=[0, 0, 4, 1] + ) + tile1_0 = TensorAccessPattern( + (9, 4), offset=12, sizes=[1, 1, 3, 2], strides=[0, 0, 4, 1] + ) + tile1_1 = TensorAccessPattern( + (9, 4), offset=14, sizes=[1, 1, 3, 2], strides=[0, 0, 4, 1] + ) assert tiles2[0] == tile0_0 assert tiles2[1] == tile0_1 assert tiles2[2] == tile1_0 assert tiles2[3] == tile1_1 - access_order, access_count = tiles2.access_tensors() + access_order, access_count = tiles2.accesses() assert (access_order == ref_access_order_tensor).all() assert (access_count == 1).all() @@ -80,17 +90,25 @@ def offset_fn(step, _prev_offset): [14, 15, 32, 33], [16, 17, 34, 35]]) # fmt: on - access_order, access_count = tiles_iter_col_major.access_tensors() + access_order, access_count = tiles_iter_col_major.accesses() assert (access_order == ref_access_order_tensor).all() assert (access_count == 1).all() tiles_tile_col_major = TensorTiler2D.simple_tiler( (9, 4), (3, 2), tile_col_major=True ) - tile0_0 = TensorTile((9, 4), offset=0, sizes=[1, 1, 2, 3], strides=[0, 0, 1, 4]) - tile0_1 = TensorTile((9, 4), offset=2, sizes=[1, 1, 2, 3], strides=[0, 0, 1, 4]) - tile1_0 = TensorTile((9, 4), offset=12, sizes=[1, 1, 2, 3], strides=[0, 0, 1, 4]) - tile1_1 = TensorTile((9, 4), offset=14, sizes=[1, 1, 2, 3], strides=[0, 0, 1, 4]) + tile0_0 = TensorAccessPattern( + (9, 4), offset=0, sizes=[1, 1, 2, 3], strides=[0, 0, 1, 4] + ) + tile0_1 = TensorAccessPattern( + (9, 4), offset=2, sizes=[1, 1, 2, 3], strides=[0, 0, 1, 4] + ) + tile1_0 = TensorAccessPattern( + (9, 4), offset=12, sizes=[1, 1, 2, 3], strides=[0, 0, 1, 4] + ) + tile1_1 = TensorAccessPattern( + (9, 4), offset=14, sizes=[1, 1, 2, 3], strides=[0, 0, 1, 4] + ) assert tiles_tile_col_major[0] == tile0_0 assert tiles_tile_col_major[1] == tile0_1 assert tiles_tile_col_major[2] == tile1_0 @@ -108,7 +126,7 @@ def offset_fn(step, _prev_offset): [25, 28, 31, 34], [26, 29, 32, 35]]) # fmt: on - access_order, access_count = tiles_tile_col_major.access_tensors() + access_order, access_count = tiles_tile_col_major.accesses() assert (access_order == ref_access_order_tensor).all() assert (access_count == 1).all() @@ -132,12 +150,12 @@ def offset_fn(step, _prev_offset): [13, 16, 31, 34], [14, 17, 32, 35]]) # fmt: on - access_order, access_count = tiles_tile_col_major_iter_col_major.access_tensors() + access_order, access_count = tiles_tile_col_major_iter_col_major.accesses() assert (access_order == ref_access_order_tensor).all() assert (access_count == 1).all() tiles_repeat = TensorTiler2D.simple_tiler((9, 4), (3, 2), pattern_repeat=5) - tile_repeat0_0 = TensorTile( + tile_repeat0_0 = TensorAccessPattern( (9, 4), offset=0, sizes=[1, 5, 3, 2], strides=[0, 0, 4, 1] ) assert tiles_repeat[0] == tile_repeat0_0 @@ -154,14 +172,14 @@ def offset_fn(step, _prev_offset): [146, 147, 176, 177], [148, 149, 178, 179]]) # fmt: on - access_order, access_count = tiles_repeat.access_tensors() + access_order, access_count = tiles_repeat.accesses() assert (access_order == ref_access_order_tensor).all() assert (access_count == 5).all() tiles_repeat = TensorTiler2D.simple_tiler( (9, 4), (3, 2), tile_col_major=True, pattern_repeat=5 ) - tile_repeat0_0 = TensorTile( + tile_repeat0_0 = TensorAccessPattern( (9, 4), offset=0, sizes=[1, 5, 2, 3], strides=[0, 0, 1, 4] ) assert tiles_repeat[0] == tile_repeat0_0 @@ -178,7 +196,7 @@ def offset_fn(step, _prev_offset): [145, 148, 175, 178], [146, 149, 176, 179]]) # fmt: on - access_order, access_count = tiles_repeat.access_tensors() + access_order, access_count = tiles_repeat.accesses() assert (access_order == ref_access_order_tensor).all() assert (access_count == 5).all() diff --git a/test/python/tensortiler/sizes_strides_clean.py b/test/python/taplib/sizes_strides_clean.py similarity index 94% rename from test/python/tensortiler/sizes_strides_clean.py rename to test/python/taplib/sizes_strides_clean.py index 63749d04f1..86226b8036 100644 --- a/test/python/tensortiler/sizes_strides_clean.py +++ b/test/python/taplib/sizes_strides_clean.py @@ -1,6 +1,4 @@ -import numpy as np - -from aie.helpers.tensortiler.utils import validate_and_clean_sizes_strides +from aie.helpers.taplib.utils import validate_and_clean_sizes_strides from util import construct_test # RUN: %python %s | FileCheck %s diff --git a/test/python/tensortiler/square_tiler.py b/test/python/taplib/square_tiler.py similarity index 98% rename from test/python/tensortiler/square_tiler.py rename to test/python/taplib/square_tiler.py index 9e6bc9743b..6b02163702 100644 --- a/test/python/tensortiler/square_tiler.py +++ b/test/python/taplib/square_tiler.py @@ -1,6 +1,6 @@ import numpy as np -from aie.helpers.tensortiler import TensorTiler2D +from aie.helpers.taplib import TensorTiler2D from util import construct_test # RUN: %python %s | FileCheck %s @@ -10,7 +10,7 @@ @construct_test def square_tiler(): tiler = TensorTiler2D.simple_tiler((32, 32), (4, 4)) - access_order, access_count = tiler.access_tensors() + access_order, access_count = tiler.accesses() reference_access = np.array( # fmt: off [ @@ -91,7 +91,7 @@ def square_tiler(): # fmt: on ) - tile_access_order, _ = tiler[1].access_tensors() + tile_access_order = tiler[1].access_order() assert (tile_access_order == tile1_reference_order).all() assert len(tiler) == 64 diff --git a/test/python/tensortiler/square_tiler2.py b/test/python/taplib/square_tiler2.py similarity index 98% rename from test/python/tensortiler/square_tiler2.py rename to test/python/taplib/square_tiler2.py index 8d1be13050..92c61ac700 100644 --- a/test/python/tensortiler/square_tiler2.py +++ b/test/python/taplib/square_tiler2.py @@ -1,6 +1,6 @@ import numpy as np -from aie.helpers.tensortiler import TensorTiler2D +from aie.helpers.taplib import TensorTiler2D from util import construct_test # RUN: %python %s | FileCheck %s @@ -10,7 +10,7 @@ @construct_test def square_tiler2(): tiler = TensorTiler2D.simple_tiler((32, 32), (8, 8)) - access_order, access_count = tiler.access_tensors() + access_order, access_count = tiler.accesses() reference_access = np.array( # fmt: off [ @@ -91,7 +91,7 @@ def square_tiler2(): # fmt: on ) - tile_access_order, _ = tiler[3].access_tensors() + tile_access_order = tiler[3].access_order() assert (tile_access_order == tile1_reference_order).all() assert len(tiler) == (32 // 8) * (32 // 8) diff --git a/test/python/tensortiler/square_tiler_col_major_tensor_and_tile_tile_grouping.py b/test/python/taplib/square_tiler_col_major_tensor_and_tile_tile_grouping.py similarity index 97% rename from test/python/tensortiler/square_tiler_col_major_tensor_and_tile_tile_grouping.py rename to test/python/taplib/square_tiler_col_major_tensor_and_tile_tile_grouping.py index c4b2a77ce0..6d85791199 100644 --- a/test/python/tensortiler/square_tiler_col_major_tensor_and_tile_tile_grouping.py +++ b/test/python/taplib/square_tiler_col_major_tensor_and_tile_tile_grouping.py @@ -1,6 +1,6 @@ import numpy as np -from aie.helpers.tensortiler import TensorTiler2D +from aie.helpers.taplib import TensorTiler2D from util import construct_test # RUN: %python %s | FileCheck %s @@ -12,7 +12,7 @@ def square_tiler_col_major_tensor_and_tile_tile_grouping(): tiler = TensorTiler2D.group_tiler( (32, 32), (4, 4), (2, 2), tile_group_col_major=True, tile_col_major=True ) - _access_order, access_count = tiler.access_tensors() + access_count = tiler.access_count() assert (access_count == 1).all() tile1_reference_order = np.array( @@ -54,7 +54,7 @@ def square_tiler_col_major_tensor_and_tile_tile_grouping(): # fmt: on ) - tile_access_order, _ = tiler[2].access_tensors() + tile_access_order = tiler[2].access_order() assert (tile_access_order == tile1_reference_order).all() assert len(tiler) == (32 // (4 * 2)) * (32 // (4 * 2)) diff --git a/test/python/tensortiler/square_tiler_col_major_tensor_tile_grouping_rectangular_col_major_groups.py b/test/python/taplib/square_tiler_col_major_tensor_tile_grouping_rectangular_col_major_groups.py similarity index 95% rename from test/python/tensortiler/square_tiler_col_major_tensor_tile_grouping_rectangular_col_major_groups.py rename to test/python/taplib/square_tiler_col_major_tensor_tile_grouping_rectangular_col_major_groups.py index 6551ab071b..3fb6c600d4 100644 --- a/test/python/tensortiler/square_tiler_col_major_tensor_tile_grouping_rectangular_col_major_groups.py +++ b/test/python/taplib/square_tiler_col_major_tensor_tile_grouping_rectangular_col_major_groups.py @@ -1,6 +1,6 @@ import numpy as np -from aie.helpers.tensortiler import TensorTiler2D +from aie.helpers.taplib import TensorTiler2D from util import construct_test # RUN: %python %s | FileCheck %s @@ -12,7 +12,7 @@ def square_tiler_col_major_tensor_tile_grouping_rectangular_col_major_groups(): tiler = TensorTiler2D.group_tiler( (16, 16), (4, 4), (2, 1), tile_group_col_major=True, iter_col_major=True ) - access_order, access_count = tiler.access_tensors() + access_order, access_count = tiler.accesses() reference_access = np.array( # fmt: off [ @@ -61,7 +61,7 @@ def square_tiler_col_major_tensor_tile_grouping_rectangular_col_major_groups(): # fmt: on ) - tile_access_order, _ = tiler[0].access_tensors() + tile_access_order = tiler[0].access_order() assert (tile_access_order == tile1_reference_order).all() assert len(tiler) == (16 // (2 * 4)) * (16 // (1 * 4)) diff --git a/test/python/tensortiler/square_tiler_col_major_tile.py b/test/python/taplib/square_tiler_col_major_tile.py similarity index 98% rename from test/python/tensortiler/square_tiler_col_major_tile.py rename to test/python/taplib/square_tiler_col_major_tile.py index bc157a0ae5..e2a7471a01 100644 --- a/test/python/tensortiler/square_tiler_col_major_tile.py +++ b/test/python/taplib/square_tiler_col_major_tile.py @@ -1,6 +1,6 @@ import numpy as np -from aie.helpers.tensortiler import TensorTiler2D +from aie.helpers.taplib import TensorTiler2D from util import construct_test # RUN: %python %s | FileCheck %s @@ -10,7 +10,7 @@ @construct_test def square_tiler_col_major_tile(): tiler = TensorTiler2D.simple_tiler((32, 32), (4, 4), tile_col_major=True) - access_order, access_count = tiler.access_tensors() + access_order, access_count = tiler.accesses() reference_access = np.array( # fmt: off [ @@ -91,7 +91,7 @@ def square_tiler_col_major_tile(): # fmt: on ) - tile_access_order, _ = tiler[5].access_tensors() + tile_access_order = tiler[5].access_order() assert (tile_access_order == tile1_reference_order).all() assert len(tiler) == (32 // 4) * (32 // 4) diff --git a/test/python/tensortiler/square_tiler_tile_grouping.py b/test/python/taplib/square_tiler_tile_grouping.py similarity index 97% rename from test/python/tensortiler/square_tiler_tile_grouping.py rename to test/python/taplib/square_tiler_tile_grouping.py index c6bda2293b..403c498e6d 100644 --- a/test/python/tensortiler/square_tiler_tile_grouping.py +++ b/test/python/taplib/square_tiler_tile_grouping.py @@ -1,6 +1,6 @@ import numpy as np -from aie.helpers.tensortiler import TensorTiler2D +from aie.helpers.taplib import TensorTiler2D from util import construct_test # RUN: %python %s | FileCheck %s @@ -10,7 +10,7 @@ @construct_test def square_tiler_tile_grouping(): tiler = TensorTiler2D.group_tiler((32, 32), (8, 8), (2, 2)) - _access_order, access_count = tiler.access_tensors() + access_count = tiler.access_count() assert (access_count == 1).all() tile1_reference_order = np.array( @@ -52,7 +52,7 @@ def square_tiler_tile_grouping(): # fmt: on ) - tile_access_order, _ = tiler[2].access_tensors() + tile_access_order = tiler[2].access_order() assert (tile_access_order == tile1_reference_order).all() assert len(tiler) == (32 // (8 * 2)) * (32 // (8 * 2)) diff --git a/test/python/tensortiler/square_tiler_tile_grouping_col_major_groups.py b/test/python/taplib/square_tiler_tile_grouping_col_major_groups.py similarity index 97% rename from test/python/tensortiler/square_tiler_tile_grouping_col_major_groups.py rename to test/python/taplib/square_tiler_tile_grouping_col_major_groups.py index 715445fc8a..0a8a318b78 100644 --- a/test/python/tensortiler/square_tiler_tile_grouping_col_major_groups.py +++ b/test/python/taplib/square_tiler_tile_grouping_col_major_groups.py @@ -1,6 +1,6 @@ import numpy as np -from aie.helpers.tensortiler import TensorTiler2D +from aie.helpers.taplib import TensorTiler2D from util import construct_test # RUN: %python %s | FileCheck %s @@ -10,7 +10,7 @@ @construct_test def square_tiler_tile_grouping_col_major_groups(): tiler = TensorTiler2D.group_tiler((32, 32), (8, 8), (2, 2), iter_col_major=True) - _access_order, access_count = tiler.access_tensors() + access_count = tiler.access_count() assert (access_count == 1).all() tile1_reference_order = np.array( @@ -52,7 +52,7 @@ def square_tiler_tile_grouping_col_major_groups(): # fmt: on ) - tile_access_order, _ = tiler[1].access_tensors() + tile_access_order = tiler[1].access_order() assert (tile_access_order == tile1_reference_order).all() assert len(tiler) == (32 // (8 * 2)) * (32 // (8 * 2)) diff --git a/test/python/tensortiler/step_tiler.py b/test/python/taplib/step_tiler.py similarity index 97% rename from test/python/tensortiler/step_tiler.py rename to test/python/taplib/step_tiler.py index 11821c60fe..d65530f815 100644 --- a/test/python/tensortiler/step_tiler.py +++ b/test/python/taplib/step_tiler.py @@ -1,6 +1,6 @@ import numpy as np -from aie.helpers.tensortiler import TensorTile, TensorTiler2D +from aie.helpers.taplib import TensorAccessPattern, TensorTiler2D from util import construct_test # RUN: %python %s | FileCheck %s @@ -17,13 +17,13 @@ def step_tiler(): tile_group_steps=(1, 1), ) assert len(tiles) == (32 // (2 * 2)) * (32 // (2 * 2)) - assert tiles[0] == TensorTile( + assert tiles[0] == TensorAccessPattern( (32, 32), offset=0, sizes=[2, 2, 2, 2], strides=[64, 2, 32, 1] ) - assert tiles[1] == TensorTile( + assert tiles[1] == TensorAccessPattern( (32, 32), offset=4, sizes=[2, 2, 2, 2], strides=[64, 2, 32, 1] ) - assert tiles[26] == TensorTile( + assert tiles[26] == TensorAccessPattern( (32, 32), offset=392, sizes=[2, 2, 2, 2], strides=[64, 2, 32, 1] ) # fmt: off @@ -61,7 +61,7 @@ def step_tiler(): [ 904, 905, 908, 909, 920, 921, 924, 925, 936, 937, 940, 941, 952, 953, 956, 957, 968, 969, 972, 973, 984, 985, 988, 989, 1000, 1001, 1004, 1005, 1016, 1017, 1020, 1021], [ 906, 907, 910, 911, 922, 923, 926, 927, 938, 939, 942, 943, 954, 955, 958, 959, 970, 971, 974, 975, 986, 987, 990, 991, 1002, 1003, 1006, 1007, 1018, 1019, 1022, 1023]]) # fmt: on - access_order, access_count = tiles.access_tensors() + access_order, access_count = tiles.accesses() assert (access_order == ref_access_order_tensor).all() assert (access_count == 1).all() @@ -73,16 +73,16 @@ def step_tiler(): tile_group_steps=(2, 1), ) assert len(tiles) == (32 // (2 * 2)) * (32 // (2 * 2)) - assert tiles[0] == TensorTile( + assert tiles[0] == TensorAccessPattern( (32, 32), offset=0, sizes=[2, 2, 2, 2], strides=[128, 2, 32, 1] ) - assert tiles[1] == TensorTile( + assert tiles[1] == TensorAccessPattern( (32, 32), offset=4, sizes=[2, 2, 2, 2], strides=[128, 2, 32, 1] ) - assert tiles[26] == TensorTile( + assert tiles[26] == TensorAccessPattern( (32, 32), offset=328, sizes=[2, 2, 2, 2], strides=[128, 2, 32, 1] ) - assert tiles[-1] == TensorTile( + assert tiles[-1] == TensorAccessPattern( (32, 32), offset=860, sizes=[2, 2, 2, 2], strides=[128, 2, 32, 1] ) # fmt: off @@ -120,7 +120,7 @@ def step_tiler(): [ 904, 905, 908, 909, 920, 921, 924, 925, 936, 937, 940, 941, 952, 953, 956, 957, 968, 969, 972, 973, 984, 985, 988, 989, 1000, 1001, 1004, 1005, 1016, 1017, 1020, 1021], [ 906, 907, 910, 911, 922, 923, 926, 927, 938, 939, 942, 943, 954, 955, 958, 959, 970, 971, 974, 975, 986, 987, 990, 991, 1002, 1003, 1006, 1007, 1018, 1019, 1022, 1023]]) # fmt: on - access_order, access_count = tiles.access_tensors() + access_order, access_count = tiles.accesses() assert (access_order == ref_access_order_tensor).all() assert (access_count == 1).all() @@ -132,16 +132,16 @@ def step_tiler(): tile_group_steps=(1, 2), ) assert len(tiles) == (32 // (2 * 2)) * (32 // (2 * 2)) - assert tiles[0] == TensorTile( + assert tiles[0] == TensorAccessPattern( (32, 32), offset=0, sizes=[2, 2, 2, 2], strides=[64, 4, 32, 1] ) - assert tiles[1] == TensorTile( + assert tiles[1] == TensorAccessPattern( (32, 32), offset=2, sizes=[2, 2, 2, 2], strides=[64, 4, 32, 1] ) - assert tiles[26] == TensorTile( + assert tiles[26] == TensorAccessPattern( (32, 32), offset=392, sizes=[2, 2, 2, 2], strides=[64, 4, 32, 1] ) - assert tiles[-1] == TensorTile( + assert tiles[-1] == TensorAccessPattern( (32, 32), offset=922, sizes=[2, 2, 2, 2], strides=[64, 4, 32, 1] ) # fmt: off @@ -179,7 +179,7 @@ def step_tiler(): [ 904, 905, 920, 921, 908, 909, 924, 925, 936, 937, 952, 953, 940, 941, 956, 957, 968, 969, 984, 985, 972, 973, 988, 989, 1000, 1001, 1016, 1017, 1004, 1005, 1020, 1021], [ 906, 907, 922, 923, 910, 911, 926, 927, 938, 939, 954, 955, 942, 943, 958, 959, 970, 971, 986, 987, 974, 975, 990, 991, 1002, 1003, 1018, 1019, 1006, 1007, 1022, 1023]]) # fmt: on - access_order, access_count = tiles.access_tensors() + access_order, access_count = tiles.accesses() assert (access_order == ref_access_order_tensor).all() assert (access_count == 1).all() @@ -191,16 +191,16 @@ def step_tiler(): tile_group_steps=(2, 2), ) assert len(tiles) == (32 // (2 * 2)) * (32 // (2 * 2)) - assert tiles[0] == TensorTile( + assert tiles[0] == TensorAccessPattern( (32, 32), offset=0, sizes=[2, 2, 2, 2], strides=[128, 4, 32, 1] ) - assert tiles[1] == TensorTile( + assert tiles[1] == TensorAccessPattern( (32, 32), offset=2, sizes=[2, 2, 2, 2], strides=[128, 4, 32, 1] ) - assert tiles[26] == TensorTile( + assert tiles[26] == TensorAccessPattern( (32, 32), offset=328, sizes=[2, 2, 2, 2], strides=[128, 4, 32, 1] ) - assert tiles[-1] == TensorTile( + assert tiles[-1] == TensorAccessPattern( (32, 32), offset=858, sizes=[2, 2, 2, 2], strides=[128, 4, 32, 1] ) # fmt: off @@ -238,7 +238,7 @@ def step_tiler(): [ 904, 905, 920, 921, 908, 909, 924, 925, 936, 937, 952, 953, 940, 941, 956, 957, 968, 969, 984, 985, 972, 973, 988, 989, 1000, 1001, 1016, 1017, 1004, 1005, 1020, 1021], [ 906, 907, 922, 923, 910, 911, 926, 927, 938, 939, 954, 955, 942, 943, 958, 959, 970, 971, 986, 987, 974, 975, 990, 991, 1002, 1003, 1018, 1019, 1006, 1007, 1022, 1023]]) # fmt: on - access_order, access_count = tiles.access_tensors() + access_order, access_count = tiles.accesses() assert (access_order == ref_access_order_tensor).all() assert (access_count == 1).all() @@ -250,16 +250,16 @@ def step_tiler(): tile_group_steps=(2, 2), ) assert len(tiles) == (32 // (2 * 2)) * (32 // (2 * 2)) - assert tiles[0] == TensorTile( + assert tiles[0] == TensorAccessPattern( (32, 32), offset=0, sizes=[2, 2, 2, 2], strides=[128, 4, 32, 1] ) - assert tiles[1] == TensorTile( + assert tiles[1] == TensorAccessPattern( (32, 32), offset=2, sizes=[2, 2, 2, 2], strides=[128, 4, 32, 1] ) - assert tiles[26] == TensorTile( + assert tiles[26] == TensorAccessPattern( (32, 32), offset=328, sizes=[2, 2, 2, 2], strides=[128, 4, 32, 1] ) - assert tiles[-1] == TensorTile( + assert tiles[-1] == TensorAccessPattern( (32, 32), offset=858, sizes=[2, 2, 2, 2], strides=[128, 4, 32, 1] ) # fmt: off @@ -297,7 +297,7 @@ def step_tiler(): [ 904, 905, 920, 921, 908, 909, 924, 925, 936, 937, 952, 953, 940, 941, 956, 957, 968, 969, 984, 985, 972, 973, 988, 989, 1000, 1001, 1016, 1017, 1004, 1005, 1020, 1021], [ 906, 907, 922, 923, 910, 911, 926, 927, 938, 939, 954, 955, 942, 943, 958, 959, 970, 971, 986, 987, 974, 975, 990, 991, 1002, 1003, 1018, 1019, 1006, 1007, 1022, 1023]]) # fmt: on - access_order, access_count = tiles.access_tensors() + access_order, access_count = tiles.accesses() assert (access_order == ref_access_order_tensor).all() assert (access_count == 1).all() @@ -309,16 +309,16 @@ def step_tiler(): tile_group_steps=(2, 2), ) assert len(tiles) == 4 # (32//(2*(32//4))) * (32//(2*(32//4))) - assert tiles[0] == TensorTile( + assert tiles[0] == TensorAccessPattern( (32, 32), offset=0, sizes=[8, 8, 2, 2], strides=[128, 4, 32, 1] ) - assert tiles[1] == TensorTile( + assert tiles[1] == TensorAccessPattern( (32, 32), offset=2, sizes=[8, 8, 2, 2], strides=[128, 4, 32, 1] ) - assert tiles[2] == TensorTile( + assert tiles[2] == TensorAccessPattern( (32, 32), offset=64, sizes=[8, 8, 2, 2], strides=[128, 4, 32, 1] ) - assert tiles[3] == TensorTile( + assert tiles[3] == TensorAccessPattern( (32, 32), offset=66, sizes=[8, 8, 2, 2], strides=[128, 4, 32, 1] ) # fmt: off @@ -356,7 +356,7 @@ def step_tiler(): [ 736, 737, 992, 993, 740, 741, 996, 997, 744, 745, 1000, 1001, 748, 749, 1004, 1005, 752, 753, 1008, 1009, 756, 757, 1012, 1013, 760, 761, 1016, 1017, 764, 765, 1020, 1021], [ 738, 739, 994, 995, 742, 743, 998, 999, 746, 747, 1002, 1003, 750, 751, 1006, 1007, 754, 755, 1010, 1011, 758, 759, 1014, 1015, 762, 763, 1018, 1019, 766, 767, 1022, 1023]]) # fmt: on - access_order, access_count = tiles.access_tensors() + access_order, access_count = tiles.accesses() assert (access_order == ref_access_order_tensor).all() assert (access_count == 1).all() @@ -368,16 +368,16 @@ def step_tiler(): tile_group_steps=(2, 2), ) assert len(tiles) == (32 // (2 * 1)) * (32 // (2 * (32 // 4))) - assert tiles[0] == TensorTile( + assert tiles[0] == TensorAccessPattern( (32, 32), offset=0, sizes=[1, 8, 2, 2], strides=[0, 4, 32, 1] ) - assert tiles[1] == TensorTile( + assert tiles[1] == TensorAccessPattern( (32, 32), offset=2, sizes=[1, 8, 2, 2], strides=[0, 4, 32, 1] ) - assert tiles[26] == TensorTile( + assert tiles[26] == TensorAccessPattern( (32, 32), offset=832, sizes=[1, 8, 2, 2], strides=[0, 4, 32, 1] ) - assert tiles[-1] == TensorTile( + assert tiles[-1] == TensorAccessPattern( (32, 32), offset=962, sizes=[1, 8, 2, 2], strides=[0, 4, 32, 1] ) # fmt: off @@ -415,7 +415,7 @@ def step_tiler(): [ 960, 961, 992, 993, 964, 965, 996, 997, 968, 969, 1000, 1001, 972, 973, 1004, 1005, 976, 977, 1008, 1009, 980, 981, 1012, 1013, 984, 985, 1016, 1017, 988, 989, 1020, 1021], [ 962, 963, 994, 995, 966, 967, 998, 999, 970, 971, 1002, 1003, 974, 975, 1006, 1007, 978, 979, 1010, 1011, 982, 983, 1014, 1015, 986, 987, 1018, 1019, 990, 991, 1022, 1023]]) # fmt: on - access_order, access_count = tiles.access_tensors() + access_order, access_count = tiles.accesses() assert (access_order == ref_access_order_tensor).all() assert (access_count == 1).all() @@ -427,16 +427,16 @@ def step_tiler(): tile_group_steps=(2, 2), ) assert len(tiles) == (32 // (2 * 1)) * (32 // (2 * (32 // 4))) - assert tiles[0] == TensorTile( + assert tiles[0] == TensorAccessPattern( (32, 32), offset=0, sizes=[1, 8, 2, 2], strides=[0, 128, 32, 1] ) - assert tiles[1] == TensorTile( + assert tiles[1] == TensorAccessPattern( (32, 32), offset=2, sizes=[1, 8, 2, 2], strides=[0, 128, 32, 1] ) - assert tiles[26] == TensorTile( + assert tiles[26] == TensorAccessPattern( (32, 32), offset=84, sizes=[1, 8, 2, 2], strides=[0, 128, 32, 1] ) - assert tiles[-1] == TensorTile( + assert tiles[-1] == TensorAccessPattern( (32, 32), offset=94, sizes=[1, 8, 2, 2], strides=[0, 128, 32, 1] ) # fmt: off @@ -474,7 +474,7 @@ def step_tiler(): [ 540, 541, 572, 573, 604, 605, 636, 637, 668, 669, 700, 701, 732, 733, 764, 765, 796, 797, 828, 829, 860, 861, 892, 893, 924, 925, 956, 957, 988, 989, 1020, 1021], [ 542, 543, 574, 575, 606, 607, 638, 639, 670, 671, 702, 703, 734, 735, 766, 767, 798, 799, 830, 831, 862, 863, 894, 895, 926, 927, 958, 959, 990, 991, 1022, 1023]]) # fmt: on - access_order, access_count = tiles.access_tensors() + access_order, access_count = tiles.accesses() assert (access_order == ref_access_order_tensor).all() assert (access_count == 1).all() @@ -486,16 +486,16 @@ def step_tiler(): tile_group_steps=(2, 4), ) assert len(tiles) == (32 // (2 * 8)) * (32 // (2 * 2)) - assert tiles[0] == TensorTile( + assert tiles[0] == TensorAccessPattern( (32, 32), offset=0, sizes=[8, 2, 2, 2], strides=[128, 8, 32, 1] ) - assert tiles[1] == TensorTile( + assert tiles[1] == TensorAccessPattern( (32, 32), offset=2, sizes=[8, 2, 2, 2], strides=[128, 8, 32, 1] ) - assert tiles[12] == TensorTile( + assert tiles[12] == TensorAccessPattern( (32, 32), offset=80, sizes=[8, 2, 2, 2], strides=[128, 8, 32, 1] ) - assert tiles[-1] == TensorTile( + assert tiles[-1] == TensorAccessPattern( (32, 32), offset=86, sizes=[8, 2, 2, 2], strides=[128, 8, 32, 1] ) # fmt: off @@ -533,7 +533,7 @@ def step_tiler(): [ 568, 569, 632, 633, 696, 697, 760, 761, 572, 573, 636, 637, 700, 701, 764, 765, 824, 825, 888, 889, 952, 953, 1016, 1017, 828, 829, 892, 893, 956, 957, 1020, 1021], [ 570, 571, 634, 635, 698, 699, 762, 763, 574, 575, 638, 639, 702, 703, 766, 767, 826, 827, 890, 891, 954, 955, 1018, 1019, 830, 831, 894, 895, 958, 959, 1022, 1023]]) # fmt: on - access_order, access_count = tiles.access_tensors() + access_order, access_count = tiles.accesses() assert (access_order == ref_access_order_tensor).all() assert (access_count == 1).all() @@ -546,16 +546,16 @@ def step_tiler(): tile_col_major=True, ) assert len(tiles) == (32 // (2 * 8)) * (32 // (2 * 2)) - assert tiles[0] == TensorTile( + assert tiles[0] == TensorAccessPattern( (32, 32), offset=0, sizes=[8, 2, 2, 2], strides=[128, 8, 1, 32] ) - assert tiles[1] == TensorTile( + assert tiles[1] == TensorAccessPattern( (32, 32), offset=2, sizes=[8, 2, 2, 2], strides=[128, 8, 1, 32] ) - assert tiles[12] == TensorTile( + assert tiles[12] == TensorAccessPattern( (32, 32), offset=80, sizes=[8, 2, 2, 2], strides=[128, 8, 1, 32] ) - assert tiles[-1] == TensorTile( + assert tiles[-1] == TensorAccessPattern( (32, 32), offset=86, sizes=[8, 2, 2, 2], strides=[128, 8, 1, 32] ) # fmt: off @@ -593,7 +593,7 @@ def step_tiler(): [ 568, 570, 632, 634, 696, 698, 760, 762, 572, 574, 636, 638, 700, 702, 764, 766, 824, 826, 888, 890, 952, 954, 1016, 1018, 828, 830, 892, 894, 956, 958, 1020, 1022], [ 569, 571, 633, 635, 697, 699, 761, 763, 573, 575, 637, 639, 701, 703, 765, 767, 825, 827, 889, 891, 953, 955, 1017, 1019, 829, 831, 893, 895, 957, 959, 1021, 1023]]) # fmt: on - access_order, access_count = tiles.access_tensors() + access_order, access_count = tiles.accesses() assert (access_order == ref_access_order_tensor).all() assert (access_count == 1).all() @@ -607,16 +607,16 @@ def step_tiler(): tile_group_col_major=True, ) assert len(tiles) == (32 // (2 * 8)) * (32 // (2 * 2)) - assert tiles[0] == TensorTile( + assert tiles[0] == TensorAccessPattern( (32, 32), offset=0, sizes=[2, 8, 2, 2], strides=[8, 128, 1, 32] ) - assert tiles[1] == TensorTile( + assert tiles[1] == TensorAccessPattern( (32, 32), offset=2, sizes=[2, 8, 2, 2], strides=[8, 128, 1, 32] ) - assert tiles[12] == TensorTile( + assert tiles[12] == TensorAccessPattern( (32, 32), offset=80, sizes=[2, 8, 2, 2], strides=[8, 128, 1, 32] ) - assert tiles[-1] == TensorTile( + assert tiles[-1] == TensorAccessPattern( (32, 32), offset=86, sizes=[2, 8, 2, 2], strides=[8, 128, 1, 32] ) # fmt: off @@ -654,7 +654,7 @@ def step_tiler(): [ 540, 542, 604, 606, 668, 670, 732, 734, 572, 574, 636, 638, 700, 702, 764, 766, 796, 798, 860, 862, 924, 926, 988, 990, 828, 830, 892, 894, 956, 958, 1020, 1022], [ 541, 543, 605, 607, 669, 671, 733, 735, 573, 575, 637, 639, 701, 703, 765, 767, 797, 799, 861, 863, 925, 927, 989, 991, 829, 831, 893, 895, 957, 959, 1021, 1023]]) # fmt: on - access_order, access_count = tiles.access_tensors() + access_order, access_count = tiles.accesses() assert (access_order == ref_access_order_tensor).all() assert (access_count == 1).all() @@ -669,16 +669,16 @@ def step_tiler(): iter_col_major=True, ) assert len(tiles) == (32 // (2 * 8)) * (32 // (2 * 2)) - assert tiles[0] == TensorTile( + assert tiles[0] == TensorAccessPattern( (32, 32), offset=0, sizes=[2, 8, 2, 2], strides=[8, 128, 1, 32] ) - assert tiles[1] == TensorTile( + assert tiles[1] == TensorAccessPattern( (32, 32), offset=64, sizes=[2, 8, 2, 2], strides=[8, 128, 1, 32] ) - assert tiles[12] == TensorTile( + assert tiles[12] == TensorAccessPattern( (32, 32), offset=20, sizes=[2, 8, 2, 2], strides=[8, 128, 1, 32] ) - assert tiles[-1] == TensorTile( + assert tiles[-1] == TensorAccessPattern( (32, 32), offset=86, sizes=[2, 8, 2, 2], strides=[8, 128, 1, 32] ) # fmt: off @@ -716,7 +716,7 @@ def step_tiler(): [ 92, 94, 220, 222, 348, 350, 476, 478, 124, 126, 252, 254, 380, 382, 508, 510, 604, 606, 732, 734, 860, 862, 988, 990, 636, 638, 764, 766, 892, 894, 1020, 1022], [ 93, 95, 221, 223, 349, 351, 477, 479, 125, 127, 253, 255, 381, 383, 509, 511, 605, 607, 733, 735, 861, 863, 989, 991, 637, 639, 765, 767, 893, 895, 1021, 1023]]) # fmt: on - access_order, access_count = tiles.access_tensors() + access_order, access_count = tiles.accesses() assert (access_order == ref_access_order_tensor).all() assert (access_count == 1).all() diff --git a/test/python/tensortiler/step_tiler_partial.py b/test/python/taplib/step_tiler_partial.py similarity index 74% rename from test/python/tensortiler/step_tiler_partial.py rename to test/python/taplib/step_tiler_partial.py index f8a7ba6e41..f637adab58 100644 --- a/test/python/tensortiler/step_tiler_partial.py +++ b/test/python/taplib/step_tiler_partial.py @@ -1,4 +1,4 @@ -from aie.helpers.tensortiler import TensorTile, TensorTileSequence, TensorTiler2D +from aie.helpers.taplib import TensorAccessPattern, TensorAccessSequence, TensorTiler2D from util import construct_test # RUN: %python %s | FileCheck %s @@ -18,39 +18,39 @@ def step_tiler_partial_row(): allow_partial=True, ) assert len(tiles) == 9 - reference_tiles = reference_tiles = TensorTileSequence.from_tiles( + reference_tiles = reference_tiles = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[5, 5, 3, 2], strides=[252, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=2, sizes=[5, 5, 3, 2], strides=[252, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=4, sizes=[5, 4, 3, 2], strides=[252, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=84, sizes=[5, 5, 3, 2], strides=[252, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=86, sizes=[5, 5, 3, 2], strides=[252, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=88, sizes=[5, 4, 3, 2], strides=[252, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=168, sizes=[5, 5, 3, 2], strides=[252, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=170, sizes=[5, 5, 3, 2], strides=[252, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=172, sizes=[5, 4, 3, 2], strides=[252, 6, 28, 1] ), ] ) assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert tiles.compare_access_orders(reference_tiles) # tile col major tiles = TensorTiler2D.step_tiler( @@ -62,39 +62,39 @@ def step_tiler_partial_row(): tile_col_major=True, ) assert len(tiles) == 9 - reference_tiles = reference_tiles = TensorTileSequence.from_tiles( + reference_tiles = reference_tiles = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[5, 5, 2, 3], strides=[252, 6, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=2, sizes=[5, 5, 2, 3], strides=[252, 6, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=4, sizes=[5, 4, 2, 3], strides=[252, 6, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=84, sizes=[5, 5, 2, 3], strides=[252, 6, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=86, sizes=[5, 5, 2, 3], strides=[252, 6, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=88, sizes=[5, 4, 2, 3], strides=[252, 6, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=168, sizes=[5, 5, 2, 3], strides=[252, 6, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=170, sizes=[5, 5, 2, 3], strides=[252, 6, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=172, sizes=[5, 4, 2, 3], strides=[252, 6, 1, 28] ), ] ) assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert tiles.compare_access_orders(reference_tiles) # tile group col major tiles = TensorTiler2D.step_tiler( @@ -106,39 +106,39 @@ def step_tiler_partial_row(): tile_group_col_major=True, ) assert len(tiles) == 9 - reference_tiles = reference_tiles = TensorTileSequence.from_tiles( + reference_tiles = reference_tiles = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[5, 5, 3, 2], strides=[6, 252, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=2, sizes=[5, 5, 3, 2], strides=[6, 252, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=4, sizes=[4, 5, 3, 2], strides=[6, 252, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=84, sizes=[5, 5, 3, 2], strides=[6, 252, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=86, sizes=[5, 5, 3, 2], strides=[6, 252, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=88, sizes=[4, 5, 3, 2], strides=[6, 252, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=168, sizes=[5, 5, 3, 2], strides=[6, 252, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=170, sizes=[5, 5, 3, 2], strides=[6, 252, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=172, sizes=[4, 5, 3, 2], strides=[6, 252, 28, 1] ), ] ) assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert tiles.compare_access_orders(reference_tiles) # iter col major tiles = TensorTiler2D.step_tiler( @@ -150,39 +150,39 @@ def step_tiler_partial_row(): iter_col_major=True, ) assert len(tiles) == 9 - reference_tiles = reference_tiles = TensorTileSequence.from_tiles( + reference_tiles = reference_tiles = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[5, 5, 3, 2], strides=[252, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=84, sizes=[5, 5, 3, 2], strides=[252, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=168, sizes=[5, 5, 3, 2], strides=[252, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=2, sizes=[5, 5, 3, 2], strides=[252, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=86, sizes=[5, 5, 3, 2], strides=[252, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=170, sizes=[5, 5, 3, 2], strides=[252, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=4, sizes=[5, 4, 3, 2], strides=[252, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=88, sizes=[5, 4, 3, 2], strides=[252, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=172, sizes=[5, 4, 3, 2], strides=[252, 6, 28, 1] ), ] ) assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert tiles.compare_access_orders(reference_tiles) # all col major tiles = TensorTiler2D.step_tiler( @@ -196,39 +196,39 @@ def step_tiler_partial_row(): iter_col_major=True, ) assert len(tiles) == 9 - reference_tiles = reference_tiles = TensorTileSequence.from_tiles( + reference_tiles = reference_tiles = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[5, 5, 2, 3], strides=[6, 252, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=84, sizes=[5, 5, 2, 3], strides=[6, 252, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=168, sizes=[5, 5, 2, 3], strides=[6, 252, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=2, sizes=[5, 5, 2, 3], strides=[6, 252, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=86, sizes=[5, 5, 2, 3], strides=[6, 252, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=170, sizes=[5, 5, 2, 3], strides=[6, 252, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=4, sizes=[4, 5, 2, 3], strides=[6, 252, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=88, sizes=[4, 5, 2, 3], strides=[6, 252, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=172, sizes=[4, 5, 2, 3], strides=[6, 252, 1, 28] ), ] ) assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert tiles.compare_access_orders(reference_tiles) # pattern repeat tiles = TensorTiler2D.step_tiler( @@ -241,39 +241,39 @@ def step_tiler_partial_row(): tile_group_col_major=True, ) assert len(tiles) == 9 - reference_tiles = reference_tiles = TensorTileSequence.from_tiles( + reference_tiles = reference_tiles = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[4, 5, 15, 2], strides=[0, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=2, sizes=[4, 5, 15, 2], strides=[0, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=4, sizes=[4, 4, 15, 2], strides=[0, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=420, sizes=[4, 5, 15, 2], strides=[0, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=422, sizes=[4, 5, 15, 2], strides=[0, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=424, sizes=[4, 4, 15, 2], strides=[0, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=840, sizes=[4, 5, 15, 2], strides=[0, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=842, sizes=[4, 5, 15, 2], strides=[0, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=844, sizes=[4, 4, 15, 2], strides=[0, 6, 28, 1] ), ] ) assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert tiles.compare_access_orders(reference_tiles) # CHECK: Pass! print("Pass!") @@ -293,36 +293,36 @@ def step_tiler_partial_col(): allow_partial=True, ) assert len(tiles) == 8 - reference_tiles = reference_tiles = TensorTileSequence.from_tiles( + reference_tiles = reference_tiles = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[5, 7, 3, 2], strides=[168, 4, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=2, sizes=[5, 7, 3, 2], strides=[168, 4, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=84, sizes=[5, 7, 3, 2], strides=[168, 4, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=86, sizes=[5, 7, 3, 2], strides=[168, 4, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=840, sizes=[3, 7, 3, 2], strides=[168, 4, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=842, sizes=[3, 7, 3, 2], strides=[168, 4, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=924, sizes=[2, 7, 3, 2], strides=[168, 4, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=926, sizes=[2, 7, 3, 2], strides=[168, 4, 28, 1] ), ] ) assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert tiles.compare_access_orders(reference_tiles) # tile col major tensor_dims = (3 * 5 * 3, 2 * 7 * 2) @@ -335,36 +335,36 @@ def step_tiler_partial_col(): tile_col_major=True, ) assert len(tiles) == 8 - reference_tiles = reference_tiles = TensorTileSequence.from_tiles( + reference_tiles = reference_tiles = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[5, 7, 2, 3], strides=[168, 4, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=2, sizes=[5, 7, 2, 3], strides=[168, 4, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=84, sizes=[5, 7, 2, 3], strides=[168, 4, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=86, sizes=[5, 7, 2, 3], strides=[168, 4, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=840, sizes=[3, 7, 2, 3], strides=[168, 4, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=842, sizes=[3, 7, 2, 3], strides=[168, 4, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=924, sizes=[2, 7, 2, 3], strides=[168, 4, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=926, sizes=[2, 7, 2, 3], strides=[168, 4, 1, 28] ), ] ) assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert tiles.compare_access_orders(reference_tiles) # tile group col major tensor_dims = (3 * 5 * 3, 2 * 7 * 2) @@ -377,36 +377,36 @@ def step_tiler_partial_col(): allow_partial=True, ) assert len(tiles) == 8 - reference_tiles = reference_tiles = TensorTileSequence.from_tiles( + reference_tiles = reference_tiles = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[7, 5, 3, 2], strides=[4, 168, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=2, sizes=[7, 5, 3, 2], strides=[4, 168, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=84, sizes=[7, 5, 3, 2], strides=[4, 168, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=86, sizes=[7, 5, 3, 2], strides=[4, 168, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=840, sizes=[7, 3, 3, 2], strides=[4, 168, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=842, sizes=[7, 3, 3, 2], strides=[4, 168, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=924, sizes=[7, 2, 3, 2], strides=[4, 168, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=926, sizes=[7, 2, 3, 2], strides=[4, 168, 28, 1] ), ] ) assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert tiles.compare_access_orders(reference_tiles) # iter col major tensor_dims = (3 * 5 * 3, 2 * 7 * 2) @@ -419,36 +419,36 @@ def step_tiler_partial_col(): allow_partial=True, ) assert len(tiles) == 8 - reference_tiles = reference_tiles = TensorTileSequence.from_tiles( + reference_tiles = reference_tiles = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[5, 7, 3, 2], strides=[168, 4, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=84, sizes=[5, 7, 3, 2], strides=[168, 4, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=840, sizes=[3, 7, 3, 2], strides=[168, 4, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=924, sizes=[2, 7, 3, 2], strides=[168, 4, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=2, sizes=[5, 7, 3, 2], strides=[168, 4, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=86, sizes=[5, 7, 3, 2], strides=[168, 4, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=842, sizes=[3, 7, 3, 2], strides=[168, 4, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=926, sizes=[2, 7, 3, 2], strides=[168, 4, 28, 1] ), ] ) assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert tiles.compare_access_orders(reference_tiles) # all col major tensor_dims = (3 * 5 * 3, 2 * 7 * 2) @@ -463,36 +463,36 @@ def step_tiler_partial_col(): tile_group_col_major=True, ) assert len(tiles) == 8 - reference_tiles = reference_tiles = TensorTileSequence.from_tiles( + reference_tiles = reference_tiles = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[7, 5, 2, 3], strides=[4, 168, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=84, sizes=[7, 5, 2, 3], strides=[4, 168, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=840, sizes=[7, 3, 2, 3], strides=[4, 168, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=924, sizes=[7, 2, 2, 3], strides=[4, 168, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=2, sizes=[7, 5, 2, 3], strides=[4, 168, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=86, sizes=[7, 5, 2, 3], strides=[4, 168, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=842, sizes=[7, 3, 2, 3], strides=[4, 168, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=926, sizes=[7, 2, 2, 3], strides=[4, 168, 1, 28] ), ] ) assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert tiles.compare_access_orders(reference_tiles) # pattern repeat tensor_dims = (3 * 5 * 3, 2 * 7 * 2) @@ -506,36 +506,36 @@ def step_tiler_partial_col(): tile_col_major=True, ) assert len(tiles) == 8 - reference_tiles = reference_tiles = TensorTileSequence.from_tiles( + reference_tiles = reference_tiles = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[2, 5, 14, 3], strides=[0, 168, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=14, sizes=[2, 5, 14, 3], strides=[0, 168, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=84, sizes=[2, 5, 14, 3], strides=[0, 168, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=98, sizes=[2, 5, 14, 3], strides=[0, 168, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=840, sizes=[2, 3, 14, 3], strides=[0, 168, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=854, sizes=[2, 3, 14, 3], strides=[0, 168, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=924, sizes=[2, 2, 14, 3], strides=[0, 168, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=938, sizes=[2, 2, 14, 3], strides=[0, 168, 1, 28] ), ] ) assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert tiles.compare_access_orders(reference_tiles) # CHECK: Pass! print("Pass!") @@ -555,48 +555,48 @@ def step_tiler_partial_both(): allow_partial=True, ) assert len(tiles) == 12 - reference_tiles = TensorTileSequence.from_tiles( + reference_tiles = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[5, 5, 3, 2], strides=[168, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=2, sizes=[5, 5, 3, 2], strides=[168, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=4, sizes=[5, 4, 3, 2], strides=[168, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=84, sizes=[5, 5, 3, 2], strides=[168, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=86, sizes=[5, 5, 3, 2], strides=[168, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=88, sizes=[5, 4, 3, 2], strides=[168, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=840, sizes=[3, 5, 3, 2], strides=[168, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=842, sizes=[3, 5, 3, 2], strides=[168, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=844, sizes=[3, 4, 3, 2], strides=[168, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=924, sizes=[2, 5, 3, 2], strides=[168, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=926, sizes=[2, 5, 3, 2], strides=[168, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=928, sizes=[2, 4, 3, 2], strides=[168, 6, 28, 1] ), ] ) assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert tiles.compare_access_orders(reference_tiles) # tile col major tiles = TensorTiler2D.step_tiler( @@ -608,48 +608,48 @@ def step_tiler_partial_both(): tile_col_major=True, ) assert len(tiles) == 12 - reference_tiles = reference_tiles = TensorTileSequence.from_tiles( + reference_tiles = reference_tiles = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[5, 5, 2, 3], strides=[168, 6, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=2, sizes=[5, 5, 2, 3], strides=[168, 6, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=4, sizes=[5, 4, 2, 3], strides=[168, 6, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=84, sizes=[5, 5, 2, 3], strides=[168, 6, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=86, sizes=[5, 5, 2, 3], strides=[168, 6, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=88, sizes=[5, 4, 2, 3], strides=[168, 6, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=840, sizes=[3, 5, 2, 3], strides=[168, 6, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=842, sizes=[3, 5, 2, 3], strides=[168, 6, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=844, sizes=[3, 4, 2, 3], strides=[168, 6, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=924, sizes=[2, 5, 2, 3], strides=[168, 6, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=926, sizes=[2, 5, 2, 3], strides=[168, 6, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=928, sizes=[2, 4, 2, 3], strides=[168, 6, 1, 28] ), ] ) assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert tiles.compare_access_orders(reference_tiles) # tile group col major tiles = TensorTiler2D.step_tiler( @@ -661,48 +661,48 @@ def step_tiler_partial_both(): tile_group_col_major=True, ) assert len(tiles) == 12 - reference_tiles = reference_tiles = TensorTileSequence.from_tiles( + reference_tiles = reference_tiles = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[5, 5, 3, 2], strides=[6, 168, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=2, sizes=[5, 5, 3, 2], strides=[6, 168, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=4, sizes=[4, 5, 3, 2], strides=[6, 168, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=84, sizes=[5, 5, 3, 2], strides=[6, 168, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=86, sizes=[5, 5, 3, 2], strides=[6, 168, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=88, sizes=[4, 5, 3, 2], strides=[6, 168, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=840, sizes=[5, 3, 3, 2], strides=[6, 168, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=842, sizes=[5, 3, 3, 2], strides=[6, 168, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=844, sizes=[4, 3, 3, 2], strides=[6, 168, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=924, sizes=[5, 2, 3, 2], strides=[6, 168, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=926, sizes=[5, 2, 3, 2], strides=[6, 168, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=928, sizes=[4, 2, 3, 2], strides=[6, 168, 28, 1] ), ] ) assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert tiles.compare_access_orders(reference_tiles) # iter col major tiles = TensorTiler2D.step_tiler( @@ -714,48 +714,48 @@ def step_tiler_partial_both(): iter_col_major=True, ) assert len(tiles) == 12 - reference_tiles = reference_tiles = TensorTileSequence.from_tiles( + reference_tiles = reference_tiles = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[5, 5, 3, 2], strides=[168, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=84, sizes=[5, 5, 3, 2], strides=[168, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=840, sizes=[3, 5, 3, 2], strides=[168, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=924, sizes=[2, 5, 3, 2], strides=[168, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=2, sizes=[5, 5, 3, 2], strides=[168, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=86, sizes=[5, 5, 3, 2], strides=[168, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=842, sizes=[3, 5, 3, 2], strides=[168, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=926, sizes=[2, 5, 3, 2], strides=[168, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=4, sizes=[5, 4, 3, 2], strides=[168, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=88, sizes=[5, 4, 3, 2], strides=[168, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=844, sizes=[3, 4, 3, 2], strides=[168, 6, 28, 1] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=928, sizes=[2, 4, 3, 2], strides=[168, 6, 28, 1] ), ] ) assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert tiles.compare_access_orders(reference_tiles) # all col major tiles = TensorTiler2D.step_tiler( @@ -769,48 +769,48 @@ def step_tiler_partial_both(): iter_col_major=True, ) assert len(tiles) == 12 - reference_tiles = reference_tiles = TensorTileSequence.from_tiles( + reference_tiles = reference_tiles = TensorAccessSequence.from_taps( [ - TensorTile( + TensorAccessPattern( tensor_dims, offset=0, sizes=[5, 5, 2, 3], strides=[6, 168, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=84, sizes=[5, 5, 2, 3], strides=[6, 168, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=840, sizes=[5, 3, 2, 3], strides=[6, 168, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=924, sizes=[5, 2, 2, 3], strides=[6, 168, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=2, sizes=[5, 5, 2, 3], strides=[6, 168, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=86, sizes=[5, 5, 2, 3], strides=[6, 168, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=842, sizes=[5, 3, 2, 3], strides=[6, 168, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=926, sizes=[5, 2, 2, 3], strides=[6, 168, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=4, sizes=[4, 5, 2, 3], strides=[6, 168, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=88, sizes=[4, 5, 2, 3], strides=[6, 168, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=844, sizes=[4, 3, 2, 3], strides=[6, 168, 1, 28] ), - TensorTile( + TensorAccessPattern( tensor_dims, offset=928, sizes=[4, 2, 2, 3], strides=[6, 168, 1, 28] ), ] ) assert tiles == reference_tiles - assert tiles.compare_tile_access_orders(reference_tiles) + assert tiles.compare_access_orders(reference_tiles) # CHECK: Pass! print("Pass!") diff --git a/test/python/tensortiler/tensor_tile_same_height.py b/test/python/taplib/tensor_tile_same_height.py similarity index 91% rename from test/python/tensortiler/tensor_tile_same_height.py rename to test/python/taplib/tensor_tile_same_height.py index 937a9930ac..6a2a8b8016 100644 --- a/test/python/tensortiler/tensor_tile_same_height.py +++ b/test/python/taplib/tensor_tile_same_height.py @@ -1,6 +1,6 @@ import numpy as np -from aie.helpers.tensortiler import TensorTiler2D +from aie.helpers.taplib import TensorTiler2D from util import construct_test # RUN: %python %s | FileCheck %s @@ -10,7 +10,7 @@ @construct_test def tensor_tile_same_height(): tiles = TensorTiler2D.simple_tiler((12, 8), (12, 2)) - access_order, access_count = tiles.access_tensors() + access_order, access_count = tiles.accesses() reference_access = np.array( # fmt: off [ @@ -51,7 +51,7 @@ def tensor_tile_same_height(): # fmt: on ) - tile_access_order, tile_access_count = tiles[2].access_tensors() + tile_access_order = tiles[2].access_order() assert (tile_access_order == tile1_reference_order).all() assert len(tiles) == (12 // 12) * (8 // 2) diff --git a/test/python/tensortiler/tensortile.py b/test/python/taplib/tensortile.py similarity index 67% rename from test/python/tensortiler/tensortile.py rename to test/python/taplib/tensortile.py index c32c0ee7ec..4263e2fa46 100644 --- a/test/python/tensortiler/tensortile.py +++ b/test/python/taplib/tensortile.py @@ -1,6 +1,6 @@ import numpy as np -from aie.helpers.tensortiler import TensorTile +from aie.helpers.taplib import TensorAccessPattern from util import construct_test # RUN: %python %s | FileCheck %s @@ -10,7 +10,7 @@ @construct_test def tensor_tile(): # Valid - tile = TensorTile((2, 3), 4, sizes=[1, 2], strides=[0, 1]) + tile = TensorAccessPattern((2, 3), 4, sizes=[1, 2], strides=[0, 1]) # Check accessors assert ( @@ -22,7 +22,7 @@ def tensor_tile(): assert tile.sizes == [1, 2] assert tile.strides == [0, 1] assert tile.transformation_dims == [(1, 0), (2, 1)] - access_order, access_count = tile.access_tensors() + access_order, access_count = tile.accesses() assert ( access_order == np.array([[-1, -1, -1], [-1, 0, 1]], dtype=access_order.dtype) ).all() @@ -30,11 +30,11 @@ def tensor_tile(): access_count == np.array([[0, 0, 0], [0, 1, 1]], dtype=access_count.dtype) ).all() - tile2 = TensorTile((2, 3), 4, sizes=[1, 2], strides=[0, 1]) + tile2 = TensorAccessPattern((2, 3), 4, sizes=[1, 2], strides=[0, 1]) assert tile2 == tile assert tile.compare_access_orders(tile2) - tile3 = TensorTile((2, 3), 2, sizes=[1, 2], strides=[0, 1]) + tile3 = TensorAccessPattern((2, 3), 2, sizes=[1, 2], strides=[0, 1]) assert tile3 != tile assert not tile.compare_access_orders(tile3) @@ -48,31 +48,31 @@ def tensor_tile_invalid(): # Bad tensor dims try: - tile = TensorTile((), 4, sizes=[1, 2], strides=[0, 1]) + tile = TensorAccessPattern((), 4, sizes=[1, 2], strides=[0, 1]) raise Exception("Should fail, bad dims (no dims)") except ValueError: # Good pass try: - tile = TensorTile((0, 1), 4, sizes=[1, 2], strides=[0, 1]) + tile = TensorAccessPattern((0, 1), 4, sizes=[1, 2], strides=[0, 1]) raise Exception("Should fail, bad dims (first dim 0)") except ValueError: # Good pass try: - tile = TensorTile((1, 0), 4, sizes=[1, 2], strides=[0, 1]) + tile = TensorAccessPattern((1, 0), 4, sizes=[1, 2], strides=[0, 1]) raise Exception("Should fail, bad dims (second dim 0)") except ValueError: # Good pass try: - tile = TensorTile((-1, 1), 4, sizes=[1, 2], strides=[0, 1]) + tile = TensorAccessPattern((-1, 1), 4, sizes=[1, 2], strides=[0, 1]) raise Exception("Should fail, bad dims (first dim negative)") except ValueError: # Good pass try: - tile = TensorTile((1, -1), 4, sizes=[1, 2], strides=[0, 1]) + tile = TensorAccessPattern((1, -1), 4, sizes=[1, 2], strides=[0, 1]) raise Exception("Should fail, bad dims (second dim negative)") except ValueError: # Good @@ -80,13 +80,13 @@ def tensor_tile_invalid(): # Bad offset try: - tile = TensorTile((2, 3), -1, sizes=[1, 2], strides=[0, 1]) + tile = TensorAccessPattern((2, 3), -1, sizes=[1, 2], strides=[0, 1]) raise Exception("Should fail, bad offset (negative)") except ValueError: # Good pass try: - tile = TensorTile((2, 3), 2 * 3, sizes=[1, 2], strides=[0, 1]) + tile = TensorAccessPattern((2, 3), 2 * 3, sizes=[1, 2], strides=[0, 1]) raise Exception("Should fail, bad offset (too large)") except ValueError: # Good @@ -94,13 +94,13 @@ def tensor_tile_invalid(): # Bad sizes try: - tile = TensorTile((2, 3), 2 * 3, sizes=[-1], strides=[1]) + tile = TensorAccessPattern((2, 3), 2 * 3, sizes=[-1], strides=[1]) raise Exception("Should fail, size (negative)") except ValueError: # Good pass try: - tile = TensorTile((2, 3), 2 * 3, sizes=[0], strides=[1]) + tile = TensorAccessPattern((2, 3), 2 * 3, sizes=[0], strides=[1]) raise Exception("Should fail, size (zero)") except ValueError: # Good @@ -108,19 +108,19 @@ def tensor_tile_invalid(): # Bad sizes + strides try: - tile = TensorTile((2, 3), 2 * 3, sizes=[], strides=[]) + tile = TensorAccessPattern((2, 3), 2 * 3, sizes=[], strides=[]) raise Exception("Should fail, size and stride empty") except ValueError: # Good pass try: - tile = TensorTile((2, 3), 2 * 3, sizes=[1], strides=[0, 1]) + tile = TensorAccessPattern((2, 3), 2 * 3, sizes=[1], strides=[0, 1]) raise Exception("Should fail, sizes and strides uneven dimensions") except ValueError: # Good pass try: - tile = TensorTile((2, 3), 2 * 3, sizes=[1, 1], strides=[0]) + tile = TensorAccessPattern((2, 3), 2 * 3, sizes=[1, 1], strides=[0]) raise Exception("Should fail, sizes and strides uneven dimensions 2") except ValueError: # Good @@ -128,7 +128,7 @@ def tensor_tile_invalid(): # Bad strides try: - tile = TensorTile((2, 3), 2 * 3, sizes=[1], strides=[-1]) + tile = TensorAccessPattern((2, 3), 2 * 3, sizes=[1], strides=[-1]) raise Exception("Should fail, bad stride (negative)") except ValueError: # Good diff --git a/test/python/tensortiler/tensortilesequence.py b/test/python/taplib/tensortilesequence.py similarity index 70% rename from test/python/tensortiler/tensortilesequence.py rename to test/python/taplib/tensortilesequence.py index 817cc509ab..1470b191ca 100644 --- a/test/python/tensortiler/tensortilesequence.py +++ b/test/python/taplib/tensortilesequence.py @@ -1,6 +1,6 @@ import numpy as np -from aie.helpers.tensortiler import TensorTile, TensorTileSequence +from aie.helpers.taplib import TensorAccessPattern, TensorAccessSequence from util import construct_test # RUN: %python %s | FileCheck %s @@ -10,28 +10,28 @@ @construct_test def tensor_tile_sequence(): - empty_tiles = TensorTileSequence((2, 2), 0) + empty_tiles = TensorAccessSequence((2, 2), 0) assert len(empty_tiles) == 0 ref_access_order = np.array([[-1, -1], [-1, -1]]) ref_access_count = np.array([[0, 0], [0, 0]]) - access_order, access_count = empty_tiles.access_tensors() + access_order, access_count = empty_tiles.accesses() assert (access_order == ref_access_order).all() assert (access_count == ref_access_count).all() def offset_fn(step, _prev_offset): return step - tiles = TensorTileSequence( + tiles = TensorAccessSequence( (2, 2), 4, sizes=[1, 1], strides=[1, 1], offset_fn=offset_fn ) assert len(tiles) == 4 ref_access_order = np.array([[0, 1], [2, 3]]) ref_access_count = np.array([[1, 1], [1, 1]]) - access_order, access_count = tiles.access_tensors() + access_order, access_count = tiles.accesses() assert (access_order == ref_access_order).all() assert (access_count == ref_access_count).all() - tile = TensorTile((2, 2), offset=2, sizes=[1, 1], strides=[1, 1]) + tile = TensorAccessPattern((2, 2), offset=2, sizes=[1, 1], strides=[1, 1]) assert tile in tiles assert tiles[2] == tile tiles2 = list(iter(tiles)) @@ -42,28 +42,28 @@ def offset_fn(step, _prev_offset): tiles.insert(2, tile) assert tile in tiles - tile2 = TensorTile((3, 3), offset=2, sizes=[1, 1], strides=[1, 1]) + tile2 = TensorAccessPattern((3, 3), offset=2, sizes=[1, 1], strides=[1, 1]) assert not (tile2 in tiles) - tiles3 = TensorTileSequence( + tiles3 = TensorAccessSequence( (2, 2), 4, sizes=[1, 1], strides=[1, 1], offset_fn=offset_fn ) assert tiles == tiles3 - tiles4 = TensorTileSequence( + tiles4 = TensorAccessSequence( (2, 2), 3, sizes=[1, 1], strides=[1, 1], offset_fn=offset_fn ) assert tiles != tiles4 ref_access_order = np.array([[0, 1], [2, -1]]) ref_access_count = np.array([[1, 1], [1, 0]]) - access_order, access_count = tiles4.access_tensors() + access_order, access_count = tiles4.accesses() assert (access_order == ref_access_order).all() assert (access_count == ref_access_count).all() - tiles4_copy = TensorTileSequence.from_tiles(tiles4) + tiles4_copy = TensorAccessSequence.from_taps(tiles4) assert tiles4_copy == tiles4 - assert tiles4_copy.compare_tile_access_orders(tiles4) + assert tiles4_copy.compare_access_orders(tiles4) - access_order, access_count = tiles4_copy.access_tensors() + access_order, access_count = tiles4_copy.accesses() assert (access_order == ref_access_order).all() assert (access_count == ref_access_count).all() @@ -78,7 +78,7 @@ def offset_fn(step, _prev_offset): return step try: - tiles = TensorTileSequence( + tiles = TensorAccessSequence( (0, 2), 4, sizes=[1, 1], strides=[1, 1], offset_fn=offset_fn ) raise Exception("Should fail, bad dims") @@ -86,7 +86,7 @@ def offset_fn(step, _prev_offset): # Good pass try: - tiles = TensorTileSequence( + tiles = TensorAccessSequence( (2, 2), -1, sizes=[1, 1], strides=[1, 1], offset_fn=offset_fn ) raise Exception("Should fail, bad num steps") @@ -94,7 +94,7 @@ def offset_fn(step, _prev_offset): # Good pass try: - tiles = TensorTileSequence( + tiles = TensorAccessSequence( (2, 2), 1, sizes=[1, 0], strides=[0, 1], offset_fn=offset_fn ) raise Exception("Should fail, bad sizes") @@ -102,7 +102,7 @@ def offset_fn(step, _prev_offset): # Good pass try: - tiles = TensorTileSequence( + tiles = TensorAccessSequence( (2, 2), 1, sizes=[1, 1], strides=[-1, 1], offset_fn=offset_fn ) raise Exception("Should fail, bad strides") @@ -110,34 +110,36 @@ def offset_fn(step, _prev_offset): # Good pass try: - tiles = TensorTileSequence((2, 2), 1, strides=[1, 1], offset_fn=offset_fn) + tiles = TensorAccessSequence((2, 2), 1, strides=[1, 1], offset_fn=offset_fn) raise Exception("Should fail, missing sizes") except ValueError: # Good pass try: - tiles = TensorTileSequence((2, 2), 1, sizes=[1, 1], offset_fn=offset_fn) + tiles = TensorAccessSequence((2, 2), 1, sizes=[1, 1], offset_fn=offset_fn) raise Exception("Should fail, missing strides") except ValueError: # Good pass try: - tiles = TensorTileSequence((2, 2), 1, strides=[1, 1], sizes=[1, 1]) + tiles = TensorAccessSequence((2, 2), 1, strides=[1, 1], sizes=[1, 1]) raise Exception("Should fail, missing offset") except ValueError: # Good pass - tiles = TensorTileSequence((2, 3), 1, offset=0, strides=[0, 1], sizes=[1, 1]) + tiles = TensorAccessSequence((2, 3), 1, offset=0, strides=[0, 1], sizes=[1, 1]) try: - tiles.append(TensorTile((3, 2), offset=0, strides=[0, 1], sizes=[1, 1])) + tiles.append( + TensorAccessPattern((3, 2), offset=0, strides=[0, 1], sizes=[1, 1]) + ) raise Exception("Should not be able to add tile with inconsistent tensor dim") except ValueError: # Good pass try: - TensorTileSequence.from_tiles([]) + TensorAccessSequence.from_taps([]) raise Exception("Should not be able to create sequence from no tiles") except ValueError: # Good diff --git a/test/python/tensortiler/tile_repeat_suite.py b/test/python/taplib/tile_repeat_suite.py similarity index 94% rename from test/python/tensortiler/tile_repeat_suite.py rename to test/python/taplib/tile_repeat_suite.py index 33d46c5302..18ac63a4d2 100644 --- a/test/python/tensortiler/tile_repeat_suite.py +++ b/test/python/taplib/tile_repeat_suite.py @@ -1,6 +1,6 @@ import numpy as np -from aie.helpers.tensortiler import TensorTiler2D +from aie.helpers.taplib import TensorTiler2D from util import construct_test #### Tests for Repeat @@ -30,7 +30,7 @@ def tile_repeat1(): tiles = TensorTiler2D.simple_tiler( (TENSOR_HEIGHT, TENSOR_WIDTH), pattern_repeat=REPEAT_COUNT ) - access_order, access_count = tiles.access_tensors() + access_order, access_count = tiles.accesses() assert (access_count == REPEAT_COUNT).all() reference_order = np.array( @@ -75,7 +75,7 @@ def tile_repeat2(): tiles = TensorTiler2D.simple_tiler( (TENSOR_HEIGHT, TENSOR_WIDTH), tile_col_major=True, pattern_repeat=REPEAT_COUNT ) - access_order, access_count = tiles.access_tensors() + access_order, access_count = tiles.accesses() assert (access_count == REPEAT_COUNT).all() reference_order = np.array( @@ -125,7 +125,7 @@ def tile_repeat3(): pattern_repeat=REPEAT_COUNT, ) tile = tiles[0] - access_order, access_count = tile.access_tensors() + access_order, access_count = tile.accesses() assert (access_count[0:TILE_HEIGHT, 0:TILE_WIDTH] == REPEAT_COUNT).all() reference_order = np.array( @@ -145,7 +145,7 @@ def tile_repeat3(): ).all(), f"{reference_order} {access_order}" tile = tiles[2] - access_order, access_count = tile.access_tensors() + access_order, access_count = tile.accesses() assert ( access_count[0:TILE_HEIGHT, TILE_WIDTH * 2 : TILE_WIDTH * 3] == REPEAT_COUNT ).all() @@ -173,7 +173,7 @@ def tile_repeat4(): iter_col_major=True, ) tile = tiles[0] - access_order, access_count = tile.access_tensors() + access_order, access_count = tile.accesses() assert (access_count[0:TILE_HEIGHT, 0:TILE_WIDTH] == REPEAT_COUNT).all() reference_order = np.array( @@ -193,7 +193,7 @@ def tile_repeat4(): ).all(), f"{reference_order} {access_order}" tile = tiles[2] - access_order, access_count = tile.access_tensors() + access_order, access_count = tile.accesses() assert ( access_count[TILE_HEIGHT * 2 : TILE_HEIGHT * 3, 0:TILE_WIDTH] == REPEAT_COUNT ).all() @@ -222,7 +222,7 @@ def tile_repeat5(): pattern_repeat=REPEAT_COUNT, ) tile = tiles[0] - access_order, access_count = tile.access_tensors() + access_order, access_count = tile.accesses() assert (access_count[0:TILE_HEIGHT, 0:TILE_WIDTH] == REPEAT_COUNT).all() reference_order = np.array( @@ -242,7 +242,7 @@ def tile_repeat5(): ).all(), f"{reference_order} {access_order}" tile = tiles[2] - access_order, access_count = tile.access_tensors() + access_order, access_count = tile.accesses() assert ( access_count[TILE_HEIGHT * 2 : TILE_HEIGHT * 3, 0:TILE_WIDTH] == REPEAT_COUNT ).all() @@ -271,7 +271,7 @@ def tile_repeat6(): pattern_repeat=REPEAT_COUNT, ) tile = tiles[0] - access_order, access_count = tile.access_tensors() + access_order, access_count = tile.accesses() assert ( access_count[0:TILE_HEIGHT, 0 : TILE_WIDTH * TILE_GROUP_WIDTH] == REPEAT_COUNT ).all() @@ -296,7 +296,7 @@ def tile_repeat6(): ).all(), f"{reference_order} {access_order}" tile = tiles[1] - access_order, access_count = tile.access_tensors() + access_order, access_count = tile.accesses() assert ( access_count[ 0:TILE_HEIGHT, @@ -334,7 +334,7 @@ def tile_repeat7(): tile_col_major=True, ) tile = tiles[0] - access_order, access_count = tile.access_tensors() + access_order, access_count = tile.accesses() assert ( access_count[0:TILE_HEIGHT, 0 : TILE_WIDTH * TILE_GROUP_WIDTH] == REPEAT_COUNT ).all() @@ -359,7 +359,7 @@ def tile_repeat7(): ).all(), f"{reference_order} {access_order}" tile = tiles[1] - access_order, access_count = tile.access_tensors() + access_order, access_count = tile.accesses() assert ( access_count[ 0:TILE_HEIGHT, @@ -396,7 +396,7 @@ def tile_repeat8(): pattern_repeat=REPEAT_COUNT, ) tile = tiles[0] - access_order, access_count = tile.access_tensors() + access_order, access_count = tile.accesses() assert ( access_count[0 : TILE_HEIGHT * TILE_GROUP_HEIGHT, 0:TILE_WIDTH] == REPEAT_COUNT ).all() @@ -425,7 +425,7 @@ def tile_repeat8(): ).all(), f"{reference_order} {access_order}" tile = tiles[1] - access_order, access_count = tile.access_tensors() + access_order, access_count = tile.accesses() assert ( access_count[0 : TILE_HEIGHT * TILE_GROUP_HEIGHT, TILE_WIDTH : TILE_WIDTH * 2] == REPEAT_COUNT @@ -457,7 +457,7 @@ def tile_repeat9(): tile_col_major=True, ) tile = tiles[0] - access_order, access_count = tile.access_tensors() + access_order, access_count = tile.accesses() assert ( access_count[0 : TILE_HEIGHT * TILE_GROUP_HEIGHT, 0:TILE_WIDTH] == REPEAT_COUNT ).all() @@ -486,7 +486,7 @@ def tile_repeat9(): ).all(), f"{reference_order} {access_order}" tile = tiles[1] - access_order, access_count = tile.access_tensors() + access_order, access_count = tile.accesses() assert ( access_count[0 : TILE_HEIGHT * TILE_GROUP_HEIGHT, TILE_WIDTH : TILE_WIDTH * 2] == REPEAT_COUNT @@ -519,7 +519,7 @@ def tile_repeat10(): tile_group_col_major=True, ) tile = tiles[0] - access_order, access_count = tile.access_tensors() + access_order, access_count = tile.accesses() assert ( access_count[ 0 : TILE_HEIGHT * TILE_GROUP_HEIGHT, 0 : TILE_WIDTH * TILE_GROUP_HEIGHT @@ -557,7 +557,7 @@ def tile_repeat10(): ).all(), f"{reference_order} {access_order}" tile = tiles[1] - access_order, access_count = tile.access_tensors() + access_order, access_count = tile.accesses() assert ( access_count[ 0 : TILE_HEIGHT * TILE_GROUP_HEIGHT, @@ -596,7 +596,7 @@ def tile_repeat11(): tile_col_major=True, ) tile = tiles[0] - access_order, access_count = tile.access_tensors() + access_order, access_count = tile.accesses() assert ( access_count[ 0 : TILE_HEIGHT * TILE_GROUP_HEIGHT, 0 : TILE_WIDTH * TILE_GROUP_HEIGHT @@ -634,7 +634,7 @@ def tile_repeat11(): ).all(), f"{reference_order} {access_order}" tile = tiles[1] - access_order, access_count = tile.access_tensors() + access_order, access_count = tile.accesses() assert ( access_count[ 0 : TILE_HEIGHT * TILE_GROUP_HEIGHT, diff --git a/test/python/tensortiler/util.py b/test/python/taplib/util.py similarity index 100% rename from test/python/tensortiler/util.py rename to test/python/taplib/util.py