Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Sarkars/flib ngenc compute #529

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
718f32f
Search for graph def in function library if not found
sayantan-nervana Apr 18, 2019
b3e57b0
Handle error (when gdef not found)
sayantan-nervana Apr 18, 2019
8015046
Fixing file path to pass ci
sayantan-nervana Apr 18, 2019
5af5bb9
Make symlinks to the pbtxts
sayantan-nervana Apr 18, 2019
0f9c6c4
Adding debug prints to see dir in ci
sayantan-nervana Apr 18, 2019
dd95ace
Copying to artifacts/test/python
sayantan-nervana Apr 18, 2019
fee79fe
WIP: check if graph is already processed
sayantan-nervana Apr 19, 2019
0b1598e
Merge branch 'master' into sarkars/flib_ngenc_compute
avijit-nervana Apr 19, 2019
4178724
Do not reprocess if already processed
sayantan-nervana Apr 19, 2019
a931716
Review comment
sayantan-nervana Apr 19, 2019
84047b2
Merge branch 'sarkars/flib_ngenc_compute' of https://github.com/Nerva…
sayantan-nervana Apr 19, 2019
354bc3e
Boolean flip
sayantan-nervana Apr 19, 2019
f404662
Making pbtxt graph default
sayantan-nervana Apr 19, 2019
d29966e
Pass pointer instead of unq ptr
sayantan-nervana Apr 19, 2019
91b88e6
Remove check from normal pass
sayantan-nervana Apr 19, 2019
ca6c165
Merge branch 'master' into sarkars/flib_ngenc_compute
avijit-nervana Apr 20, 2019
04c7a00
Change floor to flib
sayantan-nervana Apr 21, 2019
126eeb1
Minor change
sayantan-nervana Apr 21, 2019
aa0ef36
Merge branch 'sarkars/flib_ngenc_compute' of https://github.com/Nerva…
sayantan-nervana Apr 21, 2019
ca8af0a
Minor change
sayantan-nervana Apr 21, 2019
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
3 changes: 2 additions & 1 deletion src/grappler/ngraph_optimizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ Status NgraphOptimizer::Optimize(tensorflow::grappler::Cluster* cluster,
// we will not do anything; all subsequent
// passes become a no-op.
if (config::IsEnabled() == false ||
std::getenv("NGRAPH_TF_DISABLE") != nullptr) {
std::getenv("NGRAPH_TF_DISABLE") != nullptr ||
IsProcessedByNgraphPass(&graph)) {
NGRAPH_VLOG(0) << "NGTF_OPTIMIZER: Ngraph is disabled ";
Copy link
Contributor

Choose a reason for hiding this comment

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

Include the or condition in the error message.

graph.ToGraphDef(output);
return Status::OK();
Expand Down
2 changes: 1 addition & 1 deletion src/ngraph_cluster_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int NGraphClusterManager::NewCluster() {

GraphDef* NGraphClusterManager::GetClusterGraph(int idx) {
std::lock_guard<std::mutex> guard(s_cluster_graphs_mutex);
return s_cluster_graphs[idx];
return idx < s_cluster_graphs.size() ? s_cluster_graphs[idx] : nullptr;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need this change since now we might have nothing stored in NGraphClusterManager, so need to safely avoid accessing out-of-bounds requests

}

} // namespace ngraph_bridge
Expand Down
27 changes: 24 additions & 3 deletions src/ngraph_encapsulate_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <utility>

#include "tensorflow/core/common_runtime/dma_helper.h"
#include "tensorflow/core/common_runtime/function.h"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Included for FunctionBody

#include "tensorflow/core/common_runtime/optimization_registry.h"
#include "tensorflow/core/framework/graph.pb.h"
#include "tensorflow/core/framework/node_def_util.h"
Expand Down Expand Up @@ -93,9 +94,29 @@ class NGraphEncapsulateOp : public OpKernel {
OP_REQUIRES_OK(ctx, ctx->GetAttr<int>("ngraph_cluster", &m_ngraph_cluster));
graph_def = NGraphClusterManager::GetClusterGraph(m_ngraph_cluster);

GraphConstructorOptions opts;
opts.allow_internal_ops = true;
OP_REQUIRES_OK(ctx, ConvertGraphDefToGraph(opts, *graph_def, &m_graph));
if (graph_def == nullptr) {
// Read graphdef from function library
const FunctionLibraryDefinition flib =
*ctx->function_library()->GetFunctionLibraryDefinition();
const FunctionDef* fdef =
flib.Find("Enc_" + to_string(m_ngraph_cluster) + "_native_segment");
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use the node name (eg. ngraph_cluster_251) instead of this "Enc_" + to_string(m_ngraph_cluster)" ?

OP_REQUIRES(
ctx, fdef != nullptr,
errors::Internal("Did not find graphdef for encapsulate ",
m_ngraph_cluster,
" in NGraphClusterManager or function library"));
// TODO: how to convert from functiondef to graphdef. Anything easier?
FunctionBody* fnbody;
const auto get_func_sig = [&flib](const string& op, const OpDef** sig) {
return flib.LookUpOpDef(op, sig);
};
FunctionDefToBodyHelper(*fdef, {}, &flib, get_func_sig, &fnbody);
CopyGraph(*fnbody->graph, &m_graph);
} else {
GraphConstructorOptions opts;
opts.allow_internal_ops = true;
OP_REQUIRES_OK(ctx, ConvertGraphDefToGraph(opts, *graph_def, &m_graph));
}
OP_REQUIRES_OK(ctx, ctx->GetAttr("ngraph_graph_id", &m_graph_id));
//
// Initialize the "m_input_is_static" vector as follows:
Expand Down
1 change: 1 addition & 0 deletions src/ngraph_mark_for_clustering.cc
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ Status MarkForClustering(Graph* graph,
confirmation_function_map["Minimum"] = SimpleConfirmationFunction();
confirmation_function_map["Mul"] = SimpleConfirmationFunction();
confirmation_function_map["Neg"] = SimpleConfirmationFunction();
confirmation_function_map["NoOp"] = SimpleConfirmationFunction();
confirmation_function_map["OneHot"] = SimpleConfirmationFunction();
confirmation_function_map["Pad"] = SimpleConfirmationFunction();
confirmation_function_map["Pow"] = SimpleConfirmationFunction();
Expand Down
15 changes: 14 additions & 1 deletion src/ngraph_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,20 @@ void AllreduceOpControlOrder(
}
}
}
};
}

