Add test for real number exp and tanh functions.

This commit is contained in:
Zhang Xianyi 2015-04-17 08:48:59 -05:00
parent d406a6df62
commit 4f16144857
8 changed files with 279 additions and 2 deletions

View File

@ -2,6 +2,8 @@ set(OpenVML_REF_SRC
vadd.c
vsub.c
vpow.c
vexp.c
vtanh.c
)
add_library(${OpenVML_LIBNAME}_ref SHARED ${OpenVML_REF_SRC})

48
reference/vexp.c Normal file
View File

@ -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(vsExp)(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]=expf(a[i]);
}
}
void OpenVML_FUNCNAME_REF(vdExp)(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]=exp(a[i]);
}
}

48
reference/vtanh.c Normal file
View File

@ -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(vsTanh)(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]=tanhf(a[i]);
}
}
void OpenVML_FUNCNAME_REF(vdTanh)(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]=tanh(a[i]);
}
}

View File

@ -5,6 +5,8 @@ set(OpenVML_TESTSRC
test_add.c
test_sub.c
test_pow.c
test_exp.c
test_tanh.c
)
set(OpenVML_TEST_NAME run_vml_test)

55
test/test_exp.c Normal file
View File

@ -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]={"vsExp", "vdExp", NULL,NULL};
static double flop_per_elem[4]={0.0, 0.0, 0.0, 0.0};
static a_y_func_t ref_vexp[] = {
(a_y_func_t)OpenVML_FUNCNAME_REF(vsExp),
(a_y_func_t)OpenVML_FUNCNAME_REF(vdExp),
NULL,
NULL,
};
static a_y_func_t test_vexp[] = {
(a_y_func_t)OpenVML_FUNCNAME(vsExp),
(a_y_func_t)OpenVML_FUNCNAME(vdExp),
NULL,
NULL,
};
CTEST2(check_result_s, exp){
run_test_a_y(data->parameter, funcname, test_vexp, ref_vexp, flop_per_elem);
}
CTEST2(check_result_d, exp){
run_test_a_y(data->parameter, funcname, test_vexp, ref_vexp, flop_per_elem);
}

55
test/test_tanh.c Normal file
View File

@ -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]={"vsTanh", "vdTanh", NULL,NULL};
static double flop_per_elem[4]={0.0, 0.0, 0.0, 0.0};
static a_y_func_t ref_vtanh[] = {
(a_y_func_t)OpenVML_FUNCNAME_REF(vsTanh),
(a_y_func_t)OpenVML_FUNCNAME_REF(vdTanh),
NULL,
NULL,
};
static a_y_func_t test_vtanh[] = {
(a_y_func_t)OpenVML_FUNCNAME(vsTanh),
(a_y_func_t)OpenVML_FUNCNAME(vdTanh),
NULL,
NULL,
};
CTEST2(check_result_s, tanh){
run_test_a_y(data->parameter, funcname, test_vtanh, ref_vtanh, flop_per_elem);
}
CTEST2(check_result_d, tanh){
run_test_a_y(data->parameter, funcname, test_vtanh, ref_vtanh, flop_per_elem);
}

View File

@ -100,4 +100,8 @@ void init_rand(VML_INT n, void * a, int iscomplex, int isdouble);
typedef void (*ab_y_func_t)(VML_INT, const void *, const void *, void *);
void run_test_ab_y(perf_arg_t * para, char* funcname[], ab_y_func_t*test_func, ab_y_func_t* ref_func,
double * flop_per_elem);
typedef void (*a_y_func_t)(VML_INT, const void *, void *);
void run_test_a_y(perf_arg_t * para, char* funcname[], a_y_func_t*test_func, a_y_func_t* ref_func,
double * flop_per_elem);
#endif

View File

@ -294,7 +294,7 @@ void init_rand(VML_INT n, void * a, int iscomplex, int isdouble)
void flush_cache(void * flushcache)
{
if(flushcache!=NULL){
memset(flushcache, 1, FLUSHCACHE_SIZE);
//memset(flushcache, 1, FLUSHCACHE_SIZE);
}
}
@ -332,7 +332,7 @@ void run_test_ab_y(perf_arg_t * para, char* funcname[], ab_y_func_t test_func[],
mflops=flops_per_elem[para->fp_type] * i;
//need to clean cache
//flush_cache(para->flushcache);
flush_cache(para->flushcache);
start_time=getRealTime();
test_func[para->fp_type](i, para->a, para->b, para->y);
@ -361,3 +361,66 @@ void run_test_ab_y(perf_arg_t * para, char* funcname[], ab_y_func_t test_func[],
if(failed_count>0) CTEST_ERR("Result failed!\n");
}
void run_test_a_y(perf_arg_t * para, char* funcname[], a_y_func_t test_func[], a_y_func_t ref_func[],
double * flops_per_elem)
{
VML_INT start=para->start;
VML_INT end=para->end;
VML_INT step=para->step;
double mflops=0.0;
double time=0.0, start_time, end_time;
int iscomplex = (para->fp_type & 0x2) >> 1;
int isdouble = (para->fp_type & 0x1);
int result=0;
char * result_str;
int failed_count=0;
VML_INT i;
VML_TEST_LOG("\n");
VML_TEST_LOG("Func\tN\tMFlops\t\tTime(s)\t\tResult\n");
init_rand(end, para->a, iscomplex, isdouble);
memcpy(para->ref_a, para->a, end * para->element_size * para->compose_size);
for(i=start; i<=end; i+=step) {
mflops=flops_per_elem[para->fp_type] * i;
//need to clean cache
flush_cache(para->flushcache);
start_time=getRealTime();
test_func[para->fp_type](i, para->a, para->y);
end_time=getRealTime();
time=end_time-start_time;
mflops=mflops/(double)(1000000)/time;
ref_func[para->fp_type](i, para->ref_a, para->ref_y);
//check
result=check_vector(i, para->ref_y, para->y, para->eps, iscomplex, isdouble);
if(result==0){
result_str=STR_PASS;
}else if(result==1){
result_str=STR_WARN;
}else{
result_str=STR_ERR;
failed_count++;
}
VML_TEST_LOG("%s\t%d\t%lf\t%lf\t%s\n", funcname[para->fp_type], i, mflops, time, result_str);
}
if(failed_count>0) CTEST_ERR("Result failed!\n");
}