Files
FastDeploy/fastdeploy/vision/common/processors/mat_batch.h
Wang Xinyu 91a1c72f98 [CVCUDA] PP-OCR detector preprocessor integrate CV-CUDA (#1382)
* move manager initialized_ flag to ppcls

* update dbdetector preprocess api

* declare processor op

* ppocr detector preprocessor support cvcuda

* move cvcuda op to class member

* ppcls use manager register api

* refactor det preprocessor init api

* add set preprocessor api

* add create processor macro

* new processor call api

* ppcls preprocessor init resize on cpu

* ppocr detector preprocessor set normalize api

* revert ppcls pybind

* remove dbdetector set preprocessor

* refine dbdetector preprocessor includes

* remove mean std in py constructor

* add comments

* update comment

* Update __init__.py
2023-02-22 19:39:11 +08:00

78 lines
2.3 KiB
C++

// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed 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 "fastdeploy/vision/common/processors/mat.h"
#ifdef WITH_GPU
#include <cuda_runtime_api.h>
#endif
namespace fastdeploy {
namespace vision {
enum FDMatBatchLayout { NHWC, NCHW };
struct FASTDEPLOY_DECL FDMatBatch {
FDMatBatch() = default;
// MatBatch is intialized with a list of mats,
// the data is stored in the mats separately.
// Call Tensor() function to get a batched 4-dimension tensor.
explicit FDMatBatch(std::vector<FDMat>* _mats) {
mats = _mats;
layout = FDMatBatchLayout::NHWC;
mat_type = ProcLib::OPENCV;
}
// Get the batched 4-dimension tensor.
FDTensor* Tensor();
void SetTensor(FDTensor* tensor);
private:
#ifdef WITH_GPU
cudaStream_t stream = nullptr;
#endif
std::shared_ptr<FDTensor> fd_tensor = std::make_shared<FDTensor>();
public:
// When using CV-CUDA/CUDA, please set input/output cache,
// refer to manager.cc
FDTensor* input_cache;
FDTensor* output_cache;
#ifdef WITH_GPU
cudaStream_t Stream() const { return stream; }
void SetStream(cudaStream_t s);
#endif
std::vector<FDMat>* mats;
ProcLib mat_type = ProcLib::OPENCV;
FDMatBatchLayout layout = FDMatBatchLayout::NHWC;
Device device = Device::CPU;
ProcLib proc_lib = ProcLib::DEFAULT;
// False: the data is stored in the mats separately
// True: the data is stored in the fd_tensor continuously in 4 dimensions
bool has_batched_tensor = false;
};
// Create a batched input tensor on GPU and save into input_cache.
// If the MatBatch is on GPU, return the Tensor() directly.
// If the MatBatch is on CPU, then copy the CPU tensors to GPU and get a GPU
// batched input tensor.
FDTensor* CreateCachedGpuInputTensor(FDMatBatch* mat_batch);
} // namespace vision
} // namespace fastdeploy