From 845518ee64f813cd0595d936b1f2a7303af03f51 Mon Sep 17 00:00:00 2001 From: Zhang Xianyi Date: Fri, 14 Aug 2015 20:48:06 +0000 Subject: [PATCH] Refs #7. Add Floor function. --- include/openvml.h | 3 ++ include/openvml_kernel.h | 4 +++ include/openvml_macros.h | 4 +++ include/openvml_reference.h | 2 ++ interface/CMakeLists.txt | 2 +- interface/floor.c | 39 ++++++++++++++++++++++ kernel/CMakeLists.txt | 2 +- kernel/arm/Kernel_generic.txt | 2 ++ kernel/generic/Kernel_generic.txt | 3 ++ kernel/generic/floor_kernel.c | 40 ++++++++++++++++++++++ kernel/x86_64/Kernel_generic.txt | 3 ++ reference/CMakeLists.txt | 1 + reference/vfloor.c | 48 +++++++++++++++++++++++++++ test/CMakeLists.txt | 1 + test/test_floor.c | 55 +++++++++++++++++++++++++++++++ 15 files changed, 207 insertions(+), 2 deletions(-) create mode 100644 interface/floor.c create mode 100644 kernel/generic/floor_kernel.c create mode 100644 reference/vfloor.c create mode 100644 test/test_floor.c diff --git a/include/openvml.h b/include/openvml.h index e7df1d5..36f566d 100644 --- a/include/openvml.h +++ b/include/openvml.h @@ -64,6 +64,9 @@ OPENVML_EXPORT void OpenVML_FUNCNAME(vdLog1p)(VML_INT n, const double * a, doubl OPENVML_EXPORT void OpenVML_FUNCNAME(vsTanh)(VML_INT n, const float * a, float * y); OPENVML_EXPORT void OpenVML_FUNCNAME(vdTanh)(VML_INT n, const double * a, double * y); +OPENVML_EXPORT void OpenVML_FUNCNAME(vsFloor)(VML_INT n, const float * a, float * y); +OPENVML_EXPORT void OpenVML_FUNCNAME(vdFloor)(VML_INT n, const double * a, double * y); + #ifdef __cplusplus } diff --git a/include/openvml_kernel.h b/include/openvml_kernel.h index aec202c..a4449ba 100644 --- a/include/openvml_kernel.h +++ b/include/openvml_kernel.h @@ -77,4 +77,8 @@ void OpenVML_FUNCNAME(dtanh_k)(VMLLONG n, double * a, double * b, double * y, do void OpenVML_FUNCNAME(ctanh_k)(VMLLONG n, float * a, float * b, float * y, float * z, float * other_params); void OpenVML_FUNCNAME(ztanh_k)(VMLLONG n, double * a, double * b, double * y, double * z, double * other_params); + +void OpenVML_FUNCNAME(sfloor_k)(VMLLONG n, float * a, float * b, float * y, float * z, float * other_params); +void OpenVML_FUNCNAME(dfloor_k)(VMLLONG n, double * a, double * b, double * y, double * z, double * other_params); + #endif diff --git a/include/openvml_macros.h b/include/openvml_macros.h index 9d9d1e7..8208eb9 100644 --- a/include/openvml_macros.h +++ b/include/openvml_macros.h @@ -73,6 +73,8 @@ #define CTANH_K OpenVML_FUNCNAME(ctanh_k) #define ZTANH_K OpenVML_FUNCNAME(ztanh_k) +#define SFLOOR_K OpenVML_FUNCNAME(sfloor_k) +#define DFLOOR_K OpenVML_FUNCNAME(dfloor_k) #ifndef COMPLEX #ifndef DOUBLE @@ -84,6 +86,7 @@ #define LN_K SLN_K #define LOG1P_K SLOG1P_K #define TANH_K STANH_K +#define FLOOR_K SFLOOR_K #else #define ADD_K DADD_K #define SUB_K DSUB_K @@ -93,6 +96,7 @@ #define LN_K DLN_K #define LOG1P_K DLOG1P_K #define TANH_K DTANH_K +#define FLOOR_K DFLOOR_K #endif #else #ifndef DOUBLE diff --git a/include/openvml_reference.h b/include/openvml_reference.h index b368312..787a01a 100644 --- a/include/openvml_reference.h +++ b/include/openvml_reference.h @@ -64,6 +64,8 @@ OPENVML_EXPORT void OpenVML_FUNCNAME_REF(vdLog1p)(VML_INT n, const double * a, d OPENVML_EXPORT void OpenVML_FUNCNAME_REF(vsTanh)(VML_INT n, const float * a, float * y); OPENVML_EXPORT void OpenVML_FUNCNAME_REF(vdTanh)(VML_INT n, const double * a, double * y); +OPENVML_EXPORT void OpenVML_FUNCNAME_REF(vsFloor)(VML_INT n, const float * a, float * y); +OPENVML_EXPORT void OpenVML_FUNCNAME_REF(vdFloor)(VML_INT n, const double * a, double * y); #ifdef __cplusplus } diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index a96359c..8b0639e 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -5,7 +5,7 @@ set(OpenVML_LIBSRC_D "") set(OpenVML_LIBSRC_C "") set(OpenVML_LIBSRC_Z "") -set(REAL_INTERFACE_LIST add sub pow exp tanh log10 ln log1p) +set(REAL_INTERFACE_LIST add sub pow exp tanh log10 ln log1p floor) set(COMPLEX_INTERFACE_LIST add sub) function(cap_string var_name var_name_cap) diff --git a/interface/floor.c b/interface/floor.c new file mode 100644 index 0000000..34e21e0 --- /dev/null +++ b/interface/floor.c @@ -0,0 +1,39 @@ +/* * Copyright (c) 2014, 2015 Zhang Xianyi + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + + +void CNAME(VML_INT n, const VML_FLOAT * a, VML_FLOAT * y) { + + if (n<=0) return; + if (a==NULL || y==NULL) return; + + + EXEC_VML(0, FLOOR_K, n, (VML_FLOAT*)a, NULL, y, NULL, NULL); + +} diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index cd3f0b1..6f34580 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -6,7 +6,7 @@ set(OpenVML_LIBSRC_D "") set(OpenVML_LIBSRC_C "") set(OpenVML_LIBSRC_Z "") -set(KERNEL_LIST add sub pow exp tanh log10 ln log1p) #s,d +set(KERNEL_LIST add sub pow exp tanh log10 ln log1p floor) #s,d set(Z_KERNEL_LIST add sub) #c,z ######## s,d kernels diff --git a/kernel/arm/Kernel_generic.txt b/kernel/arm/Kernel_generic.txt index 0c4cebc..f068f39 100644 --- a/kernel/arm/Kernel_generic.txt +++ b/kernel/arm/Kernel_generic.txt @@ -26,3 +26,5 @@ set(log1p_D_KERNEL_SOURCE generic/log1p_kernel.c) set(tanh_S_KERNEL_SOURCE generic/tanh_kernel.c) set(tanh_D_KERNEL_SOURCE generic/tanh_kernel.c) +set(floor_S_KERNEL_SOURCE generic/floor_kernel.c) +set(floor_D_KERNEL_SOURCE generic/floor_kernel.c) diff --git a/kernel/generic/Kernel_generic.txt b/kernel/generic/Kernel_generic.txt index 158c62d..8a5634d 100644 --- a/kernel/generic/Kernel_generic.txt +++ b/kernel/generic/Kernel_generic.txt @@ -27,3 +27,6 @@ set(log1p_D_KERNEL_SOURCE ${OpenVML_ARCH}/log1p_kernel.c) set(tanh_S_KERNEL_SOURCE ${OpenVML_ARCH}/tanh_kernel.c) set(tanh_D_KERNEL_SOURCE ${OpenVML_ARCH}/tanh_kernel.c) + +set(floor_S_KERNEL_SOURCE ${OpenVML_ARCH}/floor_kernel.c) +set(floor_D_KERNEL_SOURCE ${OpenVML_ARCH}/floor_kernel.c) diff --git a/kernel/generic/floor_kernel.c b/kernel/generic/floor_kernel.c new file mode 100644 index 0000000..e298b7c --- /dev/null +++ b/kernel/generic/floor_kernel.c @@ -0,0 +1,40 @@ +/* * Copyright (c) 2014, 2015 Zhang Xianyi + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "openvml_kernel.h" + +#ifndef DOUBLE +#define FLOOR floorf +#else +#define FLOOR floor +#endif + +void KERNEL_NAME(VMLLONG n, VML_FLOAT * a, VML_FLOAT * b, VML_FLOAT * y, VML_FLOAT * z, VML_FLOAT * other_params) { + VMLLONG i=0; + for(i=0; i +#include +#include + +void OpenVML_FUNCNAME_REF(vsFloor)(VML_INT n, const float * a, float * y){ + VML_INT i; + if (n<=0) return; + if (a==NULL || y==NULL) return; + + for(i=0; i +#include +#include + +static char* funcname[4]={"vsFloor", "vdFloor", NULL,NULL}; +static double flop_per_elem[4]={0.0, 0.0, 0.0, 0.0}; + +static a_y_func_t ref_vfloor[] = { + (a_y_func_t)OpenVML_FUNCNAME_REF(vsFloor), + (a_y_func_t)OpenVML_FUNCNAME_REF(vdFloor), + NULL, + NULL, +}; + +static a_y_func_t test_vfloor[] = { + (a_y_func_t)OpenVML_FUNCNAME(vsFloor), + (a_y_func_t)OpenVML_FUNCNAME(vdFloor), + NULL, + NULL, +}; + + +CTEST2(check_result_s, floor){ + run_test_a_y(data->parameter, funcname, test_vfloor, ref_vfloor, flop_per_elem); +} + +CTEST2(check_result_d, floor){ + run_test_a_y(data->parameter, funcname, test_vfloor, ref_vfloor, flop_per_elem); +}