-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathMiopenTensor.cpp
More file actions
67 lines (55 loc) · 1.71 KB
/
Copy pathMiopenTensor.cpp
File metadata and controls
67 lines (55 loc) · 1.71 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
// Copyright © Advanced Micro Devices, Inc., or its affiliates.
// SPDX-License-Identifier: MIT
#include "MiopenTensor.hpp"
#include "MiopenUtils.hpp"
namespace miopen_legacy_plugin
{
MiopenTensor::MiopenTensor(const hipdnn_sdk::data_objects::TensorAttributes& tensor)
: _uid(tensor.uid())
{
THROW_ON_MIOPEN_FAILURE(miopenCreateTensorDescriptor(&_descriptor));
std::vector<int> dims(tensor.dims()->begin(), tensor.dims()->end());
std::vector<int> strides(tensor.strides()->begin(), tensor.strides()->end());
THROW_ON_MIOPEN_FAILURE(
miopenSetTensorDescriptor(_descriptor,
miopen_utils::tensorDataTypeToMiopenDataType(tensor.data_type()),
static_cast<int>(dims.size()),
reinterpret_cast<int*>(dims.data()),
reinterpret_cast<int*>(strides.data())));
}
MiopenTensor::MiopenTensor(MiopenTensor&& other) noexcept
: _uid(other._uid)
, _descriptor(other._descriptor)
{
other._descriptor = nullptr;
}
MiopenTensor& MiopenTensor::operator=(MiopenTensor&& other) noexcept
{
if(this != &other)
{
if(_descriptor != nullptr)
{
LOG_ON_MIOPEN_FAILURE(miopenDestroyTensorDescriptor(_descriptor));
}
_uid = other._uid;
_descriptor = other._descriptor;
other._descriptor = nullptr;
}
return *this;
}
MiopenTensor::~MiopenTensor()
{
if(_descriptor != nullptr)
{
LOG_ON_MIOPEN_FAILURE(miopenDestroyTensorDescriptor(_descriptor));
}
}
int64_t MiopenTensor::uid() const
{
return _uid;
}
miopenTensorDescriptor_t MiopenTensor::tensorDescriptor() const
{
return _descriptor;
}
}