Skip to content

Conversation

@wenju-he
Copy link
Contributor

This is ported from https://github.com/intel/llvm/blob/sycl/libclc/libspirv/lib/generic/geometric/normalize.cl and can pass a closed-source OpenCL CTS
"test_geometrics geom_normalize --half CL_DEVICE_TYPE_GPU" on intel GPU.

llvm-diff amdgcn--amdhsa.bc shows fpext/fptrunc insts are now removed from normalize function.

This is ported from https://github.com/intel/llvm/blob/sycl/libclc/libspirv/lib/generic/geometric/normalize.cl
and can pass a closed-source OpenCL CTS
"test_geometrics geom_normalize --half CL_DEVICE_TYPE_GPU" on intel GPU.

llvm-diff amdgcn--amdhsa.bc shows fpext/fptrunc insts are now removed
from normalize function.
@llvmbot llvmbot added the libclc libclc OpenCL library label Jul 23, 2025
@wenju-he
Copy link
Contributor Author

llvm-diff amdgcn--amdhsa.bc.new amdgcn--amdhsa.bc.old

in function _Z9normalizeDh:
  in block %1 / %1:
    >   %2 = fpext half %0 to float
        %2 = fcmp one half %0, 0xH0000
    >   %4 = select i1 %3, float 1.000000e+00, float 0.000000e+00
    >   %5 = tail call noundef float @llvm.copysign.f32(float %4, float %2)
    >   %6 = fptrunc float %5 to half
    >   ret half %6
    <   %3 = select i1 %2, half 0xH3C00, half 0xH0000
    <   %4 = tail call noundef half @llvm.copysign.f16(half %3, half %0)
    <   ret half %4

in function _Z9normalizeDv2_Dh:
  in block %1 / %1:
    >   %2 = fpext <2 x half> %0 to <2 x float>

in function _Z9normalizeDv3_Dh:
  in block %1 / %1:
    >   %2 = fpext <3 x half> %0 to <3 x float>

in function _Z9normalizeDv4_Dh:
  in block %1 / %1:
    >   %2 = fpext <4 x half> %0 to <4 x float>

@wenju-he wenju-he requested review from arsenm and frasercrmck July 23, 2025 05:06
@wenju-he wenju-he changed the title [libclc] Add native half implementation of __clc_normalize [libclc] Add generic native half implementation of __clc_normalize Jul 23, 2025
@wenju-he wenju-he merged commit 5223317 into llvm:main Jul 29, 2025
11 checks passed
@wenju-he wenju-he deleted the __clc_normalize-half branch July 29, 2025 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libclc libclc OpenCL library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants