-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [WIP] Remove `on_device_shape` and `logical_on_device_shape` * logical_on_device_shape -> host_output_shape * Patch in `is_dynamic_dimension` * Update patch with real pending change * Update patch * add commit hash
- Loading branch information
1 parent
a4874e2
commit dbb92c9
Showing
4 changed files
with
98 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Partial backport of 6308dba2903e78961ac4122f361bc91b09f36891. Remove in next | ||
# pin update. | ||
diff --git a/xla/pjrt/pjrt_c_api_client.cc b/xla/pjrt/pjrt_c_api_client.cc | ||
index ef0b6686c..c0341e81e 100644 | ||
--- a/xla/pjrt/pjrt_c_api_client.cc | ||
+++ b/xla/pjrt/pjrt_c_api_client.cc | ||
@@ -1584,6 +1584,34 @@ bool PjRtCApiBuffer::has_dynamic_dimensions() const { | ||
return args.num_dynamic_dims > 0; | ||
} | ||
|
||
+absl::Span<const bool> PjRtCApiBuffer::is_dynamic_dimension() const { | ||
+ { | ||
+ absl::MutexLock lock(&mu_); | ||
+ if (!is_dynamic_dimension_.has_value()) { | ||
+ absl::InlinedVector<bool, InlineRank()>& is_dynamic_dimension_value = | ||
+ is_dynamic_dimension_.emplace(); | ||
+ is_dynamic_dimension_value.assign(dimensions().size(), false); | ||
+ | ||
+ PJRT_Buffer_DynamicDimensionIndices_Args args; | ||
+ args.struct_size = PJRT_Buffer_DynamicDimensionIndices_Args_STRUCT_SIZE; | ||
+ args.priv = nullptr; | ||
+ args.buffer = buffer_.get(); | ||
+ const PJRT_Api* api = pjrt_c_api(); | ||
+ std::unique_ptr<PJRT_Error, pjrt::PJRT_ErrorDeleter> error( | ||
+ api->PJRT_Buffer_DynamicDimensionIndices(&args), | ||
+ pjrt::MakeErrorDeleter(api)); | ||
+ if (error && pjrt::GetErrorCode(error.get(), api) == | ||
+ PJRT_Error_Code_UNIMPLEMENTED) { | ||
+ return *is_dynamic_dimension_; | ||
+ } | ||
+ for (int i = 0; i < args.num_dynamic_dims; ++i) { | ||
+ is_dynamic_dimension_value[args.dynamic_dim_indices[i]] = true; | ||
+ } | ||
+ } | ||
+ } | ||
+ return *is_dynamic_dimension_; | ||
+} | ||
+ | ||
StatusOr<std::vector<int64_t>> PjRtCApiBuffer::logical_dimensions() { | ||
PJRT_Buffer_UnpaddedDimensions_Args args; | ||
args.struct_size = PJRT_Buffer_UnpaddedDimensions_Args_STRUCT_SIZE; | ||
diff --git a/xla/pjrt/pjrt_c_api_client.h b/xla/pjrt/pjrt_c_api_client.h | ||
index 9c460f246..279608e60 100644 | ||
--- a/xla/pjrt/pjrt_c_api_client.h | ||
+++ b/xla/pjrt/pjrt_c_api_client.h | ||
@@ -27,6 +27,7 @@ limitations under the License. | ||
#include <vector> | ||
|
||
#include "absl/container/flat_hash_map.h" | ||
+#include "absl/container/inlined_vector.h" | ||
#include "absl/log/check.h" | ||
#include "absl/log/log.h" | ||
#include "absl/strings/string_view.h" | ||
@@ -369,11 +370,7 @@ class PjRtCApiBuffer : public PjRtBuffer { | ||
|
||
bool has_dynamic_dimensions() const override; | ||
|
||
- absl::Span<const bool> is_dynamic_dimension() const override { | ||
- LOG(FATAL) << "PjRtCApiBuffer::is_dynamic_dimension() not implemented. " | ||
- << "Considering using has_dynamic_dimensions() or " | ||
- "logical_dimensions() if applicable."; | ||
- } | ||
+ absl::Span<const bool> is_dynamic_dimension() const override; | ||
|
||
StatusOr<std::vector<int64_t>> logical_dimensions() override; | ||
|
||
@@ -455,6 +452,9 @@ class PjRtCApiBuffer : public PjRtBuffer { | ||
std::shared_ptr<PjRtFuture<Status>::Promise> readiness_promise_; | ||
// Set and cached the first time layout() is called. | ||
mutable std::optional<xla::Layout> layout_; | ||
+ // Set and cached the first time is_dynamic_dimension() is called. | ||
+ mutable std::optional<absl::InlinedVector<bool, InlineRank()>> | ||
+ is_dynamic_dimension_; | ||
// Used to synchronize concurrent setting of cached values. | ||
mutable absl::Mutex mu_; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters