| 18 | #include "cpu_image_copy.h" |
| 19 | |
| 20 | OIDN_NAMESPACE_BEGIN |
| 21 | |
| 22 | CPUEngine::CPUEngine(CPUDevice* device, int numThreads) |
| 23 | : device(device) |
| 24 | { |
| 25 | // Get the thread affinities for one thread per core on non-hybrid CPUs with SMT |
| 26 | #if !(defined(__APPLE__) && defined(OIDN_ARCH_ARM64)) |
| 27 | if (device->setAffinity |
| 28 | #if TBB_INTERFACE_VERSION >= 12020 // oneTBB 2021.2 or later |
| 29 | && tbb::info::core_types().size() <= 1 // non-hybrid cores |
| 30 | #endif |
| 31 | ) |
| 32 | { |
| 33 | affinity = std::make_shared<ThreadAffinity>(1, device->verbose); |
| 34 | if (affinity->getNumThreads() == 0 || // detection failed |
| 35 | tbb::this_task_arena::max_concurrency() == affinity->getNumThreads() || // no SMT |
| 36 | (tbb::this_task_arena::max_concurrency() % affinity->getNumThreads()) != 0) // hybrid SMT |
| 37 | affinity.reset(); // disable affinitization |
| 38 | } |
| 39 | #endif |
| 40 | |
| 41 | // Create the task arena |
| 42 | const int maxNumThreads = affinity ? affinity->getNumThreads() : tbb::this_task_arena::max_concurrency(); |
| 43 | numThreads = (numThreads > 0) ? min(numThreads, maxNumThreads) : maxNumThreads; |
| 44 | arena = std::make_shared<tbb::task_arena>(numThreads); |
| 45 | |
| 46 | // Automatically set the thread affinities |
| 47 | if (affinity) |
| 48 | observer = std::make_shared<PinningObserver>(affinity, *arena); |
| 49 | |
| 50 | // Start the queue processing thread |
| 51 | queueThread = std::thread([&]() { processQueue(); }); |
| 52 | } |
| 53 | |
| 54 | CPUEngine::~CPUEngine() |
| 55 | { |
nothing calls this directly
no test coverage detected