You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ko...@apache.org on 2022/01/25 05:30:52 UTC

[arrow] branch master updated: ARROW-15424: [C++][GLib] Fix CUDA bindings

This is an automated email from the ASF dual-hosted git repository.

kou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new 8b3e067  ARROW-15424: [C++][GLib] Fix CUDA bindings
8b3e067 is described below

commit 8b3e067b1afd34e0cebf4d415b0cb10029ebf6f6
Author: David Li <li...@gmail.com>
AuthorDate: Tue Jan 25 14:28:27 2022 +0900

    ARROW-15424: [C++][GLib] Fix CUDA bindings
    
    ARROW-15373 changed MemoryManager::AllocateBuffer to return
    unique_ptr; the GLib bindings needed updating for this, however.
    Also, tweaked the C++ since some compilers don't implicitly
    convert unique_ptr to shared_ptr on return.
    
    Closes #12237 from lidavidm/arrow-15424
    
    Authored-by: David Li <li...@gmail.com>
    Signed-off-by: Sutou Kouhei <ko...@clear-code.com>
---
 c_glib/arrow-cuda-glib/cuda.cpp   | 8 +++++---
 cpp/src/arrow/gpu/cuda_context.cc | 6 ++++--
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/c_glib/arrow-cuda-glib/cuda.cpp b/c_glib/arrow-cuda-glib/cuda.cpp
index 142cd6f..13525b5 100644
--- a/c_glib/arrow-cuda-glib/cuda.cpp
+++ b/c_glib/arrow-cuda-glib/cuda.cpp
@@ -286,9 +286,11 @@ garrow_cuda_buffer_new(GArrowCUDAContext *context,
                        GError **error)
 {
   auto arrow_context = garrow_cuda_context_get_raw(context);
-  auto arrow_buffer = arrow_context->Allocate(size);
-  if (garrow::check(error, arrow_buffer, "[cuda][buffer][new]")) {
-    return garrow_cuda_buffer_new_raw(&(*arrow_buffer));
+  auto arrow_buffer_result = arrow_context->Allocate(size);
+  if (garrow::check(error, arrow_buffer_result, "[cuda][buffer][new]")) {
+    std::shared_ptr<arrow::cuda::CudaBuffer> arrow_buffer =
+        std::move(*arrow_buffer_result);
+    return garrow_cuda_buffer_new_raw(&arrow_buffer);
   } else {
     return NULL;
   }
diff --git a/cpp/src/arrow/gpu/cuda_context.cc b/cpp/src/arrow/gpu/cuda_context.cc
index 3173a84..6b99bf6 100644
--- a/cpp/src/arrow/gpu/cuda_context.cc
+++ b/cpp/src/arrow/gpu/cuda_context.cc
@@ -344,7 +344,8 @@ Result<std::shared_ptr<Buffer>> CudaMemoryManager::CopyBufferFrom(
   if (from->is_cpu()) {
     // CPU-to-device copy
     ARROW_ASSIGN_OR_RAISE(auto to_context, cuda_device()->GetContext());
-    ARROW_ASSIGN_OR_RAISE(auto dest, to_context->Allocate(buf->size()));
+    ARROW_ASSIGN_OR_RAISE(std::shared_ptr<Buffer> dest,
+                          to_context->Allocate(buf->size()));
     RETURN_NOT_OK(
         to_context->CopyHostToDevice(dest->address(), buf->data(), buf->size()));
     return dest;
@@ -355,7 +356,8 @@ Result<std::shared_ptr<Buffer>> CudaMemoryManager::CopyBufferFrom(
     ARROW_ASSIGN_OR_RAISE(
         auto from_context,
         checked_cast<const CudaMemoryManager&>(*from).cuda_device()->GetContext());
-    ARROW_ASSIGN_OR_RAISE(auto dest, to_context->Allocate(buf->size()));
+    ARROW_ASSIGN_OR_RAISE(std::shared_ptr<Buffer> dest,
+                          to_context->Allocate(buf->size()));
     if (to_context->handle() == from_context->handle()) {
       // Same context
       RETURN_NOT_OK(