Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Runtime] Support arbitrary bitwidth integer in LLVM execution engine #37

Merged
merged 17 commits into from
Aug 21, 2023
Merged

[Runtime] Support arbitrary bitwidth integer in LLVM execution engine #37

merged 17 commits into from
Aug 21, 2023

Conversation

chhzh123
Copy link
Member

Description

This PR ports the PR of HeteroCL #493 to support arbitrary bitwidth integers in LLVM execution engine.

Proposed Solutions

This PR constructs arrays with arbitrary bitwidth integers by creating customized numpy struct data type, packing and unpacking the results before and after the execution. Different signless integers have been tested. Unsigned types will be added in the next PR, since it still needs more annotations in the IR builder.

Examples

See the following example. Casting and (un)wrapping can be done automatically by the execution engine, so users have no need to worry about the data types, but just directly pass in the numpy arrays.

def test_arbitrary_bitwidth_gemm_alloc_output():
    M, N, K = 4, 4, 4
    T_IN, T_OUT = Int(5), Int(14)

    def gemm(A: T_IN[M, K], B: T_IN[K, N]) -> T_OUT[M, N]:
        C: T_OUT[M, N] = 0
        for i, j, k in allo.grid(M, N, K, name="C"):
            C[i, j] += A[i, k] * B[k, j]
        return C

    s = allo.customize(gemm)
    mod = s.build()
    np_A = np.random.randint(-4, 4, size=(M, K)).astype(np.int32)
    np_B = np.random.randint(-4, 4, size=(K, N)).astype(np.int32)
    np_C = np.matmul(np_A, np_B)
    np_C_allo = mod(np_A, np_B)
    np.testing.assert_allclose(np_C, np_C_allo, rtol=1e-5)

Checklist

  • PR's title starts with a category (e.g. [Bugfix], [IR], [Builder], etc)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage (It would be better to provide ~2 different test cases to test the robustness of your code)
  • Code is well-documented

@chhzh123 chhzh123 merged commit df35d4c into cornell-zhang:main Aug 21, 2023
@chhzh123 chhzh123 deleted the arbitrary_bitwidth_int branch August 31, 2023 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant