42 #include <pvsutil/Logger.h>
45 #include <SkelCL/Vector.h>
52 class ZipTest :
public ::testing::Test {
55 pvsutil::defaultLogger.setLoggingLevel(pvsutil::Logger::Severity::DebugInfo);
64 TEST_F(ZipTest, CreateZipWithString) {
65 skelcl::Zip<float(float, float)> m(
66 "float func(float x, float y){ return x*y; }");
69 TEST_F(ZipTest, CreateZipWithFile) {
70 std::string filename(
"ZipFunction.cl");
72 std::ofstream file(filename, std::ios_base::trunc);
73 file <<
"float func(float x, float y) { return x+y; }";
75 std::ifstream file(filename);
77 skelcl::Zip<float(float, float)> m(file);
79 remove(filename.c_str());
82 TEST_F(ZipTest, SimpleZip) {
83 skelcl::Zip<float(float, float)> z(
84 "float func(float x, float y){ return x+y; }");
87 for (
size_t i = 0; i < left.size(); ++i) {
90 EXPECT_EQ(10, left.size());
93 for (
size_t i = 0; i < right.size(); ++i) {
96 EXPECT_EQ(10, right.size());
98 auto output = z(left, right);
100 EXPECT_EQ(10, output.size());
101 for (
size_t i = 0; i < output.size(); ++i) {
102 EXPECT_EQ(left[i]+right[i], output[i]);
106 TEST_F(ZipTest, AddArgs) {
107 skelcl::Zip<float(float, float)> z(
108 "float func(float x, float y, float add, float add2)\
109 { return (x*y)+add+add2; }");
112 for (
size_t i = 0; i < left.size(); ++i) {
115 EXPECT_EQ(10, left.size());
118 for (
size_t i = 0; i < right.size(); ++i) {
121 EXPECT_EQ(10, right.size());
126 auto output = z(left, right, add, add2);
128 EXPECT_EQ(10, output.size());
129 for (
size_t i = 0; i < output.size(); ++i) {
130 EXPECT_EQ( (left[i]*right[i])+add+add2, output[i]);
134 TEST_F(ZipTest, LeftID) {
135 skelcl::Zip<float(float, float)> z(
136 "float func(float x, float y) { return x; }");
140 for (
size_t i = 0; i < left.size(); ++i) {
143 EXPECT_EQ(10, left.size());
147 for (
size_t i = 0; i < right.size(); ++i) {
150 EXPECT_EQ(10, right.size());
154 EXPECT_EQ(10, left.size());
155 for (
size_t i = 0; i < left.size(); ++i) {
156 EXPECT_EQ( i * 2.5f, left[i]);
160 TEST_F(ZipTest, SimpleZip2D) {
161 skelcl::Zip<float(float,float)> z(
162 "float func(float mat1,float mat2)""{ return mat1 + mat2; }");
164 std::vector<float> left(10);
165 for (
size_t i = 0; i < left.size(); ++i) {
171 std::vector<float> right(10);
172 for (
size_t i = 0; i < right.size(); ++i) {
178 auto output = z(matrix_left, matrix_right);
180 EXPECT_EQ(matrix_left.size(), output.size());
182 for (
size_t i = 0; i < output.rowCount(); ++i) {
183 for(
size_t j = 0; j < output.columnCount(); ++j) {
184 EXPECT_EQ(matrix_left[i][j] + matrix_right[i][j], output[i][j]);
189 TEST_F(ZipTest, VoidAddArgs) {
190 skelcl::Zip<void(float, float)> z(
191 "void func(float x, float y, __global float* out)\
192 { out[get_global_id(0)] = x*y; }");
195 for (
size_t i = 0; i < left.size(); ++i) {
198 EXPECT_EQ(10, left.size());
201 for (
size_t i = 0; i < right.size(); ++i) {
204 EXPECT_EQ(10, right.size());
210 EXPECT_EQ(10, output.size());
211 for (
size_t i = 0; i < output.size(); ++i) {
212 EXPECT_EQ( left[i]*right[i], output[i]);
The Matrix class is a two dimensional container which makes its data accessible on the host as well a...
Out< ContainerType< T > > out(ContainerType< T > &c)
Helper function to create a Out wrapper object.
SKELCL_DLL void init(detail::DeviceProperties properties=allDevices())
Initializes the SkelCL library. This function (or another init function) has to be called prior to ev...
std::unique_ptr< skelcl::detail::Distribution< C< T > > > Block(const C< T > &c)
Factory function to create a BlockDistribution with the types of the given container.
SKELCL_DLL detail::DeviceProperties nDevices(size_t n)
Creates a detail::DeviceProperties object representing n devices. This object should be used as param...
The Vector class is a one dimensional container which makes its data accessible on the host as well a...
This class defines a two dimensional size for a Matrix.
SKELCL_DLL void terminate()
Frees all resources allocated internally by SkelCL.