Skip to content

Commit 4925d18

Browse files
committed
Move copy_to_host source to cpp file
Should fix some issues with duplicate symbols seen during builds.
1 parent 5d3c17f commit 4925d18

File tree

4 files changed

+47
-24
lines changed

4 files changed

+47
-24
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- PR #215 Catch polymorphic exceptions by reference instead of by value
1717
- PR #221 Fix segfault calling rmmGetInfo when uninitialized
1818
- PR #225 Avoid invoking Python operations in c_free
19+
- PR #230 Fix duplicate symbol issues with `copy_to_host`
1920

2021

2122

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ link_directories("${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES}" # CMAKE_CUDA_IMPLICIT
109109

110110
add_library(rmm SHARED
111111
src/rmm.cpp
112+
src/device_buffer.cpp
112113
src/memory_manager.cpp
113114
thirdparty/cnmem/src/cnmem.cpp
114115
src/mr/default_memory_resource.cpp)

include/rmm/device_buffer.hpp

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -393,28 +393,5 @@ class device_buffer {
393393
///< allocate/deallocate device memory
394394
};
395395

396-
/**--------------------------------------------------------------------------*
397-
* @brief Copies rmm::device_buffer to a preallocated host buffer.
398-
*
399-
* Copies device memory asynchronously on the specified stream
400-
*
401-
* @throws std::runtime_error if `hb` is `nullptr` or copy fails
402-
*
403-
* @param db `rmm::device_buffer` to copy to host
404-
* @param hb host allocated buffer to copy data to
405-
* @param stream CUDA stream on which the device to host copy will be performed
406-
*-------------------------------------------------------------------------**/
407-
void copy_to_host(const device_buffer& db, void* hb, cudaStream_t stream = 0) {
408-
if (hb == nullptr) {
409-
throw std::runtime_error{"Cannot copy to `nullptr`."};
410-
}
411-
cudaError_t err = cudaMemcpyAsync(hb,
412-
db.data(),
413-
db.size(),
414-
cudaMemcpyDeviceToHost,
415-
stream);
416-
if (err != cudaSuccess) {
417-
throw std::runtime_error{"Failed to copy to host."};
418-
}
419-
}
396+
void copy_to_host(const device_buffer& db, void* hb, cudaStream_t stream = 0);
420397
} // namespace rmm

src/device_buffer.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2018, NVIDIA CORPORATION.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include <rmm/device_buffer.hpp>
18+
19+
namespace rmm {
20+
/**--------------------------------------------------------------------------*
21+
* @brief Copies rmm::device_buffer to a preallocated host buffer.
22+
*
23+
* Copies device memory asynchronously on the specified stream
24+
*
25+
* @throws std::runtime_error if `hb` is `nullptr` or copy fails
26+
*
27+
* @param db `rmm::device_buffer` to copy to host
28+
* @param hb host allocated buffer to copy data to
29+
* @param stream CUDA stream on which the device to host copy will be performed
30+
*-------------------------------------------------------------------------**/
31+
void copy_to_host(const device_buffer& db, void* hb, cudaStream_t stream) {
32+
if (hb == nullptr) {
33+
throw std::runtime_error{"Cannot copy to `nullptr`."};
34+
}
35+
cudaError_t err = cudaMemcpyAsync(hb,
36+
db.data(),
37+
db.size(),
38+
cudaMemcpyDeviceToHost,
39+
stream);
40+
if (err != cudaSuccess) {
41+
throw std::runtime_error{"Failed to copy to host."};
42+
}
43+
}
44+
} // namespace rmm

0 commit comments

Comments
 (0)