chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
8 / 10
80.0%
Branches:
3 / 4
75.0%
Functions:
2 / 2, 1 excl
100.0%

stage/views/staged.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #pragma once
3
4 #include <cstddef>
5 #include <cstdint>
6 #include <optional>
7 #include <vector>
8
9 #include <dlpack/dlpack.h>
10
11 #include "chrono_batch_render/device/buffer.h"
12 #include "chrono_batch_render/device/device.h"
13 #include "chrono_batch_render/device/ref.h"
14 #include "chrono_batch_render/device/stream.h"
15
16 namespace chrono::batch_render {
17
18 class StagedTensor {
19 public:
20 static std::optional<StagedTensor> Stage(device::Device& device, const DLTensor& source,
21 Stream producer);
22
23 DLTensor View() const;
24
25 7615 Stream Producer() const {
26 7615 return m_producer;
27 }
28
29 private:
30 std::vector<int64_t> m_shape;
31 std::vector<std::byte> m_host;
32 Ref<device::Buffer> m_buffer;
33 DLDataType m_dtype{};
34 DLDevice m_device{kDLCPU, 0};
35 uint64_t m_address = 0;
36 Stream m_producer = Stream::None();
37 };
38
39 29387 inline bool StageOptional(device::Device& device, const DLTensor* tensor, Stream producer,
40 std::optional<StagedTensor>& staged) {
41
2/2
✓ Branch 0 taken 14158 times.
✓ Branch 1 taken 15229 times.
29387 if (tensor == nullptr) {
42 return true;
43 }
44 28316 staged = StagedTensor::Stage(device, *tensor, producer);
45 14158 return staged.has_value();
46 }
47
48 15229 inline const DLTensor* ViewOptional(const std::optional<StagedTensor>& staged, DLTensor& view) {
49
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15229 times.
15229 if (!staged) {
50 return nullptr;
51 }
52 ✗ view = staged->View();
53 ✗ return &view;
54 }
55
56 }
57