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 | 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 | 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 | 2 | Info(m_column.schema).name, m_column.column->field); | |
| 41 | } | ||
| 42 | 34 | Release(); | |
| 43 | 34 | } | |
| 44 | |||
| 45 | 67 | void Mapping::Release() noexcept { | |
| 46 | 67 | if (m_open) { | |
| 47 | 32 | m_open = false; | |
| 48 | 32 | try { | |
| 49 | 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 | 32 | const auto lock = LockStore(m_view ? m_view->GetColumnStore().Lock() : nullptr); | |
| 57 | 32 | if (!m_open) { | |
| 58 | 2 | throw Error("The mapping is already closed"); | |
| 59 | } | ||
| 60 | 31 | Release(); | |
| 61 | 62 | UntypedAttribute attribute(m_view, m_column); | |
| 62 | 31 | if (m_access == MapAccess::Read || m_values.Empty()) { | |
| 63 | 7 | attribute.GetColumnStore().GetDevice().GetQueue().Follow(producer); | |
| 64 | 7 | return {}; | |
| 65 | } | ||
| 66 | 24 | if (m_rows.Empty()) { | |
| 67 | 21 | return attribute.Stamp(producer, mask); | |
| 68 | } | ||
| 69 | 6 | return attribute.Scatter(m_values.Address(), producer, attribute.Upload(mask, producer)); | |
| 70 | 32 | } | |
| 71 | |||
| 72 | } | ||
| 73 |