| 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 |
#include "aclElementSyncCopy.h" |
| 25 |
#include "../../aslUtilities.h" |
| 26 |
#include "../aclUtilities.h" |
| 27 |
#include "../aclHardware.h" |
| 28 |
|
| 29 |
using namespace asl; |
| 30 |
|
| 31 |
namespace acl |
| 32 |
{ |
| 33 |
|
| 34 |
///\todo{Think of cutting one copy operation into 3: frontRemainder, middlePart (SIMD chunks) and backRemainder} |
| 35 |
|
| 36 |
unsigned int ElementSyncCopy::syncCopyNum = 0; |
| 37 |
|
| 38 |
|
| 39 |
ElementSyncCopy::ElementSyncCopy(Element source_, |
| 40 |
Element destination_, |
| 41 |
Element srcOffset, |
| 42 |
Element dstOffset, |
| 43 |
Element length_): |
| 44 |
// typeID fictitious |
| 45 |
ElementBase(false, 0, TYPE_INT), |
| 46 |
source(source_), |
| 47 |
destination(destination_), |
| 48 |
length(length_) |
| 49 |
{ |
| 50 |
if(source->getQueue().get() == 0 && destination->getQueue().get() == 0) |
| 51 |
errorMessage("ElementSyncCopy: source and destionation have no queue"); |
| 52 |
queue = source->getQueue().get() != 0 ? source->getQueue() : destination->getQueue(); |
| 53 |
|
| 54 |
kernelSourceStr = "event_t event_" + numToStr(syncCopyNum) + " = (event_t)0;\n"; |
| 55 |
kernelSourceStr += "\tevent_" + numToStr(syncCopyNum) + " = async_work_group_copy(&((" + destination->getAddressSpaceQualifier() + " " + TYPE[destination->getTypeID()] + " *)" + destination->getName() + ")[" + |
| 56 |
dstOffset->str() + "], &((" + source->getAddressSpaceQualifier() + " " + TYPE[source->getTypeID()] + " *)" + source->getName() + ")[" + |
| 57 |
srcOffset->str() + "], " + length->str() + |
| 58 |
", (event_t)0);\n"; |
| 59 |
kernelSourceStr += "\twait_group_events (1, &event_" + numToStr(syncCopyNum) + ")"; |
| 60 |
|
| 61 |
++syncCopyNum; |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
string ElementSyncCopy::str(const KernelConfiguration & kernelConfig) const |
| 66 |
{ |
| 67 |
return kernelSourceStr; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
void ElementSyncCopy::addToKernelSource(vector<Element> & arguments, |
| 72 |
vector<Element> & localDeclarations) const |
| 73 |
{ |
| 74 |
if (isDeclarable(source)) |
| 75 |
{ |
| 76 |
if (isArgument(source)) |
| 77 |
{ |
| 78 |
arguments.push_back(source); |
| 79 |
} |
| 80 |
else |
| 81 |
{ |
| 82 |
localDeclarations.push_back(source); |
| 83 |
} |
| 84 |
} |
| 85 |
else |
| 86 |
{ |
| 87 |
source->addToKernelSource(arguments, localDeclarations); |
| 88 |
} |
| 89 |
|
| 90 |
if (isDeclarable(destination)) |
| 91 |
{ |
| 92 |
if (isArgument(destination)) |
| 93 |
{ |
| 94 |
arguments.push_back(destination); |
| 95 |
} |
| 96 |
else |
| 97 |
{ |
| 98 |
localDeclarations.push_back(destination); |
| 99 |
} |
| 100 |
} |
| 101 |
else |
| 102 |
{ |
| 103 |
destination->addToKernelSource(arguments, localDeclarations); |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
void ElementSyncCopy::setAsArgument(cl::Kernel & kernel, unsigned int argumentIndex) const |
| 109 |
{ |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
string ElementSyncCopy::getName() const |
| 114 |
{ |
| 115 |
return ""; |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
string ElementSyncCopy::getTypeSignature(const KernelConfiguration & kernelConfig) const |
| 120 |
{ |
| 121 |
return ""; |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
string ElementSyncCopy::getLocalDeclaration(const KernelConfiguration & kernelConfig) const |
| 126 |
{ |
| 127 |
return ""; |
| 128 |
} |
| 129 |
|
| 130 |
} // namespace acl |