Skip to content

Commit

Permalink
Merge pull request #240 from fixstars/185-add-carray-cindexer-test-fo…
Browse files Browse the repository at this point in the history
…r-ultima

Add CArray and CIndexer Tests for Ultima
  • Loading branch information
LWisteria authored Sep 11, 2019
2 parents 77b30d8 + 67af8c8 commit 016015a
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 1 deletion.
45 changes: 45 additions & 0 deletions tests/clpy_tests/opencl_tests/ultima_tests/test_cindexer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# flake8: noqa
# TODO(vorj): When we will meet flake8 3.7.0+,
# we should ignore only W291 for whole file
# using --per-file-ignores .

import unittest
import utility


class TestUltimaCIndexer(unittest.TestCase):

def test_cindexer_argument_mutation(self):
x = utility.exec_ultima('', _clpy_header='#include <cupy/carray.hpp>') + '''
void f(CIndexer_2 ind)
{
}
'''[1:]
y = utility.exec_ultima(
'''
void f(CIndexer<2> ind){}
''',
_clpy_header='#include <cupy/carray.hpp>')
self.maxDiff = None
self.assertEqual(x, y)

def test_cindexer_member_function(self):
x = utility.exec_ultima('', _clpy_header='#include <cupy/carray.hpp>') + '''
void f(CIndexer_2 ind)
{
ind_size;
}
'''[1:]
y = utility.exec_ultima(
'''
void f(CIndexer<2> ind){
ind.size();
}
''',
_clpy_header='#include <cupy/carray.hpp>')
self.maxDiff = None
self.assertEqual(x, y)


if __name__ == "__main__":
unittest.main()
91 changes: 91 additions & 0 deletions tests/clpy_tests/opencl_tests/ultima_tests/test_ultima_carray.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# flake8: noqa
# TODO(vorj): When we will meet flake8 3.7.0+,
# we should ignore only W291 for whole file
# using --per-file-ignores .

import unittest
import utility


class TestUltimaCArray(unittest.TestCase):

def test_carray_argument_mutation(self):
x = utility.exec_ultima('', _clpy_header='#include <cupy/carray.hpp>') + '''
void f(__global int* const __restrict__ arr, const CArray_2 arr_info)
{
}
'''[1:]
y = utility.exec_ultima(
'''
void f(CArray<int, 2> arr){}
''',
_clpy_header='#include <cupy/carray.hpp>')
self.maxDiff = None
self.assertEqual(x, y)

def test_carray_member_function(self):
x = utility.exec_ultima('', _clpy_header='#include <cupy/carray.hpp>') + '''
void f(__global int* const __restrict__ arr, const CArray_2 arr_info)
{
((const size_t)arr_info.size_);
((const size_t*)arr_info.shape_);
((const size_t*)arr_info.strides_);
}
'''[1:]
y = utility.exec_ultima(
'''
void f(CArray<int, 2> arr){
arr.size();
arr.shape();
arr.strides();
}
''',
_clpy_header='#include <cupy/carray.hpp>')
self.maxDiff = None
self.assertEqual(x, y)

def test_carray_0_member_function(self):
x = utility.exec_ultima('', _clpy_header='#include <cupy/carray.hpp>') + '''
void f(__global int* const __restrict__ arr, const CArray_0 arr_info)
{
((const size_t)arr_info.size_);
((const size_t*)NULL);
((const size_t*)NULL);
}
'''[1:]
y = utility.exec_ultima(
'''
void f(CArray<int, 0> arr){
arr.size();
arr.shape();
arr.strides();
}
''',
_clpy_header='#include <cupy/carray.hpp>')
self.maxDiff = None
self.assertEqual(x, y)

def test_carray_1_member_function(self):
x = utility.exec_ultima('', _clpy_header='#include <cupy/carray.hpp>') + '''
void f(__global int* const __restrict__ arr, const CArray_1 arr_info)
{
((const size_t)arr_info.size_);
((const size_t*)&arr_info.shape_);
((const size_t*)&arr_info.strides_);
}
'''[1:]
y = utility.exec_ultima(
'''
void f(CArray<int, 1> arr){
arr.size();
arr.shape();
arr.strides();
}
''',
_clpy_header='#include <cupy/carray.hpp>')
self.maxDiff = None
self.assertEqual(x, y)


if __name__ == "__main__":
unittest.main()
5 changes: 4 additions & 1 deletion tests/clpy_tests/opencl_tests/ultima_tests/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ def __exit__(self, exception_type, exception_value, traceback):


def exec_ultima(source, _clpy_header=''):
source = _clpy_header + '\n' \
source = \
'typedef ' + clpy.backend.opencl.utility.typeof_size() \
+ ' __kernel_arg_size_t;\n' \
+ _clpy_header + '\n' \
'static void __clpy_begin_print_out() ' \
'__attribute__((annotate("clpy_begin_print_out")));\n' \
+ source + '\n' \
Expand Down

0 comments on commit 016015a

Please sign in to comment.