blob: e48c033ac448a2aa0bcf29d436a489b1f09501ec [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <deque>
#include "memory/ColumnarBatchIterator.h"
#include "memory/GpuBufferColumnarBatch.h"
#include "memory/VeloxColumnarBatch.h"
#include "utils/Exception.h"
#include "velox/common/memory/MemoryPool.h"
namespace gluten {
class GpuBufferBatchResizer : public ColumnarBatchIterator {
public:
GpuBufferBatchResizer(
arrow::MemoryPool* arrowPool,
facebook::velox::memory::MemoryPool* pool,
int32_t minOutputBatchSize,
int64_t maxPrefetchSize,
std::unique_ptr<ColumnarBatchIterator> in);
std::shared_ptr<ColumnarBatch> next() override;
int64_t spillFixedSize(int64_t size) override;
private:
/// Read and compose one batch from the input iterator (CPU-only work).
/// Returns nullptr if input is exhausted.
std::shared_ptr<GpuBufferColumnarBatch> fetchAndComposeBatch();
arrow::MemoryPool* arrowPool_;
facebook::velox::memory::MemoryPool* pool_;
const int32_t minOutputBatchSize_;
const int64_t maxPrefetchSize_;
std::unique_ptr<ColumnarBatchIterator> in_;
std::deque<std::shared_ptr<GpuBufferColumnarBatch>> prefetchQueue_;
int64_t prefetchedBytes_ = 0;
};
} // namespace gluten