ittnotify-zca.h 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
  2. /*
  3. Copyright (C) 2005-2019 Intel Corporation
  4. SPDX-License-Identifier: GPL-2.0-only OR BSD-3-Clause
  5. */
  6. /**
  7. * Zero Cost Annotations (ZCA)
  8. *
  9. * Intel Compiler supports two intrinsics that could be used for code annotations
  10. * without incurring significant run-time costs when the tools are not in use.
  11. * Each annotation is more than a mere mark in the instruction stream.
  12. * It can accept an expression argument like a call to a routine does.
  13. * There are two forms of the intrinsic, with the following signatures:
  14. *
  15. * extern "C" void __notify_intrinsic( const char *annotation, const volatile void *tag);
  16. * extern "C" void __notify_zc_intrinsic(const char *annotation, const volatile void *tag);
  17. *
  18. * The string annotation must be a compile-time constant. It specifies the type of the annotation.
  19. * The pointer tag is computed at run time. It specifies the data associated with the annotation.
  20. * Each intrinsic implies a compiler fence: the compiler must not move any memory
  21. * operation across it. The reason for this restriction is that annotation might denote an
  22. * event that must be precisely placed with respect to memory operations.
  23. *
  24. * The difference between the two intrinsics is that __notify_intrinsic must leave a
  25. * probe-ready instruction sequence in the instruction stream where the instrinsic
  26. * occurs. The __notify_zc_intrinsic does not leave such a sequence, and hence is closer to "zero cost".
  27. **/
  28. #pragma once
  29. #include "ittnotify.h"
  30. #ifndef INTEL_NO_ITTNOTIFY_API
  31. #if (defined(__INTEL_COMPILER) || defined(__INTEL_LLVM_COMPILER)) && (ITT_PLATFORM == ITT_PLATFORM_WIN || ITT_PLATFORM == ITT_PLATFORM_POSIX)
  32. #define ITT_ENABLE_LOW_OVERHEAD_ANNOTATIONS
  33. #else
  34. #error Zero cost (low overhead) annotations are not supported on this platform
  35. #endif
  36. #endif
  37. /**
  38. * Zero cost annotations for memory allocation and deallocation
  39. **/
  40. #ifdef ITT_ENABLE_LOW_OVERHEAD_ANNOTATIONS
  41. #pragma pack(push, 1)
  42. typedef struct ___itt_zca_allocation_info {
  43. size_t size; /*!< Size of allocated memory */
  44. void** ptr; /*!< Pointer to allocated memory pointer */
  45. int initialized; /*!< Is allocated memory initialized */
  46. } __itt_zca_allocation_info;
  47. #pragma pack(pop)
  48. #define __itt_zca_mem_allocate_begin() __notify_intrinsic((char*)"mem_allocate_begin", 0)
  49. #define __itt_zca_mem_allocate_end(ptr, size, init) { __itt_zca_allocation_info __itt_zca_alloc_info = { size, ptr, init }; __notify_intrinsic((char*)"mem_allocate_end", (void*)&__itt_zca_alloc_info); }
  50. #define __itt_zca_mem_free_begin(ptr) __notify_intrinsic((char*)"mem_free_begin", (void*)ptr)
  51. #define __itt_zca_mem_free_end() __notify_intrinsic((char*)"mem_free_end", 0)
  52. #else
  53. #define __itt_zca_mem_allocate_begin()
  54. #define __itt_zca_mem_allocate_end(ptr, size, init)
  55. #define __itt_zca_mem_free_begin(ptr)
  56. #define __itt_zca_mem_free_end()
  57. #endif
  58. /**
  59. * Zero cost annotations for threading
  60. **/
  61. #ifdef ITT_ENABLE_LOW_OVERHEAD_ANNOTATIONS
  62. #define __itt_zca_suppress_push(id) __notify_zc_intrinsic((char*)"__itt_suppress_push", (void*)id);
  63. #define __itt_zca_suppress_pop(id) __notify_zc_intrinsic((char*)"__itt_suppress_pop", (void*)id);
  64. #define __itt_zca_sync_create(id) __notify_zc_intrinsic((char*)"__itt_sync_create", (void*)id)
  65. #define __itt_zca_sync_acquired(id) __notify_zc_intrinsic((char*)"__itt_sync_acquired", (void*)id)
  66. #define __itt_zca_sync_releasing(id) __notify_zc_intrinsic((char*)"__itt_sync_releasing", (void*)id)
  67. #define __itt_zca_sync_destroy(id) __notify_zc_intrinsic((char*)"__itt_sync_destroy", (void*)id)
  68. #else
  69. #define __itt_zca_suppress_push(id)
  70. #define __itt_zca_suppress_pop(id)
  71. #define __itt_zca_sync_create(id)
  72. #define __itt_zca_sync_acquired(id)
  73. #define __itt_zca_sync_releasing(id)
  74. #define __itt_zca_sync_destroy(id)
  75. #endif
  76. #else
  77. #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
  78. #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)