From 72a342d2120ac6407bd8144bb0dd65f2825bd31c Mon Sep 17 00:00:00 2001 From: wanglei648 Date: Wed, 8 Jun 2022 17:53:25 +0800 Subject: [PATCH] cleaning misra --- tf_adapter_2.x/npu_device/core/npu_managed_buffer.cpp | 4 ++-- tf_adapter_2.x/npu_device/core/npu_types.h | 2 +- tf_adapter_2.x/npu_device/core/npu_utils.cpp | 6 +++--- tf_adapter_2.x/npu_device/core/npu_utils.h | 4 ++-- .../npu_device/core/op_executors/npu_resource_op.cpp | 8 ++++---- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tf_adapter_2.x/npu_device/core/npu_managed_buffer.cpp b/tf_adapter_2.x/npu_device/core/npu_managed_buffer.cpp index 82decffc5..feaa6d7fc 100644 --- a/tf_adapter_2.x/npu_device/core/npu_managed_buffer.cpp +++ b/tf_adapter_2.x/npu_device/core/npu_managed_buffer.cpp @@ -239,9 +239,9 @@ tensorflow::Status NpuManagedBuffer::Create(ge::Format format, const std::vector break; } NPU_REQUIRES(dim_size >= 0, tensorflow::errors::InvalidArgument("Dim size invalid for shape ", VecToString(shape))); - NPU_REQUIRES(total_bytes <= total_bytes * dim_size, + NPU_REQUIRES(total_bytes <= total_bytes * static_cast(dim_size), tensorflow::errors::InvalidArgument("Total bytes overflow for shape ", VecToString(shape))); - total_bytes *= dim_size; + total_bytes *= static_cast(dim_size); } void *data = nullptr; NPU_REQUIRES_OK(NpuMemory::Malloc(total_bytes, &data)); diff --git a/tf_adapter_2.x/npu_device/core/npu_types.h b/tf_adapter_2.x/npu_device/core/npu_types.h index 26137888f..7fed0f3d3 100644 --- a/tf_adapter_2.x/npu_device/core/npu_types.h +++ b/tf_adapter_2.x/npu_device/core/npu_types.h @@ -36,7 +36,7 @@ const static uint64_t kEmptyGeGraphId = -2; class ResourceGenerator { public: - ResourceGenerator(std::shared_ptr def, int index) : def_(def), index_(index) {} + ResourceGenerator(const std::shared_ptr def, int index) : def_(def), index_(index) {} std::shared_ptr NodeDef() const { return def_; } int Index() const { return index_; } diff --git a/tf_adapter_2.x/npu_device/core/npu_utils.cpp b/tf_adapter_2.x/npu_device/core/npu_utils.cpp index f7953dd2e..c6f120a2f 100644 --- a/tf_adapter_2.x/npu_device/core/npu_utils.cpp +++ b/tf_adapter_2.x/npu_device/core/npu_utils.cpp @@ -326,7 +326,7 @@ tensorflow::Status GetSubgraphUnsupportedOps(const NpuDevice *device, const tens return tensorflow::Status::OK(); } -tensorflow::Status GetGraphUnsupportedOps(NpuDevice *device, tensorflow::Graph *graph, +tensorflow::Status GetGraphUnsupportedOps(NpuDevice *device, const tensorflow::Graph *graph, const tensorflow::FunctionLibraryDefinition *lib_def, std::set &unsupported_ops) { for (auto node : graph->op_nodes()) { @@ -458,7 +458,7 @@ uint64_t NextUUID() { * @brief: fix graph arg return value index * @param graph: graph */ -void FixGraphArgRetvalIndex(tensorflow::Graph *graph) { +void FixGraphArgRetvalIndex(const tensorflow::Graph *graph) { std::map indexed_args; std::map indexed_retvals; for (auto node : graph->nodes()) { @@ -550,7 +550,7 @@ size_t CreateChannelCapacity(const npu::TensorPartialShapes &shapes, const npu:: } else { result = shapes[i].num_elements() * tensorflow::DataTypeSize(data_type); } - if (result > kSizeTMaxsize - total_sizes) { + if (result > kSizeTMaxsize - static_cast(total_sizes)) { return kInvalidCpacity; } total_sizes += static_cast(result); diff --git a/tf_adapter_2.x/npu_device/core/npu_utils.h b/tf_adapter_2.x/npu_device/core/npu_utils.h index e7ef6f21c..28b8eb1d5 100644 --- a/tf_adapter_2.x/npu_device/core/npu_utils.h +++ b/tf_adapter_2.x/npu_device/core/npu_utils.h @@ -108,7 +108,7 @@ struct ResourceCompare { void PruneGraphByFunctionSignature(const tensorflow::FunctionDef &fdef, tensorflow::Graph *g, bool keep_signature = false); -void FixGraphArgRetvalIndex(tensorflow::Graph *graph); +void FixGraphArgRetvalIndex(const tensorflow::Graph *graph); bool IsSubstituteNode(const tensorflow::Node *node); @@ -124,7 +124,7 @@ std::set GetNodeSubgraph(const tensorflow::Node *node); tensorflow::Status GetSubgraphUnsupportedOps(const NpuDevice *device, const tensorflow::Node *node, const tensorflow::FunctionLibraryDefinition *lib_def, std::set &unsupported_ops); -tensorflow::Status GetGraphUnsupportedOps(NpuDevice *device, tensorflow::Graph *graph, +tensorflow::Status GetGraphUnsupportedOps(NpuDevice *device, const tensorflow::Graph *graph, const tensorflow::FunctionLibraryDefinition *lib_def, std::set &unsupported_ops); diff --git a/tf_adapter_2.x/npu_device/core/op_executors/npu_resource_op.cpp b/tf_adapter_2.x/npu_device/core/op_executors/npu_resource_op.cpp index 3656edf76..966c96de8 100644 --- a/tf_adapter_2.x/npu_device/core/op_executors/npu_resource_op.cpp +++ b/tf_adapter_2.x/npu_device/core/op_executors/npu_resource_op.cpp @@ -115,7 +115,7 @@ void NpuResourceOp::RunImpl(TFE_Context *context, NpuDevice *device, int num_inp for (int i = 0; i < num_inputs; i++) { if (types[static_cast(i)] == tensorflow::DT_RESOURCE) { std::shared_ptr generator = nullptr; - const auto &handle = npu_resources[resource_index++]; + const auto &handle = npu_resources[static_cast(resource_index++)]; device->GetResourceGeneratorDef(handle, &generator); NPU_CTX_REQUIRES(status, generator != nullptr, tensorflow::errors::Internal("Unknown npu resource ", handle.DebugString())); @@ -131,7 +131,7 @@ void NpuResourceOp::RunImpl(TFE_Context *context, NpuDevice *device, int num_inp } else { tensorflow::Node *node = nullptr; NPU_CTX_REQUIRES_OK(status, tensorflow::NodeBuilder("arg_" + std::to_string(i), "_Arg") - .Attr("T", types[i]) + .Attr("T", types[static_cast(i)]) .Attr("index", arg_index++) .Attr("_output_shapes", {shapes[static_cast(i)]}) .Finalize(graph.get(), &node)); @@ -146,7 +146,7 @@ void NpuResourceOp::RunImpl(TFE_Context *context, NpuDevice *device, int num_inp tensorflow::Node *node = nullptr; NPU_CTX_REQUIRES_OK(status, tensorflow::NodeBuilder("ret_" + std::to_string(i), "_Retval") .Input(target_node, i) - .Attr("T", output_types[i]) + .Attr("T", output_types[static_cast(i)]) .Attr("index", i) .Finalize(graph.get(), &node)); } @@ -159,7 +159,7 @@ void NpuResourceOp::RunImpl(TFE_Context *context, NpuDevice *device, int num_inp std::string suffix = npu_resources[0].name(); for (int i = 1; i < static_cast(npu_resources.size()); i++) { suffix += "."; - suffix += npu_resources[i].name(); + suffix += npu_resources[static_cast(i)].name(); } graph_dumper.Dump(suffix, graph->ToGraphDefDebug()); } -- Gitee