taskschedulertbb.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright 2009-2021 Intel Corporation
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include "../sys/platform.h"
  5. #include "../sys/alloc.h"
  6. #include "../sys/barrier.h"
  7. #include "../sys/thread.h"
  8. #include "../sys/mutex.h"
  9. #include "../sys/condition.h"
  10. #include "../sys/ref.h"
  11. #if defined(__WIN32__) && !defined(NOMINMAX)
  12. # define NOMINMAX
  13. #endif
  14. #if defined(__INTEL_LLVM_COMPILER)
  15. // prevents "'__thiscall' calling convention is not supported for this target" warning from TBB
  16. #pragma clang diagnostic push
  17. #pragma clang diagnostic ignored "-Wignored-attributes"
  18. #endif
  19. // We need to define these to avoid implicit linkage against
  20. // tbb_debug.lib under Windows. When removing these lines debug build
  21. // under Windows fails.
  22. #define __TBB_NO_IMPLICIT_LINKAGE 1
  23. #define __TBBMALLOC_NO_IMPLICIT_LINKAGE 1
  24. #define TBB_SUPPRESS_DEPRECATED_MESSAGES 1
  25. #define TBB_PREVIEW_ISOLATED_TASK_GROUP 1
  26. #include "tbb/tbb.h"
  27. #include "tbb/parallel_sort.h"
  28. #if defined(TASKING_TBB) && (TBB_INTERFACE_VERSION_MAJOR >= 8)
  29. # define USE_TASK_ARENA 1
  30. #else
  31. # define USE_TASK_ARENA 0
  32. #endif
  33. #if defined(TASKING_TBB) && (TBB_INTERFACE_VERSION >= 11009) // TBB 2019 Update 9
  34. # define TASKING_TBB_USE_TASK_ISOLATION 1
  35. #else
  36. # define TASKING_TBB_USE_TASK_ISOLATION 0
  37. #endif
  38. namespace embree
  39. {
  40. struct TaskScheduler
  41. {
  42. /*! initializes the task scheduler */
  43. static void create(size_t numThreads, bool set_affinity, bool start_threads);
  44. /*! destroys the task scheduler again */
  45. static void destroy();
  46. /* returns the ID of the current thread */
  47. static __forceinline size_t threadID()
  48. {
  49. return threadIndex();
  50. }
  51. /* returns the index (0..threadCount-1) of the current thread */
  52. static __forceinline size_t threadIndex()
  53. {
  54. #if TBB_INTERFACE_VERSION >= 9100
  55. return tbb::this_task_arena::current_thread_index();
  56. #elif TBB_INTERFACE_VERSION >= 9000
  57. return tbb::task_arena::current_thread_index();
  58. #else
  59. return 0;
  60. #endif
  61. }
  62. /* returns the total number of threads */
  63. static __forceinline size_t threadCount() {
  64. #if TBB_INTERFACE_VERSION >= 9100
  65. return tbb::this_task_arena::max_concurrency();
  66. #else
  67. return tbb::task_scheduler_init::default_num_threads();
  68. #endif
  69. }
  70. };
  71. };
  72. #if defined(__INTEL_LLVM_COMPILER)
  73. #pragma clang diagnostic pop
  74. #endif