42 #include <pvsutil/Logger.h>
45 #include <SkelCL/Matrix.h>
46 #include <SkelCL/Vector.h>
53 class MapTest :
public ::testing::Test {
67 TEST_F(MapTest, CreateMapWithString) {
68 skelcl::Map<float(float)> m{
"float func(float f){ return -f; }"};
71 TEST_F(MapTest, CreateMapWithFile) {
72 std::string filename{
"TestFunction.cl" };
74 std::ofstream file{ filename, std::ios_base::trunc };
75 file <<
"float func(float f) { return -f; }";
77 std::ifstream file{ filename };
79 skelcl::Map<float(float)> m{ file };
81 remove(filename.c_str());
84 TEST_F(MapTest, CreateMapWithFileII) {
85 std::string filename{
"TestFunction.cl" };
87 std::ofstream file{ filename, std::ios_base::trunc };
88 file <<
"float func(float f) { return -f; }";
91 skelcl::Map<float(float)> m{ std::ifstream{ filename } };
93 remove(filename.c_str());
96 TEST_F(MapTest, SimpleMap) {
97 skelcl::Map<float(float)> m{
"float func(float f){ return -f; }" };
100 for (
size_t i = 0; i < input.size(); ++i) {
103 EXPECT_EQ(10, input.size());
107 EXPECT_EQ(10, output.size());
108 for (
size_t i = 0; i < output.size(); ++i) {
109 EXPECT_EQ(-input[i], output[i]);
113 TEST_F(MapTest, SimpleMultiDeviceMap) {
116 skelcl::Map<float(float)> m{
"float func(float f){ return -f; }" };
119 for (
size_t i = 0; i < input.size(); ++i) {
122 EXPECT_EQ(10, input.size());
127 EXPECT_EQ(10, output.size());
128 for (
size_t i = 0; i < output.size(); ++i) {
129 EXPECT_EQ(-input[i], output[i]);
133 TEST_F(MapTest, SimpleMultiDeviceMap2) {
136 skelcl::Map<int(float)> m{
"int func(float f) \
137 { return skelcl_get_device_id(); }" };
140 EXPECT_EQ(10, input.size());
144 EXPECT_EQ(10, output.size());
145 for (
size_t i = 0; i < output.size(); ++i) {
146 if (skelcl::detail::globalDeviceList.size() == 2) {
148 EXPECT_EQ(0, output[i]);
150 EXPECT_EQ(1, output[i]);
153 EXPECT_EQ(0, output[i]);
158 TEST_F(MapTest, AddArgs) {
159 skelcl::Map<float(float)> m{
"float func(float f, float add, float add2)\
160 { return f+add+add2; }" };
163 for (
size_t i = 0; i < input.size(); ++i) {
166 EXPECT_EQ(10, input.size());
173 EXPECT_EQ(10, output.
size());
174 for (
size_t i = 0; i < output.
size(); ++i) {
175 EXPECT_EQ(input[i]+add+add2, output[i]);
179 TEST_F(MapTest, MapVoid) {
180 skelcl::Map<void(float)> m{
"void func(float f, __global float* out) \
181 { out[get_global_id(0)] = f; }" };
184 for (
size_t i = 0; i < input.size(); ++i) {
187 EXPECT_EQ(10, input.size());
192 for (
size_t i = 0; i < output.
size(); ++i) {
193 EXPECT_EQ(input[i], output[i]);
199 skelcl::Map<float(float)> m{
"float func(float f) { return -f; }" };
208 TEST_F(MapTest, TempInputVector) {
209 auto size = 1024 * 1000;
212 for (
size_t i = 0; i < input.size(); ++i) {
215 EXPECT_EQ(size, input.size());
217 output = execute(input);
219 for (
size_t i = 0; i < output.size(); ++i) {
220 EXPECT_EQ(-input[i], output[i]);
225 TEST_F(MapTest, SimpleMap2D) {
226 skelcl::Map<float(float)> m(
"float func(float f){ return -f; }");
228 std::vector<float> vec(10);
229 for (
size_t i = 0; i < vec.size(); ++i) {
230 vec[i] =
static_cast<float>(i);
238 EXPECT_EQ(input.size(), output.size());
240 for (
size_t i = 0; i < output.rowCount(); ++i) {
241 for(
size_t j = 0; j < output.columnCount(); ++j) {
242 EXPECT_EQ(-input({i,j}), output({i,j}));
243 EXPECT_EQ(-input[i][j], output[i][j]);
248 TEST_F(MapTest, MatrixAddArgs) {
249 skelcl::Map<float(float)> m(
250 "float func(float f, float add, float add2) { return f+add+add2; }");
252 std::vector<float> vec(10);
253 for (
size_t i = 0; i < 10; ++i) {
254 vec[i] =
static_cast<float>(i*2.5f);
265 EXPECT_EQ(input.size(), output.size());
267 for (
size_t i = 0; i < output.rowCount(); ++i) {
268 for (
size_t j = 0; j < output.columnCount(); ++j) {
269 EXPECT_EQ(input({i,j})+add+add2, output({i,j}));
274 TEST_F(MapTest, MatrixAddArgsMatrix) {
277 skelcl::Map<float(float)> m(R
"(
278 float func( float f,__global float* mat, uint mat_col_count, float add2)
280 return f + get(mat, 1, 1) + add2;
284 skelcl::Map<float(float)> m(R
"(
285 float func( float f, float_matrix_t mat, float add2, int_matrix_t mat2 )
287 return f + get(mat, 1, 1) + add2 + get(mat2, 1, 2);
291 std::vector<float> vec(10);
292 for (
size_t i = 0; i < 10; ++i) {
293 vec[i] =
static_cast<float>(i * 2.5f);
299 std::vector<float> vec2(10);
300 for (
size_t i = 0; i < 10; ++i) {
301 vec[i] =
static_cast<float>(i);
314 EXPECT_EQ(input.size(), output.size());
316 for (
size_t i = 0; i < output.rowCount(); ++i) {
317 for(
size_t j = 0; j < output.columnCount(); ++j) {
318 EXPECT_EQ(input[i][j]+mat({1,1})+add2+mat2[1][2], output[i][j]);
323 TEST_F(MapTest, MapWithSingleDistribution0) {
327 skelcl::Map<int(int)> map{
"int func(int i) { return -i; }"};
334 TEST_F(MapTest, MapWithSingleDistribution1) {
338 if (skelcl::detail::globalDeviceList.size() > 1) {
339 skelcl::Map<int(int)> map{
"int func(int i) { return -i; }"};
341 auto dev = ++(skelcl::detail::globalDeviceList.begin());
348 TEST_F(MapTest, MapWithLocalMemory) {
352 skelcl::Map<int(int)> map{
"int func(int i, __local int* lp) \
353 { lp[0] = i; barrier(CLK_LOCAL_MEM_FENCE); return -lp[0]; }"};
355 map.setWorkGroupSize(16);
357 for (
size_t i = 0; i < input.size(); ++i) {
362 for (
size_t i = 0; i < output.
size(); ++i) {
363 EXPECT_EQ(-input[i], output[i]);
367 TEST_F(MapTest, MapFloat4) {
368 skelcl::Map<skelcl::float4(skelcl::float4)>
369 m {
"float4 func(float4 f) { return -f; }"};
372 for (
size_t i = 0; i < input.size(); ++i) {
381 EXPECT_EQ(input.size(), output.
size());
382 for (
size_t i = 0; i < output.
size(); ++i) {
383 EXPECT_EQ(-input[i].s0, output[i].s0);
384 EXPECT_EQ(-input[i].s1, output[i].s1);
385 EXPECT_EQ(-input[i].s2, output[i].s2);
386 EXPECT_EQ(-input[i].s3, output[i].s3);
390 TEST_F(MapTest, MapDouble4) {
391 auto& devPtr = skelcl::detail::globalDeviceList.front();
392 if (devPtr->supportsDouble()) {
394 skelcl::Map<skelcl::double4(skelcl::double4)>
395 m {
"double4 func(double4 f) { return -f; }"};
398 for (
size_t i = 0; i < input.size(); ++i) {
407 EXPECT_EQ(input.size(), output.
size());
408 for (
size_t i = 0; i < output.
size(); ++i) {
409 EXPECT_EQ(-input[i].s0, output[i].s0);
410 EXPECT_EQ(-input[i].s1, output[i].s1);
411 EXPECT_EQ(-input[i].s2, output[i].s2);
412 EXPECT_EQ(-input[i].s3, output[i].s3);
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.
size_type size() const
Returns the number of elements in the Vector.
void setSingle(const C< T > &c)
This function sets the distribution of the given container to the SingleDistribution using the defaul...
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...
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.
This class represents OpenCL local memory in SkelCL.