Skip to content

Commit 1357279

Browse files
authored
[libclc] Move rsqrt to the CLC library (#129045)
This also adds missing half variants to certain targets. It also optimizes some targets' implementations to perform the operation directly in vector types, as opposed to scalarizing.
1 parent 240f226 commit 1357279

File tree

10 files changed

+70
-42
lines changed

10 files changed

+70
-42
lines changed

libclc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
3131
clc/lib/amdgcn/SOURCES;
3232
clc/lib/amdgpu/SOURCES;
3333
clc/lib/clspv/SOURCES;
34+
clc/lib/r600/SOURCES;
3435
clc/lib/spirv/SOURCES;
3536
)
3637

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef __CLC_MATH_CLC_RSQRT_H__
2+
#define __CLC_MATH_CLC_RSQRT_H__
3+
4+
#define __CLC_BODY <clc/math/unary_decl.inc>
5+
#define __CLC_FUNCTION __clc_rsqrt
6+
7+
#include <clc/math/gentype.inc>
8+
9+
#undef __CLC_BODY
10+
#undef __CLC_FUNCTION
11+
12+
#endif // __CLC_MATH_CLC_RSQRT_H__

libclc/clc/lib/generic/SOURCES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ math/clc_nan.cl
3333
math/clc_nextafter.cl
3434
math/clc_rint.cl
3535
math/clc_round.cl
36+
math/clc_rsqrt.cl
3637
math/clc_sqrt.cl
3738
math/clc_sw_fma.cl
3839
math/clc_trunc.cl
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2014,2015 Advanced Micro Devices, Inc.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*/
22+
23+
#include <clc/internal/clc.h>
24+
25+
#define __CLC_BODY <clc_rsqrt.inc>
26+
#include <clc/math/gentype.inc>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
__attribute__((weak)) _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE
2+
__clc_rsqrt(__CLC_GENTYPE val) {
3+
#pragma clang fp contract(fast)
4+
return __CLC_FP_LIT(1.0) / __builtin_elementwise_sqrt(val);
5+
}

libclc/clc/lib/r600/SOURCES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
math/clc_rsqrt_override.cl
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <clc/clcmacro.h>
2+
#include <clc/internal/clc.h>
3+
4+
_CLC_OVERLOAD _CLC_DEF float __clc_rsqrt(float x) {
5+
return __builtin_r600_recipsqrt_ieeef(x);
6+
}
7+
8+
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, __clc_rsqrt, float);
9+
10+
#ifdef cl_khr_fp64
11+
12+
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
13+
14+
_CLC_OVERLOAD _CLC_DEF double __clc_rsqrt(double x) {
15+
return __builtin_r600_recipsqrt_ieee(x);
16+
}
17+
18+
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, __clc_rsqrt, double);
19+
20+
#endif

libclc/generic/lib/math/rsqrt.cl

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,7 @@
11
#include <clc/clc.h>
2-
#include <clc/clcmacro.h>
2+
#include <clc/math/clc_rsqrt.h>
33

4-
_CLC_OVERLOAD _CLC_DEF float rsqrt(float x)
5-
{
6-
return 1.0f / sqrt(x);
7-
}
4+
#define FUNCTION rsqrt
5+
#define __CLC_BODY <clc/shared/unary_def.inc>
86

9-
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, rsqrt, float);
10-
11-
#ifdef cl_khr_fp64
12-
13-
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
14-
15-
_CLC_OVERLOAD _CLC_DEF double rsqrt(double x)
16-
{
17-
return 1.0 / sqrt(x);
18-
}
19-
20-
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, rsqrt, double);
21-
22-
#endif
7+
#include <clc/math/gentype.inc>

libclc/r600/lib/SOURCES

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
math/fmax.cl
22
math/fmin.cl
33
math/native_rsqrt.cl
4-
math/rsqrt.cl
54
synchronization/barrier.cl
65
workitem/get_global_offset.cl
76
workitem/get_group_id.cl

libclc/r600/lib/math/rsqrt.cl

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)