Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/dnn/src/vkcom/include/tensor.hpp
16344 views
1
// This file is part of OpenCV project.
2
// It is subject to the license terms in the LICENSE file found in the top-level directory
3
// of this distribution and at http://opencv.org/license.html.
4
//
5
// Copyright (C) 2018, Intel Corporation, all rights reserved.
6
// Third party copyrights are property of their respective owners.
7
8
#ifndef OPENCV_DNN_VKCOM_TENSOR_HPP
9
#define OPENCV_DNN_VKCOM_TENSOR_HPP
10
11
#ifdef HAVE_VULKAN
12
#include <vulkan/vulkan.h>
13
#endif
14
#include <memory>
15
#include "vkcom.hpp"
16
17
namespace cv { namespace dnn { namespace vkcom {
18
19
#ifdef HAVE_VULKAN
20
21
class Buffer;
22
23
class Tensor
24
{
25
public:
26
Tensor(Format fmt = kFormatFp32);
27
Tensor(const char* data, std::vector<int>& shape, Format fmt = kFormatFp32);
28
void* map();
29
void unMap();
30
Shape getShape() const;
31
int dimSize(const int dim) const;
32
int dimNum() const;
33
int count(const int start_axis = 0, const int end_axis = -1) const;
34
35
// Change shape and format to as passed in.
36
// Copy data if data != NULL
37
// Allocate new internal buffer if new size > old size or alloc flag is true
38
Tensor reshape(const char* data, const std::vector<int>& shape, bool alloc = false, Format fmt = kFormatInvalid);
39
40
void setTo(float val);
41
int getFormat() const;
42
size_t size() const { return size_in_byte_; }
43
bool isEmpty() { return size_in_byte_ == 0 ? true : false; }
44
void copyTo(Tensor& dst);
45
std::shared_ptr<Buffer> getBuffer() { return buffer_; }
46
47
private:
48
VkDevice device_;
49
std::vector<int> shape_;
50
size_t size_in_byte_;
51
std::shared_ptr<Buffer> buffer_;
52
Format format_;
53
};
54
55
#endif // HAVE_VULKAN
56
57
}}} // namespace cv::dnn::vkcom
58
59
#endif // OPENCV_DNN_VKCOM_TENSOR_HPP
60
61