Skip to content

Commit

Permalink
Refs #7. Add Floor function.
Browse files Browse the repository at this point in the history
  • Loading branch information
xianyi committed Aug 14, 2015
1 parent fc91a45 commit 845518e
Show file tree
Hide file tree
Showing 15 changed files with 207 additions and 2 deletions.
3 changes: 3 additions & 0 deletions include/openvml.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions include/openvml_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions include/openvml_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions include/openvml_reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion interface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
39 changes: 39 additions & 0 deletions interface/floor.c
Original file line number Diff line number Diff line change
@@ -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 <openvml.h>
#include <openvml_driver.h>
#include <openvml_kernel.h>


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);

}
2 changes: 1 addition & 1 deletion kernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions kernel/arm/Kernel_generic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 3 additions & 0 deletions kernel/generic/Kernel_generic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
40 changes: 40 additions & 0 deletions kernel/generic/floor_kernel.c
Original file line number Diff line number Diff line change
@@ -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 <math.h>
#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<n; i++){
y[i]=FLOOR(a[i]);
}
}
3 changes: 3 additions & 0 deletions kernel/x86_64/Kernel_generic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ set(ln_D_KERNEL_SOURCE generic/ln_kernel.c)

set(log1p_S_KERNEL_SOURCE generic/log1p_kernel.c)
set(log1p_D_KERNEL_SOURCE generic/log1p_kernel.c)

set(floor_S_KERNEL_SOURCE generic/floor_kernel.c)
set(floor_D_KERNEL_SOURCE generic/floor_kernel.c)
1 change: 1 addition & 0 deletions reference/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(OpenVML_REF_SRC
vlog10.c
vln.c
vlog1p.c
vfloor.c
)

add_library(${OpenVML_LIBNAME}_ref SHARED ${OpenVML_REF_SRC})
Expand Down
48 changes: 48 additions & 0 deletions reference/vfloor.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* * 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 <stdlib.h>
#include <math.h>
#include <openvml_reference.h>

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<n; i++){
y[i]=floorf(a[i]);
}
}

void OpenVML_FUNCNAME_REF(vdFloor)(VML_INT n, const double * a, double * y){
VML_INT i;
if (n<=0) return;
if (a==NULL || y==NULL) return;

for(i=0; i<n; i++){
y[i]=floor(a[i]);
}
}
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set(OpenVML_TESTSRC
test_log10.c
test_ln.c
test_log1p.c
test_floor.c
)

set(OpenVML_TEST_NAME run_vml_test)
Expand Down
55 changes: 55 additions & 0 deletions test/test_floor.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* * 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 "vml_test.h"
#include <stdio.h>
#include <string.h>
#include <openvml_reference.h>

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);
}

0 comments on commit 845518e

Please sign in to comment.