pd_common.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright (c) 2021 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 <stdint.h>
  16. #include <stdio.h>
  17. #if defined(_WIN32)
  18. #ifdef PADDLE_DLL_INFERENCE
  19. #define PADDLE_CAPI_EXPORT __declspec(dllexport)
  20. #else
  21. #define PADDLE_CAPI_EXPORT __declspec(dllimport)
  22. #endif // PADDLE_DLL_INFERENCE
  23. #else
  24. #define PADDLE_CAPI_EXPORT __attribute__((visibility("default")))
  25. #endif // _WIN32
  26. ///
  27. /// __pd_give means that a new object is returned. The user should make sure
  28. /// that the returned pointer is used exactly once as a value for an __pd_take
  29. /// argument. In between, it can be used as a value for as many __pd_keep
  30. /// arguments as the user likes.
  31. ///
  32. #ifndef __pd_give
  33. #define __pd_give
  34. #endif
  35. ///
  36. /// __pd_take means that the object the argument points to is taken over by the
  37. /// function and may no longer be used by the user as an argument to any other
  38. /// function. The pointer value must be one returned by a function returning an
  39. /// __pd_give pointer.
  40. ///
  41. #ifndef __pd_take
  42. #define __pd_take
  43. #endif
  44. ///
  45. /// __pd_keep means that the function will only use the object temporarily. The
  46. /// object which the argument points to is not taken over by the function. After
  47. /// the function has finished, the user can still use it as an argument to other
  48. /// functions.
  49. ///
  50. #ifndef __pd_keep
  51. #define __pd_keep
  52. #endif
  53. typedef int8_t PD_Bool;
  54. #define TRUE 1
  55. #define FALSE 0
  56. #define PD_ENUM(type) \
  57. typedef int32_t type; \
  58. enum
  59. PD_ENUM(PD_PrecisionType){
  60. PD_PRECISION_FLOAT32 = 0, PD_PRECISION_INT8, PD_PRECISION_HALF};
  61. PD_ENUM(PD_PlaceType){
  62. PD_PLACE_UNK = -1, PD_PLACE_CPU, PD_PLACE_GPU, PD_PLACE_XPU};
  63. PD_ENUM(PD_DataType){
  64. PD_DATA_UNK = -1,
  65. PD_DATA_FLOAT32,
  66. PD_DATA_INT32,
  67. PD_DATA_INT64,
  68. PD_DATA_UINT8,
  69. PD_DATA_INT8,
  70. };