Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CArray and CIndexer Tests for Ultima #240

Merged
merged 4 commits into from
Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions tests/clpy_tests/opencl_tests/ultima_tests/test_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()
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()
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