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

[Type][Backend] Support fp16 #285

Merged
merged 3 commits into from
Jan 4, 2025
Merged

[Type][Backend] Support fp16 #285

merged 3 commits into from
Jan 4, 2025

Conversation

chhzh123
Copy link
Member

@chhzh123 chhzh123 commented Jan 4, 2025

Description

This PR adds fp16 support for both LLVM and HLS backend. The LLVM backend needs to first represent the float16 value in int16, and the HLS backend uses half to represent fp16.

Examples

def test_fp16_array():
    def kernel(A: float16[10]) -> float16[10]:
        B: float16[10]
        for i in range(10):
            B[i] = A[i] + 1
        return B

    s = allo.customize(kernel)
    assert "f16" in str(s.module)
    mod = s.build()
    A = np.random.rand(10).astype(np.float16)
    B = mod(A)
    np.testing.assert_allclose(B, A + 1, 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 e8b597e into cornell-zhang:main Jan 4, 2025
1 check passed
@chhzh123 chhzh123 deleted the fp16 branch January 4, 2025 04:36
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