chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
41 / 43
95.3%
Branches:
28 / 36
77.8%
Functions:
5 / 5
100.0%

stage/views/mapping.cpp
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #include "chrono_batch_render/stage/views/mapping.h"
3
4 #include <utility>
5
6 #include "chrono_batch_render/device/device.h"
7 #include "chrono_batch_render/device/queue.h"
8 #include "chrono_batch_render/stage/columns/column_store.h"
9 #include "chrono_batch_render/stage/views/attribute.h"
10 #include "chrono_batch_render/stage/views/view_state.h"
11 #include "chrono_batch_render/util/error.h"
12 #include "chrono_batch_render/util/log.h"
13
14 namespace chrono::batch_render {
15
16 1 Mapping::Mapping(Mapping&& other) noexcept {
17 1 *this = std::move(other);
18 1 }
19
20 2 Mapping& Mapping::operator=(Mapping&& other) noexcept {
21
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (this != &other) {
22 2 Release();
23 2 m_view = std::move(other.m_view);
24 2 m_column = other.m_column;
25 2 m_access = other.m_access;
26 2 m_values = std::move(other.m_values);
27 2 m_rows = std::move(other.m_rows);
28 2 m_offsets = std::move(other.m_offsets);
29 2 m_ready = other.m_ready;
30 2 m_aliased = other.m_aliased;
31 2 m_open = std::exchange(other.m_open, false);
32 }
33 2 return *this;
34 }
35
36 34 Mapping::~Mapping() {
37
3/4
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 33 times.
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
34 if (m_open && m_access != MapAccess::Read) {
38 2 Log(LogLevel::Warning,
39 "A mapping of {}'s {} was dropped without Close; its writes aren't marked as changes",
40
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
2 Info(m_column.schema).name, m_column.column->field);
41 }
42 34 Release();
43 34 }
44
45 67 void Mapping::Release() noexcept {
46
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 35 times.
67 if (m_open) {
47 32 m_open = false;
48 32 try {
49
1/1
✓ Branch 1 taken 32 times.
32 m_view->GetColumnStore().Unpin(m_column.schema);
50 ✗ } catch (...) {
51 ✗ }
52 }
53 67 }
54
55 32 device::Operation Mapping::Close(Stream producer, const DLTensor* mask) {
56
3/4
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 15 times.
32 const auto lock = LockStore(m_view ? m_view->GetColumnStore().Lock() : nullptr);
57
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 31 times.
32 if (!m_open) {
58
2/2
✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
2 throw Error("The mapping is already closed");
59 }
60 31 Release();
61
2/3
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 31 times.
62 UntypedAttribute attribute(m_view, m_column);
62
3/4
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
31 if (m_access == MapAccess::Read || m_values.Empty()) {
63
2/2
✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
7 attribute.GetColumnStore().GetDevice().GetQueue().Follow(producer);
64 7 return {};
65 }
66
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 3 times.
24 if (m_rows.Empty()) {
67
1/1
✓ Branch 1 taken 21 times.
21 return attribute.Stamp(producer, mask);
68 }
69
3/5
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
6 return attribute.Scatter(m_values.Address(), producer, attribute.Upload(mask, producer));
70 32 }
71
72 }
73