-
Notifications
You must be signed in to change notification settings - Fork 195
Expand file tree
/
Copy pathOpCopy.cpp
More file actions
70 lines (57 loc) · 1.99 KB
/
Copy pathOpCopy.cpp
File metadata and controls
70 lines (57 loc) · 1.99 KB
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
// SPDX-License-Identifier: Apache-2.0
#include "kompute/operations/OpCopy.hpp"
#include "kompute/Image.hpp"
#include "kompute/Tensor.hpp"
namespace kp {
OpCopy::OpCopy(const std::vector<std::shared_ptr<Memory>>& memObjects)
{
KP_LOG_DEBUG("Kompute OpCopy constructor with params");
if (memObjects.size() < 2) {
throw std::runtime_error(
"Kompute OpCopy called with less than 2 memory objects");
}
this->mMemObjects = memObjects;
}
OpCopy::~OpCopy() noexcept
{
KP_LOG_DEBUG("Kompute OpCopy destructor started");
}
void
OpCopy::record(const vk::CommandBuffer& commandBuffer)
{
KP_LOG_DEBUG("Kompute OpCopy record called");
// We iterate from the second memory object onwards and record a copy to all
for (size_t i = 1; i < this->mMemObjects.size(); i++) {
this->mMemObjects[i]->recordCopyFrom(commandBuffer,
this->mMemObjects[0]);
}
}
void
OpCopy::preEval(const vk::CommandBuffer& /*commandBuffer*/)
{
KP_LOG_DEBUG("Kompute OpCopy preEval called");
}
void
OpCopy::postEval(const vk::CommandBuffer& /*commandBuffer*/)
{
KP_LOG_DEBUG("Kompute OpCopy postEval called");
// Do not copy on CPU side if source is storage memory
if (this->mMemObjects[0]->memoryType() ==
kp::Memory::MemoryTypes::eStorage) {
KP_LOG_DEBUG("Kompute OpCopy not copying tensor source given "
"it's of eStorage type");
return;
}
// Copy the data from the first memory object into all the memory objects
for (size_t i = 1; i < this->mMemObjects.size(); i++) {
if (this->mMemObjects[i]->memoryType() ==
kp::Memory::MemoryTypes::eStorage) {
KP_LOG_DEBUG("Kompute OpCopy not copying to tensor dest "
"given it's of eStorage type");
continue;
}
this->mMemObjects[i]->setData(this->mMemObjects[0]->rawData(),
this->mMemObjects[0]->memorySize());
}
}
}