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 | 239966 | m_usage(desc.usage) {} | |
| 12 | |||
| 13 | 119983 | Buffer::~Buffer() { | |
| 14 | 119983 | if (m_counted) { | |
| 15 | 119983 | GetDevice().CountMemory(*this, -1); | |
| 16 | } | ||
| 17 | 119983 | } | |
| 18 | |||
| 19 | 239966 | bool Buffer::FullyBacked() const { | |
| 20 | 239966 | return !Virtual() || !GetDevice().Adapter().features.virtualMemory; | |
| 21 | } | ||
| 22 | |||
| 23 | ✗ | ExternalAddress Buffer::External(DLDeviceType api) { | |
| 24 | ✗ | const AdapterInfo& adapter = GetDevice().Adapter(); | |
| 25 | ✗ | if ((adapter.backend == Backend::Cuda && api == kDLCUDA) || | |
| 26 | ✗ | (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 | ✗ | 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 | 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 | m_offset + (bytes == kWholeBuffer ? m_bytes : offset + bytes), | |
| 42 | 3 | m_buffer->Label(), m_offset, m_offset + m_bytes); | |
| 43 | } | ||
| 44 | 566785 | return {*m_buffer, m_offset + offset, bytes == kWholeBuffer ? m_bytes - offset : bytes}; | |
| 45 | } | ||
| 46 | |||
| 47 | } | ||
| 48 |