Automated rollback of changelist 219508843
PiperOrigin-RevId: 239515718
This commit is contained in:
parent
41b7433161
commit
9e0b9b9ff2
@ -1622,7 +1622,9 @@ TEST_F(FunctionLibraryRuntimeTest, Gradient_AddSum) {
|
||||
|
||||
GraphDef actual;
|
||||
g->ToGraphDef(&actual);
|
||||
TF_EXPECT_GRAPH_EQ(expected, actual);
|
||||
// The optimizer is non-deterministic, so we only check that the number of
|
||||
// nodes is not greater than expected.
|
||||
EXPECT_LE(actual.node_size(), expected.node_size());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ std::pair<EdgeSet::const_iterator, bool> EdgeSet::insert(value_type value) {
|
||||
}
|
||||
}
|
||||
// array is full. convert to set.
|
||||
s = new std::set<const Edge*>;
|
||||
s = new gtl::FlatSet<const Edge*>;
|
||||
s->insert(reinterpret_cast<const Edge**>(std::begin(ptrs_)),
|
||||
reinterpret_cast<const Edge**>(std::end(ptrs_)));
|
||||
ptrs_[0] = this;
|
||||
|
@ -17,17 +17,18 @@ limitations under the License.
|
||||
#define TENSORFLOW_GRAPH_EDGESET_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <set>
|
||||
|
||||
#include "tensorflow/core/lib/gtl/flatset.h"
|
||||
#include "tensorflow/core/platform/logging.h"
|
||||
#include "tensorflow/core/platform/macros.h"
|
||||
#include "tensorflow/core/platform/types.h"
|
||||
|
||||
#include "tensorflow/core/platform/logging.h"
|
||||
namespace tensorflow {
|
||||
|
||||
class Edge;
|
||||
|
||||
// An unordered set of edges. Uses very little memory for small sets.
|
||||
// Unlike std::set, EdgeSet does NOT allow mutations during iteration.
|
||||
// Unlike gtl::FlatSet, EdgeSet does NOT allow mutations during
|
||||
// iteration.
|
||||
class EdgeSet {
|
||||
public:
|
||||
EdgeSet();
|
||||
@ -54,12 +55,15 @@ class EdgeSet {
|
||||
private:
|
||||
// Up to kInline elements are stored directly in ptrs_ (nullptr means none).
|
||||
// If ptrs_[0] == this then ptrs_[1] points to a set<const Edge*>.
|
||||
static const int kInline = 4; // Must be >= 2.
|
||||
// kInline must be >= 2, and is chosen such that ptrs_ fills a 64 byte
|
||||
// cacheline.
|
||||
static constexpr int kInline = 64 / sizeof(const void*);
|
||||
const void* ptrs_[kInline];
|
||||
|
||||
std::set<const Edge*>* get_set() const {
|
||||
gtl::FlatSet<const Edge*>* get_set() const {
|
||||
if (ptrs_[0] == this) {
|
||||
return static_cast<std::set<const Edge*>*>(const_cast<void*>(ptrs_[1]));
|
||||
return static_cast<gtl::FlatSet<const Edge*>*>(
|
||||
const_cast<void*>(ptrs_[1]));
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
@ -99,7 +103,7 @@ class EdgeSet::const_iterator {
|
||||
friend class EdgeSet;
|
||||
|
||||
void const* const* array_iter_ = nullptr;
|
||||
typename std::set<const Edge*>::const_iterator tree_iter_;
|
||||
typename gtl::FlatSet<const Edge*>::const_iterator tree_iter_;
|
||||
|
||||
#ifdef NDEBUG
|
||||
inline void Init(const EdgeSet* e) {}
|
||||
|
@ -337,9 +337,13 @@ TEST_F(OptimizerCSETest, Constant_Dedup) {
|
||||
EXPECT_EQ(OriginalGraph(),
|
||||
"n/_0(Const);n/_1(Const);n/_2(Const);n/_3(Const);"
|
||||
"n/_4(Const);n/_5(Const);n/_6(Const);n/_7(Const)|");
|
||||
// In theory, there are 2^4 possible correct output of CSE. In this
|
||||
// test, it happens to eliminate the last 4 nodes.
|
||||
EXPECT_EQ(DoCSE(), "n/_0(Const);n/_1(Const);n/_2(Const);n/_3(Const)|");
|
||||
std::vector<string> nodes = str_util::Split(DoCSE(), ";|");
|
||||
std::set<string> node_set(nodes.begin(), nodes.end());
|
||||
// Expect exactly one of each type of node to be retained after CSE.
|
||||
EXPECT_EQ(node_set.count("n/_0(Const)") + node_set.count("n/_7(Const)"), 1);
|
||||
EXPECT_EQ(node_set.count("n/_1(Const)") + node_set.count("n/_6(Const)"), 1);
|
||||
EXPECT_EQ(node_set.count("n/_2(Const)") + node_set.count("n/_5(Const)"), 1);
|
||||
EXPECT_EQ(node_set.count("n/_3(Const)") + node_set.count("n/_4(Const)"), 1);
|
||||
}
|
||||
|
||||
static void BM_CSE(int iters, int op_nodes) {
|
||||
|
Loading…
Reference in New Issue
Block a user