bool IsProcessedByNgraphPass(Graph* g) {
// TODO: place a dummy node as a marker
// Current method may fail when graph had no encapsulates or ngvars after
// first pass
// Also variable/optimizer change introduces other types of ng nodes
for (Node* node : g->nodes()) {
if (node->type_string() == "NGraphEncapsulate" ||
node->type_string() == "NGraphVariable")
return true;
}
return false;
}

} // namespace ngraph_bridge

Expand Down
2 changes: 2 additions & 0 deletions src/ngraph_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ bool IsNGVariableType(string node_type);
// Node-types that are executed on nGraph
bool IsNGSupportedType(string node_type);

bool IsProcessedByNgraphPass(Graph* g);

// Taken from: tensorflow/core/grappler/optimizers/arithmetic_optimizer.cc
// Extract values from a Const op to `values`. Returns true if succeeds.
//
Expand Down
5 changes: 5 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,8 @@ install(
DESTINATION ${CMAKE_INSTALL_PREFIX}/test
FILES_MATCHING PATTERN "*.py"
)
install(
DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/python
DESTINATION ${CMAKE_INSTALL_PREFIX}/test
FILES_MATCHING PATTERN "*.pbtxt"
)
11 changes: 11 additions & 0 deletions test/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,15 @@ foreach(file ${files})
)
endforeach()

execute_process(
COMMAND ${CMAKE_COMMAND} -E create_symlink
${CMAKE_CURRENT_SOURCE_DIR}/flib_graph_1.pbtxt
${CMAKE_CURRENT_BINARY_DIR}/flib_graph_1.pbtxt
)

execute_process(
COMMAND ${CMAKE_COMMAND} -E create_symlink
${CMAKE_CURRENT_SOURCE_DIR}/flib_graph_2.pbtxt
${CMAKE_CURRENT_BINARY_DIR}/flib_graph_2.pbtxt
)

Loading