tf-nightly-cpu 2.20.0.dev20250220__cp311-cp311-win_amd64.whl → 2.20.0.dev20250222__cp311-cp311-win_amd64.whl
Sign up to get free protection for your applications and to get access to all the features.
- tensorflow/_api/v2/compat/v1/summary/__init__.py +2 -2
- tensorflow/_api/v2/compat/v1/tpu/experimental/embedding/__init__.py +2 -2
- tensorflow/_api/v2/compat/v2/summary/__init__.py +10 -10
- tensorflow/_api/v2/compat/v2/summary/experimental/__init__.py +4 -4
- tensorflow/_api/v2/compat/v2/tpu/experimental/embedding/__init__.py +2 -2
- tensorflow/_api/v2/summary/__init__.py +10 -10
- tensorflow/_api/v2/summary/experimental/__init__.py +4 -4
- tensorflow/_api/v2/tpu/experimental/embedding/__init__.py +2 -2
- tensorflow/compiler/mlir/stablehlo/stablehlo_extension.pyd +0 -0
- tensorflow/compiler/tf2tensorrt/_pywrap_py_utils.pyd +0 -0
- tensorflow/compiler/tf2xla/ops/_xla_ops.so +0 -0
- tensorflow/include/external/llvm-project/mlir/include/mlir/Analysis/DataFlow/IntegerRangeAnalysis.h +12 -0
- tensorflow/include/external/llvm-project/mlir/include/mlir/Dialect/Math/IR/MathOps.h.inc +4 -0
- tensorflow/include/external/shardy/shardy/dialect/sdy/transforms/propagation/aggressive_factor_propagation.h +9 -0
- tensorflow/include/external/stablehlo/_virtual_includes/stablehlo_pass_utils/stablehlo/transforms/PassUtils.h +7 -0
- tensorflow/include/external/stablehlo/_virtual_includes/stablehlo_passes/stablehlo/transforms/PassUtils.h +7 -0
- tensorflow/include/external/stablehlo/_virtual_includes/version/stablehlo/dialect/Version.h +1 -1
- tensorflow/include/external/stablehlo/stablehlo/dialect/Version.h +1 -1
- tensorflow/include/external/stablehlo/stablehlo/transforms/PassUtils.h +7 -0
- tensorflow/include/tensorflow/compiler/xla/backends/cpu/codegen/kernel_api_ir_builder.h +3 -2
- tensorflow/include/tensorflow/compiler/xla/backends/cpu/runtime/convolution_thunk_internal.h +8 -10
- tensorflow/include/tensorflow/compiler/xla/backends/cpu/runtime/kernel_thunk.h +9 -3
- tensorflow/include/tensorflow/compiler/xla/backends/cpu/runtime/work_queue.h +81 -19
- tensorflow/include/tensorflow/compiler/xla/codegen/kernel_spec.h +24 -7
- tensorflow/include/tensorflow/compiler/xla/hlo/ir/hlo_casting_utils.h +0 -44
- tensorflow/include/tensorflow/compiler/xla/hlo/ir/hlo_instruction.h +12 -0
- tensorflow/include/tensorflow/compiler/xla/mlir_hlo/_virtual_includes/stablehlo_extension_pass_inc_gen/stablehlo_ext/transforms/passes.h.inc +149 -4
- tensorflow/include/tensorflow/compiler/xla/mlir_hlo/stablehlo_ext/transforms/passes.h.inc +149 -4
- tensorflow/include/tensorflow/compiler/xla/pjrt/distributed/client.h +5 -0
- tensorflow/include/tensorflow/compiler/xla/pjrt/gpu/se_gpu_pjrt_client.h +1 -92
- tensorflow/include/tensorflow/compiler/xla/pjrt/gpu/se_gpu_topology_description.h +126 -0
- tensorflow/include/tensorflow/compiler/xla/pjrt/pjrt_stream_executor_client.h +1 -49
- tensorflow/include/tensorflow/compiler/xla/pjrt/pjrt_stream_executor_device_description.h +75 -0
- tensorflow/include/tensorflow/compiler/xla/pjrt/plugin/xla_cpu/cpu_execute_options.h +57 -0
- tensorflow/include/tensorflow/compiler/xla/pjrt/plugin/xla_cpu/cpu_topology.h +4 -0
- tensorflow/include/tensorflow/compiler/xla/service/constant_value.h +1 -0
- tensorflow/include/tensorflow/compiler/xla/service/hlo_module_util.h +52 -1
- tensorflow/include/tensorflow/compiler/xla/service/hlo_proto_util.h +0 -12
- tensorflow/include/tensorflow/compiler/xla/tsl/concurrency/async_value.h +50 -21
- tensorflow/include/tensorflow/compiler/xla/tsl/framework/convolution/eigen_spatial_convolutions-inl.h +5 -5
- tensorflow/include/tensorflow/core/kernels/data/experimental/random_access_ops.h +0 -2
- tensorflow/include/tensorflow/core/kernels/eigen_attention.h +4 -4
- tensorflow/include/tensorflow/core/kernels/eigen_backward_cuboid_convolutions.h +6 -6
- tensorflow/include/tensorflow/core/kernels/eigen_backward_spatial_convolutions.h +10 -8
- tensorflow/include/tensorflow/core/kernels/eigen_cuboid_convolution.h +6 -6
- tensorflow/include/tensorflow/core/kernels/eigen_pooling.h +12 -12
- tensorflow/include/tensorflow/core/public/release_version.h +39 -0
- tensorflow/include/tensorflow/core/public/version.h +112 -127
- tensorflow/include/tensorflow/python/eager/pywrap_tfe.h +1 -1
- tensorflow/include/xla/backends/cpu/codegen/kernel_api_ir_builder.h +3 -2
- tensorflow/include/xla/backends/cpu/runtime/convolution_thunk_internal.h +8 -10
- tensorflow/include/xla/backends/cpu/runtime/kernel_thunk.h +9 -3
- tensorflow/include/xla/backends/cpu/runtime/work_queue.h +81 -19
- tensorflow/include/xla/codegen/kernel_spec.h +24 -7
- tensorflow/include/xla/hlo/ir/hlo_casting_utils.h +0 -44
- tensorflow/include/xla/hlo/ir/hlo_instruction.h +12 -0
- tensorflow/include/xla/mlir_hlo/_virtual_includes/stablehlo_extension_pass_inc_gen/stablehlo_ext/transforms/passes.h.inc +149 -4
- tensorflow/include/xla/mlir_hlo/stablehlo_ext/transforms/passes.h.inc +149 -4
- tensorflow/include/xla/pjrt/distributed/client.h +5 -0
- tensorflow/include/xla/pjrt/gpu/se_gpu_pjrt_client.h +1 -92
- tensorflow/include/xla/pjrt/gpu/se_gpu_topology_description.h +126 -0
- tensorflow/include/xla/pjrt/pjrt_stream_executor_client.h +1 -49
- tensorflow/include/xla/pjrt/pjrt_stream_executor_device_description.h +75 -0
- tensorflow/include/xla/pjrt/plugin/xla_cpu/cpu_execute_options.h +57 -0
- tensorflow/include/xla/pjrt/plugin/xla_cpu/cpu_topology.h +4 -0
- tensorflow/include/xla/service/constant_value.h +1 -0
- tensorflow/include/xla/service/hlo_module_util.h +52 -1
- tensorflow/include/xla/service/hlo_proto_util.h +0 -12
- tensorflow/include/xla/tsl/concurrency/async_value.h +50 -21
- tensorflow/include/xla/tsl/framework/convolution/eigen_spatial_convolutions-inl.h +5 -5
- tensorflow/lite/experimental/microfrontend/python/ops/_audio_microfrontend_op.so +0 -0
- tensorflow/lite/python/analyzer_wrapper/_pywrap_analyzer_wrapper.pyd +0 -0
- tensorflow/lite/python/interpreter_wrapper/_pywrap_tensorflow_interpreter_wrapper.pyd +0 -0
- tensorflow/lite/python/optimize/_pywrap_tensorflow_lite_calibration_wrapper.pyd +0 -0
- tensorflow/python/_pywrap_dtensor_device.pyd +0 -0
- tensorflow/python/_pywrap_mlir.pyd +0 -0
- tensorflow/python/_pywrap_parallel_device.pyd +0 -0
- tensorflow/python/_pywrap_quantize_training.pyd +0 -0
- tensorflow/python/_pywrap_tensorflow_internal.pyd +0 -0
- tensorflow/python/_pywrap_tfcompile.pyd +0 -0
- tensorflow/python/_pywrap_tfe.pyd +0 -0
- tensorflow/python/client/_pywrap_debug_events_writer.pyd +0 -0
- tensorflow/python/client/_pywrap_device_lib.pyd +0 -0
- tensorflow/python/client/_pywrap_events_writer.pyd +0 -0
- tensorflow/python/client/_pywrap_tf_session.pyd +0 -0
- tensorflow/python/compat/compat.py +1 -1
- tensorflow/python/data/experimental/service/_pywrap_server_lib.pyd +0 -0
- tensorflow/python/data/experimental/service/_pywrap_utils_exp.pyd +0 -0
- tensorflow/python/eager/imperative_grad.py +5 -5
- tensorflow/python/eager/polymorphic_function/atomic_function.py +1 -1
- tensorflow/python/eager/polymorphic_function/compiler_ir.py +1 -1
- tensorflow/python/eager/polymorphic_function/polymorphic_function.py +45 -41
- tensorflow/python/eager/tape.py +2 -2
- tensorflow/python/framework/_dtypes.pyd +0 -0
- tensorflow/python/framework/_op_def_library_pybind.pyd +0 -0
- tensorflow/python/framework/_op_def_registry.pyd +0 -0
- tensorflow/python/framework/_proto_comparators.pyd +0 -0
- tensorflow/python/framework/_pywrap_python_op_gen.pyd +0 -0
- tensorflow/python/framework/_test_metrics_util.pyd +0 -0
- tensorflow/python/grappler/_pywrap_tf_cluster.pyd +0 -0
- tensorflow/python/grappler/_pywrap_tf_item.pyd +0 -0
- tensorflow/python/grappler/_pywrap_tf_optimizer.pyd +0 -0
- tensorflow/python/lib/core/_pywrap_py_func.pyd +0 -0
- tensorflow/python/lib/io/_pywrap_file_io.pyd +0 -0
- tensorflow/python/lib/io/_pywrap_record_io.pyd +0 -0
- tensorflow/python/ops/summary_ops_v2.py +5 -1
- tensorflow/python/platform/_pywrap_tf2.pyd +0 -0
- tensorflow/python/profiler/internal/_pywrap_profiler.pyd +0 -0
- tensorflow/python/profiler/internal/_pywrap_profiler_plugin.pyd +0 -0
- tensorflow/python/saved_model/pywrap_saved_model.pyd +0 -0
- tensorflow/python/tpu/_pywrap_sparse_core_layout.pyd +0 -0
- tensorflow/python/tpu/_pywrap_tpu_embedding.pyd +0 -0
- tensorflow/python/tpu/tpu_embedding_v3.py +14 -7
- tensorflow/python/tpu/tpu_embedding_v3_checkpoint_adapter.py +10 -1
- tensorflow/python/util/_pywrap_checkpoint_reader.pyd +0 -0
- tensorflow/python/util/_pywrap_kernel_registry.pyd +0 -0
- tensorflow/python/util/_pywrap_stat_summarizer.pyd +0 -0
- tensorflow/python/util/_pywrap_tfprof.pyd +0 -0
- tensorflow/python/util/_pywrap_transform_graph.pyd +0 -0
- tensorflow/python/util/_pywrap_utils.pyd +0 -0
- tensorflow/python/util/_tf_stack.pyd +0 -0
- tensorflow/tools/pip_package/setup.py +2 -2
- tensorflow/xla_aot_runtime_src/xla/tsl/concurrency/async_value.cc +26 -51
- {tf_nightly_cpu-2.20.0.dev20250220.dist-info → tf_nightly_cpu-2.20.0.dev20250222.dist-info}/METADATA +1 -1
- {tf_nightly_cpu-2.20.0.dev20250220.dist-info → tf_nightly_cpu-2.20.0.dev20250222.dist-info}/RECORD +128 -123
- tensorflow/include/tensorflow/compiler/xla/backends/cpu/runtime/concurrency.h +0 -77
- tensorflow/include/xla/backends/cpu/runtime/concurrency.h +0 -77
- {tf_nightly_cpu-2.20.0.dev20250220.dist-info → tf_nightly_cpu-2.20.0.dev20250222.dist-info}/WHEEL +0 -0
- {tf_nightly_cpu-2.20.0.dev20250220.dist-info → tf_nightly_cpu-2.20.0.dev20250222.dist-info}/entry_points.txt +0 -0
- {tf_nightly_cpu-2.20.0.dev20250220.dist-info → tf_nightly_cpu-2.20.0.dev20250222.dist-info}/top_level.txt +0 -0
@@ -29,7 +29,6 @@ limitations under the License.
|
|
29
29
|
#include "absl/base/attributes.h"
|
30
30
|
#include "absl/base/optimization.h"
|
31
31
|
#include "absl/container/fixed_array.h"
|
32
|
-
#include "absl/log/check.h"
|
33
32
|
#include "absl/status/status.h"
|
34
33
|
#include "xla/tsl/concurrency/async_value_ref.h"
|
35
34
|
#include "xla/tsl/concurrency/chain.h"
|
@@ -44,15 +43,6 @@ namespace xla::cpu {
|
|
44
43
|
// A work queue that partitions `num_tasks` tasks into `num_partitions`
|
45
44
|
// partitions processed by parallel workers.
|
46
45
|
class WorkQueue {
|
47
|
-
// Align all atomic counters to a cache line boundary to avoid false
|
48
|
-
// sharing between multiple worker threads.
|
49
|
-
static constexpr size_t kAtomicAlignment =
|
50
|
-
#if defined(__cpp_lib_hardware_interference_size)
|
51
|
-
std::hardware_destructive_interference_size;
|
52
|
-
#else
|
53
|
-
64;
|
54
|
-
#endif
|
55
|
-
|
56
46
|
public:
|
57
47
|
WorkQueue(size_t num_tasks, size_t num_partitions);
|
58
48
|
|
@@ -60,13 +50,23 @@ class WorkQueue {
|
|
60
50
|
// if the partition is complete.
|
61
51
|
std::optional<size_t> Pop(size_t partition_index);
|
62
52
|
|
63
|
-
|
53
|
+
// Return the partition [begin, end) task range.
|
54
|
+
std::pair<size_t, size_t> partition_range(size_t partition_index) const;
|
64
55
|
|
65
|
-
|
56
|
+
size_t num_partitions() const { return partitions_.size(); }
|
66
57
|
|
67
58
|
private:
|
68
59
|
friend class Worker;
|
69
60
|
|
61
|
+
// Align all atomic counters to a cache line boundary to avoid false
|
62
|
+
// sharing between multiple worker threads.
|
63
|
+
static constexpr size_t kAtomicAlignment =
|
64
|
+
#if defined(__cpp_lib_hardware_interference_size)
|
65
|
+
std::hardware_destructive_interference_size;
|
66
|
+
#else
|
67
|
+
64;
|
68
|
+
#endif
|
69
|
+
|
70
70
|
struct Partition {
|
71
71
|
void Initialize(size_t begin, size_t end);
|
72
72
|
|
@@ -76,8 +76,21 @@ class WorkQueue {
|
|
76
76
|
size_t end;
|
77
77
|
};
|
78
78
|
|
79
|
+
// An empty work queue flag to stop worker threads from looping through all
|
80
|
+
// partitions looking for work.
|
81
|
+
bool IsEmpty() const { return empty_.load(std::memory_order_relaxed); }
|
82
|
+
void SetEmpty() { empty_.store(true, std::memory_order_relaxed); }
|
83
|
+
|
84
|
+
// Notify that one of the workers switched to the work stealing mode.
|
85
|
+
void NotifyWorkStealingWorker();
|
86
|
+
|
87
|
+
// Decrements the number of work stealing workers by at most `max_workers` and
|
88
|
+
// returns the number of decremented work stealing workers.
|
89
|
+
size_t DecrementWorkStealingWorkers(size_t max_workers);
|
90
|
+
|
79
91
|
absl::FixedArray<Partition, 32> partitions_;
|
80
92
|
alignas(kAtomicAlignment) std::atomic<bool> empty_;
|
93
|
+
alignas(kAtomicAlignment) std::atomic<size_t> num_work_stealing_workers_;
|
81
94
|
};
|
82
95
|
|
83
96
|
// Worker processes tasks from the work queue starting from the assigned
|
@@ -130,10 +143,14 @@ inline void WorkQueue::Partition::Initialize(size_t begin, size_t end) {
|
|
130
143
|
}
|
131
144
|
|
132
145
|
inline WorkQueue::WorkQueue(size_t num_tasks, size_t num_partitions)
|
133
|
-
: partitions_(num_partitions),
|
134
|
-
|
135
|
-
|
136
|
-
|
146
|
+
: partitions_(num_partitions),
|
147
|
+
empty_(num_tasks == 0),
|
148
|
+
num_work_stealing_workers_(0) {
|
149
|
+
size_t partition_size =
|
150
|
+
tsl::MathUtil::FloorOfRatio(num_tasks, num_partitions);
|
151
|
+
size_t rem_tasks = num_tasks % num_partitions;
|
152
|
+
for (size_t i = 0, begin = 0, end = 0; i < num_partitions; ++i, begin = end) {
|
153
|
+
end = begin + partition_size + ((i < rem_tasks) ? 1 : 0);
|
137
154
|
partitions_[i].Initialize(begin, end);
|
138
155
|
}
|
139
156
|
}
|
@@ -154,6 +171,29 @@ inline std::optional<size_t> WorkQueue::Pop(size_t partition_index) {
|
|
154
171
|
: std::make_optional(index);
|
155
172
|
}
|
156
173
|
|
174
|
+
inline std::pair<size_t, size_t> WorkQueue::partition_range(
|
175
|
+
size_t partition_index) const {
|
176
|
+
DCHECK(partition_index < partitions_.size()) << "Invalid partition index";
|
177
|
+
return {partitions_[partition_index].begin, partitions_[partition_index].end};
|
178
|
+
}
|
179
|
+
|
180
|
+
inline void WorkQueue::NotifyWorkStealingWorker() {
|
181
|
+
num_work_stealing_workers_.fetch_add(1, std::memory_order_relaxed);
|
182
|
+
}
|
183
|
+
|
184
|
+
inline size_t WorkQueue::DecrementWorkStealingWorkers(size_t max_workers) {
|
185
|
+
size_t n = num_work_stealing_workers_.load(std::memory_order_relaxed);
|
186
|
+
|
187
|
+
size_t decrement = std::min(n, max_workers);
|
188
|
+
while (decrement && !num_work_stealing_workers_.compare_exchange_weak(
|
189
|
+
n, n - decrement, std::memory_order_relaxed,
|
190
|
+
std::memory_order_relaxed)) {
|
191
|
+
decrement = std::min(n, max_workers);
|
192
|
+
}
|
193
|
+
|
194
|
+
return decrement;
|
195
|
+
}
|
196
|
+
|
157
197
|
inline Worker::Worker(size_t worker_index, WorkQueue* queue)
|
158
198
|
: worker_index_(worker_index),
|
159
199
|
partition_index_(worker_index),
|
@@ -163,7 +203,13 @@ inline std::optional<size_t> Worker::Pop() {
|
|
163
203
|
std::optional<size_t> task = queue_->Pop(partition_index_);
|
164
204
|
if (ABSL_PREDICT_TRUE(task)) return task;
|
165
205
|
|
166
|
-
|
206
|
+
// If we didn't find a task in the initially assigned partition, notify the
|
207
|
+
// work queue that we are switching to work stealing mode.
|
208
|
+
if (ABSL_PREDICT_FALSE(partition_index_ == worker_index_)) {
|
209
|
+
queue_->NotifyWorkStealingWorker();
|
210
|
+
}
|
211
|
+
|
212
|
+
while (!task.has_value() && !queue_->IsEmpty()) {
|
167
213
|
// Wrap around to the first partition.
|
168
214
|
if (ABSL_PREDICT_FALSE(++partition_index_ >= queue_->num_partitions())) {
|
169
215
|
partition_index_ = 0;
|
@@ -171,7 +217,7 @@ inline std::optional<size_t> Worker::Pop() {
|
|
171
217
|
|
172
218
|
// We checked all partitions and got back to the partition we started from.
|
173
219
|
if (ABSL_PREDICT_FALSE(partition_index_ == worker_index_)) {
|
174
|
-
queue_->
|
220
|
+
queue_->SetEmpty();
|
175
221
|
break;
|
176
222
|
}
|
177
223
|
|
@@ -205,6 +251,7 @@ Worker::ParallelizeContext<ParallelTask>::ParallelizeContext(
|
|
205
251
|
parallel_task(std::forward<ParallelTask>(parallel_task)) {}
|
206
252
|
|
207
253
|
template <typename ParallelTask>
|
254
|
+
// NOLINTNEXTLINE(readability-function-cognitive-complexity)
|
208
255
|
void Worker::ParallelizeWithContext(ParallelizeContext<ParallelTask>* ctx,
|
209
256
|
uint16_t start_index, uint16_t end_index) {
|
210
257
|
DCHECK_LT(start_index, end_index) << "Invalid worker index range";
|
@@ -223,11 +270,26 @@ void Worker::ParallelizeWithContext(ParallelizeContext<ParallelTask>* ctx,
|
|
223
270
|
while (end_index - start_index > 1) {
|
224
271
|
// If work queue is empty, we don't need to keep enqueuing more workers and
|
225
272
|
// can simply count down for the remaining workers.
|
226
|
-
if (ABSL_PREDICT_FALSE(ctx->work_queue.
|
273
|
+
if (ABSL_PREDICT_FALSE(ctx->work_queue.IsEmpty())) {
|
227
274
|
count_down(end_index - start_index, absl::OkStatus());
|
228
275
|
return;
|
229
276
|
}
|
230
277
|
|
278
|
+
// If we have workers in the work stealing mode, we can skip enqueuing
|
279
|
+
// more tasks as existing workers will process remaining partitions. By
|
280
|
+
// doing this optimization we avoid unnecessary thread pool overheads.
|
281
|
+
size_t skip_workers =
|
282
|
+
ctx->work_queue.DecrementWorkStealingWorkers(end_index - start_index);
|
283
|
+
if (ABSL_PREDICT_FALSE(skip_workers > 0)) {
|
284
|
+
DCHECK_LE(skip_workers, end_index - start_index);
|
285
|
+
count_down(skip_workers, absl::OkStatus());
|
286
|
+
|
287
|
+
end_index -= skip_workers;
|
288
|
+
if (start_index == end_index) return;
|
289
|
+
if (end_index - start_index == 1) break;
|
290
|
+
}
|
291
|
+
|
292
|
+
DCHECK_GE(end_index - start_index, 1);
|
231
293
|
uint16_t mid_index = (start_index + end_index) / 2;
|
232
294
|
ctx->device->enqueueNoNotification([ctx, mid_index, end_index] {
|
233
295
|
ParallelizeWithContext(ctx, mid_index, end_index);
|
@@ -17,12 +17,14 @@ limitations under the License.
|
|
17
17
|
#define XLA_CODEGEN_KERNEL_SPEC_H_
|
18
18
|
|
19
19
|
#include <cstddef>
|
20
|
+
#include <cstdint>
|
20
21
|
#include <optional>
|
21
22
|
#include <string>
|
22
23
|
|
24
|
+
#include "absl/container/flat_hash_set.h"
|
23
25
|
#include "absl/container/inlined_vector.h"
|
24
26
|
#include "absl/strings/string_view.h"
|
25
|
-
#include "xla/
|
27
|
+
#include "xla/service/buffer_assignment.h"
|
26
28
|
#include "xla/stream_executor/launch_dim.h"
|
27
29
|
|
28
30
|
namespace xla {
|
@@ -33,15 +35,17 @@ namespace xla {
|
|
33
35
|
// will load kernel PTX on device and instantiate a KernelThunk.
|
34
36
|
class KernelSpec {
|
35
37
|
public:
|
36
|
-
using
|
38
|
+
using Buffers = absl::InlinedVector<BufferAllocation::Slice, 8>;
|
37
39
|
|
38
40
|
KernelSpec(absl::string_view name, se::ThreadDim thread_dim,
|
39
|
-
|
41
|
+
Buffers argument_buffers, Buffers result_buffers,
|
42
|
+
absl::flat_hash_set<int64_t> invariant_arguments,
|
40
43
|
std::optional<size_t> scratch_bytes = std::nullopt);
|
41
44
|
|
42
45
|
KernelSpec(absl::string_view name, se::ClusterDim cluster_dim,
|
43
46
|
se::BlockDim block_dim, se::ThreadDim thread_dim,
|
44
|
-
|
47
|
+
Buffers argument_buffers, Buffers result_buffers,
|
48
|
+
absl::flat_hash_set<int64_t> invariant_arguments,
|
45
49
|
std::optional<size_t> scratch_bytes = std::nullopt);
|
46
50
|
|
47
51
|
// Get the backend specific name of the kernel.
|
@@ -67,15 +71,28 @@ class KernelSpec {
|
|
67
71
|
// managed buffer that is likely to be in L1/L2 cache).
|
68
72
|
std::optional<size_t> scratch_bytes() const { return scratch_bytes_; }
|
69
73
|
|
70
|
-
//
|
71
|
-
const
|
74
|
+
// Argument buffers read by the kernel.
|
75
|
+
const Buffers& argument_buffers() const { return argument_buffers_; }
|
76
|
+
// Result buffers written to by the kernel.
|
77
|
+
const Buffers& result_buffers() const { return result_buffers_; }
|
78
|
+
|
79
|
+
// Returns a set of invariant arguments (corresponding to the indices in the
|
80
|
+
// argument buffers list).
|
81
|
+
const absl::flat_hash_set<int64_t>& invariant_arguments() const {
|
82
|
+
return invariant_arguments_;
|
83
|
+
}
|
72
84
|
|
73
85
|
private:
|
74
86
|
std::string name_;
|
75
87
|
se::ClusterDim cluster_dim_;
|
76
88
|
se::BlockDim block_dim_;
|
77
89
|
se::ThreadDim thread_dim_;
|
78
|
-
|
90
|
+
|
91
|
+
Buffers argument_buffers_;
|
92
|
+
Buffers result_buffers_;
|
93
|
+
|
94
|
+
absl::flat_hash_set<int64_t> invariant_arguments_;
|
95
|
+
|
79
96
|
std::optional<size_t> scratch_bytes_;
|
80
97
|
};
|
81
98
|
|
@@ -44,28 +44,6 @@ T* Cast(HloInstruction* instr) {
|
|
44
44
|
return tsl::down_cast<T*>(instr);
|
45
45
|
}
|
46
46
|
|
47
|
-
// Downcasts a const HloInstruction pointer or returns nullptr if argument is
|
48
|
-
// nullptr. Dies if TargetClass::ClassOf() does not match.
|
49
|
-
template <typename T>
|
50
|
-
const T* CastOrNull(const HloInstruction* i) {
|
51
|
-
if (i == nullptr) {
|
52
|
-
return nullptr;
|
53
|
-
}
|
54
|
-
CHECK(T::ClassOf(i));
|
55
|
-
return tsl::down_cast<const T*>(i);
|
56
|
-
}
|
57
|
-
|
58
|
-
// Downcasts a const HloInstruction pointer or returns nullptr if argument is
|
59
|
-
// nullptr. Dies if TargetClass::ClassOf() does not match.
|
60
|
-
template <typename T>
|
61
|
-
T* CastOrNull(HloInstruction* i) {
|
62
|
-
if (i == nullptr) {
|
63
|
-
return nullptr;
|
64
|
-
}
|
65
|
-
CHECK(T::ClassOf(i));
|
66
|
-
return tsl::down_cast<T*>(i);
|
67
|
-
}
|
68
|
-
|
69
47
|
// Downcasts a const HloInstruction pointer or returns nullptr if
|
70
48
|
// TargetClass::ClassOf() does not match. Dies if argument is nullptr. Similar
|
71
49
|
// to LLVM's dyn_cast.
|
@@ -84,28 +62,6 @@ T* DynCast(HloInstruction* i) {
|
|
84
62
|
return !T::ClassOf(i) ? nullptr : tsl::down_cast<T*>(i);
|
85
63
|
}
|
86
64
|
|
87
|
-
// Downcasts a const HloInstruction pointer. Return nullptr if argument is
|
88
|
-
// nullptr orTargetClass::ClassOf() does not match. Similar to LLVM's
|
89
|
-
// dyn_cast_or_null.
|
90
|
-
template <typename T>
|
91
|
-
const T* DynCastOrNull(const HloInstruction* instruction) {
|
92
|
-
if (instruction == nullptr || !T::ClassOf(instruction)) {
|
93
|
-
return nullptr;
|
94
|
-
}
|
95
|
-
return tsl::down_cast<const T*>(instruction);
|
96
|
-
}
|
97
|
-
|
98
|
-
// Downcasts a non-const HloInstruction pointer. Return nullptr if argument is
|
99
|
-
// nullptr orTargetClass::ClassOf() does not match. Similar to LLVM's
|
100
|
-
// dyn_cast_or_null.
|
101
|
-
template <typename T>
|
102
|
-
T* DynCastOrNull(HloInstruction* instruction) {
|
103
|
-
if (instruction == nullptr || !T::ClassOf(instruction)) {
|
104
|
-
return nullptr;
|
105
|
-
}
|
106
|
-
return tsl::down_cast<T*>(instruction);
|
107
|
-
}
|
108
|
-
|
109
65
|
} // namespace xla
|
110
66
|
|
111
67
|
#endif // XLA_HLO_IR_HLO_CASTING_UTILS_H_
|
@@ -1914,6 +1914,18 @@ class HloInstruction {
|
|
1914
1914
|
result_accuracy().mode() != ResultAccuracy::DEFAULT);
|
1915
1915
|
}
|
1916
1916
|
|
1917
|
+
bool equal_result_accuracy(const HloInstruction* other) const {
|
1918
|
+
return result_accuracy().has_tolerance() ==
|
1919
|
+
other->result_accuracy().has_tolerance() &&
|
1920
|
+
result_accuracy().tolerance().atol() ==
|
1921
|
+
other->result_accuracy().tolerance().atol() &&
|
1922
|
+
result_accuracy().tolerance().rtol() ==
|
1923
|
+
other->result_accuracy().tolerance().rtol() &&
|
1924
|
+
result_accuracy().tolerance().ulps() ==
|
1925
|
+
other->result_accuracy().tolerance().ulps() &&
|
1926
|
+
result_accuracy().mode() == other->result_accuracy().mode();
|
1927
|
+
}
|
1928
|
+
|
1917
1929
|
void add_single_statistic(Statistic statistic) {
|
1918
1930
|
*mutable_rare()->statistics_viz.add_statistics() = std::move(statistic);
|
1919
1931
|
}
|
@@ -3,6 +3,7 @@
|
|
3
3
|
#ifdef GEN_PASS_DECL
|
4
4
|
// Generate declarations for all passes.
|
5
5
|
#define GEN_PASS_DECL_CHLORECOMPOSEOPSPASS
|
6
|
+
#define GEN_PASS_DECL_STABLEHLOADDQDQAFTERCONVPASS
|
6
7
|
#define GEN_PASS_DECL_STABLEHLOCANONICALIZEDYNAMISMPASS
|
7
8
|
#define GEN_PASS_DECL_STABLEHLOFLATTENENTRYFUNCTIONTUPLESPASS
|
8
9
|
#define GEN_PASS_DECL_STABLEHLOFLATTENTUPLEPASS
|
@@ -87,6 +88,82 @@ std::unique_ptr<::mlir::Pass> createChloRecomposeOpsPass() {
|
|
87
88
|
#undef GEN_PASS_DEF_CHLORECOMPOSEOPSPASS
|
88
89
|
#endif // GEN_PASS_DEF_CHLORECOMPOSEOPSPASS
|
89
90
|
|
91
|
+
//===----------------------------------------------------------------------===//
|
92
|
+
// StablehloAddQDQAfterConvPass
|
93
|
+
//===----------------------------------------------------------------------===//
|
94
|
+
#ifdef GEN_PASS_DECL_STABLEHLOADDQDQAFTERCONVPASS
|
95
|
+
std::unique_ptr<::mlir::Pass> createStablehloAddQDQAfterConvPass();
|
96
|
+
#undef GEN_PASS_DECL_STABLEHLOADDQDQAFTERCONVPASS
|
97
|
+
#endif // GEN_PASS_DECL_STABLEHLOADDQDQAFTERCONVPASS
|
98
|
+
#ifdef GEN_PASS_DEF_STABLEHLOADDQDQAFTERCONVPASS
|
99
|
+
|
100
|
+
namespace impl {
|
101
|
+
std::unique_ptr<::mlir::Pass> createStablehloAddQDQAfterConvPass();
|
102
|
+
} // namespace impl
|
103
|
+
namespace impl {
|
104
|
+
|
105
|
+
template <typename DerivedT>
|
106
|
+
class StablehloAddQDQAfterConvPassBase : public ::mlir::OperationPass<ModuleOp> {
|
107
|
+
public:
|
108
|
+
using Base = StablehloAddQDQAfterConvPassBase;
|
109
|
+
|
110
|
+
StablehloAddQDQAfterConvPassBase() : ::mlir::OperationPass<ModuleOp>(::mlir::TypeID::get<DerivedT>()) {}
|
111
|
+
StablehloAddQDQAfterConvPassBase(const StablehloAddQDQAfterConvPassBase &other) : ::mlir::OperationPass<ModuleOp>(other) {}
|
112
|
+
StablehloAddQDQAfterConvPassBase& operator=(const StablehloAddQDQAfterConvPassBase &) = delete;
|
113
|
+
StablehloAddQDQAfterConvPassBase(StablehloAddQDQAfterConvPassBase &&) = delete;
|
114
|
+
StablehloAddQDQAfterConvPassBase& operator=(StablehloAddQDQAfterConvPassBase &&) = delete;
|
115
|
+
~StablehloAddQDQAfterConvPassBase() = default;
|
116
|
+
|
117
|
+
/// Returns the command-line argument attached to this pass.
|
118
|
+
static constexpr ::llvm::StringLiteral getArgumentName() {
|
119
|
+
return ::llvm::StringLiteral("stablehlo-ext-add-qdq-after-conv");
|
120
|
+
}
|
121
|
+
::llvm::StringRef getArgument() const override { return "stablehlo-ext-add-qdq-after-conv"; }
|
122
|
+
|
123
|
+
::llvm::StringRef getDescription() const override { return "Add quant and dequant ops after convolution op."; }
|
124
|
+
|
125
|
+
/// Returns the derived pass name.
|
126
|
+
static constexpr ::llvm::StringLiteral getPassName() {
|
127
|
+
return ::llvm::StringLiteral("StablehloAddQDQAfterConvPass");
|
128
|
+
}
|
129
|
+
::llvm::StringRef getName() const override { return "StablehloAddQDQAfterConvPass"; }
|
130
|
+
|
131
|
+
/// Support isa/dyn_cast functionality for the derived pass class.
|
132
|
+
static bool classof(const ::mlir::Pass *pass) {
|
133
|
+
return pass->getTypeID() == ::mlir::TypeID::get<DerivedT>();
|
134
|
+
}
|
135
|
+
|
136
|
+
/// A clone method to create a copy of this pass.
|
137
|
+
std::unique_ptr<::mlir::Pass> clonePass() const override {
|
138
|
+
return std::make_unique<DerivedT>(*static_cast<const DerivedT *>(this));
|
139
|
+
}
|
140
|
+
|
141
|
+
/// Return the dialect that must be loaded in the context before this pass.
|
142
|
+
void getDependentDialects(::mlir::DialectRegistry ®istry) const override {
|
143
|
+
registry.insert<mlir::quant::QuantDialect>();
|
144
|
+
registry.insert<stablehlo::StablehloDialect>();
|
145
|
+
}
|
146
|
+
|
147
|
+
/// Explicitly declare the TypeID for this class. We declare an explicit private
|
148
|
+
/// instantiation because Pass classes should only be visible by the current
|
149
|
+
/// library.
|
150
|
+
MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(StablehloAddQDQAfterConvPassBase<DerivedT>)
|
151
|
+
|
152
|
+
protected:
|
153
|
+
private:
|
154
|
+
|
155
|
+
friend std::unique_ptr<::mlir::Pass> createStablehloAddQDQAfterConvPass() {
|
156
|
+
return std::make_unique<DerivedT>();
|
157
|
+
}
|
158
|
+
};
|
159
|
+
} // namespace impl
|
160
|
+
|
161
|
+
std::unique_ptr<::mlir::Pass> createStablehloAddQDQAfterConvPass() {
|
162
|
+
return impl::createStablehloAddQDQAfterConvPass();
|
163
|
+
}
|
164
|
+
#undef GEN_PASS_DEF_STABLEHLOADDQDQAFTERCONVPASS
|
165
|
+
#endif // GEN_PASS_DEF_STABLEHLOADDQDQAFTERCONVPASS
|
166
|
+
|
90
167
|
//===----------------------------------------------------------------------===//
|
91
168
|
// StablehloCanonicalizeDynamismPass
|
92
169
|
//===----------------------------------------------------------------------===//
|
@@ -360,9 +437,9 @@ public:
|
|
360
437
|
|
361
438
|
/// Returns the command-line argument attached to this pass.
|
362
439
|
static constexpr ::llvm::StringLiteral getArgumentName() {
|
363
|
-
return ::llvm::StringLiteral("legalize-quant-composite");
|
440
|
+
return ::llvm::StringLiteral("stablehlo-ext-legalize-quant-composite");
|
364
441
|
}
|
365
|
-
::llvm::StringRef getArgument() const override { return "legalize-quant-composite"; }
|
442
|
+
::llvm::StringRef getArgument() const override { return "stablehlo-ext-legalize-quant-composite"; }
|
366
443
|
|
367
444
|
::llvm::StringRef getDescription() const override { return "Lowers the quantization related composites op to native quantized ops."; }
|
368
445
|
|
@@ -576,6 +653,23 @@ inline void registerChloRecomposeOpsPassPass() {
|
|
576
653
|
});
|
577
654
|
}
|
578
655
|
|
656
|
+
//===----------------------------------------------------------------------===//
|
657
|
+
// StablehloAddQDQAfterConvPass Registration
|
658
|
+
//===----------------------------------------------------------------------===//
|
659
|
+
|
660
|
+
inline void registerStablehloAddQDQAfterConvPass() {
|
661
|
+
::mlir::registerPass([]() -> std::unique_ptr<::mlir::Pass> {
|
662
|
+
return createStablehloAddQDQAfterConvPass();
|
663
|
+
});
|
664
|
+
}
|
665
|
+
|
666
|
+
// Old registration code, kept for temporary backwards compatibility.
|
667
|
+
inline void registerStablehloAddQDQAfterConvPassPass() {
|
668
|
+
::mlir::registerPass([]() -> std::unique_ptr<::mlir::Pass> {
|
669
|
+
return createStablehloAddQDQAfterConvPass();
|
670
|
+
});
|
671
|
+
}
|
672
|
+
|
579
673
|
//===----------------------------------------------------------------------===//
|
580
674
|
// StablehloCanonicalizeDynamismPass Registration
|
581
675
|
//===----------------------------------------------------------------------===//
|
@@ -684,6 +778,7 @@ inline void registerStablehloRefineShapesPassPass() {
|
|
684
778
|
|
685
779
|
inline void registerPasses() {
|
686
780
|
registerChloRecomposeOpsPass();
|
781
|
+
registerStablehloAddQDQAfterConvPass();
|
687
782
|
registerStablehloCanonicalizeDynamismPass();
|
688
783
|
registerStablehloFlattenEntryFunctionTuplesPass();
|
689
784
|
registerStablehloFlattenTuplePass();
|
@@ -745,6 +840,56 @@ public:
|
|
745
840
|
protected:
|
746
841
|
};
|
747
842
|
|
843
|
+
template <typename DerivedT>
|
844
|
+
class StablehloAddQDQAfterConvPassBase : public ::mlir::OperationPass<ModuleOp> {
|
845
|
+
public:
|
846
|
+
using Base = StablehloAddQDQAfterConvPassBase;
|
847
|
+
|
848
|
+
StablehloAddQDQAfterConvPassBase() : ::mlir::OperationPass<ModuleOp>(::mlir::TypeID::get<DerivedT>()) {}
|
849
|
+
StablehloAddQDQAfterConvPassBase(const StablehloAddQDQAfterConvPassBase &other) : ::mlir::OperationPass<ModuleOp>(other) {}
|
850
|
+
StablehloAddQDQAfterConvPassBase& operator=(const StablehloAddQDQAfterConvPassBase &) = delete;
|
851
|
+
StablehloAddQDQAfterConvPassBase(StablehloAddQDQAfterConvPassBase &&) = delete;
|
852
|
+
StablehloAddQDQAfterConvPassBase& operator=(StablehloAddQDQAfterConvPassBase &&) = delete;
|
853
|
+
~StablehloAddQDQAfterConvPassBase() = default;
|
854
|
+
|
855
|
+
/// Returns the command-line argument attached to this pass.
|
856
|
+
static constexpr ::llvm::StringLiteral getArgumentName() {
|
857
|
+
return ::llvm::StringLiteral("stablehlo-ext-add-qdq-after-conv");
|
858
|
+
}
|
859
|
+
::llvm::StringRef getArgument() const override { return "stablehlo-ext-add-qdq-after-conv"; }
|
860
|
+
|
861
|
+
::llvm::StringRef getDescription() const override { return "Add quant and dequant ops after convolution op."; }
|
862
|
+
|
863
|
+
/// Returns the derived pass name.
|
864
|
+
static constexpr ::llvm::StringLiteral getPassName() {
|
865
|
+
return ::llvm::StringLiteral("StablehloAddQDQAfterConvPass");
|
866
|
+
}
|
867
|
+
::llvm::StringRef getName() const override { return "StablehloAddQDQAfterConvPass"; }
|
868
|
+
|
869
|
+
/// Support isa/dyn_cast functionality for the derived pass class.
|
870
|
+
static bool classof(const ::mlir::Pass *pass) {
|
871
|
+
return pass->getTypeID() == ::mlir::TypeID::get<DerivedT>();
|
872
|
+
}
|
873
|
+
|
874
|
+
/// A clone method to create a copy of this pass.
|
875
|
+
std::unique_ptr<::mlir::Pass> clonePass() const override {
|
876
|
+
return std::make_unique<DerivedT>(*static_cast<const DerivedT *>(this));
|
877
|
+
}
|
878
|
+
|
879
|
+
/// Register the dialects that must be loaded in the context before this pass.
|
880
|
+
void getDependentDialects(::mlir::DialectRegistry ®istry) const override {
|
881
|
+
registry.insert<mlir::quant::QuantDialect>();
|
882
|
+
registry.insert<stablehlo::StablehloDialect>();
|
883
|
+
}
|
884
|
+
|
885
|
+
/// Explicitly declare the TypeID for this class. We declare an explicit private
|
886
|
+
/// instantiation because Pass classes should only be visible by the current
|
887
|
+
/// library.
|
888
|
+
MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(StablehloAddQDQAfterConvPassBase<DerivedT>)
|
889
|
+
|
890
|
+
protected:
|
891
|
+
};
|
892
|
+
|
748
893
|
template <typename DerivedT>
|
749
894
|
class StablehloCanonicalizeDynamismPassBase : public ::mlir::OperationPass<func::FuncOp> {
|
750
895
|
public:
|
@@ -907,9 +1052,9 @@ public:
|
|
907
1052
|
|
908
1053
|
/// Returns the command-line argument attached to this pass.
|
909
1054
|
static constexpr ::llvm::StringLiteral getArgumentName() {
|
910
|
-
return ::llvm::StringLiteral("legalize-quant-composite");
|
1055
|
+
return ::llvm::StringLiteral("stablehlo-ext-legalize-quant-composite");
|
911
1056
|
}
|
912
|
-
::llvm::StringRef getArgument() const override { return "legalize-quant-composite"; }
|
1057
|
+
::llvm::StringRef getArgument() const override { return "stablehlo-ext-legalize-quant-composite"; }
|
913
1058
|
|
914
1059
|
::llvm::StringRef getDescription() const override { return "Lowers the quantization related composites op to native quantized ops."; }
|
915
1060
|
|