diff options
author | Jan Vesely <jan.vesely@rutgers.edu> | 2015-04-11 19:41:09 -0400 |
---|---|---|
committer | Jan Vesely <jan.vesely@rutgers.edu> | 2015-04-20 16:59:45 -0400 |
commit | e4b46dc198a6482d34280748022afd0e29729eaa (patch) | |
tree | a49ad661758927406e74d967d6a7baffc7fb180e | |
parent | 64ea3b50b042879c7c55729997cc4cdad1fe22bd (diff) |
cl: Add tests for common builtin functions
Move sign and mix out of math
All tests pass on Turks
All tests except step pass on Intel CPU, it fails in NaN cases.
v2: Remove min/max NaN tests.
OpenCL 1.1 changed the wording, making the results undefined
Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
Reviewed-by: Tom Stellard <thomas.stellard@amd.com>
-rw-r--r-- | generated_tests/CMakeLists.txt | 4 | ||||
-rw-r--r-- | generated_tests/gen_cl_common_builtins.py | 154 | ||||
-rw-r--r-- | generated_tests/gen_cl_math_builtins.py | 21 | ||||
-rw-r--r-- | tests/cl.py | 3 |
4 files changed, 161 insertions, 21 deletions
diff --git a/generated_tests/CMakeLists.txt b/generated_tests/CMakeLists.txt index 82679e151..5036a5db6 100644 --- a/generated_tests/CMakeLists.txt +++ b/generated_tests/CMakeLists.txt @@ -134,6 +134,9 @@ piglit_make_generated_tests( piglit_make_generated_tests( builtin_cl_relational_tests.list gen_cl_relational_builtins.py) +piglit_make_generated_tests( + builtin_cl_common_tests.list + gen_cl_common_builtins.py) # Create a custom target for generating OpenGL tests # This is not added to the default target, instead it is added @@ -167,6 +170,7 @@ add_custom_target(gen-cl-tests DEPENDS builtin_cl_int_tests.list builtin_cl_math_tests.list builtin_cl_relational_tests.list + builtin_cl_common_tests.list cl_store_tests.list ) diff --git a/generated_tests/gen_cl_common_builtins.py b/generated_tests/gen_cl_common_builtins.py new file mode 100644 index 000000000..19563eb43 --- /dev/null +++ b/generated_tests/gen_cl_common_builtins.py @@ -0,0 +1,154 @@ +# Copyright 2013 Advanced Micro Devices, Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice (including the next +# paragraph) shall be included in all copies or substantial portions of the +# Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +# Authors: Tom Stellard <thomas.stellard@amd.com> +# Aaron Watry <awatry@gmail.com> +# + +from __future__ import print_function, division, absolute_import +import os + +from genclbuiltins import gen, NEGNAN +from math import radians, degrees, pi + +CLC_VERSION_MIN = { + 'clamp' : 10, + 'degrees' : 10, + 'max' : 10, + 'min' : 10, + 'mix' : 10, + 'radians' : 10, + 'step' : 10, + 'smoothstep' : 10, + 'sign' : 10 +} + +DATA_TYPES = ['float'] + +F = { + 'float' : 'float' +} + +I = { + 'float' : 'int' +} + +tests = { + 'clamp' : { + 'arg_types': [F, F, F, F], + 'function_type': 'tss', + 'values': [ + [0.5, 0.0, 0.0, 0.0, float("nan")], #Result + [1.0, -0.5, 0.0, 0.0, float("nan")], #Arg0 + [0.0, 0.0, 0.0, -0.5, float("nan")], #Arg1 + [0.5, 0.5, 0.0, 0.5, float("nan")], #Arg2 + ] + }, + 'degrees' : { + 'arg_types': [F, F], + 'function_type': 'ttt', + 'values': [ + [degrees(0.5), degrees(-0.5), 180.0, 0.0, 360, 1800.0, 18000, 90], #Result + [0.5, -0.5, pi, 0.0, 2*pi, 10*pi, 100*pi, pi/2] #Arg0 + ] + }, + 'max' : { + 'arg_types': [F, F, F], + 'function_type': 'tss', + 'values': [ + [1.0, 0.0, 0.0, 0.0 ], #Result + [1.0, -0.5, 0.0, 0.0 ], #Arg0 + [0.0, 0.0, 0.0, -0.5 ] #Arg1 + ] + }, + 'min' : { + 'arg_types': [F, F, F], + 'function_type': 'tss', + 'values': [ + [0.0, -0.5, 0.0, -0.5 ], #Result + [1.0, -0.5, 0.0, 0.0 ], #Arg0 + [0.0, 0.0, 0.0, -0.5 ] #Arg1 + ] + }, + 'mix' : { #x + (y - x) * a + 'arg_types': [F, F, F, F], + 'function_type': 'tts', + 'values': [ + [0.5, -0.25, 0.0, -0.5, 1.0, 3.0, 10.0, float("nan"), float("nan"), float("nan")], #Result + [1.0, -0.5, 0.0, 0.0, 1.0, 4.0, 15.0, 5.0, 4.0, float("nan")], #Arg0 + [0.0, 0.0, 0.0, -0.5, 2.0, 2.0, 10.0, -0.2, float("nan"), 1.5], #Arg1 + [0.5, 0.5, 0.0, 1.0, 0.0, 0.5, 1.0, float("nan"), 1.0, 0.0], #Arg2 + ] + }, + 'radians' : { + 'arg_types': [F, F], + 'function_type': 'ttt', + 'values': [ + [0.5, -0.5, pi, 0.0, 2*pi, 10*pi, 100*pi, pi/2], #Result + [degrees(0.5), degrees(-0.5), 180.0, 0.0, 360, 1800.0, 18000, 90] #Arg0 + ] + }, + #TODO Add scalar combination (tst?) + 'step' : { + 'arg_types': [F, F, F], + 'function_type': 'ttt', + 'values': [ + [0.0, 1.0, 1.0, 0.0, 1.0, 1.0], #Result + [1.0, -0.5, 0.0, 0.0, 1.0, float("nan")], #Arg0 + [0.0, 0.0, 0.0, -0.5, float("nan"), 1.0] #Arg1 + ] + }, + #TODO Add scalar combination (tst?) + 'smoothstep' : { + 'arg_types': [F, F, F, F], + 'function_type': 'ttt', + 'values': [ + [0.0, 0.0, 1.0, 1.0, 0.5, 0.896], #Result + [0.0, 0.0, 0.0, -0.5, 0.0, 0.0], #Arg0 + [1.0, 1.0, 0.5, 0.0, 0.5, 0.5], #Arg1 + [-0.5, 0.0, 0.5, 1.0, 0.25, 0.4] #Arg2 + ] + }, + 'sign' : { + 'arg_types': [F, F], + 'function_type': 'ttt', + 'values': [ + [1.0, -1.0, 0.0, -0.0, 0.0], #Result + [0.5, -0.5, 0.0, -0.0, float("nan")] #Arg0 + ] + } +} + + +def main(): + dirName = os.path.join("cl", "builtin", "common") + + testDefs = {} + functions = sorted(tests.keys()) + for dataType in DATA_TYPES: + for fnName in functions: + testDefs[(dataType, fnName)] = tests[fnName] + + gen(DATA_TYPES, CLC_VERSION_MIN, functions, testDefs, dirName) + + +if __name__ == '__main__': + main() diff --git a/generated_tests/gen_cl_math_builtins.py b/generated_tests/gen_cl_math_builtins.py index 331202ccb..489be9d53 100644 --- a/generated_tests/gen_cl_math_builtins.py +++ b/generated_tests/gen_cl_math_builtins.py @@ -57,10 +57,8 @@ CLC_VERSION_MIN = { 'ldexp' : 10, 'log10' : 10, 'log1p' : 10, - 'mix' : 10, 'nextafter' : 10, 'round' : 10, - 'sign' : 10, 'sin' : 10, 'sinh' : 10, 'sinpi' : 10, @@ -317,16 +315,6 @@ tests = { ], 'tolerance' : 2 }, - 'mix' : { #x + (y - x) * a - 'arg_types': [F, F, F, F], - 'function_type': 'tts', - 'values': [ - [float("nan"), float("nan"), 1.0, 3.0, 10.0 ], # Result - [1.0 , 1.0, 1.0, 4.0, 15.0 ], # Arg0 - [2.0 , float("nan"), 2.0, 2.0, 10.0 ], # Arg1 - [float("nan"), 0.0, 0.0, 0.5, 1.0 ], # Arg2 - ] - }, 'nextafter' : { 'arg_types': [F, F, F], 'function_type': 'ttt', @@ -344,15 +332,6 @@ tests = { [0.5, -0.5, 0.0, -0.0, float("nan"), -3.99, 1.5, 0.4, 0.6] ] }, - 'sign' : { # This is really a Common function but it uses the same types - # as a lot of the math functions. - 'arg_types': [F, F], - 'function_type': 'ttt', - 'values': [ - [1.0, -1.0, 0.0, -0.0, 0.0], - [0.5, -0.5, 0.0, -0.0, float("nan")] - ] - }, 'sin' : { 'arg_types' : [F, F], 'function_type': 'ttt', diff --git a/tests/cl.py b/tests/cl.py index dbc923283..064072948 100644 --- a/tests/cl.py +++ b/tests/cl.py @@ -123,5 +123,8 @@ add_program_test_dir(grouptools.join('program', 'execute', 'builtin'), add_program_test_dir(grouptools.join('program', 'execute', 'builtin'), os.path.join(GENERATED_TESTS_DIR, 'cl', 'builtin', 'relational')) +add_program_test_dir(grouptools.join('program', 'execute', 'builtin'), + os.path.join(GENERATED_TESTS_DIR, 'cl', 'builtin', + 'common')) add_program_test_dir(grouptools.join('program', 'execute', 'store'), os.path.join(GENERATED_TESTS_DIR, 'cl', 'store')) |