File: testKernelMerger.cc

package info (click to toggle)
asl 0.1.7-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,536 kB
  • sloc: cpp: 36,180; makefile: 26
file content (91 lines) | stat: -rw-r--r-- 2,487 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
 * Advanced Simulation Library <http://asl.org.il>
 * 
 * Copyright 2015 Avtech Scientific <http://avtechscientific.com>
 *
 *
 * This file is part of Advanced Simulation Library (ASL).
 *
 * ASL is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, version 3 of the License.
 *
 * ASL is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with ASL. If not, see <http://www.gnu.org/licenses/>.
 *
 */


/**
	\example testKernelMerger.cc
 */


#include "acl/acl.h"
#include "acl/DataTypes/aclConstant.h"
#include "acl/DataTypes/aclArray.h"
#include "acl/Kernels/aclKernel.h"
#include "acl/Kernels/aclKernelMerger.h"
#include "aslUtilities.h"
#include <math.h>
#include <initializer_list>

using namespace acl;
using namespace std;

bool testKernelMerger()
{
	cout << "Test of \"KernelMerger\" functionality..." << flush;
	ElementData vec0(new Array<cl_float> (10));
	ElementData vec1(new Array<cl_float> (5));
	ElementData vec2(new Array<cl_float> (8));
	ElementData vec3(new Array<cl_float> (20));	

	Element c0(new Constant<cl_double>(2));
	Element c1(new Constant<cl_double>(1));
	Element c2(new Constant<cl_double>(4));
	Element c3(new Constant<cl_double>(7));
	
	SPKernel k0(new Kernel());
	SPKernel k1(new Kernel());
	SPKernel k2(new Kernel());
	SPKernel k3(new Kernel());
	{ 
		using namespace elementOperators;
		k0->addExpression(operatorAssignment (vec0, c0));
		k1->addExpression(operatorAssignment (vec1, c1));
		k2->addExpression(operatorAssignment (vec2, c2));
		k3->addExpression(operatorAssignment (vec3, c3));
	}

	KernelMerger km;
	km.addKernel(k0);
	km.addKernel(k1);
	km.addKernel(k2);
//	km.addKernel(k3);

	km.setup();
	km.compute();

	bool status((acl::map<float>(vec0).get()[9] == 2) && 
	            (acl::map<float>(vec1).get()[3] == 1) &&
	            (acl::map<float>(vec2).get()[7] == 4));// &&
//	            (acl::map<float>(vec3).get()[19] == 7));
	errorMessage(status);
	cout << km.getKernelSource() << endl;
	return status;		
}

int main()
{
	bool allTestsPassed(true);

	allTestsPassed &= testKernelMerger();
	
	return allTestsPassed ? EXIT_SUCCESS : EXIT_FAILURE;
}