ASL
0.1.7
Advanced Simulation Library
Toggle main menu visibility
Loading...
Searching...
No Matches
src
acl
DataTypes
aclArray.h
Go to the documentation of this file.
1
/*
2
* Advanced Simulation Library <http://asl.org.il>
3
*
4
* Copyright 2015 Avtech Scientific <http://avtechscientific.com>
5
*
6
*
7
* This file is part of Advanced Simulation Library (ASL).
8
*
9
* ASL is free software: you can redistribute it and/or modify it
10
* under the terms of the GNU Affero General Public License as
11
* published by the Free Software Foundation, version 3 of the License.
12
*
13
* ASL is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU Affero General Public License for more details.
17
*
18
* You should have received a copy of the GNU Affero General Public License
19
* along with ASL. If not, see <http://www.gnu.org/licenses/>.
20
*
21
*/
22
23
24
#ifndef ACLARRAY_H
25
#define ACLARRAY_H
26
27
#include "
../aclStdIncludes.h
"
28
#include "
aclMemBlock.h
"
29
30
using namespace
asl
;
31
32
namespace
acl
33
{
34
36
template
<
typename
T>
class
Array
:
public
MemBlock
37
{
38
protected
:
39
string
name
;
40
static
const
string
prefix
;
41
static
unsigned
int
id
;
42
public
:
43
explicit
Array
(
unsigned
int
size
,
CommandQueue
queue_ =
hardware
.defaultQueue);
44
Array
(
unsigned
int
size
, T *initArray,
CommandQueue
queue_ =
hardware
.defaultQueue);
45
virtual
string
str
(
const
KernelConfiguration
& kernelConfig)
const
;
46
virtual
string
getName
()
const
;
47
virtual
string
getAddressSpaceQualifier
()
const
;
48
virtual
string
getTypeSignature
(
const
KernelConfiguration
& kernelConfig)
const
;
49
virtual
string
getLocalDeclaration
(
const
KernelConfiguration
& kernelConfig)
const
;
50
virtual
void
addToKernelSource
(vector<Element> & arguments,
51
vector<Element> & localDeclarations)
const
;
52
virtual
void
setAsArgument
(
cl::Kernel
& kernel,
unsigned
int
argumentIndex)
const
;
54
};
55
56
typedef
shared_ptr<Array<cl_int> >
ElementArrayInt
;
57
typedef
shared_ptr<Array<cl_float> >
ElementArrayFloat
;
58
typedef
shared_ptr<Array<cl_double> >
ElementArrayDouble
;
59
typedef
shared_ptr<Array<cl_long> >
ElementArrayLong
;
60
61
//------------------- Implementation -------------------------------
62
63
template
<
typename
T>
Array<T>::Array
(
unsigned
int
size_,
CommandQueue
queue_):
64
MemBlock
(size_,
typeToTypeID
<T>(), queue_)
65
{
66
++
id
;
67
name
=
prefix
+
asl::numToStr
(
id
);
68
}
69
70
71
template
<
typename
T>
Array<T>::Array
(
unsigned
int
size_, T *initArray,
CommandQueue
queue_):
72
MemBlock
(size_,
typeToTypeID
<T>(), queue_, (char*)initArray)
73
{
74
++
id
;
75
name
=
prefix
+
asl::numToStr
(
id
);
76
}
77
78
79
80
template
<
typename
T>
string
Array<T>::getName
()
const
81
{
82
return
name
;
83
}
84
85
86
template
<
typename
T>
string
Array<T>::str
(
const
KernelConfiguration
& kernelConfig)
const
87
{
88
if
(kernelConfig.
unaligned
&& kernelConfig.
vectorWidth
> 1)
89
{
90
return
"vload"
+
numToStr
(kernelConfig.
vectorWidth
) +
"(0, &"
+
name
+
"["
+
INDEX
+
"])"
;
91
}
92
else
93
{
94
return
name
+
"["
+
INDEX
+
"]"
;
95
}
96
}
97
98
99
template
<
typename
T>
string
Array<T>::getTypeSignature
(
const
KernelConfiguration
& kernelConfig)
const
100
{
101
return
"__global "
+
typeToStr<T>
(kernelConfig.
unaligned
? 1 : kernelConfig.
vectorWidth
) +
" *"
+
name
;
102
}
103
104
105
template
<
typename
T>
string
Array<T>::getAddressSpaceQualifier
()
const
106
{
107
return
"__global"
;
108
}
109
110
111
template
<
typename
T>
string
Array<T>::getLocalDeclaration
(
const
KernelConfiguration
& kernelConfig)
const
112
{
113
return
""
;
114
}
115
116
117
// Must be empty. Only operators can add arguments.
118
template
<
typename
T>
119
void
Array<T>::addToKernelSource
(vector<Element> & arguments, vector<Element> & localDeclarations)
const
120
{
121
}
122
123
124
template
<
typename
T>
125
void
Array<T>::setAsArgument
(
cl::Kernel
& kernel,
unsigned
int
argumentIndex)
const
126
{
127
cl_int status = 0;
128
status = kernel.
setArg
(argumentIndex, *
buffer
);
129
errorMessage
(status,
"Kernel::setArg() - "
+
name
130
+
", argument "
+
numToStr
(argumentIndex));
131
}
132
133
134
}
// namespace acl
135
136
#endif
// ACLARRAY_H
aclMemBlock.h
aclStdIncludes.h
acl::Array::id
static unsigned int id
Definition
aclArray.h:41
acl::Array::prefix
static const string prefix
Definition
aclArray.h:40
acl::Array::addToKernelSource
virtual void addToKernelSource(vector< Element > &arguments, vector< Element > &localDeclarations) const
Definition
aclArray.h:119
acl::Array::getAddressSpaceQualifier
virtual string getAddressSpaceQualifier() const
Definition
aclArray.h:105
acl::Array::name
string name
Definition
aclArray.h:39
acl::Array::str
virtual string str(const KernelConfiguration &kernelConfig) const
Definition
aclArray.h:86
acl::Array::setAsArgument
virtual void setAsArgument(cl::Kernel &kernel, unsigned int argumentIndex) const
Definition
aclArray.h:125
acl::Array::getName
virtual string getName() const
Definition
aclArray.h:80
acl::Array::getLocalDeclaration
virtual string getLocalDeclaration(const KernelConfiguration &kernelConfig) const
Definition
aclArray.h:111
acl::Array::getTypeSignature
virtual string getTypeSignature(const KernelConfiguration &kernelConfig) const
Definition
aclArray.h:99
acl::Array::Array
Array(unsigned int size, CommandQueue queue_=hardware.defaultQueue)
Definition
aclArray.h:63
acl::ElementBase::size
unsigned int size
Definition
aclElementBase.h:52
acl::KernelConfiguration
ACL Kernel configuration class.
Definition
aclKernelConfiguration.h:35
acl::KernelConfiguration::unaligned
bool unaligned
Definition
aclKernelConfiguration.h:44
acl::KernelConfiguration::vectorWidth
unsigned int vectorWidth
Definition
aclKernelConfiguration.h:43
acl::MemBlock::MemBlock
MemBlock()
acl::MemBlock::buffer
shared_ptr< cl::Buffer > buffer
Definition
aclMemBlock.h:42
cl::Kernel
Class interface for cl_kernel.
Definition
cl.hpp:4722
cl::Kernel::setArg
cl_int setArg(cl_uint index, const T &value)
Definition
cl.hpp:4845
asl::errorMessage
void errorMessage(cl_int status, const char *errorMessage)
Prints errorMessage and exits depending on the status.
asl::numToStr
std::string numToStr(T i)
Converts numbers or another type to string.
Definition
aslUtilities.h:48
acl
Advanced Computational Language.
Definition
acl.h:41
acl::INDEX
const std::string INDEX
Definition
aclUtilities.h:39
acl::ElementArrayDouble
shared_ptr< Array< cl_double > > ElementArrayDouble
Definition
aclArray.h:58
acl::CommandQueue
std::shared_ptr< cl::CommandQueue > CommandQueue
Definition
acl.h:51
acl::typeToTypeID
constexpr const TypeID typeToTypeID()
acl::hardware
Hardware hardware
acl::ElementArrayLong
shared_ptr< Array< cl_long > > ElementArrayLong
Definition
aclArray.h:59
acl::ElementArrayFloat
shared_ptr< Array< cl_float > > ElementArrayFloat
Definition
aclArray.h:57
acl::typeToStr
const std::string & typeToStr()
acl::ElementArrayInt
shared_ptr< Array< cl_int > > ElementArrayInt
Definition
aclArray.h:56
asl
Advanced Simulation Library.
Definition
aslDataInc.h:31
Generated by
1.17.0