utils.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #include <iostream>
  16. #include <memory>
  17. #include <string>
  18. #include <vector>
  19. #include "onnxruntime_cxx_api.h" // NOLINT
  20. #include "ultra_infer/runtime/backends/backend.h"
  21. namespace ultra_infer {
  22. // Convert FDDataType to OrtDataType
  23. ONNXTensorElementDataType GetOrtDtype(const FDDataType &fd_dtype);
  24. // Convert OrtDataType to FDDataType
  25. FDDataType GetFdDtype(const ONNXTensorElementDataType &ort_dtype);
  26. // Create Ort::Value
  27. // is_backend_cuda specify if the onnxruntime use CUDAExectionProvider
  28. // While is_backend_cuda = true, and tensor.device = Device::GPU
  29. // Will directly share the cuda data in tensor to OrtValue
  30. Ort::Value CreateOrtValue(FDTensor &tensor, bool is_backend_cuda = false);
  31. } // namespace ultra_infer