-
Notifications
You must be signed in to change notification settings - Fork 191
Expand file tree
/
Copy pathOpTensorCopyRegion.cpp
More file actions
75 lines (63 loc) · 2.55 KB
/
OpTensorCopyRegion.cpp
File metadata and controls
75 lines (63 loc) · 2.55 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
71
72
73
74
75
// SPDX-License-Identifier: Apache-2.0
#include "kompute/operations/OpTensorCopyRegion.hpp"
#include "kompute/Tensor.hpp"
namespace kp {
OpTensorCopyRegion::OpTensorCopyRegion(const TensorCopyRegions regions)
{
KP_LOG_DEBUG("Kompute OpTensorCopyRegion constructor with params");
if (regions.dstRegions.size() < 1) {
throw std::runtime_error(
"Kompute OpTensorCopyRegion called with no destination region");
}
kp::Tensor::TensorDataTypes dataType = regions.srcTensor->dataType();
for (const TensorRegion& region : regions.dstRegions) {
if (region.tensor->dataType() != dataType) {
throw std::runtime_error(fmt::format(
"Kompute OpTensorCopyRegion called with different types from {} to {}",
Tensor::toString(dataType),
Tensor::toString(region.tensor->dataType())));
}
if (region.elemCount == 0) {
throw std::runtime_error(
"Kompute OpTensorCopyRegion called with elemCount == 0");
}
if (region.srcIndex + region.elemCount > regions.srcTensor->size()) {
throw std::runtime_error(
"Kompute OpTensorCopyRegion called with out of bounds source region");
}
if (region.dstIndex + region.elemCount > region.tensor->size()) {
throw std::runtime_error(
"Kompute OpTensorCopyRegion called with out of bounds destination region");
}
}
this->mRegions = regions;
}
OpTensorCopyRegion::~OpTensorCopyRegion()
{
KP_LOG_DEBUG("Kompute OpTensorCopyRegion destructor started");
}
void
OpTensorCopyRegion::record(const vk::CommandBuffer& commandBuffer)
{
KP_LOG_DEBUG("Kompute OpTensorCopyRegion record called");
for (size_t i = 0; i < this->mRegions.dstRegions.size(); i++) {
const uint32_t dataTypeMemorySize = this->mRegions.dstRegions[i].tensor->dataTypeMemorySize();
const vk::BufferCopy copy = {
dataTypeMemorySize * this->mRegions.dstRegions[i].srcIndex,
dataTypeMemorySize * this->mRegions.dstRegions[i].dstIndex,
dataTypeMemorySize * this->mRegions.dstRegions[i].elemCount,
};
this->mRegions.dstRegions[i].tensor->recordCopyFrom(commandBuffer, this->mRegions.srcTensor, copy);
}
}
void
OpTensorCopyRegion::preEval(const vk::CommandBuffer& /*commandBuffer*/)
{
KP_LOG_DEBUG("Kompute OpTensorCopyRegion preEval called");
}
void
OpTensorCopyRegion::postEval(const vk::CommandBuffer& /*commandBuffer*/)
{
KP_LOG_DEBUG("Kompute OpTensorCopyRegion postEval called");
}
}