Skip to content

Commit dbc15f8

Browse files
ezhulenevtensorflower-gardener
authored andcommitted
[xla:cpu] Worker/WorkQueue micro-optimizations
PiperOrigin-RevId: 725314843
1 parent 8d2185f commit dbc15f8

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

third_party/xla/xla/backends/cpu/runtime/work_queue.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,9 @@ limitations under the License.
3131
#include "absl/container/fixed_array.h"
3232
#include "absl/log/check.h"
3333
#include "absl/status/status.h"
34-
#include "absl/time/time.h"
3534
#include "xla/tsl/concurrency/async_value_ref.h"
3635
#include "xla/tsl/concurrency/chain.h"
3736
#include "xla/tsl/lib/math/math_util.h"
38-
#include "xla/tsl/platform/env.h"
39-
#include "xla/tsl/platform/errors.h"
4037
#include "xla/tsl/platform/logging.h"
4138

4239
#define EIGEN_USE_THREADS
@@ -80,7 +77,7 @@ class WorkQueue {
8077
};
8178

8279
absl::FixedArray<Partition, 32> partitions_;
83-
alignas(kAtomicAlignment) std::atomic<size_t> empty_;
80+
alignas(kAtomicAlignment) std::atomic<bool> empty_;
8481
};
8582

8683
// Worker processes tasks from the work queue starting from the assigned
@@ -165,10 +162,7 @@ inline std::optional<size_t> Worker::Pop() {
165162
std::optional<size_t> task = queue_->Pop(partition_index_);
166163
if (task) return task;
167164

168-
// If work queue is empty, we are not going to find any more tasks.
169-
if (queue_->empty()) return std::nullopt;
170-
171-
while (!task.has_value()) {
165+
while (!task.has_value() && !queue_->empty()) {
172166
// Wrap around to the first partition.
173167
if (ABSL_PREDICT_FALSE(++partition_index_ >= queue_->num_partitions())) {
174168
partition_index_ = 0;

0 commit comments

Comments
 (0)