Skip to content

Commit

Permalink
fix test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
vorj committed Feb 5, 2020
1 parent 909ec19 commit d5e4865
Showing 1 changed file with 40 additions and 12 deletions.
52 changes: 40 additions & 12 deletions tests/clpy_tests/opencl_tests/ultima_tests/test_half.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cupy/carray.hpp>',
_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<half>(42.f);
half a = 42.f;
return a;
}
''')
self.assertEqual(x[1:], y)
''',
'#include <cupy/carray.hpp>',
_options=options)
self.assertEqual(x, y)

def test_variable_named_half(self):
x = '''
Expand Down Expand Up @@ -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 <cupy/carray.hpp>',
_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 <cupy/carray.hpp>',
_options=options)
self.assertEqual(x, y)


if __name__ == "__main__":
Expand Down

0 comments on commit d5e4865

Please sign in to comment.