|
| 1 | +// |
| 2 | +// Copyright (c) 2021-2024 Advanced Micro Devices, Inc. All rights reserved. |
| 3 | +// |
| 4 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | +// of this software and associated documentation files (the "Software"), to deal |
| 6 | +// in the Software without restriction, including without limitation the rights |
| 7 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | +// copies of the Software, and to permit persons to whom the Software is |
| 9 | +// furnished to do so, subject to the following conditions: |
| 10 | +// |
| 11 | +// The above copyright notice and this permission notice shall be included in |
| 12 | +// all copies or substantial portions of the Software. |
| 13 | +// |
| 14 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 20 | +// THE SOFTWARE. |
| 21 | +// |
| 22 | + |
1 | 23 | #pragma once
|
2 | 24 |
|
3 | 25 | #include <Orochi/OrochiUtils.h>
|
@@ -91,9 +113,35 @@ class GpuMemory final
|
91 | 113 | *this = std::move( tmp );
|
92 | 114 | }
|
93 | 115 |
|
| 116 | + /// @brief Asynchronous version of 'resize' using a given Orochi stream. |
| 117 | + /// @param new_size The new memory size after the function is called. |
| 118 | + /// @param copy If true, the function will copy the data to the newly created memory space as well. |
| 119 | + /// @param stream The Orochi stream used for the underlying operations. |
| 120 | + void resizeAsync( const size_t new_size, const bool copy = false, oroStream stream = 0 ) noexcept |
| 121 | + { |
| 122 | + if( new_size <= m_capacity ) |
| 123 | + { |
| 124 | + m_size = new_size; |
| 125 | + return; |
| 126 | + } |
| 127 | + |
| 128 | + GpuMemory tmp( new_size ); |
| 129 | + |
| 130 | + if( copy ) |
| 131 | + { |
| 132 | + OrochiUtils::copyDtoDAsync( tmp.m_data, m_data, m_size, stream ); |
| 133 | + } |
| 134 | + |
| 135 | + *this = std::move( tmp ); |
| 136 | + } |
| 137 | + |
94 | 138 | /// @brief Reset the memory space so that all bits inside are cleared to zero.
|
95 | 139 | void reset() noexcept { OrochiUtils::memset( m_data, 0, m_size * sizeof( T ) ); }
|
96 | 140 |
|
| 141 | + /// @brief Asynchronous version of 'reset' using a given Orochi stream. |
| 142 | + /// @param stream The Orochi stream used for the underlying operations. |
| 143 | + void resetAsync( oroStream stream = 0 ) noexcept { OrochiUtils::memsetAsync( m_data, 0, m_size * sizeof( T ), stream ); } |
| 144 | + |
97 | 145 | /// @brief Copy the data from device memory to host.
|
98 | 146 | /// @param host_ptr The host pointer.
|
99 | 147 | /// @param host_data_size The size of the host memory which represents the number of elements.
|
|
0 commit comments