forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStorage.hpp
52 lines (39 loc) · 1.27 KB
/
Storage.hpp
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
#pragma once
#include "Type.hpp"
#include <cstddef>
#include <cstdint>
#include <initializer_list>
#include <memory>
#include <type_traits>
#include <unordered_map>
#include <vector>
namespace thd {
class Tensor;
struct Storage {
Storage() {};
Storage(const Storage& other) = delete;
Storage(Storage&& other) = delete;
virtual ~Storage() {};
virtual std::size_t elementSize() const = 0;
virtual std::size_t size() const = 0;
virtual void* data() = 0;
virtual const void* data() const = 0;
virtual Storage& retain() = 0;
virtual Storage& free() = 0;
virtual Storage& resize(long new_size) = 0;
virtual thd::Type type() const = 0;
virtual std::unique_ptr<Tensor> newTensor() const = 0;
};
template<typename real>
struct StorageScalarInterface : public Storage {
using scalar_type = real;
virtual StorageScalarInterface& fill(scalar_type value) = 0;
virtual StorageScalarInterface& set(std::size_t ind, scalar_type value) = 0;
virtual StorageScalarInterface& fast_set(std::size_t ind, scalar_type value) = 0;
virtual scalar_type get(std::size_t ind) = 0;
virtual scalar_type fast_get(std::size_t ind) = 0;
};
using FloatStorage = StorageScalarInterface<double>;
using IntStorage = StorageScalarInterface<long long>;
} // namespace thd
#include "Tensor.hpp"