Add pthreadpool_create and pthreadpool_destroy (#15492)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/15492

Add pthreadpool_create and pthreadpool_destroy, which are used by NNPACK tests.

Reviewed By: Maratyszcza

Differential Revision: D13540997

fbshipit-source-id: 628c599df87b552ca1a3703854ec170243f04d2e
This commit is contained in:
Hao Lu
2018-12-21 20:23:14 -08:00
committed by Facebook Github Bot
parent 90aa21e795
commit 58a7f2aed1

View File

@ -30,3 +30,18 @@ void pthreadpool_compute_1d(
size_t pthreadpool_get_threads_count(pthreadpool_t threadpool) {
return reinterpret_cast<caffe2::ThreadPool*>(threadpool)->getNumThreads();
}
pthreadpool_t pthreadpool_create(size_t threads_count) {
std::mutex thread_pool_creation_mutex_;
std::lock_guard<std::mutex> guard(thread_pool_creation_mutex_);
return reinterpret_cast<pthreadpool_t>(new caffe2::ThreadPool(threads_count));
}
void pthreadpool_destroy(pthreadpool_t pthreadpool) {
if (pthreadpool) {
caffe2::ThreadPool* threadpool =
reinterpret_cast<caffe2::ThreadPool*>(pthreadpool);
delete threadpool;
}
}