diff options
author | Sanjoy Das <sanjoy@google.com> | 2018-05-01 18:46:31 -0700 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2018-05-01 18:49:56 -0700 |
commit | 69b2c639f55b065a5dbf829351034441bebc8437 (patch) | |
tree | 89869d4af178dba875557e4280ece30a642bf20b /tensorflow/compiler/xla/layout_util.cc | |
parent | c8ae9e86f33053484b05e405dadd2c8a98b8b41b (diff) |
[XLA:CPU] Re-use the same llvm::GlobalVariable for identical literals
This isn't necessary today, but it will be after an optimization change I'm
about to make.
LLVM has a constant merging pass too, but one of the motivations here is to
avoid the LLVM compile time overhead of having many large arrays in the IR.
PiperOrigin-RevId: 195032900
Diffstat (limited to 'tensorflow/compiler/xla/layout_util.cc')
-rw-r--r-- | tensorflow/compiler/xla/layout_util.cc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tensorflow/compiler/xla/layout_util.cc b/tensorflow/compiler/xla/layout_util.cc index fdc4bbdd8b..c6f8f6766e 100644 --- a/tensorflow/compiler/xla/layout_util.cc +++ b/tensorflow/compiler/xla/layout_util.cc @@ -29,6 +29,7 @@ limitations under the License. #include "tensorflow/compiler/xla/types.h" #include "tensorflow/compiler/xla/util.h" #include "tensorflow/core/lib/core/errors.h" +#include "tensorflow/core/lib/hash/hash.h" #include "tensorflow/core/lib/strings/numbers.h" #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/strcat.h" @@ -465,4 +466,25 @@ std::ostream& operator<<(std::ostream& out, const Layout& layout) { return out; } +/*static*/ size_t LayoutUtil::Hash(const Layout& layout) { + using tensorflow::hash; + using tensorflow::Hash64Combine; + + size_t hash_value = hash<Format>()(layout.format()); + + for (int64 minor_to_major : layout.minor_to_major()) { + hash_value = Hash64Combine(hash_value, hash<int64>()(minor_to_major)); + } + + for (int64 padded_dim : layout.padded_dimensions()) { + hash_value = Hash64Combine(hash_value, hash<int64>()(padded_dim)); + } + + hash_value = + Hash64Combine(hash_value, hash<PaddingValue>()(layout.padding_value())); + hash_value = Hash64Combine(hash_value, layout.max_sparse_elements()); + + return hash_value; +} + } // namespace xla |