aclArray.h
Go to the documentation of this file.
/*
* 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/>.
*
*/
#ifndef ACLARRAY_H
#define ACLARRAY_H
#include "../aclStdIncludes.h"
#include "aclMemBlock.h"
using namespace asl;
namespace acl
{
template <typename T> class Array: public MemBlock
{
protected:
string name;
static const string prefix;
static unsigned int id;
public:
explicit Array(unsigned int size, CommandQueue queue_ = hardware.defaultQueue);
Array(unsigned int size, T *initArray, CommandQueue queue_ = hardware.defaultQueue);
virtual string str(const KernelConfiguration & kernelConfig) const;
virtual string getName() const;
virtual string getAddressSpaceQualifier() const;
virtual string getTypeSignature(const KernelConfiguration & kernelConfig) const;
virtual string getLocalDeclaration(const KernelConfiguration & kernelConfig) const;
virtual void addToKernelSource(vector<Element> & arguments,
vector<Element> & localDeclarations) const;
virtual void setAsArgument(cl::Kernel & kernel, unsigned int argumentIndex) const;
};
typedef shared_ptr<Array<cl_int> > ElementArrayInt;
typedef shared_ptr<Array<cl_float> > ElementArrayFloat;
typedef shared_ptr<Array<cl_double> > ElementArrayDouble;
typedef shared_ptr<Array<cl_long> > ElementArrayLong;
//------------------- Implementation -------------------------------
template <typename T> Array<T>::Array(unsigned int size_, CommandQueue queue_):
MemBlock(size_, typeToTypeID<T>(), queue_)
{
++id;
name = prefix + asl::numToStr(id);
}
template <typename T> Array<T>::Array(unsigned int size_, T *initArray, CommandQueue queue_):
MemBlock(size_, typeToTypeID<T>(), queue_, (char*)initArray)
{
++id;
name = prefix + asl::numToStr(id);
}
template <typename T> string Array<T>::getName() const
{
return name;
}
template <typename T> string Array<T>::str(const KernelConfiguration & kernelConfig) const
{
if (kernelConfig.unaligned && kernelConfig.vectorWidth > 1)
{
return "vload" + numToStr(kernelConfig.vectorWidth) + "(0, &" + name + "[" + INDEX + "])";
}
else
{
return name + "[" + INDEX + "]";
}
}
template <typename T> string Array<T>::getTypeSignature(const KernelConfiguration & kernelConfig) const
{
return "__global " + typeToStr<T>(kernelConfig.unaligned ? 1 : kernelConfig.vectorWidth) + " *" + name;
}
template <typename T> string Array<T>::getAddressSpaceQualifier() const
{
return "__global";
}
template <typename T> string Array<T>::getLocalDeclaration(const KernelConfiguration & kernelConfig) const
{
return "";
}
// Must be empty. Only operators can add arguments.
template <typename T>
void Array<T>::addToKernelSource(vector<Element> & arguments, vector<Element> & localDeclarations) const
{
}
template <typename T>
void Array<T>::setAsArgument(cl::Kernel & kernel, unsigned int argumentIndex) const
{
cl_int status = 0;
status = kernel.setArg(argumentIndex, *buffer);
errorMessage(status, "Kernel::setArg() - " + name
+ ", argument " + numToStr(argumentIndex));
}
} // namespace acl
#endif // ACLARRAY_H
acl::Array
Global array.
Definition: aclArray.h:37
acl::Array::id
static unsigned int id
Definition: aclArray.h:41
acl::Array::Array
Array(unsigned int size, T *initArray, CommandQueue queue_=hardware.defaultQueue)
acl::Array::getAddressSpaceQualifier
virtual string getAddressSpaceQualifier() const
acl::Array::getTypeSignature
virtual string getTypeSignature(const KernelConfiguration &kernelConfig) const
acl::Array::addToKernelSource
virtual void addToKernelSource(vector< Element > &arguments, vector< Element > &localDeclarations) const
Definition: aclArray.h:119
acl::Array::setAsArgument
virtual void setAsArgument(cl::Kernel &kernel, unsigned int argumentIndex) const
acl::Array::getAddressSpaceQualifier
virtual string getAddressSpaceQualifier() const
Definition: aclArray.h:105
acl::Array::addToKernelSource
virtual void addToKernelSource(vector< Element > &arguments, vector< Element > &localDeclarations) const
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::prefix
static const string prefix
Definition: aclArray.h:40
acl::Array::getLocalDeclaration
virtual string getLocalDeclaration(const KernelConfiguration &kernelConfig) const
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::getName
virtual string getName() const
acl::Array::str
virtual string str(const KernelConfiguration &kernelConfig) const
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)
acl::Hardware::defaultQueue
CommandQueue defaultQueue
Definition: aclHardware.h:154
acl::KernelConfiguration
ACL Kernel configuration class.
Definition: aclKernelConfiguration.h:35
acl::MemBlock
Definition: aclMemBlock.h:40
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::CommandQueue
std::shared_ptr< cl::CommandQueue > CommandQueue
Definition: acl.h:51
acl::typeToTypeID
constexpr const TypeID typeToTypeID()
acl::hardware
Hardware hardware
Definition: aclHardware.h:163
acl::ElementArrayDouble
shared_ptr< Array< cl_double > > ElementArrayDouble
Definition: aclArray.h:58
acl::ElementArrayFloat
shared_ptr< Array< cl_float > > ElementArrayFloat
Definition: aclArray.h:57
acl::ElementArrayInt
shared_ptr< Array< cl_int > > ElementArrayInt
Definition: aclArray.h:56
acl::ElementArrayLong
shared_ptr< Array< cl_long > > ElementArrayLong
Definition: aclArray.h:59
asl
Advanced Simulation Library.
Definition: aslDataInc.h:31
aclMemBlock.h