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

[spirv] Add 16 bit float immediate number #4787

Merged
merged 3 commits into from
Apr 14, 2022
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
5 changes: 5 additions & 0 deletions taichi/codegen/spirv/spirv_ir_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ Value IRBuilder::float_immediate_number(const SType &dtype,
uint32_t *ptr = reinterpret_cast<uint32_t *>(&fvalue);
uint64_t data = ptr[0];
return get_const(dtype, &data, cache);
} else if (data_type_bits(dtype.dt) == 16) {
float fvalue = static_cast<float>(value);
uint16_t *ptr = reinterpret_cast<uint16_t *>(&fvalue);
uint64_t data = ptr[0];
return get_const(dtype, &data, cache);
} else {
TI_ERROR("Type {} not supported.", dtype.dt->to_string());
}
Expand Down
4 changes: 1 addition & 3 deletions tests/python/test_f16.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,7 @@ def complex_sqr(z):
def paint(t: float):
for i, j in pixels: # Parallelized over all pixels
c = ti.Vector([-0.8, ti.cos(t) * 0.2], dt=ti.f16)
z = ti.Vector([
i / n - 1, j / n - 0.5
]) * 2 # FIXME: the kernel crashes when z stores f16
z = ti.Vector([i / n - 1, j / n - 0.5], dt=ti.f16) * 2
iterations = 0
while z.norm() < 20 and iterations < 50:
z = complex_sqr(z) + c
Expand Down