gtsam_points
Loading...
Searching...
No Matches
offloadable.hpp
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2021 Kenji Koide (k.koide@aist.go.jp)
3
4#pragma once
5
6#include <memory>
7#include <vector>
8#include <atomic>
9#include <cstdint>
10
11// forward declaration
12struct CUstream_st;
13
14namespace gtsam_points {
15
20public:
21 using Ptr = std::shared_ptr<OffloadableGPU>;
22 using ConstPtr = std::shared_ptr<const OffloadableGPU>;
23
25 virtual ~OffloadableGPU();
26
28 static std::uint64_t current_access_time();
29
31 std::uint64_t last_accessed_time() const;
32
34 virtual size_t memory_usage_gpu() const { return 0; }
35
37 virtual bool loaded_on_gpu() const = 0;
38
41 virtual bool touch(CUstream_st* stream = 0);
42
45 virtual bool offload_gpu(CUstream_st* stream = 0) = 0;
46
49 virtual bool reload_gpu(CUstream_st* stream = 0) = 0;
50
51protected:
52 static std::atomic_uint64_t access_counter;
53 std::uint64_t last_access;
54};
55
56} // namespace gtsam_points
An interface class for offloading data from GPU to CPU.
Definition offloadable.hpp:19
std::uint64_t last_access
Last access time of this object.
Definition offloadable.hpp:53
virtual bool touch(CUstream_st *stream=0)
Reload data from CPU to GPU (if necessary) and update the last access time.
virtual bool loaded_on_gpu() const =0
Check if the data is loaded on the GPU.
virtual bool reload_gpu(CUstream_st *stream=0)=0
Reload data from CPU to GPU.
static std::uint64_t current_access_time()
Current global access time counter.
virtual size_t memory_usage_gpu() const
Memory usage in bytes on the GPU.
Definition offloadable.hpp:34
virtual bool offload_gpu(CUstream_st *stream=0)=0
Offload data from GPU to CPU.
std::uint64_t last_accessed_time() const
Time of the last access to this object.
static std::atomic_uint64_t access_counter
Global counter for the last access time.
Definition offloadable.hpp:52