diff --git a/examples/text/ernie-3.0/cpp/seq_cls_infer.cc b/examples/text/ernie-3.0/cpp/seq_cls_infer.cc index 01ef403a0..b7ab495bd 100644 --- a/examples/text/ernie-3.0/cpp/seq_cls_infer.cc +++ b/examples/text/ernie-3.0/cpp/seq_cls_infer.cc @@ -187,11 +187,11 @@ struct ErnieForSequenceClassificationPredictor { std::vector* seq_cls_results) { const auto& logits = outputs[0]; fastdeploy::FDTensor probs; - fastdeploy::Softmax(logits, &probs); + fastdeploy::function::Softmax(logits, &probs); fastdeploy::FDTensor labels, confidences; - fastdeploy::Max(probs, &confidences, {-1}); - fastdeploy::ArgMax(probs, &labels, -1); + fastdeploy::function::Max(probs, &confidences, {-1}); + fastdeploy::function::ArgMax(probs, &labels, -1); if (labels.Numel() != confidences.Numel()) { return false; } diff --git a/fastdeploy/backends/tensorrt/trt_backend.cc b/fastdeploy/backends/tensorrt/trt_backend.cc index 87d4f6072..82cb45464 100755 --- a/fastdeploy/backends/tensorrt/trt_backend.cc +++ b/fastdeploy/backends/tensorrt/trt_backend.cc @@ -318,7 +318,7 @@ bool TrtBackend::Infer(std::vector& inputs, casted_output_tensors_[(*outputs)[i].name].Resize((*outputs)[i].shape, (*outputs)[i].dtype, (*outputs)[i].name, Device::GPU); - CudaCast(output_tensor, &casted_output_tensors_[(*outputs)[i].name], stream_); + function::CudaCast(output_tensor, &casted_output_tensors_[(*outputs)[i].name], stream_); } else { casted_output_tensors_[(*outputs)[i].name].SetExternalData( (*outputs)[i].shape, model_output_dtype, @@ -392,7 +392,7 @@ void TrtBackend::SetInputs(const std::vector& inputs) { input_tensor.SetExternalData(item.shape, FDDataType::INT32, inputs_device_buffer_[item.name].data(), Device::GPU); - CudaCast(item, &input_tensor, stream_); + function::CudaCast(item, &input_tensor, stream_); } else { // no copy inputs_device_buffer_[item.name].SetExternalData(dims, item.Data()); diff --git a/fastdeploy/function/concat.cc b/fastdeploy/function/concat.cc index 32ca407c0..cccd1768e 100644 --- a/fastdeploy/function/concat.cc +++ b/fastdeploy/function/concat.cc @@ -21,7 +21,7 @@ #include "fastdeploy/utils/utils.h" namespace fastdeploy { - +namespace function { std::string Str(const std::vector& shape) { std::ostringstream oss; oss << "[ " << shape[0]; @@ -121,4 +121,5 @@ void Concat(const std::vector& x, FDTensor* out, int axis) { *out = std::move(out_temp); } -} // namespace fastdeploy \ No newline at end of file +} // namespace function +} // namespace fastdeploy diff --git a/fastdeploy/function/concat.h b/fastdeploy/function/concat.h index 22e388b0f..2a89300bc 100644 --- a/fastdeploy/function/concat.h +++ b/fastdeploy/function/concat.h @@ -17,6 +17,7 @@ #include "fastdeploy/core/fd_tensor.h" namespace fastdeploy { +namespace function { /** Excute the concatenate operation for input FDTensor along given axis. @param x The input tensor. @@ -27,4 +28,5 @@ namespace fastdeploy { FASTDEPLOY_DECL void Concat(const std::vector& x, FDTensor* out, int axis = 0); +} // namespace function } // namespace fastdeploy diff --git a/fastdeploy/function/cuda_cast.cu b/fastdeploy/function/cuda_cast.cu index 5bdf337e5..ceb7b1b13 100644 --- a/fastdeploy/function/cuda_cast.cu +++ b/fastdeploy/function/cuda_cast.cu @@ -15,7 +15,7 @@ #include "fastdeploy/function/cuda_cast.h" namespace fastdeploy { - +namespace function { template __global__ void CudaCastKernel(const T_IN* in, T_OUT* out, int edge) { int position = blockDim.x * blockIdx.x + threadIdx.x; @@ -42,4 +42,5 @@ void CudaCast(const FDTensor& in, FDTensor* out, cudaStream_t stream) { } } +} // namespace function } // namespace fastdeploy diff --git a/fastdeploy/function/cuda_cast.h b/fastdeploy/function/cuda_cast.h index f467e78fe..0d6d65ca0 100644 --- a/fastdeploy/function/cuda_cast.h +++ b/fastdeploy/function/cuda_cast.h @@ -17,7 +17,7 @@ #include "fastdeploy/core/fd_tensor.h" namespace fastdeploy { - +namespace function { /** Cast the type of the data in GPU buffer. @param in The input tensor. @param out The output tensor @@ -25,5 +25,5 @@ namespace fastdeploy { */ FASTDEPLOY_DECL void CudaCast(const FDTensor& in, FDTensor* out, cudaStream_t stream); - +} // namespace function } // namespace fastdeploy diff --git a/fastdeploy/function/eigen.cc b/fastdeploy/function/eigen.cc index adcfbb195..d3ac0f1fa 100644 --- a/fastdeploy/function/eigen.cc +++ b/fastdeploy/function/eigen.cc @@ -15,7 +15,7 @@ #include "fastdeploy/function/eigen.h" namespace fastdeploy { - +namespace function { std::shared_ptr EigenDeviceWrapper::instance_ = nullptr; std::shared_ptr EigenDeviceWrapper::GetInstance() { @@ -29,4 +29,5 @@ const Eigen::DefaultDevice* EigenDeviceWrapper::GetDevice() const { return &device_; } +} } // namespace fastdeploy diff --git a/fastdeploy/function/eigen.h b/fastdeploy/function/eigen.h index b07204cab..cde0700d8 100644 --- a/fastdeploy/function/eigen.h +++ b/fastdeploy/function/eigen.h @@ -22,6 +22,7 @@ #include "unsupported/Eigen/CXX11/Tensor" namespace fastdeploy { +namespace function { // EigenDim converts shape into Eigen::DSizes. template struct EigenDim { @@ -135,4 +136,5 @@ class EigenDeviceWrapper { static std::shared_ptr instance_; }; +} // namespace function } // namespace fastdeploy diff --git a/fastdeploy/function/pad.cc b/fastdeploy/function/pad.cc index 42585781b..fcd901f8a 100644 --- a/fastdeploy/function/pad.cc +++ b/fastdeploy/function/pad.cc @@ -20,7 +20,7 @@ #include "fastdeploy/utils/utils.h" namespace fastdeploy { - +namespace function { template struct PadEigen { using Array = std::array, Rank>; @@ -123,4 +123,5 @@ void Pad(const FDTensor& x, FDTensor* out, const std::vector& pads, float v +} // namespace function } // namespace fastdeploy diff --git a/fastdeploy/function/pad.h b/fastdeploy/function/pad.h index fef7e5c5c..4995ba584 100644 --- a/fastdeploy/function/pad.h +++ b/fastdeploy/function/pad.h @@ -17,7 +17,7 @@ #include "fastdeploy/core/fd_tensor.h" namespace fastdeploy { - +namespace function { /** Excute the pad operation for input FDTensor along given dims. @param x The input tensor. @param out The output tensor which stores the result. @@ -27,4 +27,5 @@ namespace fastdeploy { FASTDEPLOY_DECL void Pad(const FDTensor& x, FDTensor* out, const std::vector& pads, float pad_value = 0); +} } // namespace fastdeploy diff --git a/fastdeploy/function/reduce.cc b/fastdeploy/function/reduce.cc index f005285bf..1059061c2 100644 --- a/fastdeploy/function/reduce.cc +++ b/fastdeploy/function/reduce.cc @@ -23,7 +23,7 @@ #include "fastdeploy/utils/utils.h" namespace fastdeploy { - +namespace function { template void ReduceFunctor(const FDTensor& input, FDTensor* output, const std::vector& dims, bool keep_dim) { @@ -402,4 +402,5 @@ void ArgMin(const FDTensor& x, FDTensor* out, int64_t axis, })); } -} // namespace fastdeploy \ No newline at end of file +} // namespace function +} // namespace fastdeploy diff --git a/fastdeploy/function/reduce.h b/fastdeploy/function/reduce.h index 77ec2c5c0..3521f16f1 100644 --- a/fastdeploy/function/reduce.h +++ b/fastdeploy/function/reduce.h @@ -17,7 +17,7 @@ #include "fastdeploy/core/fd_tensor.h" namespace fastdeploy { - +namespace function { /** Excute the maximum operation for input FDTensor along given dims. @param x The input tensor. @param out The output tensor which stores the result. @@ -123,4 +123,5 @@ FASTDEPLOY_DECL void ArgMin(const FDTensor& x, FDTensor* out, int64_t axis, FDDataType output_dtype = FDDataType::INT64, bool keep_dim = false, bool flatten = false); +} // namespace function } // namespace fastdeploy diff --git a/fastdeploy/function/reduce_functor.h b/fastdeploy/function/reduce_functor.h index de0c45bb3..d048beca9 100644 --- a/fastdeploy/function/reduce_functor.h +++ b/fastdeploy/function/reduce_functor.h @@ -16,7 +16,7 @@ #include "fastdeploy/function/eigen.h" namespace fastdeploy { - +namespace function { //////// Max Functor /////// struct MaxFunctor { template @@ -73,4 +73,5 @@ struct ProdFunctor { } }; +} // namespace function } // namespace fastdeploy diff --git a/fastdeploy/function/softmax.cc b/fastdeploy/function/softmax.cc index b58d33d8e..777d626c5 100644 --- a/fastdeploy/function/softmax.cc +++ b/fastdeploy/function/softmax.cc @@ -21,6 +21,7 @@ #include "fastdeploy/utils/utils.h" namespace fastdeploy { +namespace function { template struct ValueClip { T operator()(const T& x) const { @@ -124,4 +125,5 @@ void Softmax(const FDTensor& x, FDTensor* out, int axis) { ([&] { SoftmaxKernel(x, &out_tmp, axis); })); *out = std::move(out_tmp); } +} // namespace function } // namespace fastdeploy diff --git a/fastdeploy/function/softmax.h b/fastdeploy/function/softmax.h index 2c3aa78d3..3cd2ed3a7 100644 --- a/fastdeploy/function/softmax.h +++ b/fastdeploy/function/softmax.h @@ -17,7 +17,7 @@ #include "fastdeploy/core/fd_tensor.h" namespace fastdeploy { - +namespace function { /** Excute the softmax operation for input FDTensor along given dims. @param x The input tensor. @param out The output tensor which stores the result. @@ -25,4 +25,5 @@ namespace fastdeploy { */ FASTDEPLOY_DECL void Softmax(const FDTensor& x, FDTensor* out, int axis = -1); +} // namespace function } // namespace fastdeploy diff --git a/fastdeploy/function/transpose.cc b/fastdeploy/function/transpose.cc index eed631885..fb4dd52ee 100644 --- a/fastdeploy/function/transpose.cc +++ b/fastdeploy/function/transpose.cc @@ -17,7 +17,7 @@ #include "fastdeploy/utils/utils.h" namespace fastdeploy { - +namespace function { template struct TransposeNormalKernel { void operator()(const FDTensor& in, FDTensor* out, @@ -121,4 +121,5 @@ void Transpose(const FDTensor& x, FDTensor* out, *out = std::move(out_temp); } -} // namespace fastdeploy \ No newline at end of file +} // namespace function +} // namespace fastdeploy diff --git a/fastdeploy/function/transpose.h b/fastdeploy/function/transpose.h index e59fe10f7..9bae6e66c 100644 --- a/fastdeploy/function/transpose.h +++ b/fastdeploy/function/transpose.h @@ -17,7 +17,7 @@ #include "fastdeploy/core/fd_tensor.h" namespace fastdeploy { - +namespace function { /** Excute the transpose operation for input FDTensor along given dims. @param x The input tensor. @param out The output tensor which stores the result. @@ -25,4 +25,5 @@ namespace fastdeploy { */ FASTDEPLOY_DECL void Transpose(const FDTensor& x, FDTensor* out, const std::vector& dims); +} // namespace function } // namespace fastdeploy diff --git a/fastdeploy/vision/classification/contrib/resnet.cc b/fastdeploy/vision/classification/contrib/resnet.cc index 8050ceccb..2eed67992 100644 --- a/fastdeploy/vision/classification/contrib/resnet.cc +++ b/fastdeploy/vision/classification/contrib/resnet.cc @@ -87,7 +87,7 @@ bool ResNet::Postprocess(FDTensor& infer_result, // 1. Softmax 2. Choose topk labels 3. Put the result into ClassifyResult variable. int num_classes = infer_result.shape[1]; - Softmax(infer_result, &infer_result); + function::Softmax(infer_result, &infer_result); const float* infer_result_buffer = reinterpret_cast(infer_result.Data()); topk = std::min(num_classes, topk); result->label_ids = diff --git a/fastdeploy/vision/classification/contrib/yolov5cls.cc b/fastdeploy/vision/classification/contrib/yolov5cls.cc index 59f6740be..8dfc0a9a0 100755 --- a/fastdeploy/vision/classification/contrib/yolov5cls.cc +++ b/fastdeploy/vision/classification/contrib/yolov5cls.cc @@ -75,7 +75,7 @@ bool YOLOv5Cls::Postprocess(const FDTensor& infer_result, ClassifyResult* result, int topk) { // Softmax FDTensor infer_result_softmax; - Softmax(infer_result, &infer_result_softmax, 1); + function::Softmax(infer_result, &infer_result_softmax, 1); int num_classes = infer_result_softmax.shape[1]; const float* infer_result_buffer = reinterpret_cast(infer_result_softmax.Data()); diff --git a/fastdeploy/vision/classification/ppcls/preprocessor.cc b/fastdeploy/vision/classification/ppcls/preprocessor.cc index d2aaca2c7..8f7d91358 100644 --- a/fastdeploy/vision/classification/ppcls/preprocessor.cc +++ b/fastdeploy/vision/classification/ppcls/preprocessor.cc @@ -99,7 +99,11 @@ bool PaddleClasPreprocessor::Run(std::vector* images, std::vector dim{0, 2, 3, 1}; - Transpose(alpha_tensor, &alpha_tensor, dim); + function::Transpose(alpha_tensor, &alpha_tensor, dim); alpha_tensor.Squeeze(0); Mat mat = Mat::Create(alpha_tensor); diff --git a/fastdeploy/vision/segmentation/ppseg/model.cc b/fastdeploy/vision/segmentation/ppseg/model.cc index fccdf3688..6c6628528 100644 --- a/fastdeploy/vision/segmentation/ppseg/model.cc +++ b/fastdeploy/vision/segmentation/ppseg/model.cc @@ -220,7 +220,7 @@ bool PaddleSegModel::Postprocess( } if (!is_with_softmax && apply_softmax) { - Softmax(*infer_result, infer_result, 1); + function::Softmax(*infer_result, infer_result, 1); } if (!is_with_argmax) { @@ -228,7 +228,7 @@ bool PaddleSegModel::Postprocess( result->contain_score_map = true; std::vector dim{0, 2, 3, 1}; - Transpose(*infer_result, infer_result, dim); + function::Transpose(*infer_result, infer_result, dim); } // batch always 1, so ignore infer_result->shape = {infer_height, infer_width, infer_channel}; @@ -284,11 +284,11 @@ bool PaddleSegModel::Postprocess( std::vector reduce_dim{-1}; // argmax if (is_resized) { - ArgMax(new_infer_result, &argmax_infer_result, -1, FDDataType::INT32); - Max(new_infer_result, &max_score_result, reduce_dim); + function::ArgMax(new_infer_result, &argmax_infer_result, -1, FDDataType::INT32); + function::Max(new_infer_result, &max_score_result, reduce_dim); } else { - ArgMax(*infer_result, &argmax_infer_result, -1, FDDataType::INT32); - Max(*infer_result, &max_score_result, reduce_dim); + function::ArgMax(*infer_result, &argmax_infer_result, -1, FDDataType::INT32); + function::Max(*infer_result, &max_score_result, reduce_dim); } argmax_infer_result_buffer = static_cast(argmax_infer_result.Data()); diff --git a/tests/function/test_concat.cc b/tests/function/test_concat.cc index 4bdd49dd1..f53c6389c 100644 --- a/tests/function/test_concat.cc +++ b/tests/function/test_concat.cc @@ -21,7 +21,7 @@ #include "gtest_utils.h" namespace fastdeploy { - +namespace function { TEST(fastdeploy, concat1) { CheckShape check_shape; std::vector inputs(3); @@ -77,4 +77,5 @@ TEST(fastdeploy, concat5) { check_shape(output.shape, {5, 6, 4, 5}); } +} // namespace function } // namespace fastdeploy diff --git a/tests/function/test_pad.cc b/tests/function/test_pad.cc index bec7b8252..e99b07f5b 100644 --- a/tests/function/test_pad.cc +++ b/tests/function/test_pad.cc @@ -22,7 +22,7 @@ #include "gtest_utils.h" namespace fastdeploy { - +namespace function { TEST(fastdeploy, pad_2d) { FDTensor input, output; CheckShape check_shape; @@ -65,28 +65,5 @@ TEST(fastdeploy, pad_2d_int32_t) { check_type(input.dtype, output.dtype); } -//TEST(fastdeploy, transpose_5d) { -// FDTensor input, output; -// CheckShape check_shape; -// CheckData check_data; -// -// std::vector input_shape = {2, 1, 3, 1, 2}; -// auto total_size = std::accumulate(input_shape.begin(), input_shape.end(), 1, -// std::multiplies()); -// std::vector inputs(total_size, 1); -// std::iota(inputs.begin(), inputs.end(), 1); -// std::vector expected_result = {1, 3, 5, 2, 4, 6, 7, 9, 11, 8, 10, 12}; -// input.SetExternalData(input_shape, FDDataType::INT32, inputs.data()); -// -// Transpose(input, &output, {0, 1, 4, 3, 2}); -// check_shape(output.shape, {2, 1, 2, 1, 3}); -// check_data(reinterpret_cast(output.Data()), -// expected_result.data(), expected_result.size()); -// -// Transpose(input, &input, {0, 1, 4, 3, 2}); -// check_shape(input.shape, {2, 1, 2, 1, 3}); -// check_data(reinterpret_cast(input.Data()), expected_result.data(), -// expected_result.size()); -//} - +} // namespace function } // namespace fastdeploy diff --git a/tests/function/test_reduce.cc b/tests/function/test_reduce.cc index 6a7c7bcf1..7faf9aec6 100644 --- a/tests/function/test_reduce.cc +++ b/tests/function/test_reduce.cc @@ -21,7 +21,7 @@ #include "gtest_utils.h" namespace fastdeploy { - +namespace function { TEST(fastdeploy, reduce_max) { FDTensor input, output; CheckShape check_shape; @@ -371,4 +371,5 @@ TEST(fastdeploy, reduce_argmin) { expected_result_noaxis.data(), expected_result_noaxis.size()); } +} // namespace function } // namespace fastdeploy diff --git a/tests/function/test_softmax.cc b/tests/function/test_softmax.cc index 92e0d5cc7..1cd834faf 100644 --- a/tests/function/test_softmax.cc +++ b/tests/function/test_softmax.cc @@ -20,7 +20,7 @@ #include "gtest_utils.h" namespace fastdeploy { - +namespace function { TEST(fastdeploy, softmax) { FDTensor input, input1, output; CheckShape check_shape; @@ -57,4 +57,5 @@ TEST(fastdeploy, softmax) { expected_result_axis1.data(), expected_result_axis1.size()); } -} // namespace fastdeploy \ No newline at end of file +} // namespace function +} // namespace fastdeploy diff --git a/tests/function/test_transpose.cc b/tests/function/test_transpose.cc index a076aac07..1d4e42039 100644 --- a/tests/function/test_transpose.cc +++ b/tests/function/test_transpose.cc @@ -22,7 +22,7 @@ #include "gtest_utils.h" namespace fastdeploy { - +namespace function { TEST(fastdeploy, transpose_2d) { FDTensor input, output; CheckShape check_shape; @@ -67,4 +67,5 @@ TEST(fastdeploy, transpose_5d) { expected_result.size()); } +} // namespace function } // namespace fastdeploy