chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
18 / 25
72.0%
Branches:
16 / 31
51.6%
Functions:
5 / 6
83.3%

device/buffer.cpp
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #include "chrono_batch_render/device/buffer.h"
3
4 #include "chrono_batch_render/device/device.h"
5 #include "chrono_batch_render/util/error.h"
6
7 namespace chrono::batch_render::device {
8
9 119983 Buffer::Buffer(Device& device, const BufferDesc& desc)
10 239966 : Resource(device, desc.label), m_bytes(desc.bytes), m_memory(desc.memory),
11
1/1
✓ Branch 2 taken 119983 times.
239966 m_usage(desc.usage) {}
12
13 119983 Buffer::~Buffer() {
14
1/2
✓ Branch 0 taken 119983 times.
✗ Branch 1 not taken.
119983 if (m_counted) {
15 119983 GetDevice().CountMemory(*this, -1);
16 }
17 119983 }
18
19 239966 bool Buffer::FullyBacked() const {
20
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 239966 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
239966 return !Virtual() || !GetDevice().Adapter().features.virtualMemory;
21 }
22
23 ✗ ExternalAddress Buffer::External(DLDeviceType api) {
24
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ const AdapterInfo& adapter = GetDevice().Adapter();
25
0/6
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ if ((adapter.backend == Backend::Cuda && api == kDLCUDA) ||
26
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ (adapter.backend == Backend::Hip && api == kDLROCM)) {
27 ✗ return {{api, int32_t(adapter.ordinal)}, Address()};
28 }
29 ✗ throw UnsupportedError("Buffer \"{}\" on {} isn't shared with device type {}", Label(),
30
0/1
✗ Branch 2 not taken.
✗ adapter.alias, int(api));
31 }
32
33 470226 BufferRange Buffer::Slice(uint64_t offset, uint64_t bytes) {
34 470226 return BufferRange(*this).Slice(offset, bytes);
35 }
36
37 566787 BufferRange BufferRange::Slice(uint64_t offset, uint64_t bytes) const {
38
6/6
✓ Branch 0 taken 566786 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 565080 times.
✓ Branch 3 taken 1706 times.
✓ Branch 4 taken 1 time.
✓ Branch 5 taken 565079 times.
566787 if (offset > m_bytes || (bytes != kWholeBuffer && bytes > m_bytes - offset)) {
39 2 throw Error("bytes {} to {} of buffer \"{}\" are past the end of its range, bytes {} to {}",
40 4 m_offset + offset,
41
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
2 m_offset + (bytes == kWholeBuffer ? m_bytes : offset + bytes),
42
3/3
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1 time.
✓ Branch 4 taken 2 times.
3 m_buffer->Label(), m_offset, m_offset + m_bytes);
43 }
44
2/2
✓ Branch 0 taken 1706 times.
✓ Branch 1 taken 565079 times.
566785 return {*m_buffer, m_offset + offset, bytes == kWholeBuffer ? m_bytes - offset : bytes};
45 }
46
47 }
48