[Beignet] [PATCH] utests: Add a case generator for relational builtin functions.
Yi Sun
yi.sun at intel.com
Sun Feb 16 23:27:32 PST 2014
utests/utest_relational_gen.py can generate test cases automatically for 13 out of 18 relational builtin functions.
Now all these test cases are passed.
Signed-off-by: Yi Sun <yi.sun at intel.com>
Signed-off-by: YangweiX Shui <yangweix.shui at intel.com>
---
utests/CMakeLists.txt | 17 ++-
utests/utest_relational_gen.py | 263 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 277 insertions(+), 3 deletions(-)
create mode 100755 utests/utest_relational_gen.py
diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt
index b7d6f71..40ae066 100644
--- a/utests/CMakeLists.txt
+++ b/utests/CMakeLists.txt
@@ -6,12 +6,23 @@ EXEC_PROGRAM(mkdir ${CMAKE_CURRENT_SOURCE_DIR} ARGS generated -p)
EXEC_PROGRAM(${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR} ARGS utest_math_gen.py OUTPUT_VARIABLE GEN_MATH_STRING)
string(REGEX REPLACE " " ";" ADDMATHFUNC ${GEN_MATH_STRING})
string(REGEX REPLACE " " "\n" NAMEMATHLIST ${GEN_MATH_STRING})
-MESSAGE(STATUS "Generated Builtin Math Functions:\n" ${NAMEMATHLIST})
+#MESSAGE(STATUS "Generated Builtin Math Functions" ${NAMEMATHLIST})
+MESSAGE(STATUS "Generated Builtin Math Functions")
string(REGEX REPLACE "generated/([^\ ]*)\\.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/../kernels/\\1.cl" KERNEL_MATH_LIST ${GEN_MATH_STRING})
string(REGEX REPLACE " " ";" KERNEL_MATH_LIST ${KERNEL_MATH_LIST})
string(REGEX REPLACE "generated/([^\ ]*)\\.cpp" "\\1.cl" KERNEL_GITIGNORE_LIST ${GEN_MATH_STRING})
-set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "generated;${KERNEL_MATH_LIST}")
+
+##### Ralational Function Part:
+EXEC_PROGRAM(${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR} ARGS utest_relational_gen.py OUTPUT_VARIABLE GEN_RELATIONAL_STRING)
+string(REGEX REPLACE " " ";" ADDRELATIONALFUNC ${GEN_RELATIONAL_STRING})
+string(REGEX REPLACE " " "\n" NAMERELATIONALLIST ${GEN_RELATIONAL_STRING})
+
+string(REGEX REPLACE "generated/([^\ ]*)\\.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/../kernels/\\1.cl" KERNEL_RELATIONAL_LIST ${GEN_RELATIONAL_STRING})
+string(REGEX REPLACE " " ";" KERNEL_RELATIONAL_LIST ${KERNEL_RELATIONAL_LIST})
+MESSAGE(STATUS "Generated Builtin Relational Functions")
+
+set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "generated;${KERNEL_RELATIONAL_LIST};${KERNEL_MATH_LIST}")
configure_file (
"setenv.sh.in"
@@ -201,7 +212,7 @@ SET(CMAKE_CXX_FLAGS "-DHAS_EGL ${CMAKE_CXX_FLAGS} ${DEF_OCL_PCH_PCM_PATH}")
SET(CMAKE_C_FLAGS "-DHAS_EGL ${CMAKE_C_FLAGS} ${DEF_OCL_PCH_PCM_PATH}")
endif (EGL_FOUND AND MESA_SOURCE_FOUND)
-ADD_LIBRARY(utests SHARED ${ADDMATHFUNC} ${utests_sources})
+ADD_LIBRARY(utests SHARED ${ADDRELATIONALFUNC} ${ADDMATHFUNC} ${utests_sources})
TARGET_LINK_LIBRARIES(utests cl m ${OPENGL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
diff --git a/utests/utest_relational_gen.py b/utests/utest_relational_gen.py
new file mode 100755
index 0000000..2debaa3
--- /dev/null
+++ b/utests/utest_relational_gen.py
@@ -0,0 +1,263 @@
+#!/usr/bin/python
+from utest_generator import *
+import os,sys
+
+#base_input_values = [80, -80, 3.14, -3.14, -0.5, 0.5, 1, -1, 0.0,6,-6,1500.24,-1500.24]
+#extend_input_values = [FLT_MAX_POSI,FLT_MIN_NEGA,FLT_MIN_POSI,FLT_MAX_NEGA,80, -80, 3.14, -3.14, -0.5, 0.5, 1, -1, 0.0,6,-6,1500.24,-1500.24]
+base_input_values = [ 0, 1, 3.14]
+def main():
+ ##### intn isequal(floatn x,floatn y)
+ isequal_base_values = base_input_values
+ isequal_input_values1 = []
+ isequal_input_values2 = []
+ isequal_input_values1,isequal_input_values2=gene2ValuesLoop(isequal_input_values1,isequal_input_values2,isequal_base_values)
+ isequal_input_type1 = ['float','float2','float4','float8','float16']
+ isequal_input_type2 = ['float','float2','float4','float8','float16']
+ isequal_output_type = ['int','int2','int4','int8','int16']
+ isequal_cpu_func='''
+static int isequal_v(float x, float y){
+ if (x == y && vector == 1)
+ return 1;
+ else if (x == y && vector != 1)
+ return -1;
+ else
+ return 0;
+} '''
+ isequalUtests = func('isequal','isequal_v',[isequal_input_type1,isequal_input_type2],isequal_output_type,[isequal_input_values1,isequal_input_values2],'0 * INT_ULP',isequal_cpu_func)
+
+ ##### intn isnotequal(floatn x,floatn y)
+ isnotequal_base_values = base_input_values
+ isnotequal_input_values1 = []
+ isnotequal_input_values2 = []
+ isnotequal_input_values1,isnotequal_input_values2=gene2ValuesLoop(isnotequal_input_values1,isnotequal_input_values2,isnotequal_base_values)
+ isnotequal_input_type1 = ['float','float2','float4','float8','float16']
+ isnotequal_input_type2 = ['float','float2','float4','float8','float16']
+ isnotequal_output_type = ['int','int2','int4','int8','int16']
+ isnotequal_cpu_func='''
+static int isnotequal(float x, float y){
+ if (x != y && vector == 1)
+ return 1;
+ else if (x != y && vector != 1)
+ return -1;
+ else
+ return 0;
+} '''
+ isnotequalUtests = func('isnotequal','isnotequal',[isnotequal_input_type1,isnotequal_input_type2],isnotequal_output_type,[isnotequal_input_values1,isnotequal_input_values2],'0 * INT_ULP',isnotequal_cpu_func)
+
+ ##### intn isgreater(floatn x,floatn y)
+ isgreater_base_values = base_input_values
+ isgreater_input_values1 = []
+ isgreater_input_values2 = []
+ isgreater_input_values1,isgreater_input_values2=gene2ValuesLoop(isgreater_input_values1,isgreater_input_values2,isgreater_base_values)
+ isgreater_input_type1 = ['float','float2','float4','float8','float16']
+ isgreater_input_type2 = ['float','float2','float4','float8','float16']
+ isgreater_output_type = ['int','int2','int4','int8','int16']
+ isgreater_cpu_func='''
+static int isgreater(float x, float y){
+ if (x > y && vector == 1)
+ return 1;
+ else if (x > y && vector != 1)
+ return -1;
+ else
+ return 0;
+} '''
+ isgreaterUtests = func('isgreater','isgreater',[isgreater_input_type1,isgreater_input_type2],isgreater_output_type,[isgreater_input_values1,isgreater_input_values2],'0 * INT_ULP',isgreater_cpu_func)
+
+ ##### intn isgreaterequal(floatn x,floatn y)
+ isgreaterequal_base_values = base_input_values
+ isgreaterequal_input_values1 = []
+ isgreaterequal_input_values2 = []
+ isgreaterequal_input_values1,isgreaterequal_input_values2=gene2ValuesLoop(isgreaterequal_input_values1,isgreaterequal_input_values2,isgreaterequal_base_values)
+ isgreaterequal_input_type1 = ['float','float2','float4','float8','float16']
+ isgreaterequal_input_type2 = ['float','float2','float4','float8','float16']
+ isgreaterequal_output_type = ['int','int2','int4','int8','int16']
+ isgreaterequal_cpu_func='''
+static int isgreaterequal(float x, float y){
+ if (x >= y && vector == 1)
+ return 1;
+ else if (x >= y && vector != 1)
+ return -1;
+ else
+ return 0;
+} '''
+ isgreaterequalUtests = func('isgreaterequal','isgreaterequal',[isgreaterequal_input_type1,isgreaterequal_input_type2],isgreaterequal_output_type,[isgreaterequal_input_values1,isgreaterequal_input_values2],'0 * INT_ULP',isgreaterequal_cpu_func)
+
+ ##### intn isless(floatn x,floatn y)
+ isless_base_values = base_input_values
+ isless_input_values1 = []
+ isless_input_values2 = []
+ isless_input_values1,isless_input_values2=gene2ValuesLoop(isless_input_values1,isless_input_values2,isless_base_values)
+ isless_input_type1 = ['float','float2','float4','float8','float16']
+ isless_input_type2 = ['float','float2','float4','float8','float16']
+ isless_output_type = ['int','int2','int4','int8','int16']
+ isless_cpu_func='''
+static int isless(float x, float y){
+ if (x < y && vector == 1)
+ return 1;
+ else if (x < y && vector != 1)
+ return -1;
+ else
+ return 0;
+} '''
+ islessUtests = func('isless','isless',[isless_input_type1,isless_input_type2],isless_output_type,[isless_input_values1,isless_input_values2],'0 * INT_ULP',isless_cpu_func)
+
+ ##### intn islessequal(floatn x,floatn y)
+ islessequal_base_values = base_input_values
+ islessequal_input_values1 = []
+ islessequal_input_values2 = []
+ islessequal_input_values1,islessequal_input_values2=gene2ValuesLoop(islessequal_input_values1,islessequal_input_values2,islessequal_base_values)
+ islessequal_input_type1 = ['float','float2','float4','float8','float16']
+ islessequal_input_type2 = ['float','float2','float4','float8','float16']
+ islessequal_output_type = ['int','int2','int4','int8','int16']
+ islessequal_cpu_func='''
+static int islessequal(float x, float y){
+ if (x <= y && vector == 1)
+ return 1;
+ else if (x <= y && vector != 1)
+ return -1;
+ else
+ return 0;
+} '''
+ islessequalUtests = func('islessequal','islessequal',[islessequal_input_type1,islessequal_input_type2],islessequal_output_type,[islessequal_input_values1,islessequal_input_values2],'0 * INT_ULP',islessequal_cpu_func)
+
+ ##### intn islessgreater(floatn x,floatn y)
+ islessgreater_base_values = base_input_values
+ islessgreater_input_values1 = []
+ islessgreater_input_values2 = []
+ islessgreater_input_values1,islessgreater_input_values2=gene2ValuesLoop(islessgreater_input_values1,islessgreater_input_values2,islessgreater_base_values)
+ islessgreater_input_type1 = ['float','float2','float4','float8','float16']
+ islessgreater_input_type2 = ['float','float2','float4','float8','float16']
+ islessgreater_output_type = ['int','int2','int4','int8','int16']
+ islessgreater_cpu_func='''
+static int islessgreater(float x, float y){
+ if ((x < y || x > y) && vector == 1)
+ return 1;
+ else if ((x < y || x > y) && vector != 1)
+ return -1;
+ else
+ return 0;
+} '''
+ islessgreaterUtests = func('islessgreater','islessgreater',[islessgreater_input_type1,islessgreater_input_type2],islessgreater_output_type,[islessgreater_input_values1,islessgreater_input_values2],'0 * INT_ULP',islessgreater_cpu_func)
+
+ ##### intn isinf(floatn x)
+ isinf_input_values = [ '(float)0.0','(float)(1.0/0.0)','(float)(-1.0/0.0)','(float)sqrt(-1.0)' ]
+ isinf_input_type = ['float','float2','float4','float8','float16']
+ isinf_output_type = ['int','int2','int4','int8','int16']
+ isinf_cpu_func='''
+static int isinf_v(float x){
+ if (isinf(x) == 1 && vector == 1)
+ return 1;
+ else if (isinf(x) == 1 && vector != 1)
+ return -1;
+ else
+ return 0;
+} '''
+ isinfUtests = func('isinf','isinf_v',[isinf_input_type],isinf_output_type,[isinf_input_values],'0 * INT_ULP',isinf_cpu_func)
+
+ ##### intn isnan(floatn x)
+ isnan_input_values = [ '(float)0.0','(float)(1.0/0.0)','(float)(-1.0/0.0)','(float)sqrt(-1.0)' ]
+ isnan_input_type = ['float','float2','float4','float8','float16']
+ isnan_output_type = ['int','int2','int4','int8','int16']
+ isnan_cpu_func='''
+static int isnan_v(float x){
+ if (isnan(x) == 1 && vector == 1)
+ return 1;
+ else if (isnan(x) == 1 && vector != 1)
+ return -1;
+ else
+ return 0;
+} '''
+ isnanUtests = func('isnan','isnan_v',[isnan_input_type],isnan_output_type,[isnan_input_values],'0 * INT_ULP',isnan_cpu_func)
+
+ ##### intn isnormal(floatn x)
+ isnormal_input_values = [ '(float)0.0','(float)(1.0/0.0)','(float)(-1.0/0.0)','(float)sqrt(-1.0)',1,51222.00 ]
+ isnormal_input_type = ['float','float2','float4','float8','float16']
+ isnormal_output_type = ['int','int2','int4','int8','int16']
+ isnormal_cpu_func='''
+static int isnormal(float x)
+{
+ union { uint u; float f; } u;
+ u.f=x;
+ u.u &= 0x7FFFFFFF;
+ return (u.u < 0x7F800000) && (u.u >=1);
+}
+static int isnormal_v(float x){
+ if (isnormal(x) == 1 && vector == 1)
+ return 1;
+ else if (isnormal(x) == 1 && vector != 1)
+ return -1;
+ else
+ return 0;
+} '''
+ isnormalUtests = func('isnormal','isnormal_v',[isnormal_input_type],isnormal_output_type,[isnormal_input_values],'0 * INT_ULP',isnormal_cpu_func)
+
+ ##### intn isordered(floatn x,floatn y)
+ isordered_base_values = base_input_values
+ isordered_input_values1 = []
+ isordered_input_values2 = []
+ isordered_input_values1,isordered_input_values2=gene2ValuesLoop(isordered_input_values1,isordered_input_values2,isordered_base_values)
+ isordered_input_type1 = ['float','float2','float4','float8','float16']
+ isordered_input_type2 = ['float','float2','float4','float8','float16']
+ isordered_output_type = ['int','int2','int4','int8','int16']
+ isordered_cpu_func='''
+static int isequal(float x, float y) { return x == y; }
+static int isordered(float x,float y)
+{
+ return isequal(x, x) && isequal(y, y);
+}
+static int isordered_v(float x, float y){
+ if (isordered(x,y) == 1 && vector == 1)
+ return 1;
+ else if (isordered(x,y) == 1 && vector != 1)
+ return -1;
+ else
+ return 0;
+} '''
+ isorderedUtests = func('isordered','isordered_v',[isordered_input_type1,isordered_input_type2],isordered_output_type,[isordered_input_values1,isordered_input_values2],'0 * INT_ULP',isordered_cpu_func)
+
+ ##### intn isunordered(floatn x,floatn y)
+ isunordered_base_values = base_input_values
+ isunordered_input_values1 = []
+ isunordered_input_values2 = []
+ isunordered_input_values1,isunordered_input_values2=gene2ValuesLoop(isunordered_input_values1,isunordered_input_values2,isunordered_base_values)
+ isunordered_input_type1 = ['float','float2','float4','float8','float16']
+ isunordered_input_type2 = ['float','float2','float4','float8','float16']
+ isunordered_output_type = ['int','int2','int4','int8','int16']
+ isunordered_cpu_func='''
+static int isunordered(float x,float y)
+{
+ return isnan(x) && isnan(y);
+}
+static int isunordered_v(float x, float y){
+ if (isunordered(x,y) == 1 && vector == 1)
+ return 1;
+ else if (isunordered(x,y) == 1 && vector != 1)
+ return -1;
+ else
+ return 0;
+} '''
+ isunorderedUtests = func('isunordered','isunordered_v',[isunordered_input_type1,isunordered_input_type2],isunordered_output_type,[isunordered_input_values1,isunordered_input_values2],'0 * INT_ULP',isunordered_cpu_func)
+
+ ##### intn signbit(floatn x)
+ signbit_input_values = [ '(float)0.0','(float)(1.0/0.0)','(float)(-1.0/0.0)','(float)sqrt(-1.0)',1,51222.00 ]
+ signbit_input_type = ['float','float2','float4','float8','float16']
+ signbit_output_type = ['int','int2','int4','int8','int16']
+ signbit_cpu_func='''
+static int signbit(float x)
+{
+ union { uint u; float f; } u;
+ u.f=x;
+ return u.u >> 31;
+}
+static int signbit_v(float x){
+ if (signbit(x) == 1 && vector == 1)
+ return 1;
+ else if (signbit(x) == 1 && vector != 1)
+ return -1;
+ else
+ return 0;
+} '''
+ signbitUtests = func('signbit','signbit_v',[signbit_input_type],signbit_output_type,[signbit_input_values],'0 * INT_ULP',signbit_cpu_func)
+
+if __name__ == "__main__":
+ main()
--
1.8.5.3
More information about the Beignet
mailing list