Skip to content

Commit

Permalink
Fix native builtins with double as the input.
Browse files Browse the repository at this point in the history
If double was used as the input for the native builtins then we would
get a link error. native builtins don't have an overload for double
but we were providing one. This was also true of some half native builtins.

Removing from the overloads fixes the issue as double or half are then
cast to float.
  • Loading branch information
coldav committed May 23, 2024
1 parent c5d7cf5 commit 86fb0fd
Show file tree
Hide file tree
Showing 9 changed files with 1,732 additions and 96 deletions.
96 changes: 0 additions & 96 deletions modules/compiler/builtins/include/builtins/builtins.h

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions source/cl/test/UnitCL/kernels/kernel_source_list.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ set(KERNEL_FILES
${CMAKE_CURRENT_SOURCE_DIR}/regression.106_varying_lcssa_phi.cl
${CMAKE_CURRENT_SOURCE_DIR}/regression.107_byval_struct_align.cl
${CMAKE_CURRENT_SOURCE_DIR}/regression.108_absdiff_int.cl
${CMAKE_CURRENT_SOURCE_DIR}/regression.109_libm_native_double_input.cl
${CMAKE_CURRENT_SOURCE_DIR}/regression.110_libm_native_half_input.cl
${CMAKE_CURRENT_SOURCE_DIR}/spirv.01_copy.cl
${CMAKE_CURRENT_SOURCE_DIR}/spirv.02_async_copy.cl
${CMAKE_CURRENT_SOURCE_DIR}/spirv.03_test_atomic_add.cl
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (C) Codeplay Software Limited
//
// Licensed under the Apache License, Version 2.0 (the "License") with LLVM
// Exceptions; you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://github.com/codeplaysoftware/oneapi-construction-kit/blob/main/LICENSE.txt
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
//
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// CLC OPTIONS: -cl-fast-relaxed-math
// SPIRV OPTIONS: -cl-fast-relaxed-math

// The purpose of this test is to exercise builtin native functions where we use
// half as input. We use the same logic as other testing of builtin functions
// where we give opportunity to be replaced by LLVM intrinsics, which may in
// turn be replaced by calls to libm. That can either only happen when libm is
// accessible (e.g. by the loader linking in libm functions).
//
// This test specifically requires fast-math because that gives the compiler
// more lee-way to do the replacement.

// To avoid needing to account for ULP errors in the various functions being
// tested, just compare the result against an impossible value (for the given
// inputs, which the compiler does not know). For the trig functions a smart
// compiler could maybe figure out that the comparison is impossible, but at
// the time of writing ComputeAorta is not that smart.

// REQUIRES: double

#define BIG_VALF 5.0f

kernel void libm_native_double_input(__global double* in, __global double* out) {
uint index = 0;

out[index] = native_cos(in[index]) >= BIG_VALF ? 2.0f : 1.0f; index++;
out[index] = native_exp(in[index]) >= BIG_VALF ? 2.0f : 1.0f; index++;
out[index] = native_exp2(in[index]) >= BIG_VALF ? 2.0f : 1.0f; index++;
out[index] = native_exp10(in[index]) >= BIG_VALF * 3.0 ? 2.0f : 1.0f; index++;
out[index] = native_log(in[index]) >= BIG_VALF ? 2.0f : 1.0f; index++;
out[index] = native_log2(in[index]) >= BIG_VALF ? 2.0f : 1.0f; index++;
out[index] = native_log10(in[index]) >= BIG_VALF ? 2.0f : 1.0f; index++;
out[index] = native_rsqrt(in[index]) >= BIG_VALF ? 2.0f : 1.0f; index++;
out[index] = native_sin(in[index]) >= BIG_VALF ? 2.0f : 1.0f; index++;
out[index] = native_sqrt(in[index]) >= BIG_VALF ? 2.0f : 1.0f; index++;
out[index] = native_divide(in[index], 1000.0) >= BIG_VALF ? 2.0f : 1.0f; index++;
out[index] = native_powr(in[index], 1.0) >= BIG_VALF ? 2.0f : 1.0f; index++;

}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (C) Codeplay Software Limited
//
// Licensed under the Apache License, Version 2.0 (the "License") with LLVM
// Exceptions; you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://github.com/codeplaysoftware/oneapi-construction-kit/blob/main/LICENSE.txt
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
//
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// CLC OPTIONS: -cl-fast-relaxed-math
// SPIRV OPTIONS: -cl-fast-relaxed-math

// The purpose of this test is to exercise builtin native functions where we use
// half as input. We use the same logic as other testing of builtin functions
// where we give opportunity to be replaced by LLVM intrinsics, which may in
// turn be replaced by calls to libm. That can either only happen when libm is
// accessible (e.g. by the loader linking in libm functions).
//
// This test specifically requires fast-math because that gives the compiler
// more lee-way to do the replacement.

// To avoid needing to account for ULP errors in the various functions being
// tested, just compare the result against an impossible value (for the given
// inputs, which the compiler does not know). For the trig functions a smart
// compiler could maybe figure out that the comparison is impossible, but at
// the time of writing ComputeAorta is not that smart.

// REQUIRES: half

#pragma OPENCL EXTENSION cl_khr_fp16 : enable

#define BIG_VALF 5.0h

kernel void libm_native_half_input(__global half* in, __global half* out) {
uint index = 0;

out[index] = native_cos(in[index]) >= BIG_VALF ? 2.0h : 1.0h; index++;
out[index] = native_exp(in[index]) >= BIG_VALF ? 2.0h : 1.0h; index++;
out[index] = native_exp2(in[index]) >= BIG_VALF ? 2.0h : 1.0h; index++;
out[index] = native_exp10(in[index]) >= BIG_VALF * 3.0 ? 2.0h : 1.0h; index++;
out[index] = native_log(in[index]) >= BIG_VALF ? 2.0h : 1.0h; index++;
out[index] = native_log2(in[index]) >= BIG_VALF ? 2.0h : 1.0h; index++;
out[index] = native_log10(in[index]) >= BIG_VALF ? 2.0h : 1.0h; index++;
out[index] = native_rsqrt(in[index]) >= BIG_VALF ? 2.0h : 1.0h; index++;
out[index] = native_sin(in[index]) >= BIG_VALF ? 2.0h : 1.0h; index++;
out[index] = native_sqrt(in[index]) >= BIG_VALF ? 2.0h : 1.0h; index++;
out[index] = native_divide(in[index], (double)1000.0) >= BIG_VALF ? 2.0h : 1.0h; index++;
out[index] = native_powr(in[index], 1.0h) >= BIG_VALF ? 2.0h : 1.0h; index++;
out[index] = native_divide(in[index], 1000.0h) >= BIG_VALF ? 2.0h : 1.0h; index++;
}
Loading

0 comments on commit 86fb0fd

Please sign in to comment.