kou opened a new issue, #55360:
URL: https://github.com/apache/arrow/issues/55360

   ### Describe the bug, including details regarding any error messages, 
version, and platform.
   
   `GrpcCudaDataTest.TestDoGet`, `GrpcCudaDataTest.TestDoPut` and 
`GrpcCudaDataTest.TestDoExchange` in `arrow-flight-test` fail on a system where 
HMM (Heterogeneous Memory Management) is enabled:
   
   ```text
   [ RUN      ] GrpcCudaDataTest.TestDoGet
   unknown file: Failure
   C++ exception with description "std::bad_cast" thrown in the test body.
   
   [  FAILED  ] GrpcCudaDataTest.TestDoGet (125 ms)
   [ RUN      ] GrpcCudaDataTest.TestDoPut
   .../cpp/src/arrow/flight/test_definitions.cc:1368: Failure
   Failed
   'do_put_result.writer->WriteRecordBatch(*cuda_batch)' failed with Unknown 
error: Flight RPC failed with message: Unexpected error in RPC handling. ...
   [  FAILED  ] GrpcCudaDataTest.TestDoPut (7 ms)
   [ RUN      ] GrpcCudaDataTest.TestDoExchange
   .../cpp/src/arrow/flight/test_definitions.cc:1408: Failure
   Failed
   '_error_or_value132.status()' failed with Unknown error: Flight RPC failed 
with message: Unexpected error in RPC handling. ...
   [  FAILED  ] GrpcCudaDataTest.TestDoExchange (4 ms)
   ```
   
   Backtrace of the `std::bad_cast` in `TestDoGet`:
   
   ```text
   #0  __cxa_throw ()
   #1  
arrow::cuda::CudaBufferReader::CudaBufferReader(std::shared_ptr<arrow::Buffer> 
const&)
   #2  
arrow::cuda::CudaMemoryManager::GetBufferReader(std::shared_ptr<arrow::Buffer>)
   #3  arrow::Buffer::GetReader(std::shared_ptr<arrow::Buffer>)
   #4  arrow::ipc::StreamDecoderInternal::OnRecordBatchMessageDecoded(...)
   ...
   #8  arrow::flight::ClientStreamReader::Next()
   #9  arrow::flight::CudaDataTest::TestDoGet()
   ```
   
   `CudaMemoryManager::ViewBufferFrom()` creates a CPU-on-device view when 
`CudaContext::GetDeviceAddress()` succeeds:
   
   
https://github.com/apache/arrow/blob/9e5d6978e9acf372cc989aaaf94e863fe8582c90/cpp/src/arrow/gpu/cuda_context.cc#L499-L508
   
   `CudaContext::GetDeviceAddress()` uses 
`cuPointerGetAttribute(CU_POINTER_ATTRIBUTE_DEVICE_POINTER)`:
   
   
https://github.com/apache/arrow/blob/9e5d6978e9acf372cc989aaaf94e863fe8582c90/cpp/src/arrow/gpu/cuda_context.cc#L748-L755
   
   The view is a plain `arrow::Buffer` on the CUDA device, not a `CudaBuffer`.
   
   Without HMM, `cuPointerGetAttribute()` succeeds only for page-locked host 
memory registered to CUDA. With HMM, it also succeeds for pageable host memory 
allocated by `malloc()` and so on. So `Buffer::ViewOrCopy()` returns a view 
instead of a copy for normal CPU buffers.
   
   Flight client uses `Buffer::ViewOrCopy(data->body, memory_manager_)`. The 
result is passed to `CudaBufferReader` via `Buffer::GetReader()`. 
`CudaBufferReader` requires a `CudaBuffer`. So it throws `std::bad_cast`:
   
   
https://github.com/apache/arrow/blob/9e5d6978e9acf372cc989aaaf94e863fe8582c90/cpp/src/arrow/gpu/cuda_memory.cc#L221-L229
   
   
   ### Component(s)
   
   C++, GPU, FlightRPC


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to