From baa8fc68a1b3b3280968fa526413b486ffd5229b Mon Sep 17 00:00:00 2001 From: MediaPipe Team Date: Wed, 3 May 2023 05:55:25 -0700 Subject: [PATCH] Make uploading to GPU optional in Image.GetGpuBuffer(). PiperOrigin-RevId: 529066617 --- .../tensor/image_to_tensor_converter_frame_buffer.cc | 3 ++- mediapipe/framework/formats/image.h | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/mediapipe/calculators/tensor/image_to_tensor_converter_frame_buffer.cc b/mediapipe/calculators/tensor/image_to_tensor_converter_frame_buffer.cc index 093f50d76..6f6f6f11c 100644 --- a/mediapipe/calculators/tensor/image_to_tensor_converter_frame_buffer.cc +++ b/mediapipe/calculators/tensor/image_to_tensor_converter_frame_buffer.cc @@ -95,7 +95,8 @@ absl::Status FrameBufferProcessor::Convert(const mediapipe::Image& input, static_cast(range_max) == 255); } - auto input_frame = input.GetGpuBuffer().GetReadView(); + auto input_frame = + input.GetGpuBuffer(/*upload_to_gpu=*/false).GetReadView(); const auto& output_shape = output_tensor.shape(); MP_RETURN_IF_ERROR(ValidateTensorShape(output_shape)); FrameBuffer::Dimension output_dimension{/*width=*/output_shape.dims[2], diff --git a/mediapipe/framework/formats/image.h b/mediapipe/framework/formats/image.h index ffb6362f3..936a3554e 100644 --- a/mediapipe/framework/formats/image.h +++ b/mediapipe/framework/formats/image.h @@ -113,11 +113,11 @@ class Image { #endif // MEDIAPIPE_GPU_BUFFER_USE_CV_PIXEL_BUFFER #endif // !MEDIAPIPE_DISABLE_GPU - // Get a GPU view. Automatically uploads from CPU if needed. - const mediapipe::GpuBuffer GetGpuBuffer() const { -#if !MEDIAPIPE_DISABLE_GPU - if (use_gpu_ == false) ConvertToGpu(); -#endif // !MEDIAPIPE_DISABLE_GPU + // Provides access to the underlying GpuBuffer storage. + // Automatically uploads from CPU to GPU if needed and requested through the + // `upload_to_gpu` argument. + const mediapipe::GpuBuffer GetGpuBuffer(bool upload_to_gpu = true) const { + if (!use_gpu_ && upload_to_gpu) ConvertToGpu(); return gpu_buffer_; }