Add tanh for real numbers.

This commit is contained in:
Zhang Xianyi 2015-01-08 14:56:38 +08:00
parent 40d5f98efc
commit fd711810d7
7 changed files with 101 additions and 2 deletions

View File

@ -53,4 +53,10 @@ void OpenVML_FUNCNAME(dexp_k)(VMLLONG n, double * a, double * b, double * y, dou
void OpenVML_FUNCNAME(cexp_k)(VMLLONG n, float * a, float * b, float * y, float * z, float * other_params);
void OpenVML_FUNCNAME(zexp_k)(VMLLONG n, double * a, double * b, double * y, double * z, double * other_params);
void OpenVML_FUNCNAME(stanh_k)(VMLLONG n, float * a, float * b, float * y, float * z, float * other_params);
void OpenVML_FUNCNAME(dtanh_k)(VMLLONG n, double * a, double * b, double * y, double * z, double * other_params);
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);
#endif

View File

@ -53,17 +53,26 @@
#define CEXP_K OpenVML_FUNCNAME(cexp_k)
#define ZEXP_K OpenVML_FUNCNAME(zexp_k)
#define STANH_K OpenVML_FUNCNAME(stanh_k)
#define DTANH_K OpenVML_FUNCNAME(dtanh_k)
#define CTANH_K OpenVML_FUNCNAME(ctanh_k)
#define ZTANH_K OpenVML_FUNCNAME(ztanh_k)
#ifndef COMPLEX
#ifndef DOUBLE
#define ADD_K SADD_K
#define SUB_K SSUB_K
#define POW_K SPOW_K
#define EXP_K SEXP_K
#define TANH_K STANH_K
#else
#define ADD_K DADD_K
#define SUB_K DSUB_K
#define POW_K DPOW_K
#define EXP_K DEXP_K
#define TANH_K DTANH_K
#endif
#else
#ifndef DOUBLE
@ -71,11 +80,13 @@
#define SUB_K CSUB_K
#define POW_K CPOW_K
#define EXP_K CEXP_K
#define TANH_K CTANH_K
#else
#define ADD_K ZADD_K
#define SUB_K ZSUB_K
#define POW_K ZPOW_K
#define EXP_K ZEXP_K
#define TANH_K ZTANH_K
#endif
#endif

View File

@ -5,7 +5,7 @@ set(OpenVML_LIBSRC_D "")
set(OpenVML_LIBSRC_C "")
set(OpenVML_LIBSRC_Z "")
set(REAL_INTERFACE_LIST add sub pow exp)
set(REAL_INTERFACE_LIST add sub pow exp tanh)
set(COMPLEX_INTERFACE_LIST add sub)
function(cap_string var_name var_name_cap)

39
interface/tanh.c Normal file
View File

@ -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, TANH_K, n, (VML_FLOAT*)a, NULL, y, NULL, NULL);
}

View File

@ -6,7 +6,7 @@ set(OpenVML_LIBSRC_D "")
set(OpenVML_LIBSRC_C "")
set(OpenVML_LIBSRC_Z "")
set(KERNEL_LIST add sub pow exp) #s,d
set(KERNEL_LIST add sub pow exp tanh) #s,d
set(Z_KERNEL_LIST add sub) #c,z
######## s,d kernels

View File

@ -16,3 +16,6 @@ set(pow_D_KERNEL_SOURCE ${OpenVML_ARCH}/pow_kernel.c)
set(exp_S_KERNEL_SOURCE ${OpenVML_ARCH}/exp_kernel.c)
set(exp_D_KERNEL_SOURCE ${OpenVML_ARCH}/exp_kernel.c)
set(tanh_S_KERNEL_SOURCE ${OpenVML_ARCH}/tanh_kernel.c)
set(tanh_D_KERNEL_SOURCE ${OpenVML_ARCH}/tanh_kernel.c)

View File

@ -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 TANH tanhf
#else
#define TANH tanh
#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]=TANH(a[i]);
}
}