diff options
author | 2018-01-25 11:17:08 -0800 | |
---|---|---|
committer | 2018-01-25 11:21:05 -0800 | |
commit | a8c4e8d96de7c0978851a5f9718bbd6b8056d862 (patch) | |
tree | 2d1a77cbd07b8f578c5ae5e1c749ab30403e5cfa /tensorflow/compiler/xla/map_util.h | |
parent | 949dd29d3a8bdc21328c9e94721b344310686eab (diff) |
[XLA] Make xla_hlo_profile_test less flaky
Instead of relying on some oeprations always taking longer than others (and this
appearing in a specific order in the rendered HLO profile), pick them out by
opcode.
PiperOrigin-RevId: 183268593
Diffstat (limited to 'tensorflow/compiler/xla/map_util.h')
-rw-r--r-- | tensorflow/compiler/xla/map_util.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tensorflow/compiler/xla/map_util.h b/tensorflow/compiler/xla/map_util.h index 50659c1240..0ad0b91330 100644 --- a/tensorflow/compiler/xla/map_util.h +++ b/tensorflow/compiler/xla/map_util.h @@ -16,6 +16,11 @@ limitations under the License. #ifndef TENSORFLOW_COMPILER_XLA_MAP_UTIL_H_ #define TENSORFLOW_COMPILER_XLA_MAP_UTIL_H_ +#include <functional> +#include <sstream> + +#include "tensorflow/compiler/xla/statusor.h" +#include "tensorflow/compiler/xla/util.h" #include "tensorflow/core/platform/logging.h" namespace xla { @@ -44,6 +49,22 @@ typename Collection::value_type::second_type& FindOrDie( return it->second; } +// Like FindOrDie but returns an error instead of dying if `key` is not in +// `container`. +template <class Collection> +StatusOr< + std::reference_wrapper<const typename Collection::value_type::second_type>> +MaybeFind(const Collection& collection, + const typename Collection::value_type::first_type& key) { + typename Collection::const_iterator it = collection.find(key); + if (it == collection.end()) { + std::ostringstream os; + os << key; + return NotFound("key not found: %s", os.str().c_str()); + } + return {it->second}; +} + // Inserts the key-value pair into the collection. Dies if key was already // present. template <class Collection> |