Files
tilelang/testing/python/transform/test_simplifiler.py
T
57ab687cf7 [Initialization] Migration of Codebase from Dev Branch into Main (#10)
* Add format.sh script for code formatting and linting

* docs update

* center align the title

* lint fix

* add ignore

* Add .gitignore for 3rdparty directory

* Add requirements-dev.txt, requirements-test.txt, and requirements.txt

* 3rdparty

* Add gemm.h, CMakeLists.txt, _ffi_api.py, __init__.py, runtime.h, reduce.h, loop_partition.h, utils.h, and loop_vectorize.h

* Refactor CMakeLists.txt and include statements

- Update CMakeLists.txt to use a newer version of CMake and add project name
- Remove unnecessary include directories

Fix include paths in layout.cc, codegen.cc, codegen.h, rt_mod.cc, frontend_legalize.cc, inject_pipeline.cc, layout_inference.cc, loop_vectorize.cc, and lower_tile_op.cc

- Update include paths to use relative paths instead of absolute paths

* Update submodule for 3rdparty/tvm

* update

* load dll first

* Refactor CMakeLists.txt and include statements

* Refactor CMakeLists.txt and include statements

* git keep update

* Refactor CMakeLists.txt and include statements

* Refactor CMakeLists.txt and include statements

* refactor code structure

* Update Readme

* CMakeLists Customized

* update readme

* update README

* update readme

* update usage

* with TVM_IMPORT_PYTHON_PATH to handle own tvm build python import

* annotate lower transform global func with `transform` prefix

* Migrate Simplify Pass from tilelang tvm branch

* enhance system environment handling with __init__ and CMake

* Initial commit

* CODE_OF_CONDUCT.md committed

* LICENSE committed

* README.md committed

* SECURITY.md committed

* SUPPORT.md committed

* CODE_OF_CONDUCT Commit

* LICENSE Commit

* SECURITY Commit

* SUPPORT Commit

* Modify Support

* Update README.md

* security ci update

* remove examples

* Update and implement clang-format

* add composable kernel components

* Migrate from latest update

* submodule update

* Test update

* Update License

* Spell check

* lint fix

* add clang-tidy to apply static analysis for c source

* update tilelang examples

* Update Install Docs

* Refactor filetree

* Enhance Install

* conflict resloved

* annotate_version

* Initial Update

* test fix

* install

* Implement setup.py

* lint fix

* Separate Init

* Separate test

* docker file commit

* add logo

* Update Readme and Examples

* update readme

* update logo

* Implement AMD Installation

* Add License

* Update AMD MI300x Benchmark

* update README

* update mi300 benchmark scripts

* update ignore

* enhance build scirpt

* update image

* enhance setup.py to remove duplicated libraries

* remove debug files

* update readme

* update image

* update gemm examples

* update flashattention README

* readme update

* add cmake into requirements

* libinfo fix

* auto update submodule

* lint fix

* Fix AMD Build and Test

* Update check for transpose attribute for CDNA Arch

* typo fix for amd

* Implement Matmul Benchmark

* Refactor Code

* [TypoFix] Fix GEMM Example

* [Docs] Init Linear Attention README

* [TYPO] Typo fix

* [Lint] Lint Fix

* enhance example with intrinsics

* [Enhancement] Improve Buffer Collection during IR Parser

* [Dev] Introduce Current classmethod to get current frame

* submodule update

* fake test pass update

* support thread_extent_api

* code optimize

* Add GEMM function implementation for matrix multiplication

* Update logging format to reflect TileLang in logger messages

* Refactor CMakeLists.txt for improved readability and set default build type to Release

* Support Gemm SS Primitives Implementation

* [README] Upload Tile Language Logo (#5)

* update logo

* Update README.md to enhance formatting and center the title

---------

Co-authored-by: microsoft-github-operations[bot] <55726097+microsoft-github-operations[bot]@users.noreply.github.com>
Co-authored-by: Microsoft Open Source <microsoftopensource@users.noreply.github.com>
Co-authored-by: Yu Cheng <yu.cheng@pku.edu.cn>
2025-01-11 17:03:47 +08:00

98 lines
3.0 KiB
Python

# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from tilelang import tvm as tvm
import tilelang as tl
import tilelang.language as T
import tilelang.testing
def modify(
with_B: bool = False,
with_bias: bool = False,
):
@T.prim_func
def main(
A: T.Buffer((64, 64)),
B: T.Buffer((64, 64)),
C: T.Buffer((64, 64)),
D: T.Buffer((64, 64)),
bias: T.Buffer((64, 64)),
):
if with_B:
if with_bias:
T.gemm(A, bias, D)
T.gemm(A, B, D)
else:
with T.block():
A_shared = T.alloc_shared((64, 64), dtype="float32")
C_shared = T.alloc_shared((64, 64), dtype="float32")
D_shared = T.alloc_shared((64, 64), dtype="float32")
T.copy(A, A_shared)
T.copy(C, C_shared)
T.gemm(A_shared, C_shared, D_shared)
T.copy(D_shared, D)
return main
def test_modify(with_B=False, with_bias=False):
tester = modify(with_B=with_B, with_bias=with_bias)
mod = tvm.IRModule({tester.attrs["global_symbol"]: tester})
mod2 = tl.transform.Simplify()(mod)
assert mod != mod2
def matmul(M, N, K, block_M, block_N, block_K, dtype="float16", accum_dtype="float"):
@T.prim_func
def main(
a: T.handle,
b: T.handle,
c: T.handle,
):
A = T.match_buffer(a, (M, K), dtype=dtype)
B = T.match_buffer(b, (K, N), dtype=dtype)
C = T.match_buffer(c, (M, N), dtype=accum_dtype)
with T.Kernel(T.ceildiv(N, block_N), T.ceildiv(M, block_M), threads=128) as (bx, by):
A_shared = T.alloc_shared((block_M, block_K), dtype)
B_shared = T.alloc_shared((block_K, block_N), dtype)
C_local = T.alloc_fragment((block_M, block_N), accum_dtype)
T.clear(C_local)
for k in T.Pipelined(T.ceildiv(K, block_K), num_stages=3):
T.copy(A[by * block_M, k * block_K], A_shared)
T.copy(B[k * block_K, bx * block_N], B_shared)
T.gemm(A_shared, B_shared, C_local)
T.copy(C_local, C[by * block_M, bx * block_N])
return main
def test_matmul():
func = matmul(1024, 1024, 1024, 128, 128, 32)
mod = tvm.IRModule({func.attrs["global_symbol"]: func})
mod = tl.transform.Simplify()(mod)
rt_mod, params = tl.lower(mod.functions_items()[0][1], runtime_only=False)
# TODO Profiler only support TensorType, not dynamic variable
profiler = tl.Profiler(rt_mod, params, result_idx=[2])
import torch
a = torch.randn(1024, 1024, dtype=torch.float16).cuda().half()
b = torch.randn(1024, 1024, dtype=torch.float16).cuda().half()
c = profiler(a, b)
ref_c = a @ b
ref_c = ref_c.float()
torch.testing.assert_close(c, ref_c, rtol=1e-2, atol=1e-2)
# Get CUDA Source
# print(rt_mod.imported_modules[0].get_source())
if __name__ == "__main__":
tilelang.testing.main()