Automated rollback of change 141209775

Change: 141555939
This commit is contained in:
Dan Ringwalt 2016-12-09 07:41:36 -08:00 committed by TensorFlower Gardener
parent 346c461991
commit 63dc340e23
3 changed files with 1 additions and 55 deletions

View File

@ -123,15 +123,6 @@ void ThreadPool::ParallelFor(int64 total, int64 cost_per_unit,
impl_->ParallelFor(total, cost_per_unit, std::move(fn));
}
void ThreadPool::ParallelForWithWorkerId(
int64 total, int64 cost_per_unit,
const std::function<void(int64, int64, int)>& fn) {
impl_->ParallelFor(total, cost_per_unit,
[this, &fn](int64 start, int64 limit) {
fn(start, limit, CurrentThreadId());
});
}
int ThreadPool::NumThreads() const { return impl_->NumThreads(); }
int ThreadPool::CurrentThreadId() const { return impl_->CurrentThreadId(); }

View File

@ -47,7 +47,7 @@ class ThreadPool {
// Schedule fn() for execution in the pool of threads.
void Schedule(std::function<void()> fn);
// ParallelFor shards the "total" units of work assuming each unit of work
// ParallelFor shards the "total" unit of work assuming each unit of work
// having roughly "cost_per_unit" cost, in cycles. Each unit of work is
// indexed 0, 1, ..., total - 1. Each shard contains 1 or more units of work
// and the total cost of each shard is roughly the same.
@ -60,15 +60,6 @@ class ThreadPool {
void ParallelFor(int64 total, int64 cost_per_unit,
std::function<void(int64, int64)> fn);
// Shard the "total" units of work. For more details, see "ParallelFor".
//
// The function is passed a thread_id in the range [0, NumThreads()]. The
// functions can safely write to a partial result for their id, in a tensor of
// size (NumThreads(), ...).
void ParallelForWithWorkerId(
int64 total, int64 cost_per_unit,
const std::function<void(int64, int64, int)>& fn);
// Returns the number of threads in the pool.
int NumThreads() const;

View File

@ -80,42 +80,6 @@ TEST(ThreadPool, ParallelFor) {
}
}
TEST(ThreadPool, ParallelForWithWorkerId) {
// Make ParallelForWithWorkerId use as many threads as possible.
int64 kHugeCost = 1 << 30;
for (int num_threads = 1; num_threads < kNumThreads; num_threads++) {
fprintf(stderr, "Testing with %d threads\n", num_threads);
const int kWorkItems = 15;
bool work[kWorkItems];
ThreadPool pool(Env::Default(), "test", num_threads);
for (int i = 0; i < kWorkItems; i++) {
work[i] = false;
}
std::atomic<bool> threads_running[kNumThreads];
for (int i = 0; i < num_threads; i++) {
threads_running[i] = false;
}
pool.ParallelForWithWorkerId(
kWorkItems, kHugeCost,
[&threads_running, &work](int64 begin, int64 end, int64 id) {
// Store true for the current thread, and assert that another thread
// is not running with the same id.
ASSERT_FALSE(threads_running[id].exchange(true));
for (int64 i = begin; i < end; ++i) {
ASSERT_FALSE(work[i]);
work[i] = true;
}
ASSERT_TRUE(threads_running[id].exchange(false));
});
for (int i = 0; i < kWorkItems; i++) {
ASSERT_TRUE(work[i]);
}
for (int i = 0; i < num_threads; i++) {
ASSERT_FALSE(threads_running[i]);
}
}
}
static void BM_Sequential(int iters) {
ThreadPool pool(Env::Default(), "test", kNumThreads);
// Decrement count sequentially until 0.