From bfbd52525a2518af51dbdde702f55db0287cb63e Mon Sep 17 00:00:00 2001 From: Kanvi Khanna Date: Tue, 10 Sep 2019 16:56:23 -0700 Subject: [PATCH 1/9] Fixed few warnings reported in Klocworks + some more seen with -Wextra --- bazel/BUILD | 5 +- .../inference_engine.cc | 4 +- .../inference_engine.h | 2 +- examples/cpp/infer_multiple_networks/main.cc | 6 +- ngraph_bridge/ngraph_assign_clusters.cc | 9 +- ngraph_bridge/ngraph_builder.cc | 108 +++++++++--------- ngraph_bridge/ngraph_cluster_manager.cc | 6 +- ngraph_bridge/ngraph_cluster_manager.h | 4 +- ngraph_bridge/ngraph_encapsulate_clusters.cc | 1 + ngraph_bridge/ngraph_encapsulate_impl.cc | 4 +- ngraph_bridge/ngraph_mark_for_clustering.cc | 10 +- ngraph_bridge/ngraph_utils.cc | 3 +- 12 files changed, 86 insertions(+), 76 deletions(-) diff --git a/bazel/BUILD b/bazel/BUILD index e30eef426..960a8907e 100644 --- a/bazel/BUILD +++ b/bazel/BUILD @@ -95,9 +95,12 @@ cc_binary( "-pthread", "-std=c++11", "-D_FORTIFY_SOURCE=2", + "-Wall", + "-Wextra", + "-Wno-comment", + "-Wno-sign-compare", "-Wformat", "-Wformat-security", - "-Wformat", "-fstack-protector-all", "-D NDEBUG", '-D SHARED_LIB_PREFIX=\\"lib\\"', diff --git a/examples/cpp/infer_multiple_networks/inference_engine.cc b/examples/cpp/infer_multiple_networks/inference_engine.cc index 795ca388c..1ce45bf8e 100644 --- a/examples/cpp/infer_multiple_networks/inference_engine.cc +++ b/examples/cpp/infer_multiple_networks/inference_engine.cc @@ -50,8 +50,8 @@ extern tf::Status ReadTensorFromImageFile(const std::vector& file_names, namespace infer_multiple_networks { -InferenceEngine::InferenceEngine(const string& name, const string& backend) - : m_name(name) {} +InferenceEngine::InferenceEngine(const string& name) : m_name(name) {} + Status InferenceEngine::Load(const string& network, const std::vector& image_files, int input_width, int input_height, diff --git a/examples/cpp/infer_multiple_networks/inference_engine.h b/examples/cpp/infer_multiple_networks/inference_engine.h index 30d659702..420290b45 100644 --- a/examples/cpp/infer_multiple_networks/inference_engine.h +++ b/examples/cpp/infer_multiple_networks/inference_engine.h @@ -42,7 +42,7 @@ namespace infer_multiple_networks { class InferenceEngine { public: - InferenceEngine(const string& name, const string& backend); + InferenceEngine(const string& name); ~InferenceEngine(); Status Load(const string& network, const std::vector& image_files, diff --git a/examples/cpp/infer_multiple_networks/main.cc b/examples/cpp/infer_multiple_networks/main.cc index 7ddd1eee5..5500f53ba 100644 --- a/examples/cpp/infer_multiple_networks/main.cc +++ b/examples/cpp/infer_multiple_networks/main.cc @@ -150,15 +150,15 @@ int main(int argc, char** argv) { std::cout << "Component versions\n"; PrintVersion(); - infer_multiple_networks::InferenceEngine infer_engine_1("engine_1", "CPU:0"); + infer_multiple_networks::InferenceEngine infer_engine_1("engine_1"); TF_CHECK_OK(infer_engine_1.Load( graph, images, input_width, input_height, input_mean, input_std, input_layer, output_layer, use_NCHW, preload_images, input_channels)); - infer_multiple_networks::InferenceEngine infer_engine_2("engine_2", "CPU:0"); + infer_multiple_networks::InferenceEngine infer_engine_2("engine_2"); TF_CHECK_OK(infer_engine_2.Load( graph, images, input_width, input_height, input_mean, input_std, input_layer, output_layer, use_NCHW, preload_images, input_channels)); - infer_multiple_networks::InferenceEngine infer_engine_3("engine_3", "CPU:0"); + infer_multiple_networks::InferenceEngine infer_engine_3("engine_3"); TF_CHECK_OK(infer_engine_3.Load( graph, images, input_width, input_height, input_mean, input_std, input_layer, output_layer, use_NCHW, preload_images, input_channels)); diff --git a/ngraph_bridge/ngraph_assign_clusters.cc b/ngraph_bridge/ngraph_assign_clusters.cc index d5da383f0..279a7a1c3 100644 --- a/ngraph_bridge/ngraph_assign_clusters.cc +++ b/ngraph_bridge/ngraph_assign_clusters.cc @@ -653,7 +653,7 @@ Status AssignClusters(Graph* graph) { continue; } - int cluster_idx = NGraphClusterManager::NewCluster(); + size_t cluster_idx = NGraphClusterManager::NewCluster(); for (auto node : cluster->nodes) { if (NGRAPH_VLOG_IS_ON(5)) { @@ -669,7 +669,7 @@ Status AssignClusters(Graph* graph) { } // TODO(amprocte): move attr name to a constant - node->AddAttr("_ngraph_cluster", cluster_idx); + node->AddAttr("_ngraph_cluster", (int)cluster_idx); if (config::IsLoggingPlacement()) { // map from cluster id to ngraph_cluster id @@ -798,7 +798,10 @@ Status AssignClusters(Graph* graph) { std::cout << "NGTF_SUMMARY: Summary of reasons why a pair of edge " "connected clusters did not merge\n"; print_reason_summary(reason_count_clusters, - [](EdgeNonContractionReasons x) { return false; }); + [](EdgeNonContractionReasons x) { + NGRAPH_VLOG(5) << "EdgeNonContractionReasons: " << x; + return false; + }); } return Status::OK(); diff --git a/ngraph_bridge/ngraph_builder.cc b/ngraph_bridge/ngraph_builder.cc index 27094c8e9..a5d7c7f53 100644 --- a/ngraph_bridge/ngraph_builder.cc +++ b/ngraph_bridge/ngraph_builder.cc @@ -166,8 +166,8 @@ static Status GetInputNode(const Builder::OpMap& ng_op_map, const Node* op, } namespace detail { -static Status GetInputNodes(const Builder::OpMap& ng_op_map, const Node* op, - size_t index) { +static Status GetInputNodes(const Builder::OpMap& , const Node* , + size_t ) { return Status::OK(); } @@ -366,7 +366,7 @@ Builder::TF_NGRAPH_CONST_MAP() { // }); // } static Status TranslateUnaryOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map, std::function(std::shared_ptr)> create_unary_op) { @@ -422,7 +422,7 @@ static Status TranslateUnaryOp( // static Status TranslateBinaryOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map, std::function(std::shared_ptr, std::shared_ptr)> @@ -461,7 +461,7 @@ static Status TranslateBinaryOp( // Helper function for translating QuantizedAvgPool and QuantizedMaxPool static Status TranslateQuantizedPoolOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map, std::string pooling_name) { bool is_quantizedAvgPool = pooling_name == "QuantizedAvgPool"; bool is_quantizedMaxPool = pooling_name == "QuantizedMaxPool"; @@ -534,7 +534,7 @@ static Status TranslateQuantizedPoolOp( } static Status TranslateAddNOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { std::vector> ng_arg_vec(op->num_inputs()); @@ -597,7 +597,7 @@ static Status TranslateArgMinMaxOp( } static Status TranslateAvgPoolOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); @@ -911,7 +911,7 @@ static Status TranslateBatchMatMulOp( } static Status TranslateBiasAddOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_input, ng_bias; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input, &ng_bias)); @@ -960,7 +960,7 @@ static Status TranslateBiasAddOp( } static Status TranslateBiasAddGradOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); @@ -1010,7 +1010,7 @@ static Status TranslateBiasAddGradOp( } static Status TranslateCastOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); @@ -1157,7 +1157,7 @@ static Status TranslateConcatV2Op( } static Status TranslateConstOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { DataType dtype; TF_RETURN_IF_ERROR(GetNodeAttr(op->attrs(), "dtype", &dtype)); @@ -1187,7 +1187,7 @@ static Status TranslateConstOp( } static Status TranslateConv2DOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_input, ng_filter; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input, &ng_filter)); @@ -1473,7 +1473,7 @@ static Status TranslateConv2DBackpropInputOp( // Translate Conv3D Op static Status TranslateConv3DOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_input, ng_filter; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input, &ng_filter)); @@ -1548,7 +1548,7 @@ static Status TranslateConv3DOp( // Translate DepthToSpace op static Status TranslateDepthToSpaceOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); @@ -1707,7 +1707,7 @@ static Status TranslateDepthToSpaceOp( } static Status TranslateDepthwiseConv2dNativeOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_input, ng_filter; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input, &ng_filter)); @@ -1996,7 +1996,7 @@ static Status TranslateFusedBatchNormOp( } static Status TranslateFusedBatchNormGradOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { bool is_v3 = op->type_string() == "FusedBatchNormGradV3"; TF_RETURN_IF_ERROR(ValidateInputCount(op, is_v3 ? 6 : 5)); @@ -2097,7 +2097,7 @@ static Status TranslateFusedBatchNormGradOp( } static Status TranslateGatherNdOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_params; shared_ptr ng_indices; @@ -2128,7 +2128,7 @@ static Status TranslateGatherNdOp( } static Status TranslateFusedMatMulOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { int num_args; TF_RETURN_IF_ERROR(GetNodeAttr(op->attrs(), "num_args", &num_args)); @@ -2245,7 +2245,7 @@ static Status TranslateGatherV2Op( // Negative axis is supported. Accounting for that auto ng_input_shape = ng_input->get_shape(); size_t ng_input_rank = ng_input_shape.size(); - size_t axis; + int axis; if (tf_axis[0] >= 0) { axis = tf_axis[0]; } else { @@ -2269,7 +2269,7 @@ static Status TranslateGatherV2Op( } static Status TranslateFusedConv2DOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { int num_args; TF_RETURN_IF_ERROR(GetNodeAttr(op->attrs(), "num_args", &num_args)); @@ -2450,7 +2450,7 @@ static Status TranslateFusedConv2DOp( } static Status TranslateIdentityOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_arg; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_arg)); @@ -2459,7 +2459,7 @@ static Status TranslateIdentityOp( } static Status TranslateL2LossOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); @@ -2486,7 +2486,7 @@ static Status TranslateL2LossOp( } static Status TranslateLogSoftmaxOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_inp; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_inp)); @@ -2514,7 +2514,7 @@ static Status TranslateLogSoftmaxOp( } static Status TranslateSoftplusOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_inp; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_inp)); @@ -2529,7 +2529,7 @@ static Status TranslateSoftplusOp( } static Status TranslateMatMulOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_lhs, ng_rhs; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_lhs, &ng_rhs)); @@ -2555,7 +2555,7 @@ static Status TranslateMatMulOp( } static Status TranslateMaxPoolOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); @@ -2617,7 +2617,7 @@ static Status TranslateMaxPoolOp( } static Status TranslateMaxPool3DOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); @@ -2679,7 +2679,7 @@ static Status TranslateMaxPool3DOp( } static Status TranslateMaxPoolGradOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_input, ng_grad, ng_fwd; TF_RETURN_IF_ERROR( @@ -2944,7 +2944,7 @@ static Status TranslateOneHotOp( } static Status TranslatePackOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { TF_RETURN_IF_ERROR(ValidateInputCountMin(op, 1)); @@ -2971,14 +2971,14 @@ static Status TranslatePackOp( // if inputs shape is (2, 3, 4), and axis is 1, then we want // to create output_shape (2, num_inputs, 3, 4) for (size_t i = 0; i < input_rank; ++i) { - output_shape[(i < concat_axis) ? i : i + 1] = input_shape[i]; + output_shape[((int)i < concat_axis) ? i : i + 1] = input_shape[i]; } output_shape[concat_axis] = op->num_inputs(); ng::AxisVector ng_axis_order(input_rank); std::iota(ng_axis_order.begin(), ng_axis_order.end(), 0); - if (concat_axis == input_rank) { + if ((size_t)concat_axis == input_rank) { // need to add extra dimension before we concatenate // along it ng::Shape extended_shape = input_shape; @@ -3041,7 +3041,7 @@ static Status TranslatePadOp(const Node* op, } static Status TranslateRankOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_input; @@ -3399,7 +3399,7 @@ static Status TranslateQuantizedConv( template static Status TranslateQuantizedConv2DWithBiasMaybeReluAndRequantizeOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { auto create_quantized_conv_node = []( std::vector> node_inps, ng::Strides ng_strides, @@ -3415,7 +3415,7 @@ static Status TranslateQuantizedConv2DWithBiasMaybeReluAndRequantizeOp( } static Status TranslateQuantizedConv2DWithBiasSumAndReluAndRequantizeOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { auto create_quantized_conv_node = []( std::vector> node_inps, ng::Strides ng_strides, @@ -3431,7 +3431,7 @@ static Status TranslateQuantizedConv2DWithBiasSumAndReluAndRequantizeOp( } static Status TranslateQuantizedConv2DWithBiasSignedSumAndReluAndRequantizeOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { auto create_quantized_conv_node = []( std::vector> node_inps, ng::Strides ng_strides, @@ -3454,7 +3454,7 @@ static Status TranslateQuantizedMaxPoolOp( } static Status TranslateQuantizeV2Op( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_input, ng_min, ng_max; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input, &ng_min, &ng_max)); @@ -3480,7 +3480,7 @@ static Status TranslateQuantizeV2Op( } static Status TranslateDequantizeOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_input, ng_min, ng_max; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input, &ng_min, &ng_max)); @@ -3493,7 +3493,7 @@ static Status TranslateDequantizeOp( } static Status TranslateRelu6Op( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); @@ -3510,7 +3510,7 @@ static Status TranslateRelu6Op( } static Status TranslateReluGradOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_arg, ng_delta; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_delta, &ng_arg)); @@ -3607,7 +3607,7 @@ static Status TranslateRsqrtOp( } static Status TranslateRsqrtGradOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_input; shared_ptr ng_delta; @@ -3638,7 +3638,7 @@ static Status TranslateRsqrtGradOp( } static Status TranslateShapeOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); @@ -3668,7 +3668,7 @@ static Status TranslateShapeOp( } static Status TranslateSigmoidGradOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_input; shared_ptr ng_delta; @@ -3686,7 +3686,7 @@ static Status TranslateSigmoidGradOp( } static Status TranslateSigmoidOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); @@ -3706,7 +3706,7 @@ static Status TranslateSigmoidOp( } static Status TranslateSizeOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); @@ -3791,7 +3791,7 @@ static Status TranslateSliceOp( } static Status TranslateSoftmaxOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); @@ -3811,7 +3811,7 @@ static Status TranslateSoftmaxOp( // Translate SpaceToDepthOp static Status TranslateSpaceToDepthOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); @@ -3891,7 +3891,7 @@ static Status TranslateSpaceToDepthOp( } static Status TranslateSparseSoftmaxCrossEntropyWithLogitsOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { // TF op Inputs: // 1. Logits/Features: @@ -4144,7 +4144,7 @@ static Status TranslateSquaredDifferenceOp( } static Status TranslateSqueezeOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); @@ -4324,7 +4324,7 @@ static Status TranslateStridedSliceOp( size_t ng_begin_idx, ng_end_idx; if (!shrink_mask) { - if (clamped_begin_idx == clamped_end_idx) { + if ((int)clamped_begin_idx == clamped_end_idx) { // Empty due to matching indexes ng_begin_idx = clamped_begin_idx; // Type safety: clamped_begin_idx == clamped_end_idx implies, @@ -4514,7 +4514,7 @@ static Status TranslateStridedSliceOp( // grad = dy * (1 - y * y) // where y = tanh(x) and dy is the corresponding input gradient static Status TranslateTanhGradOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_input, ng_delta; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input, &ng_delta)); @@ -4665,7 +4665,7 @@ static Status TranslateTransposeOp( } static Status TranslateUnpackOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { TF_RETURN_IF_ERROR(ValidateInputCount(op, 1)); @@ -4688,7 +4688,7 @@ static Status TranslateUnpackOp( ng::Shape output_shape; for (size_t i = 0; i < input_rank; ++i) { - if (i != unpack_axis) { + if ((int)i != unpack_axis) { output_shape.push_back(input_shape[i]); } } @@ -4718,7 +4718,7 @@ static Status TranslateUnpackOp( } static Status TranslateSelectOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_input1, ng_input2, ng_input3; TF_RETURN_IF_ERROR( @@ -4779,7 +4779,7 @@ static Status TranslateSelectOp( } static Status TranslateZerosLikeOp( - const Node* op, const std::vector& static_input_map, + const Node* op, const std::vector& , Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); diff --git a/ngraph_bridge/ngraph_cluster_manager.cc b/ngraph_bridge/ngraph_cluster_manager.cc index e6fafc0d0..1d4603807 100644 --- a/ngraph_bridge/ngraph_cluster_manager.cc +++ b/ngraph_bridge/ngraph_cluster_manager.cc @@ -24,15 +24,15 @@ namespace ngraph_bridge { std::vector NGraphClusterManager::s_cluster_graphs; std::mutex NGraphClusterManager::s_cluster_graphs_mutex; -int NGraphClusterManager::NewCluster() { +size_t NGraphClusterManager::NewCluster() { std::lock_guard guard(s_cluster_graphs_mutex); - int new_idx = s_cluster_graphs.size(); + size_t new_idx = s_cluster_graphs.size(); s_cluster_graphs.push_back(new GraphDef()); return new_idx; } -GraphDef* NGraphClusterManager::GetClusterGraph(int idx) { +GraphDef* NGraphClusterManager::GetClusterGraph(size_t idx) { std::lock_guard guard(s_cluster_graphs_mutex); return idx < s_cluster_graphs.size() ? s_cluster_graphs[idx] : nullptr; } diff --git a/ngraph_bridge/ngraph_cluster_manager.h b/ngraph_bridge/ngraph_cluster_manager.h index 34ed38d50..acc0814d0 100644 --- a/ngraph_bridge/ngraph_cluster_manager.h +++ b/ngraph_bridge/ngraph_cluster_manager.h @@ -27,8 +27,8 @@ namespace ngraph_bridge { class NGraphClusterManager { public: - static int NewCluster(); - static tensorflow::GraphDef* GetClusterGraph(int idx); + static size_t NewCluster(); + static tensorflow::GraphDef* GetClusterGraph(size_t idx); static void EvictAllClusters(); private: diff --git a/ngraph_bridge/ngraph_encapsulate_clusters.cc b/ngraph_bridge/ngraph_encapsulate_clusters.cc index 022da98f3..11ec968a9 100644 --- a/ngraph_bridge/ngraph_encapsulate_clusters.cc +++ b/ngraph_bridge/ngraph_encapsulate_clusters.cc @@ -816,6 +816,7 @@ Status EncapsulateClusters( try { op_backend = BackendManager::GetBackend(op_backend_name); } catch (const std::out_of_range& e) { + NGRAPH_VLOG(5) << "Exception: " << e.what(); BackendManager::ReleaseBackend(op_backend_name); throw; } diff --git a/ngraph_bridge/ngraph_encapsulate_impl.cc b/ngraph_bridge/ngraph_encapsulate_impl.cc index f7a767b73..72e3f793d 100644 --- a/ngraph_bridge/ngraph_encapsulate_impl.cc +++ b/ngraph_bridge/ngraph_encapsulate_impl.cc @@ -344,7 +344,9 @@ Status NGraphEncapsulateImpl::AllocateNGInputTensors( } catch (const std::exception& exp) { errors::Internal( - "Caught exception while transferring tensor data to nGraph\n"); + "Caught exception while transferring tensor data to nGraph. " + "Exception: ", + exp.what()); } catch (...) { errors::Internal("Error in transferring tensor data to nGraph\n"); } diff --git a/ngraph_bridge/ngraph_mark_for_clustering.cc b/ngraph_bridge/ngraph_mark_for_clustering.cc index 28c03ef1e..14b6e8f0f 100644 --- a/ngraph_bridge/ngraph_mark_for_clustering.cc +++ b/ngraph_bridge/ngraph_mark_for_clustering.cc @@ -59,7 +59,7 @@ using SetAttributesFunction = std::function; // // FIXME(amprocte): stubbed out for now because NGRAPH device is gone. // -static Status NGraphPlacementRequested(Node* node, bool& placement_ok) { +static Status NGraphPlacementRequested(Node* , bool& placement_ok) { placement_ok = true; return Status::OK(); } @@ -129,7 +129,7 @@ static SetAttributesFunction SetStaticInputs( // Generates a "simple" confirmation function which always returns true, static ConfirmationFunction SimpleConfirmationFunction() { - auto cf = [](Node* n, bool* result) { + auto cf = [](Node* , bool* result) { *result = true; return Status::OK(); }; @@ -655,7 +655,7 @@ Status MarkForClustering(Graph* graph, const std::set skip_these_nodes, // Right now it cannot be inside the if(!initialized) block, because it is // backend dependent, which might change with different sess.run()s - confirmation_function_map["GatherV2"] = [¤t_backend](Node* n, + confirmation_function_map["GatherV2"] = [¤t_backend](Node* , bool* result) { // TODO: replace current_backend -> // BackendManager::GetCurrentlySetBackendName() @@ -666,7 +666,7 @@ Status MarkForClustering(Graph* graph, const std::set skip_these_nodes, }; confirmation_function_map["NonMaxSuppressionV4"] = [¤t_backend]( - Node* n, bool* result) { + Node* , bool* result) { auto config_map = BackendManager::GetBackendAttributeValues(current_backend); *result = (config_map.at("ngraph_backend") == "NNPI"); @@ -674,7 +674,7 @@ Status MarkForClustering(Graph* graph, const std::set skip_these_nodes, }; confirmation_function_map["CombinedNonMaxSuppression"] = [¤t_backend]( - Node* n, bool* result) { + Node* , bool* result) { auto config_map = BackendManager::GetBackendAttributeValues(current_backend); *result = (config_map.at("ngraph_backend") == "NNPI"); diff --git a/ngraph_bridge/ngraph_utils.cc b/ngraph_bridge/ngraph_utils.cc index 8dbea634b..483bbae8a 100644 --- a/ngraph_bridge/ngraph_utils.cc +++ b/ngraph_bridge/ngraph_utils.cc @@ -55,7 +55,8 @@ Status IsNgraphTFLogTensorCopiesEnabled(int graph_id, test_graph_id = stoi(string(copy_env_var)); } catch (const std::invalid_argument& ia) { return errors::InvalidArgument( - "Invalid argument for NGRAPH_TF_LOG_TENSOR_COPIES"); + "Invalid argument for NGRAPH_TF_LOG_TENSOR_COPIES. Exception: ", + ia.what()); } // if -1 copies are logged for all graphs is_copy_log_enabled = (test_graph_id == -1 || test_graph_id == graph_id); From a1b4835c6059c0cb69c52d68f32c457163b0d091 Mon Sep 17 00:00:00 2001 From: Kanvi Khanna Date: Wed, 11 Sep 2019 10:39:02 -0700 Subject: [PATCH 2/9] Fix formatting --- ngraph_bridge/ngraph_builder.cc | 253 ++++++++++---------- ngraph_bridge/ngraph_mark_for_clustering.cc | 10 +- 2 files changed, 129 insertions(+), 134 deletions(-) diff --git a/ngraph_bridge/ngraph_builder.cc b/ngraph_bridge/ngraph_builder.cc index a5d7c7f53..5d5fdd6aa 100644 --- a/ngraph_bridge/ngraph_builder.cc +++ b/ngraph_bridge/ngraph_builder.cc @@ -166,8 +166,7 @@ static Status GetInputNode(const Builder::OpMap& ng_op_map, const Node* op, } namespace detail { -static Status GetInputNodes(const Builder::OpMap& , const Node* , - size_t ) { +static Status GetInputNodes(const Builder::OpMap&, const Node*, size_t) { return Status::OK(); } @@ -366,7 +365,7 @@ Builder::TF_NGRAPH_CONST_MAP() { // }); // } static Status TranslateUnaryOp( - const Node* op, const std::vector& , + const Node* op, const std::vector&, Builder::OpMap& ng_op_map, std::function(std::shared_ptr)> create_unary_op) { @@ -422,7 +421,7 @@ static Status TranslateUnaryOp( // static Status TranslateBinaryOp( - const Node* op, const std::vector& , + const Node* op, const std::vector&, Builder::OpMap& ng_op_map, std::function(std::shared_ptr, std::shared_ptr)> @@ -460,9 +459,10 @@ static Status TranslateBinaryOp( } // Helper function for translating QuantizedAvgPool and QuantizedMaxPool -static Status TranslateQuantizedPoolOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map, std::string pooling_name) { +static Status TranslateQuantizedPoolOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map, + std::string pooling_name) { bool is_quantizedAvgPool = pooling_name == "QuantizedAvgPool"; bool is_quantizedMaxPool = pooling_name == "QuantizedMaxPool"; @@ -533,9 +533,8 @@ static Status TranslateQuantizedPoolOp( return Status::OK(); } -static Status TranslateAddNOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateAddNOp(const Node* op, const std::vector&, + Builder::OpMap& ng_op_map) { std::vector> ng_arg_vec(op->num_inputs()); for (int inp_idx = 0; inp_idx < op->num_inputs(); inp_idx++) @@ -596,9 +595,9 @@ static Status TranslateArgMinMaxOp( return Status::OK(); } -static Status TranslateAvgPoolOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateAvgPoolOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); @@ -910,9 +909,9 @@ static Status TranslateBatchMatMulOp( return Status::OK(); } -static Status TranslateBiasAddOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateBiasAddOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_input, ng_bias; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input, &ng_bias)); @@ -959,9 +958,9 @@ static Status TranslateBiasAddOp( return Status::OK(); } -static Status TranslateBiasAddGradOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateBiasAddGradOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); @@ -1009,9 +1008,8 @@ static Status TranslateBiasAddGradOp( return Status::OK(); } -static Status TranslateCastOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateCastOp(const Node* op, const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); @@ -1156,9 +1154,9 @@ static Status TranslateConcatV2Op( return Status::OK(); } -static Status TranslateConstOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateConstOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { DataType dtype; TF_RETURN_IF_ERROR(GetNodeAttr(op->attrs(), "dtype", &dtype)); @@ -1186,9 +1184,9 @@ static Status TranslateConstOp( return Status::OK(); } -static Status TranslateConv2DOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateConv2DOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_input, ng_filter; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input, &ng_filter)); @@ -1472,9 +1470,9 @@ static Status TranslateConv2DBackpropInputOp( } // Translate Conv3D Op -static Status TranslateConv3DOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateConv3DOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_input, ng_filter; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input, &ng_filter)); @@ -1547,9 +1545,9 @@ static Status TranslateConv3DOp( } // Translate DepthToSpace op -static Status TranslateDepthToSpaceOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateDepthToSpaceOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); @@ -1707,7 +1705,7 @@ static Status TranslateDepthToSpaceOp( } static Status TranslateDepthwiseConv2dNativeOp( - const Node* op, const std::vector& , + const Node* op, const std::vector&, Builder::OpMap& ng_op_map) { shared_ptr ng_input, ng_filter; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input, &ng_filter)); @@ -1995,9 +1993,9 @@ static Status TranslateFusedBatchNormOp( return Status::OK(); } -static Status TranslateFusedBatchNormGradOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateFusedBatchNormGradOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { bool is_v3 = op->type_string() == "FusedBatchNormGradV3"; TF_RETURN_IF_ERROR(ValidateInputCount(op, is_v3 ? 6 : 5)); @@ -2096,9 +2094,9 @@ static Status TranslateFusedBatchNormGradOp( return Status::OK(); } -static Status TranslateGatherNdOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateGatherNdOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_params; shared_ptr ng_indices; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_params, &ng_indices)); @@ -2127,9 +2125,9 @@ static Status TranslateGatherNdOp( return Status::OK(); } -static Status TranslateFusedMatMulOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateFusedMatMulOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { int num_args; TF_RETURN_IF_ERROR(GetNodeAttr(op->attrs(), "num_args", &num_args)); @@ -2268,9 +2266,9 @@ static Status TranslateGatherV2Op( return Status::OK(); } -static Status TranslateFusedConv2DOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateFusedConv2DOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { int num_args; TF_RETURN_IF_ERROR(GetNodeAttr(op->attrs(), "num_args", &num_args)); @@ -2449,18 +2447,18 @@ static Status TranslateFusedConv2DOp( return Status::OK(); } -static Status TranslateIdentityOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateIdentityOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_arg; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_arg)); SaveNgOp(ng_op_map, op->name(), ng_arg); return Status::OK(); } -static Status TranslateL2LossOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateL2LossOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); @@ -2485,9 +2483,9 @@ static Status TranslateL2LossOp( return Status::OK(); } -static Status TranslateLogSoftmaxOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateLogSoftmaxOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_inp; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_inp)); auto inp_shape = ng_inp->get_shape(); @@ -2513,9 +2511,9 @@ static Status TranslateLogSoftmaxOp( return Status::OK(); } -static Status TranslateSoftplusOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateSoftplusOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_inp; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_inp)); auto ng_exp = ConstructNgNode(op->name(), ng_inp); @@ -2528,9 +2526,9 @@ static Status TranslateSoftplusOp( return Status::OK(); } -static Status TranslateMatMulOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateMatMulOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_lhs, ng_rhs; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_lhs, &ng_rhs)); @@ -2554,9 +2552,9 @@ static Status TranslateMatMulOp( return Status::OK(); } -static Status TranslateMaxPoolOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateMaxPoolOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); @@ -2616,9 +2614,9 @@ static Status TranslateMaxPoolOp( return Status::OK(); } -static Status TranslateMaxPool3DOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateMaxPool3DOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); @@ -2678,9 +2676,9 @@ static Status TranslateMaxPool3DOp( return Status::OK(); } -static Status TranslateMaxPoolGradOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateMaxPoolGradOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_input, ng_grad, ng_fwd; TF_RETURN_IF_ERROR( GetInputNodes(ng_op_map, op, &ng_input, &ng_fwd, &ng_grad)); @@ -2943,9 +2941,8 @@ static Status TranslateOneHotOp( return Status::OK(); } -static Status TranslatePackOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslatePackOp(const Node* op, const std::vector&, + Builder::OpMap& ng_op_map) { TF_RETURN_IF_ERROR(ValidateInputCountMin(op, 1)); ng::NodeVector ng_concat_inputs; @@ -3040,9 +3037,8 @@ static Status TranslatePadOp(const Node* op, return Status::OK(); } -static Status TranslateRankOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateRankOp(const Node* op, const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); @@ -3399,7 +3395,7 @@ static Status TranslateQuantizedConv( template static Status TranslateQuantizedConv2DWithBiasMaybeReluAndRequantizeOp( - const Node* op, const std::vector& , + const Node* op, const std::vector&, Builder::OpMap& ng_op_map) { auto create_quantized_conv_node = []( std::vector> node_inps, ng::Strides ng_strides, @@ -3415,7 +3411,7 @@ static Status TranslateQuantizedConv2DWithBiasMaybeReluAndRequantizeOp( } static Status TranslateQuantizedConv2DWithBiasSumAndReluAndRequantizeOp( - const Node* op, const std::vector& , + const Node* op, const std::vector&, Builder::OpMap& ng_op_map) { auto create_quantized_conv_node = []( std::vector> node_inps, ng::Strides ng_strides, @@ -3431,7 +3427,7 @@ static Status TranslateQuantizedConv2DWithBiasSumAndReluAndRequantizeOp( } static Status TranslateQuantizedConv2DWithBiasSignedSumAndReluAndRequantizeOp( - const Node* op, const std::vector& , + const Node* op, const std::vector&, Builder::OpMap& ng_op_map) { auto create_quantized_conv_node = []( std::vector> node_inps, ng::Strides ng_strides, @@ -3453,9 +3449,9 @@ static Status TranslateQuantizedMaxPoolOp( "QuantizedMaxPool"); } -static Status TranslateQuantizeV2Op( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateQuantizeV2Op(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_input, ng_min, ng_max; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input, &ng_min, &ng_max)); @@ -3479,9 +3475,9 @@ static Status TranslateQuantizeV2Op( return Status::OK(); } -static Status TranslateDequantizeOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateDequantizeOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_input, ng_min, ng_max; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input, &ng_min, &ng_max)); @@ -3492,9 +3488,9 @@ static Status TranslateDequantizeOp( return Status::OK(); } -static Status TranslateRelu6Op( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateRelu6Op(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); @@ -3509,9 +3505,9 @@ static Status TranslateRelu6Op( return Status::OK(); } -static Status TranslateReluGradOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateReluGradOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_arg, ng_delta; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_delta, &ng_arg)); @@ -3606,9 +3602,9 @@ static Status TranslateRsqrtOp( }); } -static Status TranslateRsqrtGradOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateRsqrtGradOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_input; shared_ptr ng_delta; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input, &ng_delta)); @@ -3637,9 +3633,9 @@ static Status TranslateRsqrtGradOp( return Status::OK(); } -static Status TranslateShapeOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateShapeOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); @@ -3667,9 +3663,9 @@ static Status TranslateShapeOp( return Status::OK(); } -static Status TranslateSigmoidGradOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateSigmoidGradOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_input; shared_ptr ng_delta; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input, &ng_delta)); @@ -3685,9 +3681,9 @@ static Status TranslateSigmoidGradOp( return Status::OK(); } -static Status TranslateSigmoidOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateSigmoidOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); @@ -3705,9 +3701,8 @@ static Status TranslateSigmoidOp( return Status::OK(); } -static Status TranslateSizeOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateSizeOp(const Node* op, const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); @@ -3790,9 +3785,9 @@ static Status TranslateSliceOp( return Status::OK(); } -static Status TranslateSoftmaxOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateSoftmaxOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); @@ -3810,9 +3805,9 @@ static Status TranslateSoftmaxOp( } // Translate SpaceToDepthOp -static Status TranslateSpaceToDepthOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateSpaceToDepthOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); @@ -3891,7 +3886,7 @@ static Status TranslateSpaceToDepthOp( } static Status TranslateSparseSoftmaxCrossEntropyWithLogitsOp( - const Node* op, const std::vector& , + const Node* op, const std::vector&, Builder::OpMap& ng_op_map) { // TF op Inputs: // 1. Logits/Features: @@ -4143,9 +4138,9 @@ static Status TranslateSquaredDifferenceOp( }); } -static Status TranslateSqueezeOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateSqueezeOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); size_t input_dims = ng_input->get_shape().size(); @@ -4513,9 +4508,9 @@ static Status TranslateStridedSliceOp( // Computes the gradient for tanh of 'x' w.r.t its input // grad = dy * (1 - y * y) // where y = tanh(x) and dy is the corresponding input gradient -static Status TranslateTanhGradOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateTanhGradOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_input, ng_delta; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input, &ng_delta)); @@ -4664,9 +4659,9 @@ static Status TranslateTransposeOp( return Status::OK(); } -static Status TranslateUnpackOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateUnpackOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { TF_RETURN_IF_ERROR(ValidateInputCount(op, 1)); shared_ptr ng_input; @@ -4717,9 +4712,9 @@ static Status TranslateUnpackOp( return Status::OK(); } -static Status TranslateSelectOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateSelectOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_input1, ng_input2, ng_input3; TF_RETURN_IF_ERROR( GetInputNodes(ng_op_map, op, &ng_input1, &ng_input2, &ng_input3)); @@ -4778,9 +4773,9 @@ static Status TranslateSelectOp( return Status::OK(); } -static Status TranslateZerosLikeOp( - const Node* op, const std::vector& , - Builder::OpMap& ng_op_map) { +static Status TranslateZerosLikeOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { shared_ptr ng_input; TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_input)); diff --git a/ngraph_bridge/ngraph_mark_for_clustering.cc b/ngraph_bridge/ngraph_mark_for_clustering.cc index 14b6e8f0f..6d2693daa 100644 --- a/ngraph_bridge/ngraph_mark_for_clustering.cc +++ b/ngraph_bridge/ngraph_mark_for_clustering.cc @@ -59,7 +59,7 @@ using SetAttributesFunction = std::function; // // FIXME(amprocte): stubbed out for now because NGRAPH device is gone. // -static Status NGraphPlacementRequested(Node* , bool& placement_ok) { +static Status NGraphPlacementRequested(Node*, bool& placement_ok) { placement_ok = true; return Status::OK(); } @@ -129,7 +129,7 @@ static SetAttributesFunction SetStaticInputs( // Generates a "simple" confirmation function which always returns true, static ConfirmationFunction SimpleConfirmationFunction() { - auto cf = [](Node* , bool* result) { + auto cf = [](Node*, bool* result) { *result = true; return Status::OK(); }; @@ -655,7 +655,7 @@ Status MarkForClustering(Graph* graph, const std::set skip_these_nodes, // Right now it cannot be inside the if(!initialized) block, because it is // backend dependent, which might change with different sess.run()s - confirmation_function_map["GatherV2"] = [¤t_backend](Node* , + confirmation_function_map["GatherV2"] = [¤t_backend](Node*, bool* result) { // TODO: replace current_backend -> // BackendManager::GetCurrentlySetBackendName() @@ -666,7 +666,7 @@ Status MarkForClustering(Graph* graph, const std::set skip_these_nodes, }; confirmation_function_map["NonMaxSuppressionV4"] = [¤t_backend]( - Node* , bool* result) { + Node*, bool* result) { auto config_map = BackendManager::GetBackendAttributeValues(current_backend); *result = (config_map.at("ngraph_backend") == "NNPI"); @@ -674,7 +674,7 @@ Status MarkForClustering(Graph* graph, const std::set skip_these_nodes, }; confirmation_function_map["CombinedNonMaxSuppression"] = [¤t_backend]( - Node* , bool* result) { + Node*, bool* result) { auto config_map = BackendManager::GetBackendAttributeValues(current_backend); *result = (config_map.at("ngraph_backend") == "NNPI"); From 0427d5bcad4df4939ab0eab74ff4d683fddddbf9 Mon Sep 17 00:00:00 2001 From: Kanvi Khanna Date: Wed, 11 Sep 2019 11:03:59 -0700 Subject: [PATCH 3/9] Add full paths where missing --- .../encapsulate_clusters_test.cc | 2 +- test/graph_rewrites/enter_in_catalog_test.cc | 28 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/test/graph_rewrites/encapsulate_clusters_test.cc b/test/graph_rewrites/encapsulate_clusters_test.cc index 898feec6b..b46d812fe 100644 --- a/test/graph_rewrites/encapsulate_clusters_test.cc +++ b/test/graph_rewrites/encapsulate_clusters_test.cc @@ -17,10 +17,10 @@ #include "gtest/gtest.h" #include "tensorflow/core/graph/node_builder.h" -#include "version.h" #include "ngraph_bridge/ngraph_cluster_manager.h" #include "ngraph_bridge/ngraph_encapsulate_clusters.h" +#include "ngraph_bridge/version.h" #include "test/test_utilities.h" using namespace std; diff --git a/test/graph_rewrites/enter_in_catalog_test.cc b/test/graph_rewrites/enter_in_catalog_test.cc index 51321aac6..f2893611b 100644 --- a/test/graph_rewrites/enter_in_catalog_test.cc +++ b/test/graph_rewrites/enter_in_catalog_test.cc @@ -22,20 +22,20 @@ #include "tensorflow/core/graph/graph.h" #include "tensorflow/core/public/session.h" -#include "enable_variable_ops/ngraph_catalog.h" -#include "enable_variable_ops/ngraph_enter_in_catalog.h" -#include "enable_variable_ops/ngraph_replace_op_utilities.h" -#include "enable_variable_ops/ngraph_replace_variable_modifiers.h" -#include "ngraph_api.h" -#include "ngraph_assign_clusters.h" -#include "ngraph_capture_variables.h" -#include "ngraph_cluster_manager.h" -#include "ngraph_deassign_clusters.h" -#include "ngraph_encapsulate_clusters.h" -#include "ngraph_mark_for_clustering.h" -#include "ngraph_rewrite_for_tracking.h" -#include "ngraph_utils.h" -#include "tf_graph_writer.h" +#include "logging/tf_graph_writer.h" +#include "ngraph_bridge/enable_variable_ops/ngraph_catalog.h" +#include "ngraph_bridge/enable_variable_ops/ngraph_enter_in_catalog.h" +#include "ngraph_bridge/enable_variable_ops/ngraph_replace_op_utilities.h" +#include "ngraph_bridge/enable_variable_ops/ngraph_replace_variable_modifiers.h" +#include "ngraph_bridge/ngraph_api.h" +#include "ngraph_bridge/ngraph_assign_clusters.h" +#include "ngraph_bridge/ngraph_capture_variables.h" +#include "ngraph_bridge/ngraph_cluster_manager.h" +#include "ngraph_bridge/ngraph_deassign_clusters.h" +#include "ngraph_bridge/ngraph_encapsulate_clusters.h" +#include "ngraph_bridge/ngraph_mark_for_clustering.h" +#include "ngraph_bridge/ngraph_rewrite_for_tracking.h" +#include "ngraph_bridge/ngraph_utils.h" using namespace std; namespace ng = ngraph; From ad40c62c4f5c773de6717fc54ff313f72a6c6a72 Mon Sep 17 00:00:00 2001 From: Kanvi Khanna Date: Wed, 11 Sep 2019 18:22:11 -0700 Subject: [PATCH 4/9] Fix warnings discovered with clang++-8 --- CMakeLists.txt | 2 +- examples/cpp/infer_multiple_networks/main.cc | 18 +++++++++--------- examples/cpp/tf_label_image_utils.cc | 6 +++--- ngraph_bridge/enable_variable_ops/ngraph_var.h | 2 +- ngraph_bridge/ngraph_builder.cc | 2 +- ngraph_bridge/ngraph_encapsulate_clusters.cc | 4 ++-- ngraph_bridge/ngraph_encapsulate_impl.cc | 5 +++-- ngraph_bridge/ngraph_encapsulate_op.cc | 11 +++++++++-- ngraph_bridge/tf_deadness_analysis.cc | 6 +++--- test/encapsulate_op/encapsulate_op_test.cc | 6 +++--- test/opexecuter.cpp | 5 ++++- test/test_variable_ops.cpp | 2 +- 12 files changed, 40 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c69ded92..5025fcf5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ include(ExternalProject) include(CMakeDependentOption) include(cmake/sdl.cmake) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wno-comment -Wno-sign-compare") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wno-comment -Wno-sign-compare -Wbackslash-newline-escape") # In order to compile ngraph-tf with memory leak detection, run `cmake` with `-DCMAKE_BUILD_TYPE=Sanitize`. # N.B.: This *will* crash python unit tests because ngraph-tf will be loaded "too late" via `dlopen`, diff --git a/examples/cpp/infer_multiple_networks/main.cc b/examples/cpp/infer_multiple_networks/main.cc index 5500f53ba..2e098433f 100644 --- a/examples/cpp/infer_multiple_networks/main.cc +++ b/examples/cpp/infer_multiple_networks/main.cc @@ -164,28 +164,28 @@ int main(int argc, char** argv) { input_layer, output_layer, use_NCHW, preload_images, input_channels)); bool engine_1_running = true; - infer_engine_1.Start([&](int step_count) { + TF_CHECK_OK(infer_engine_1.Start([&](int step_count) { if (step_count == (iteration_count - 1)) { - infer_engine_1.Stop(); + TF_CHECK_OK(infer_engine_1.Stop()); engine_1_running = false; } - }); + })); bool engine_2_running = true; - infer_engine_2.Start([&](int step_count) { + TF_CHECK_OK(infer_engine_2.Start([&](int step_count) { if (step_count == (iteration_count - 1)) { - infer_engine_2.Stop(); + TF_CHECK_OK(infer_engine_2.Stop()); engine_2_running = false; } - }); + })); bool engine_3_running = true; - infer_engine_3.Start([&](int step_count) { + TF_CHECK_OK(infer_engine_3.Start([&](int step_count) { if (step_count == (iteration_count - 1)) { - infer_engine_3.Stop(); + TF_CHECK_OK(infer_engine_3.Stop()); engine_3_running = false; } - }); + })); while (engine_1_running || engine_2_running || engine_3_running) { std::this_thread::sleep_for(std::chrono::milliseconds(1000)); diff --git a/examples/cpp/tf_label_image_utils.cc b/examples/cpp/tf_label_image_utils.cc index ed609b415..eaca1c142 100644 --- a/examples/cpp/tf_label_image_utils.cc +++ b/examples/cpp/tf_label_image_utils.cc @@ -172,15 +172,15 @@ Status ReadTensorFromImageFile(const std::vector& file_names, // Now try to figure out what kind of file it is and decode it. tensorflow::Output image_reader; - if (tensorflow::str_util::EndsWith(file_names[i], ".png")) { + if (absl::EndsWith(file_names[i], ".png")) { image_reader = DecodePng(root.WithOpName("png_reader"), file_reader, DecodePng::Channels(input_channels)); - } else if (tensorflow::str_util::EndsWith(file_names[i], ".gif")) { + } else if (absl::EndsWith(file_names[i], ".gif")) { // gif decoder returns 4-D tensor, remove the first dim image_reader = Squeeze(root.WithOpName("squeeze_first_dim"), DecodeGif(root.WithOpName("gif_reader"), file_reader)); - } else if (tensorflow::str_util::EndsWith(file_names[i], ".bmp")) { + } else if (absl::EndsWith(file_names[i], ".bmp")) { image_reader = DecodeBmp(root.WithOpName("bmp_reader"), file_reader); } else { // Assume if it's neither a PNG nor a GIF then it must be a JPEG. diff --git a/ngraph_bridge/enable_variable_ops/ngraph_var.h b/ngraph_bridge/enable_variable_ops/ngraph_var.h index cc0462c69..80662f8e2 100644 --- a/ngraph_bridge/enable_variable_ops/ngraph_var.h +++ b/ngraph_bridge/enable_variable_ops/ngraph_var.h @@ -56,7 +56,7 @@ class NGraphVar : public ResourceBase { // Create Backend NGRAPH_VLOG(4) << "NGraphVar::Create Backend "; - BackendManager::CreateBackend(ng_backend_name_); + TF_RETURN_IF_ERROR(BackendManager::CreateBackend(ng_backend_name_)); ng::runtime::Backend* op_backend = BackendManager::GetBackend(ng_backend_name_); diff --git a/ngraph_bridge/ngraph_builder.cc b/ngraph_bridge/ngraph_builder.cc index 5d5fdd6aa..289f48a89 100644 --- a/ngraph_bridge/ngraph_builder.cc +++ b/ngraph_bridge/ngraph_builder.cc @@ -2442,7 +2442,7 @@ static Status TranslateFusedConv2DOp(const Node* op, } } else { return errors::Unimplemented("Unsupported _FusedConv2D " + - str_util::Join(fused_ops, ",")); + absl::StrJoin(fused_ops, ",")); } return Status::OK(); } diff --git a/ngraph_bridge/ngraph_encapsulate_clusters.cc b/ngraph_bridge/ngraph_encapsulate_clusters.cc index 11ec968a9..48563c43f 100644 --- a/ngraph_bridge/ngraph_encapsulate_clusters.cc +++ b/ngraph_bridge/ngraph_encapsulate_clusters.cc @@ -791,8 +791,8 @@ Status EncapsulateClusters( "Caught exception while creating backend string ", exp.what(), "\n"); } - BackendManager::CreateBackend( - op_backend_name); // Created a backend here. must free it + TF_RETURN_IF_ERROR(BackendManager::CreateBackend( + op_backend_name)); // Created a backend here. must free it std::unordered_map additional_attribute_map; for (auto itr : node->attrs()) { // Find the optional attributes to be sent to the backend. diff --git a/ngraph_bridge/ngraph_encapsulate_impl.cc b/ngraph_bridge/ngraph_encapsulate_impl.cc index 72e3f793d..721317348 100644 --- a/ngraph_bridge/ngraph_encapsulate_impl.cc +++ b/ngraph_bridge/ngraph_encapsulate_impl.cc @@ -343,12 +343,13 @@ Status NGraphEncapsulateImpl::AllocateNGInputTensors( input_copy_events.push_back(std::move(event_copy_input_next)); } catch (const std::exception& exp) { - errors::Internal( + return errors::Internal( "Caught exception while transferring tensor data to nGraph. " "Exception: ", exp.what()); } catch (...) { - errors::Internal("Error in transferring tensor data to nGraph\n"); + return errors::Internal( + "Error in transferring tensor data to nGraph\n"); } } input_caches[i] = std::make_pair(current_src_ptr, current_ng_tensor); diff --git a/ngraph_bridge/ngraph_encapsulate_op.cc b/ngraph_bridge/ngraph_encapsulate_op.cc index 597fab0b1..60128b06f 100644 --- a/ngraph_bridge/ngraph_encapsulate_op.cc +++ b/ngraph_bridge/ngraph_encapsulate_op.cc @@ -99,7 +99,11 @@ NGraphEncapsulateOp::NGraphEncapsulateOp(OpKernelConstruction* ctx) const auto get_func_sig = [&flib](const string& op, const OpDef** sig) { return flib.LookUpOpDef(op, sig); }; - FunctionDefToBodyHelper(*fdef, {}, &flib, get_func_sig, &fnbody); + Status status = + FunctionDefToBodyHelper(*fdef, {}, &flib, get_func_sig, &fnbody); + if (!status.ok()) { + NGRAPH_VLOG(2) << "FunctionDefToBodyHelper returned a not ok status."; + } CopyGraph(*fnbody->graph, &ng_encap_impl.m_graph); } else { GraphConstructorOptions opts; @@ -186,7 +190,10 @@ NGraphEncapsulateOp::NGraphEncapsulateOp(OpKernelConstruction* ctx) OP_REQUIRES_OK(ctx, status); } NGRAPH_VLOG(4) << "NGraphEncapsulateOp::Create backend " << def().name(); - BackendManager::CreateBackend(ng_encap_impl.GetOpBackend()); + Status status = BackendManager::CreateBackend(ng_encap_impl.GetOpBackend()); + if (!status.ok()) { + NGRAPH_VLOG(2) << "Cannot create backend " << ng_encap_impl.GetOpBackend(); + } // SetConfig will be called for each EncapsulateOp BackendManager::SetConfig(ng_encap_impl.GetOpBackend(), additional_attribute_map); diff --git a/ngraph_bridge/tf_deadness_analysis.cc b/ngraph_bridge/tf_deadness_analysis.cc index 53189f0e1..6c81d7e1a 100644 --- a/ngraph_bridge/tf_deadness_analysis.cc +++ b/ngraph_bridge/tf_deadness_analysis.cc @@ -118,7 +118,7 @@ class AndPredicate : public Predicate { std::transform(operands().begin(), operands().end(), std::back_inserter(operands_str), [](Predicate* pred) { return pred->ToString(); }); - return strings::StrCat("(", str_util::Join(operands_str, " & "), ")"); + return strings::StrCat("(", absl::StrJoin(operands_str, " & "), ")"); } bool operator==(const Predicate& other) const override { return other.kind() == Kind::kAnd && @@ -147,7 +147,7 @@ class OrPredicate : public Predicate { std::transform(operands().begin(), operands().end(), std::back_inserter(operands_str), [](Predicate* pred) { return pred->ToString(); }); - return strings::StrCat("(", str_util::Join(operands_str, " | "), ")"); + return strings::StrCat("(", absl::StrJoin(operands_str, " | "), ")"); } bool operator==(const Predicate& other) const override { return other.kind() == Kind::kOr && @@ -312,7 +312,7 @@ class DeadnessAnalysisImpl : public DeadnessAnalysis { Status Populate(); bool HasInputsWithMismatchingDeadness(const Node& node) override; void Print() const override; - Status GetNodePredicate(const Node& node, string& pred_string); + Status GetNodePredicate(const Node& node, string& pred_string) override; private: enum class EdgeKind { kDataAndControl, kDataOnly, kControlOnly }; diff --git a/test/encapsulate_op/encapsulate_op_test.cc b/test/encapsulate_op/encapsulate_op_test.cc index 7cb550d8b..b92f10650 100644 --- a/test/encapsulate_op/encapsulate_op_test.cc +++ b/test/encapsulate_op/encapsulate_op_test.cc @@ -103,7 +103,7 @@ TEST(EncapsulateOp, GetNgExecutable) { } ng_encap_impl.SetOpBackend("CPU"); - BackendManager::CreateBackend(ng_encap_impl.GetOpBackend()); + ASSERT_OK(BackendManager::CreateBackend(ng_encap_impl.GetOpBackend())); ng::runtime::Backend* op_backend; op_backend = BackendManager::GetBackend(ng_encap_impl.GetOpBackend()); @@ -125,7 +125,7 @@ TEST(EncapsulateOp, AllocateNGInputTensors) { ng::ParameterVector{A, B}); ng_encap_impl.SetOpBackend("CPU"); - BackendManager::CreateBackend(ng_encap_impl.GetOpBackend()); + ASSERT_OK(BackendManager::CreateBackend(ng_encap_impl.GetOpBackend())); ng::runtime::Backend* op_backend; op_backend = BackendManager::GetBackend(ng_encap_impl.GetOpBackend()); auto ng_exec = op_backend->compile(f); @@ -161,7 +161,7 @@ TEST(EncapsulateOp, AllocateNGOutputTensors) { ng::ParameterVector{A, B}); ng_encap_impl.SetOpBackend("CPU"); - BackendManager::CreateBackend(ng_encap_impl.GetOpBackend()); + ASSERT_OK(BackendManager::CreateBackend(ng_encap_impl.GetOpBackend())); ng::runtime::Backend* op_backend; op_backend = BackendManager::GetBackend(ng_encap_impl.GetOpBackend()); auto ng_exec = op_backend->compile(f); diff --git a/test/opexecuter.cpp b/test/opexecuter.cpp index d0142e880..72ffa392a 100644 --- a/test/opexecuter.cpp +++ b/test/opexecuter.cpp @@ -217,7 +217,10 @@ void OpExecuter::ExecuteOnNGraph(vector& ngraph_outputs, } NGRAPH_VLOG(5) << " Creating NG Backend " << ng_backend_type; - BackendManager::CreateBackend(ng_backend_type); + Status status = BackendManager::CreateBackend(ng_backend_type); + if (!status.ok()) { + NGRAPH_VLOG(5) << "Cannot create backend " << ng_backend_type; + } auto backend = BackendManager::GetBackend(ng_backend_type); // Add the _ngraph_backend attr to the node diff --git a/test/test_variable_ops.cpp b/test/test_variable_ops.cpp index 3ce35e282..258d4f2df 100644 --- a/test/test_variable_ops.cpp +++ b/test/test_variable_ops.cpp @@ -166,7 +166,7 @@ TEST(VariableTest, SmallGraph2) { ASSERT_OK(tf_session.Run({assign_sub}, &tf_outputs2)); } - tf_session.Run({var}, &tf_outputs3); + ASSERT_OK(tf_session.Run({var}, &tf_outputs3)); Compare(tf_outputs1, ng_outputs1); Compare(tf_outputs2, ng_outputs2); From 8f405b286fbd559691ebe0699e5d6ee156fc9257 Mon Sep 17 00:00:00 2001 From: Kanvi Khanna Date: Thu, 12 Sep 2019 11:06:46 -0700 Subject: [PATCH 5/9] Fix build error seen in CI --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5025fcf5b..50ba5f34b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,11 @@ include(ExternalProject) include(CMakeDependentOption) include(cmake/sdl.cmake) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wno-comment -Wno-sign-compare -Wbackslash-newline-escape") +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wno-comment -Wno-sign-compare") +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wno-comment -Wno-sign-compare -Wbackslash-newline-escape") +endif() # In order to compile ngraph-tf with memory leak detection, run `cmake` with `-DCMAKE_BUILD_TYPE=Sanitize`. # N.B.: This *will* crash python unit tests because ngraph-tf will be loaded "too late" via `dlopen`, From a4b6c2918a99b4a142be472bc6a42346f746a733 Mon Sep 17 00:00:00 2001 From: Kanvi Khanna Date: Thu, 12 Sep 2019 11:22:49 -0700 Subject: [PATCH 6/9] Fix missed warning --- ngraph_bridge/enable_variable_ops/ngraph_tracked_variable.cc | 2 +- ngraph_bridge/ngraph_tracked_variable.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ngraph_bridge/enable_variable_ops/ngraph_tracked_variable.cc b/ngraph_bridge/enable_variable_ops/ngraph_tracked_variable.cc index f91bd278d..459bff98f 100644 --- a/ngraph_bridge/enable_variable_ops/ngraph_tracked_variable.cc +++ b/ngraph_bridge/enable_variable_ops/ngraph_tracked_variable.cc @@ -230,7 +230,7 @@ void NGraphVariableOp::Compute(OpKernelContext* ctx) { // conditional on whether any reader is taking in a reference. More // conservative condition that would work for now: invalidate if any // reader is not NGraphEncapsulateOp. - auto t_creator = [this](NGraphFreshnessTracker** tracker) { + auto t_creator = [](NGraphFreshnessTracker** tracker) { *tracker = new NGraphFreshnessTracker(); return Status::OK(); }; diff --git a/ngraph_bridge/ngraph_tracked_variable.cc b/ngraph_bridge/ngraph_tracked_variable.cc index c45145165..bf277b6c1 100644 --- a/ngraph_bridge/ngraph_tracked_variable.cc +++ b/ngraph_bridge/ngraph_tracked_variable.cc @@ -133,7 +133,7 @@ void NGraphVariableOp::Compute(OpKernelContext* ctx) { // conditional on whether any reader is taking in a reference. More // conservative condition that would work for now: invalidate if any // reader is not NGraphEncapsulateOp. - auto t_creator = [this](NGraphFreshnessTracker** tracker) { + auto t_creator = [](NGraphFreshnessTracker** tracker) { *tracker = new NGraphFreshnessTracker(); return Status::OK(); }; From 678f56af07d6f3461f3a123b56cf2732b564ff5d Mon Sep 17 00:00:00 2001 From: Kanvi Khanna Date: Thu, 12 Sep 2019 13:21:38 -0700 Subject: [PATCH 7/9] Fix error on enable_var_opts pipeline --- ngraph_bridge/enable_variable_ops/ngraph_var.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ngraph_bridge/enable_variable_ops/ngraph_var.h b/ngraph_bridge/enable_variable_ops/ngraph_var.h index 80662f8e2..cdfeba5b3 100644 --- a/ngraph_bridge/enable_variable_ops/ngraph_var.h +++ b/ngraph_bridge/enable_variable_ops/ngraph_var.h @@ -56,7 +56,10 @@ class NGraphVar : public ResourceBase { // Create Backend NGRAPH_VLOG(4) << "NGraphVar::Create Backend "; - TF_RETURN_IF_ERROR(BackendManager::CreateBackend(ng_backend_name_)); + Status status = BackendManager::CreateBackend(ng_backend_name_); + if (!status.ok()) { + NGRAPH_VLOG(2) << "Cannot create backend " << ng_backend_name_; + } ng::runtime::Backend* op_backend = BackendManager::GetBackend(ng_backend_name_); From 0634cb41a6480967192f6d3894e1890f62fbc915 Mon Sep 17 00:00:00 2001 From: Kanvi Khanna Date: Fri, 13 Sep 2019 14:43:21 -0700 Subject: [PATCH 8/9] Fix build on mac --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 50ba5f34b..38aa1e36c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,10 +23,10 @@ include(ExternalProject) include(CMakeDependentOption) include(cmake/sdl.cmake) -if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") +if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(Apple)?Clang$") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wno-comment -Wno-sign-compare -Wno-backslash-newline-escape") +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wno-comment -Wno-sign-compare") -elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wno-comment -Wno-sign-compare -Wbackslash-newline-escape") endif() # In order to compile ngraph-tf with memory leak detection, run `cmake` with `-DCMAKE_BUILD_TYPE=Sanitize`. From 8fe9a79461705a84a8f39268154b4aec7e95a2d4 Mon Sep 17 00:00:00 2001 From: kanvi-nervana Date: Sat, 14 Sep 2019 13:23:44 -0700 Subject: [PATCH 9/9] Kanvi/fix bazel build for infer multi (#241) * fix bazel build for infer multi * fix formatting --- bazel/BUILD | 31 ++++++++++++++++++++ examples/cpp/infer_multiple_networks/BUILD | 33 ---------------------- tools/test_utils.py | 7 +++-- 3 files changed, 35 insertions(+), 36 deletions(-) delete mode 100644 examples/cpp/infer_multiple_networks/BUILD diff --git a/bazel/BUILD b/bazel/BUILD index 664318348..c701790b0 100644 --- a/bazel/BUILD +++ b/bazel/BUILD @@ -150,3 +150,34 @@ tf_cc_binary( linkstatic=True, visibility = ["//visibility:public"], ) + +tf_cc_binary( + name = 'infer_multi', + srcs = [ + "examples/cpp/infer_multiple_networks/main.cc", + "examples/cpp/infer_multiple_networks/inference_engine.h", + "examples/cpp/infer_multiple_networks/inference_engine.cc", + "examples/cpp/tf_label_image_utils.cc", + ], + deps = [ + "@org_tensorflow//tensorflow/cc:cc_ops", + "@org_tensorflow//tensorflow/cc:client_session", + "@org_tensorflow//tensorflow/core:tensorflow", + ":ngraph_bridge_lib", + "@ngraph//:cpu_backend", + ], + copts = [ + "-pthread", + "-std=c++11", + "-D_FORTIFY_SOURCE=2", + "-Wformat", + "-Wformat-security", + "-Wformat", + "-fstack-protector-all", + "-I ngraph_bridge", + "-I external/ngraph/src", + "-I logging", + ] + CXX_ABI, + linkstatic=False, + visibility = ["//visibility:public"], +) diff --git a/examples/cpp/infer_multiple_networks/BUILD b/examples/cpp/infer_multiple_networks/BUILD deleted file mode 100644 index 8ddf49dc8..000000000 --- a/examples/cpp/infer_multiple_networks/BUILD +++ /dev/null @@ -1,33 +0,0 @@ -load("//:cxx_abi_option.bzl", "CXX_ABI") -load("@org_tensorflow//tensorflow:tensorflow.bzl", "tf_cc_binary") - -tf_cc_binary( - name = 'infer_multi', - srcs = [ - "main.cc", - "inference_engine.h", - "inference_engine.cc", - "tf_label_image_utils.cc" - ], - deps = [ - "@org_tensorflow//tensorflow/cc:cc_ops", - "@org_tensorflow//tensorflow/cc:client_session", - "@org_tensorflow//tensorflow/core:tensorflow", - "//:ngraph_bridge_lib", - "@ngraph//:cpu_backend", - ], - copts = [ - "-pthread", - "-std=c++11", - "-D_FORTIFY_SOURCE=2", - "-Wformat", - "-Wformat-security", - "-Wformat", - "-fstack-protector-all", - "-I ngraph_bridge", - "-I external/ngraph/src", - "-I logging", - ] + CXX_ABI, - linkstatic=False, - visibility = ["//visibility:public"], -) \ No newline at end of file diff --git a/tools/test_utils.py b/tools/test_utils.py index d7bafc493..a640c9e5c 100755 --- a/tools/test_utils.py +++ b/tools/test_utils.py @@ -599,9 +599,7 @@ def run_bazel_build_test(venv_dir, build_dir): command_executor(['bazel-bin/hello_tf']) # Now built the bigger app - command_executor([ - 'bazel', 'build', '//examples/cpp/infer_multiple_networks:infer_multi' - ]) + command_executor(['bazel', 'build', 'infer_multi']) # Return to the original directory os.chdir(root_pwd) @@ -620,5 +618,8 @@ def run_bazel_build(): # Run the cpp app - hello_tf command_executor(['bazel-bin/hello_tf']) + # Now built the bigger app + command_executor(['bazel', 'build', 'infer_multi']) + # Return to the original directory os.chdir(root_pwd)