diff --git a/tests/clpy_tests/opencl_tests/ultima_tests/test_half.py b/tests/clpy_tests/opencl_tests/ultima_tests/test_half.py index 93f8a854c09..a7e860f91e6 100644 --- a/tests/clpy_tests/opencl_tests/ultima_tests/test_half.py +++ b/tests/clpy_tests/opencl_tests/ultima_tests/test_half.py @@ -10,21 +10,35 @@ class TestUltimaHalfTrick(unittest.TestCase): def test_type_half(self): - x = ''' + supports_cl_khr_fp16 = clpy.backend.opencl.env.supports_cl_khr_fp16() + options = ('-D__CLPY_ENABLE_CL_KHR_FP16' + if supports_cl_khr_fp16 + else '', ) + x = clpy.backend.ultima.exec_ultima('', + '#include ', + _options=options) + (''' __clpy__half f() { - __clpy__half a; - return (__clpy__half)(42.F); + __clpy__half a = 42.F; + return a; } -''' +''' if supports_cl_khr_fp16 else ''' +__clpy__half f() +{ + __clpy__half a;constructor___clpy__half___left_paren____clpy__half_float__right_paren__(&a, 42.F); + return a; +} +''')[1:] y = clpy.backend.ultima.exec_ultima( ''' half f(){ - half a; - return static_cast(42.f); + half a = 42.f; + return a; } - ''') - self.assertEqual(x[1:], y) + ''', + '#include ', + _options=options) + self.assertEqual(x, y) def test_variable_named_half(self): x = ''' @@ -54,21 +68,35 @@ def test_argument_named_half(self): self.assertEqual(x[1:], y) def test_clpy_half(self): - x = ''' + supports_cl_khr_fp16 = clpy.backend.opencl.env.supports_cl_khr_fp16() + options = ('-D__CLPY_ENABLE_CL_KHR_FP16' + if supports_cl_khr_fp16 + else '', ) + x = clpy.backend.ultima.exec_ultima('', + '#include ', + _options=options) + (''' void f() { __clpy__half half_ = 42.F; int __clpy__half = half_; } -''' +''' if supports_cl_khr_fp16 else ''' +void f() +{ + __clpy__half half_;constructor___clpy__half___left_paren____clpy__half_float__right_paren__(&half_, 42.F); + int __clpy__half = operatorfloat___clpy__half_(&half_); +} +''')[1:] y = clpy.backend.ultima.exec_ultima( ''' void f(){ __clpy__half half_ = 42.f; int __clpy__half = half_; } - ''') - self.assertEqual(x[1:], y) + ''', + '#include ', + _options=options) + self.assertEqual(x, y) if __name__ == "__main__":