From 551a669e8050470b70798474e1829e8b2edb9185 Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Mon, 23 Mar 2015 17:01:35 +0000 Subject: [PATCH] Implement distance builtin v2 This implementation was ported from the AMD builtin library and has been tested with piglit, OpenCV, and the ocl conformance tests. v2: - Remove unnecessary copyright. llvm-svn: 232964 --- libclc/generic/include/clc/clc.h | 1 + .../include/clc/geometric/distance.inc | 23 ++++++++++++++ libclc/generic/lib/SOURCES | 1 + libclc/generic/lib/geometric/distance.cl | 30 +++++++++++++++++++ libclc/generic/lib/geometric/distance.inc | 25 ++++++++++++++++ 5 files changed, 80 insertions(+) create mode 100644 libclc/generic/include/clc/geometric/distance.inc create mode 100644 libclc/generic/lib/geometric/distance.cl create mode 100644 libclc/generic/lib/geometric/distance.inc diff --git a/libclc/generic/include/clc/clc.h b/libclc/generic/include/clc/clc.h index 1c12cf3f1660..4be4850b0e6a 100644 --- a/libclc/generic/include/clc/clc.h +++ b/libclc/generic/include/clc/clc.h @@ -117,6 +117,7 @@ /* 6.11.5 Geometric Functions */ #include +#include #include #include #include diff --git a/libclc/generic/include/clc/geometric/distance.inc b/libclc/generic/include/clc/geometric/distance.inc new file mode 100644 index 000000000000..6babbdc30d5d --- /dev/null +++ b/libclc/generic/include/clc/geometric/distance.inc @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2014,2015 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +_CLC_OVERLOAD _CLC_DECL __CLC_FLOAT distance(__CLC_FLOATN p0, __CLC_FLOATN p1); diff --git a/libclc/generic/lib/SOURCES b/libclc/generic/lib/SOURCES index 0110e15b0f4b..f1d3053c754b 100644 --- a/libclc/generic/lib/SOURCES +++ b/libclc/generic/lib/SOURCES @@ -34,6 +34,7 @@ common/sign.cl common/smoothstep.cl common/step.cl geometric/cross.cl +geometric/distance.cl geometric/dot.cl geometric/length.cl geometric/normalize.cl diff --git a/libclc/generic/lib/geometric/distance.cl b/libclc/generic/lib/geometric/distance.cl new file mode 100644 index 000000000000..4a5b8e258790 --- /dev/null +++ b/libclc/generic/lib/geometric/distance.cl @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2014,2015 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#ifdef cl_khr_fp64 +#pragma OPENCL EXTENSION cl_khr_fp64 : enable +#endif + +#define __CLC_BODY +#include diff --git a/libclc/generic/lib/geometric/distance.inc b/libclc/generic/lib/geometric/distance.inc new file mode 100644 index 000000000000..193665ed2e2e --- /dev/null +++ b/libclc/generic/lib/geometric/distance.inc @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2014,2015 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +_CLC_OVERLOAD _CLC_DEF __CLC_FLOAT distance(__CLC_FLOATN p0, __CLC_FLOATN p1) { + return length(p0 - p1); +}