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

dialects: (builtin) add support for f16 packing and unpacking #3605

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions tests/dialects/test_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
VectorBaseTypeConstraint,
VectorRankConstraint,
VectorType,
f16,
f32,
f64,
i1,
Expand All @@ -58,8 +59,7 @@ def test_FloatType_bitwidths():
def test_FloatType_formats():
with pytest.raises(NotImplementedError):
BFloat16Type().format
with pytest.raises(NotImplementedError):
Float16Type().format
assert Float16Type().format == "<e"
assert Float32Type().format == "<f"
assert Float64Type().format == "<d"
with pytest.raises(NotImplementedError):
Expand Down Expand Up @@ -172,6 +172,12 @@ def test_IntegerType_packing():
unpacked_i64 = i64.unpack(buffer_i64, len(nums_i64))
assert nums_i64 == unpacked_i64

# f16
nums_f16 = (-3.140625, -1.0, 0.0, 1.0, 3.140625)
buffer_f16 = f16.pack(nums_f16)
unpacked_f16 = f16.unpack(buffer_f16, len(nums_f16))
assert nums_f16 == unpacked_f16

# f32
nums_f32 = (-3.140000104904175, -1.0, 0.0, 1.0, 3.140000104904175)
buffer_f32 = f32.pack(nums_f32)
Expand Down
2 changes: 1 addition & 1 deletion xdsl/dialects/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ def bitwidth(self) -> int:

@property
def format(self) -> str:
raise NotImplementedError()
return "<e"


@irdl_attr_definition
Expand Down
Loading