From 67aa6e4c88e0f19a99154ce4cd9dbd8884e959cd Mon Sep 17 00:00:00 2001 From: David G Yu Date: Fri, 25 Aug 2023 09:33:35 -0700 Subject: [PATCH] Marked deprecated Osd::*Evaluator::SetNumThreads() The existing implementation in Osd::TbbEvaluator has never been implemented correctly and that implementation is incompatible with the oneTBB API. These methods are now marked deprecated in the two places where defined in Osd::TbbEvaluator and Osd::OmpEvaluator, but for consistency we preserve the existing implementation when building with older versions of tbb. We've already removed all use of these methods from the tests and examples. --- opensubdiv/osd/ompEvaluator.cpp | 2 ++ opensubdiv/osd/ompEvaluator.h | 1 + opensubdiv/osd/tbbEvaluator.cpp | 9 +++++++++ opensubdiv/osd/tbbEvaluator.h | 3 +-- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/opensubdiv/osd/ompEvaluator.cpp b/opensubdiv/osd/ompEvaluator.cpp index 1fb3d21d..543824b5 100644 --- a/opensubdiv/osd/ompEvaluator.cpp +++ b/opensubdiv/osd/ompEvaluator.cpp @@ -361,6 +361,8 @@ OmpEvaluator::Synchronize(void * /*deviceContext*/) { /* static */ void OmpEvaluator::SetNumThreads(int numThreads) { + // This is deprecated functionality. We preserve the existing behavior + // for consistency. omp_set_num_threads(numThreads); } diff --git a/opensubdiv/osd/ompEvaluator.h b/opensubdiv/osd/ompEvaluator.h index b1d27d73..e7d91239 100644 --- a/opensubdiv/osd/ompEvaluator.h +++ b/opensubdiv/osd/ompEvaluator.h @@ -1225,6 +1225,7 @@ public: static void Synchronize(void *deviceContext = NULL); + /// \brief Deprecated. Client code should initialize OpenMP. static void SetNumThreads(int numThreads); }; diff --git a/opensubdiv/osd/tbbEvaluator.cpp b/opensubdiv/osd/tbbEvaluator.cpp index c98db9f6..69f9687f 100644 --- a/opensubdiv/osd/tbbEvaluator.cpp +++ b/opensubdiv/osd/tbbEvaluator.cpp @@ -25,7 +25,12 @@ #include "../osd/tbbEvaluator.h" #include "../osd/tbbKernel.h" +// Get TBB version from tbb/parallel_for used by osd/tbbKernel +#include +#if defined(TBB_INTERFACE_VERSION_MAJOR) && (TBB_INTERFACE_VERSION_MAJOR < 12) +// This is deprecated functionality. #include +#endif namespace OpenSubdiv { namespace OPENSUBDIV_VERSION { @@ -215,11 +220,15 @@ TbbEvaluator::Synchronize(void *) { /* static */ void TbbEvaluator::SetNumThreads(int numThreads) { +#if defined(TBB_INTERFACE_VERSION_MAJOR) && (TBB_INTERFACE_VERSION_MAJOR < 12) + // This is deprecated functionality. We preserve the existing behavior + // for consistency (when using older versions of tbb). if (numThreads == -1) { tbb::task_scheduler_init init; } else { tbb::task_scheduler_init init(numThreads); } +#endif } } // end namespace Osd diff --git a/opensubdiv/osd/tbbEvaluator.h b/opensubdiv/osd/tbbEvaluator.h index 6bd365bc..34f24ff4 100644 --- a/opensubdiv/osd/tbbEvaluator.h +++ b/opensubdiv/osd/tbbEvaluator.h @@ -1226,8 +1226,7 @@ public: /// \brief synchronize all asynchronous computation invoked on this device. static void Synchronize(void *deviceContext = NULL); - /// \brief initialize tbb task schedular - /// (optional: client may use tbb::task_scheduler_init) + /// \brief Deprecated. Client code should initialize TBB. /// /// @param numThreads how many threads ///