Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ target_link_libraries(
ff_set_cxx_properties(${project_target})

add_subdirectory(ffi)
# add_subdirectory(test)
add_subdirectory(test)
196 changes: 0 additions & 196 deletions lib/utils/include/utils/graph/README.md
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you delete the README?

This file was deleted.

5 changes: 4 additions & 1 deletion lib/utils/include/utils/graph/adjacency_digraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ class AdjacencyDiGraph : public IDiGraph {
return new AdjacencyDiGraph(this->next_node_idx, this->adjacency);
}

AdjacencyDiGraph() = default;

private:
using ContentsType = std::unordered_map<Node, std::unordered_set<Node>>;

AdjacencyDiGraph(std::size_t, ContentsType);
AdjacencyDiGraph(std::size_t idx, ContentsType adjacency)
: next_node_idx(idx), adjacency(adjacency) {}

std::size_t next_node_idx = 0;
ContentsType adjacency;
Expand Down
7 changes: 6 additions & 1 deletion lib/utils/include/utils/graph/adjacency_multidigraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@ class AdjacencyMultiDiGraph : public IMultiDiGraph {
return new AdjacencyMultiDiGraph(this->next_node_idx, this->adjacency);
}

AdjacencyMultiDiGraph() = default;
~AdjacencyMultiDiGraph() = default;

private:
using ContentsType = std::unordered_map<
Node,
std::unordered_map<
Node,
std::unordered_map<std::size_t, std::unordered_set<std::size_t>>>>;

AdjacencyMultiDiGraph(std::size_t, ContentsType const &);
AdjacencyMultiDiGraph(std::size_t next_node_idx,
ContentsType const &adjacency)
: next_node_idx(next_node_idx), adjacency(adjacency) {}

private:
std::size_t next_node_idx = 0;
Expand Down
2 changes: 2 additions & 0 deletions lib/utils/include/utils/graph/algorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ std::unordered_map<Node, std::unordered_set<Node>>
std::unordered_map<Node, std::unordered_set<Node>>
get_predecessors(DiGraphView const &, std::unordered_set<Node> const &);

// return the set of nodes without incoming edges
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to doxygen syntax

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get it

std::unordered_set<Node> get_sources(DiGraphView const &);
std::unordered_set<Node> get_sources(MultiDiGraphView const &);

// return the set of nodes without outgoing edges
std::unordered_set<Node> get_sinks(DiGraphView const &);
std::unordered_set<Node> get_sinks(MultiDiGraphView const &);

Expand Down
37 changes: 23 additions & 14 deletions lib/utils/include/utils/graph/cow_ptr_t.h
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a separate commit -- pull in changes from the commit linked in #758

Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,26 @@ struct cow_ptr_t {
}

T const *operator->() const {
return &this->get();
return this->get();
}

std::shared_ptr<T const> get_shared_ptr() const {
if (this->has_unique_access()) {
this->set_shared(shared_ptr(this->get_unique()));
this->set_shared(shared_t(this->get_unique()));
}
return this->get_shared();
}

T *mutable_ptr() const {
if (this->has_unique_access()) {
return *this->get_unique();
return this->get_unique().get();
} else {
this->set_unique(unique_t(this->get_shared()->clone()));
auto shared = this->get_shared();
this->set_unique(unique_t(shared->clone()));
if (auto ptr = mpark::get_if<unique_t>(&this->ptr)) {
return ptr->get();
}
return nullptr;
}
}

Expand All @@ -91,25 +96,29 @@ struct cow_ptr_t {
}

private:
void set_shared(shared_t ptr) {
this->ptr = variant<shared_t>(std::move(ptr));
void set_shared(shared_t ptr) const {
this->ptr =
variant<std::unique_ptr<T>, std::shared_ptr<T const>>(std::move(ptr));
}

void set_unique(unique_t ptr) {
this->ptr = variant<unique_t>(std::move(ptr));
void set_unique(std::unique_ptr<T> ptr) const {
this->ptr =
variant<std::unique_ptr<T>, std::shared_ptr<T const>>(std::move(ptr));
}

std::unique_ptr<T> &get_unique() const {
return ::FlexFlow::get<unique_t>(this->ptr);
std::unique_ptr<T> get_unique() const {
auto ptr = mpark::get_if<unique_t>(&this->ptr);
return std::move(*ptr);
}

std::shared_ptr<T const> &get_shared() const {
return ::FlexFlow::get<shared_t>(this->ptr);
std::shared_ptr<T const> get_shared() const {
auto ptr = mpark::get_if<shared_t>(&this->ptr);
return *ptr;
}

mutable variant<unique_t, shared_t> ptr;
mutable variant<std::unique_ptr<T>, std::shared_ptr<T const>> ptr;
};

} // namespace FlexFlow

#endif
#endif
10 changes: 6 additions & 4 deletions lib/utils/include/utils/graph/digraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct IDiGraphView : public IGraphView {
IDiGraphView &operator=(IDiGraphView const &) = delete;

virtual std::unordered_set<Edge> query_edges(EdgeQuery const &) const = 0;
virtual ~IDiGraphView();
virtual ~IDiGraphView() = default;

protected:
IDiGraphView() = default;
Expand All @@ -62,7 +62,9 @@ struct DiGraphView {

DiGraphView() = delete;

operator GraphView() const;
operator GraphView() const {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move implementations to .cc files to avoid unnecessary compilations

return GraphView(this->ptr);
}

friend void swap(DiGraphView &, DiGraphView &);

Expand All @@ -87,9 +89,9 @@ struct DiGraphView {
return DiGraphView(std::make_shared<T>(std::forward<Args>(args)...));
}

private:
DiGraphView(std::shared_ptr<IDiGraphView const>);
DiGraphView(std::shared_ptr<IDiGraphView const> ptr) : ptr(ptr) {}

private:
friend DiGraphView unsafe(IDiGraphView const &);

private:
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/include/utils/graph/labelled_graph_interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static_assert(
struct MultiDiOutput : public use_visitable_cmp<MultiDiOutput> {
public:
MultiDiOutput() = delete;
MultiDiOutput(Node const &, size_t);
MultiDiOutput(Node const &node, size_t idx) : node(node), idx(idx) {}

public:
Node node;
Expand All @@ -57,7 +57,7 @@ struct MultiDiOutput : public use_visitable_cmp<MultiDiOutput> {

struct MultiDiInput : public use_visitable_cmp<MultiDiInput> {
public:
MultiDiInput(Node const &, size_t);
MultiDiInput(Node const &node, size_t idx) : node(node), idx(idx) {}

public:
Node node;
Expand Down
Loading