提交 87668d6e 编写于 作者: Z z00505269

remove predict

上级 6c4ee3f3
......@@ -60,11 +60,6 @@ if(ENABLE_GPU)
add_compile_definitions(ENABLE_GPU)
endif ()
## make flatuffer files
include_directories("${CMAKE_BINARY_DIR}/predict/schema/inner")
file(GLOB_RECURSE FLATBUFFER_IN RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "predict/schema/*.fbs")
set(FLATBUFFER_OU "${CMAKE_BINARY_DIR}/predict/schema/inner")
ms_build_flatbuffers("${FLATBUFFER_IN}" "${FLATBUFFER_IN}" flat_input "${FLATBUFFER_OU}")
## make protobuf files
file(COPY "${ms_onnx_INC}/onnx/onnx.proto" DESTINATION ${CMAKE_BINARY_DIR}/proto)
......@@ -104,13 +99,9 @@ endif ()
if (ENABLE_D)
include_directories("${CMAKE_BINARY_DIR}/backend/kernel_compiler/aicpu")
include_directories("${CMAKE_BINARY_DIR}/predict/generator/ir")
file(GLOB_RECURSE PROTO_IN RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "backend/kernel_compiler/aicpu/proto/*.proto")
ms_protobuf_generate(PROTOSRCS PROTOHDRS ${PROTO_IN})
file(GLOB_RECURSE PROTO_INNER RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "predict/proto/*.proto")
ms_protobuf_generate(PREDICT_PROTOSRCS PREDICT_PROTOHDRS ${PROTO_INNER})
file(GLOB_RECURSE PROTO_DUMP RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "runtime/device/ascend/dump/proto/*.proto")
ms_protobuf_generate(DUMP_PROTOSRCS PROTOHDRS ${PROTO_DUMP})
......@@ -139,7 +130,7 @@ set(SUB_COMP
frontend/operator
pipeline/jit
pipeline/pynative
common debug gvar predict pybind_api utils vm
common debug gvar pybind_api utils vm
)
foreach (_comp ${SUB_COMP})
......@@ -147,7 +138,7 @@ foreach (_comp ${SUB_COMP})
string(REPLACE "/" "_" sub ${_comp})
if (TARGET _mindspore_${sub}_obj)
list(APPEND SUB_OBJECTS_SRC $<TARGET_OBJECTS:_mindspore_${sub}_obj>)
add_dependencies(_mindspore_${sub}_obj proto_input flat_input)
add_dependencies(_mindspore_${sub}_obj proto_input )
endif ()
endforeach ()
add_subdirectory(${CMAKE_SOURCE_DIR}/mindspore/core/base base)
......@@ -158,7 +149,7 @@ add_subdirectory(${CMAKE_SOURCE_DIR}/mindspore/core/utils util)
list(APPEND SUB_OBJECTS_SRC $<TARGET_OBJECTS:_mindspore_core_utils_obj>)
add_subdirectory(${CMAKE_SOURCE_DIR}/mindspore/core/ir ir)
list(APPEND SUB_OBJECTS_SRC $<TARGET_OBJECTS:_mindspore_ir_obj>)
add_dependencies(_mindspore_core_utils_obj _mindspore_base_obj _mindspore_ir_obj _mindspore_abstract_obj proto_input flat_input)
add_dependencies(_mindspore_core_utils_obj _mindspore_base_obj _mindspore_ir_obj _mindspore_abstract_obj proto_input )
set_property(SOURCE ${SUB_OBJECTS_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_ME)
add_library(mindspore STATIC ${SUB_OBJECTS_SRC})
......
......@@ -34,7 +34,6 @@
#include "runtime/device/kernel_adjust.h"
#include "runtime/device/ascend/ascend_stream_assign.h"
#include "runtime/device/ascend/ascend_label_assign.h"
#include "predict/predict.h"
#include "backend/session/anf_runtime_algorithm.h"
#include "ir/scalar.h"
#include "debug/anf_ir_dump.h"
......@@ -303,8 +302,6 @@ void AscendSession::CompileChildGraph(const KernelGraphPtr &child_graph) {
save_graphs_path + "/" + "select_kernel_after" + "_graph_" + std::to_string(child_graph->graph_id()) + ".ir";
DumpIR(file_path, child_graph);
}
// convert kernel Graph to model
predictmodel::StepConvertGraph(child_graph);
// optimize graph
HardwareOptimize(child_graph);
// assign static memory of parameters
......@@ -333,8 +330,6 @@ void AscendSession::RunGraph(const GraphId &graph_id, const std::vector<tensor::
InitPSParamAndOptim(kernel_graph, inputs);
}
#endif
// convert inputs to model
predictmodel::StepConvertWeight(inputs);
{
py::gil_scoped_release release;
// run task on device
......@@ -1036,8 +1031,6 @@ void AscendSession::HardwareOptimize(NotNull<KernelGraphPtr> graph,
memo->insert(graph.get());
MS_LOG(INFO) << "Start to do HardwareOptimize in graph: " << graph->graph_id();
// convert kernel Graph to model
predictmodel::StepConvertGraph(graph.get());
HardwareOptimize(graph.get());
for (auto &child_graph : graph->child_graph_order()) {
......
......@@ -23,7 +23,6 @@
#include "common/utils.h"
#include "backend/session/anf_runtime_algorithm.h"
#include "runtime/device/kernel_runtime.h"
#include "predict/predict.h"
#include "backend/kernel_compiler/cpu/cpu_kernel_factory.h"
#include "runtime/device/cpu/kernel_select_cpu.h"
#include "backend/optimizer/common/optimizer.h"
......@@ -79,7 +78,6 @@ GraphId CPUSession::CompileGraph(const AnfNodePtrList &lst, const AnfNodePtrList
Optimize(graph);
}
#endif
predictmodel::StepConvertGraph(graph);
MS_LOG(INFO) << "Build kernel";
BuildKernel(graph.get());
MS_LOG(INFO) << "Assign kernel address";
......@@ -100,7 +98,6 @@ void CPUSession::RunGraph(const GraphId &graph_id, const std::vector<tensor::Ten
std::vector<tensor::TensorPtr> need_sync_outputs;
runtime_.BindInputOutput(kernel_graph.get(), inputs, outputs, &need_sync_outputs);
MS_LOG(INFO) << "Run graph start";
predictmodel::StepConvertWeight(inputs);
auto execution_order = kernel_graph->execution_order();
Reorder(&execution_order);
......
......@@ -31,7 +31,6 @@
#include "backend/optimizer/gpu/replace_momentum_cast_fusion.h"
#include "backend/optimizer/gpu/replace_addn_fusion.h"
#include "runtime/device/kernel_runtime_manager.h"
#include "predict/predict.h"
#include "common/utils.h"
#include "common/trans.h"
#include "utils/context/ms_context.h"
......@@ -190,8 +189,6 @@ GraphId GPUSession::CompileGraph(const AnfNodePtrList &lst, const AnfNodePtrList
// Assign parameter keys.
AssignParamKey(graph);
#endif
// Convert kernel Graph to model
predictmodel::StepConvertGraph(graph);
// Start gpu kernel runtime
StartKernelRT();
// Dump .pb graph before hardware optimization
......@@ -245,8 +242,6 @@ void GPUSession::RunGraph(const GraphId &graph_id, const std::vector<tensor::Ten
}
#endif
MS_EXCEPTION_IF_NULL(kernel_graph);
// Convert inputs to model
predictmodel::StepConvertWeight(inputs);
{
py::gil_scoped_release gil_release;
// Run graph on GPU
......
......@@ -123,10 +123,6 @@ PYBIND11_MODULE(_c_expression, m) {
"Set whether to enable reduce precision.")
.def("get_save_graphs_path", &mindspore::MsContext::save_graphs_path, "Get save graphs path.")
.def("set_save_graphs_path", &mindspore::MsContext::set_save_graphs_path, "Set save graphs path.")
.def("get_save_ms_model_flag", &mindspore::MsContext::save_ms_model_flag, "Get whether to save ms model.")
.def("set_save_ms_model_flag", &mindspore::MsContext::set_save_ms_model_flag, "Set whether to save ms model.")
.def("get_save_ms_model_path", &mindspore::MsContext::save_ms_model_path, "Get path to save ms model.")
.def("set_save_ms_model_path", &mindspore::MsContext::set_save_ms_model_path, "Set path to save ms model")
.def("get_enable_dump", &mindspore::MsContext::enable_dump, "Get whether to enable dump.")
.def("set_enable_dump", &mindspore::MsContext::set_enable_dump, "Set whether to enable dump.")
.def("get_save_dump_path", &mindspore::MsContext::save_dump_path, "Get path to dump.")
......
file(GLOB_RECURSE _PREDICT_SRC_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
"predict.cc"
"generator/utils/ir_model_util.cc"
"converter/*.cc"
"converter/attr_utils/*.cc"
"converter/lite_model/*.cc"
"converter/lite_model/operations/*.cc"
)
if (ENABLE_D)
file(GLOB_RECURSE _D_SRC_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "generator/ir/*.cc")
list(APPEND _PREDICT_SRC_LIST ${_D_SRC_LIST})
endif ()
add_library(_mindspore_predict_obj OBJECT ${_PREDICT_SRC_LIST})
\ No newline at end of file
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "predict/converter/attr_utils/convert_util.h"
namespace mindspore {
namespace predict {
namespace utils {
TypePtr GetTypePtr(const AnfNodePtr &anf_node) {
MS_EXCEPTION_IF_NULL(anf_node);
TypePtr type_ptr = anf_node->Type();
MS_EXCEPTION_IF_NULL(type_ptr);
if (type_ptr->isa<TensorType>()) {
auto tensor_ptr = type_ptr->cast<TensorTypePtr>();
MS_EXCEPTION_IF_NULL(tensor_ptr);
TypePtr elem = tensor_ptr->element();
return elem;
} else if (type_ptr->isa<Tuple>()) {
auto tuple_ptr = type_ptr->cast<TuplePtr>();
MS_EXCEPTION_IF_NULL(tuple_ptr);
auto tuple_i = (*tuple_ptr)[0];
MS_EXCEPTION_IF_NULL(tuple_i);
if (tuple_i->isa<TensorType>()) {
auto tensor_ptr = tuple_i->cast<TensorTypePtr>();
MS_EXCEPTION_IF_NULL(tensor_ptr);
TypePtr elem = tensor_ptr->element();
MS_EXCEPTION_IF_NULL(elem);
return elem;
} else if (tuple_i->isa<Number>()) {
return type_ptr;
} else {
MS_LOG(EXCEPTION) << "unsupported type: " << type_ptr->ToString();
}
} else if (type_ptr->isa<Number>()) {
return type_ptr;
}
std::string type_name = type_ptr->ToString();
MS_LOG(EXCEPTION)
<< "The output type of node should be a tensor type a number or a tuple of tensor type, but this is: "
<< type_name;
}
MsDataType GetMSDataType(TypeId ori_data_type) {
MsDataType dst_data_type;
switch (ori_data_type) {
case kNumberTypeFloat16:
dst_data_type = mindspore::predict::DataType_DT_FLOAT16;
return dst_data_type;
case kNumberTypeFloat32:
dst_data_type = mindspore::predict::DataType_DT_FLOAT;
return dst_data_type;
case kNumberTypeInt8:
dst_data_type = mindspore::predict::DataType_DT_INT8;
return dst_data_type;
case kNumberTypeInt32:
dst_data_type = mindspore::predict::DataType_DT_INT32;
return dst_data_type;
case kNumberTypeUInt8:
dst_data_type = mindspore::predict::DataType_DT_UINT8;
return dst_data_type;
case kNumberTypeUInt32:
dst_data_type = mindspore::predict::DataType_DT_UINT32;
return dst_data_type;
case kTypeUnknown:
dst_data_type = mindspore::predict::DataType_DT_UNDEFINED;
return dst_data_type;
default:
MS_LOG(EXCEPTION) << "Ms don't support this DataType";
}
}
MsFormat GetMsFormat(const std::string &format_str) {
if (format_str == kOpFormat_DEFAULT) {
MsFormat ms_format = predict::Format_NCHW;
return ms_format;
} else {
// all middle format default to NCHW
return predict::Format_NCHW;
}
}
TensorPtr GetParaAscendTensor(const AnfNodePtr &anf_node) {
MS_EXCEPTION_IF_NULL(anf_node);
if (!anf_node->isa<Parameter>()) {
return nullptr;
}
auto device_type_id = AnfAlgo::GetOutputDeviceDataType(anf_node, 0);
// device type_ptr
auto device_type_ptr = GetTypePtr(anf_node);
// device shape
auto shape = AnfAlgo::GetOutputDeviceShape(anf_node, 0);
std::vector<int> tensor_shape;
(void)std::transform(shape.begin(), shape.end(), std::back_inserter(tensor_shape), SizeToInt);
// device format
auto format = AnfAlgo::GetOutputFormat(anf_node, 0);
// device tensor
TensorPtr device_tensor = std::make_shared<tensor::Tensor>(device_type_id, tensor_shape);
// device info
device_tensor->SetDeviceInfo(format, device_type_ptr);
return device_tensor;
}
TensorPtr GetParaCpuTensor(const AnfNodePtr &anf_node) {
MS_EXCEPTION_IF_NULL(anf_node);
if (!(anf_node->isa<Parameter>())) {
return nullptr;
} else {
auto ori_type_id = AnfAlgo::GetOutputInferDataType(anf_node, 0);
auto ori_type_ptr = GetTypePtr(anf_node);
auto ori_shape = AnfAlgo::GetOutputInferShape(anf_node, 0);
std::vector<int> tensor_shape;
(void)std::transform(ori_shape.begin(), ori_shape.end(), std::back_inserter(tensor_shape), SizeToInt);
auto ori_format = AnfAlgo::GetOutputFormat(anf_node, 0);
TensorPtr cpu_tensor = std::make_shared<tensor::Tensor>(ori_type_id, tensor_shape);
cpu_tensor->SetDeviceInfo(ori_format, ori_type_ptr);
return cpu_tensor;
}
}
TensorPtr GetValueTensor(const ValueNodePtr &const_node) {
MS_EXCEPTION_IF_NULL(const_node);
auto value_ptr = const_node->value();
MS_EXCEPTION_IF_NULL(value_ptr);
if (!value_ptr->isa<tensor::Tensor>()) {
return nullptr;
}
TensorPtr tensor = value_ptr->cast<TensorPtr>();
MS_EXCEPTION_IF_NULL(tensor);
auto data_type = tensor->Dtype();
MS_EXCEPTION_IF_NULL(data_type);
auto type_id = data_type->type_id();
auto shape = tensor->shape();
TensorPtr tensor_constant = std::make_shared<tensor::Tensor>(type_id, shape);
tensor_constant->SetDeviceInfo(tensor->device_info().format_, tensor->device_info().data_type_);
return tensor_constant;
}
TensorPtr GetKernelCpuTensor(const CNodePtr &c_node_ptr, size_t inx) {
if (c_node_ptr == nullptr || inx >= AnfAlgo::GetOutputTensorNum(c_node_ptr)) {
MS_LOG(ERROR) << "GetKernelCpuTensor failed";
return nullptr;
}
auto ori_shape = AnfAlgo::GetOutputInferShape(c_node_ptr, inx);
auto ori_type_id = AnfAlgo::GetOutputInferDataType(c_node_ptr, inx);
std::vector<int> tensor_shape;
(void)std::transform(ori_shape.begin(), ori_shape.end(), std::back_inserter(tensor_shape), SizeToInt);
auto ori_output_type = GetTypePtr(c_node_ptr);
TensorPtr device_tensor = std::make_shared<tensor::Tensor>(ori_type_id, tensor_shape);
auto format = AnfAlgo::GetOutputFormat(c_node_ptr, inx);
device_tensor->SetDeviceInfo(format, ori_output_type);
return device_tensor;
}
TensorPtr GetKernelAscendTensor(const CNodePtr &c_node_ptr, size_t inx) {
if (c_node_ptr == nullptr || inx >= AnfAlgo::GetOutputTensorNum(c_node_ptr)) {
MS_LOG(ERROR) << "GetKernelAscendTensor failed";
return nullptr;
}
auto shape = AnfAlgo::GetOutputDeviceShape(c_node_ptr, inx);
std::vector<int> tensor_shape;
(void)std::transform(shape.begin(), shape.end(), std::back_inserter(tensor_shape), SizeToInt);
auto format = AnfAlgo::GetOutputFormat(c_node_ptr, inx);
auto type_id = AnfAlgo::GetOutputDeviceDataType(c_node_ptr, inx);
auto output_type_ptr = GetTypePtr(c_node_ptr);
TensorPtr device_tensor = std::make_shared<tensor::Tensor>(type_id, tensor_shape);
device_tensor->SetDeviceInfo(format, output_type_ptr);
return device_tensor;
}
TensorPtr GetOutputTensor(const AnfNodePtr &out_node, size_t inx) {
MS_EXCEPTION_IF_NULL(out_node);
auto shape = AnfAlgo::GetOutputInferShape(out_node, inx);
std::vector<int> tensor_shape;
(void)std::transform(shape.begin(), shape.end(), std::back_inserter(tensor_shape), SizeToInt);
auto type_id = AnfAlgo::GetOutputInferDataType(out_node, inx);
auto output_type_ptr = GetTypePtr(out_node);
auto format = AnfAlgo::GetOutputFormat(out_node, inx);
TensorPtr output_tensor = std::make_shared<tensor::Tensor>(type_id, tensor_shape);
output_tensor->SetDeviceInfo(format, output_type_ptr);
return output_tensor;
}
bool FindNodeInMap(const std::unordered_map<MsKernelKey, int> &node_map, const AnfNodePtr &node) {
return std::any_of(node_map.begin(), node_map.end(),
[node](const std::pair<MsKernelKey, int> &kernel_key) { return kernel_key.first == node.get(); });
}
bool SaveDeviceModelUtil(const std::shared_ptr<GraphDefT> &new_ms_graph_ptr, const std::string &save_path_name,
SubGraphDefT *sub_graph) {
MS_EXCEPTION_IF_NULL(new_ms_graph_ptr);
MS_EXCEPTION_IF_NULL(sub_graph);
// save mindspore schema to file
new_ms_graph_ptr->name = "default_graph";
std::unique_ptr<mindspore::predict::SubGraphDefT> sub_graph_ptr(sub_graph);
new_ms_graph_ptr->subgraphs.emplace_back(std::move(sub_graph_ptr));
// get flatbuffer builder
flatbuffers::FlatBufferBuilder builder(1024);
auto offset = mindspore::predict::GraphDef::Pack(builder, new_ms_graph_ptr.get());
builder.Finish(offset);
auto size = builder.GetSize();
if (size == 0) {
MS_LOG(ERROR) << "builder has no size";
return false;
}
auto content = builder.GetBufferPointer();
std::ofstream output(save_path_name);
if (!output.is_open()) {
MS_LOG(EXCEPTION) << "mindspore.mindspoire output failed";
}
(void)output.write((const char *)content, size);
output.close();
return true;
}
} // namespace utils
} // namespace predict
} // namespace mindspore
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MINDSPORE_CCSRC_PREDICT_CONVERTER_ATTR_UTILS_CONVERT_UTIL_H_
#define MINDSPORE_CCSRC_PREDICT_CONVERTER_ATTR_UTILS_CONVERT_UTIL_H_
#include <vector>
#include <utility>
#include <algorithm>
#include <memory>
#include <unordered_map>
#include <string>
#include <fstream>
#include "ir/tensor.h"
#include "backend/session/anf_runtime_algorithm.h"
#include "predict/schema/inner/ms_generated.h"
using TensorPtr = mindspore::tensor::TensorPtr;
using TensorPtrList = std::vector<mindspore::tensor::TensorPtr>;
using AllOutputTensors = std::unordered_map<int, TensorPtrList>;
using OpDefT = mindspore::predict::OpDefT;
using GraphDefT = mindspore::predict::GraphDefT;
using TensorDefT = mindspore::predict::TensorDefT;
using SubGraphDefT = mindspore::predict::SubGraphDefT;
using SubGraphPtr = std::unique_ptr<mindspore::predict::SubGraphDefT>;
using MsDataType = mindspore::predict::DataType;
using MsFormat = mindspore::predict::Format;
using MsKernelKey = void *;
namespace mindspore {
namespace predict {
namespace utils {
TypePtr GetTypePtr(const AnfNodePtr &anf_node);
MsDataType GetMSDataType(TypeId ori_data_type);
MsFormat GetMsFormat(const std::string &format_str);
TensorPtr GetParaAscendTensor(const AnfNodePtr &anf_node);
TensorPtr GetParaCpuTensor(const AnfNodePtr &anf_node);
TensorPtr GetValueTensor(const ValueNodePtr &const_node);
TensorPtr GetKernelCpuTensor(const CNodePtr &c_node_ptr, size_t inx);
TensorPtr GetKernelAscendTensor(const CNodePtr &c_node_ptr, size_t inx);
TensorPtr GetOutputTensor(const AnfNodePtr &out_node, size_t inx);
bool FindNodeInMap(const std::unordered_map<MsKernelKey, int> &Nodemap, const AnfNodePtr &node);
bool SaveDeviceModelUtil(const std::shared_ptr<GraphDefT> &new_ms_graph_ptr, const std::string &save_path_name,
SubGraphDefT *sub_graph_def_t);
} // namespace utils
} // namespace predict
} // namespace mindspore
#endif // MINDSPORE_CCSRC_PREDICT_CONVERTER_ATTR_UTILS_CONVERT_UTIL_H_
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MINDSPORE_CCSRC_PREDICT_CONVERTER_CPU_ATTR_UTILS_OP_ATTR_TYPE_H_
#define MINDSPORE_CCSRC_PREDICT_CONVERTER_CPU_ATTR_UTILS_OP_ATTR_TYPE_H_
namespace mindspore {
namespace predict {
namespace convert {
typedef enum CpuOpType {
CPU_OP_PAD = 0,
CPU_OP_MAXIMUM,
CPU_OP_CONCAT,
CPU_OP_SOFTMAX,
CPU_OP_ACTIVATION,
CPU_OP_CONV2D,
CPU_OP_FUSEDBATCHNORM,
CPU_OP_CAFFEBATCHNORM,
CPU_OP_SQUEEZE,
CPU_OP_BIASADD,
CPU_OP_POOLING,
CPU_OP_DEPTHWISECONV2D,
CPU_OP_DEDEPTHWISECONV2D,
CPU_OP_RESIZE,
CPU_OP_DETECTIONPOSTPROCESS,
CPU_OP_FULLCONNECTION,
CPU_OP_MEAN,
CPU_OP_DECONV2D,
CPU_OP_SCALE,
CPU_OP_ELTWISE,
CPU_OP_ADD,
CPU_OP_SLICE,
CPU_OP_MUL,
CPU_OP_EXP,
CPU_OP_RESHAPE,
CPU_OP_POWER,
CPU_OP_ARGMAX,
CPU_OP_ARGMAX_NETOUTPUT,
CPU_OP_MATMUL,
CPU_OP_CAFFEPRELU,
CPU_OP_STRIDEDSLICE,
CPU_OP_STACK,
CPU_OP_RANGE,
CPU_OP_EXPANDDIMS,
CPU_OP_TILE,
CPU_OP_CAST,
CPU_OP_CAFFECROP,
CPU_OP_PRESERVEED = 37
} CpuOpType_t;
} // namespace convert
} // namespace predict
} // namespace mindspore
#endif // MINDSPORE_CCSRC_PREDICT_CONVERTER_CPU_ATTR_UTILS_OP_ATTR_TYPE_H_
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "predict/converter/executor_tensor.h"
namespace mindspore {
namespace executor {
int TensorCache::addExTensor(int tensor_key, const TensorPtr &tensor, int refCount, const std::vector<int> &host_shape,
ExTensorType stable, bool inc) {
MS_EXCEPTION_IF_NULL(tensor);
TensorPtr tmp_tensor = tensor;
ExTensorPtr ex_tensor_ptr =
std::make_shared<ExTensor>(tensor_key, tmp_tensor, refCount, nodeIndex, host_shape, stable);
int pre_index = ex_tensor_ptr->index_;
if (inc) {
nodeIndex++;
}
// no need to judge,just add to map directly
tensors[tensor_key].push_back(ex_tensor_ptr);
return pre_index;
}
std::vector<ExTensorPtr> TensorCache::findTensor(int key) {
std::vector<ExTensorPtr> ex_tensors;
auto iter = tensors.find(key);
if (iter != tensors.end()) {
return iter->second;
} else {
MS_LOG(INFO) << "can not find any tensorlist";
return ex_tensors;
}
}
void TensorCache::deleteTensor(int key) { (void)tensors.erase(key); }
} // namespace executor
} // namespace mindspore
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MINDSPORE_CCSRC_PREDICT_CONVERTER_EXECUTOR_TENSOR_H_
#define MINDSPORE_CCSRC_PREDICT_CONVERTER_EXECUTOR_TENSOR_H_
#include <vector>
#include <memory>
#include <unordered_map>
#include <utility>
#include "ir/tensor.h"
namespace mindspore {
namespace executor {
using TensorPtr = tensor::TensorPtr;
static constexpr int MS_MAX_REFCOUNT = 999;
enum ExTensorType { INPUTDATA, WEIGHTS, CONSTANT, KERNEL, OUTPUT };
class ExTensor {
public:
int key_;
TensorPtr device_tensor_ptr_;
int ref_count_;
int index_;
std::vector<int> host_shape_;
ExTensorType stable_;
ExTensor(int key, TensorPtr tensor_ptr, int ref_count, int index, std::vector<int> host_shape,
ExTensorType ex_tensor_type)
: key_(key),
device_tensor_ptr_(std::move(tensor_ptr)),
ref_count_(ref_count),
index_(index),
host_shape_(std::move(host_shape)),
stable_(ex_tensor_type) {}
~ExTensor() { host_shape_.clear(); }
};
using ExTensorPtr = std::shared_ptr<ExTensor>;
class TensorCache {
public:
TensorCache() = default;
~TensorCache() { tensors.clear(); }
int addExTensor(int tensor_key, const TensorPtr &tensor, int refCount, const std::vector<int> &host_shape,
ExTensorType stable, bool inc = true);
// just adjust for dynamic tensor
std::vector<ExTensorPtr> findTensor(int key);
void deleteTensor(int key);
const std::unordered_map<int, std::vector<ExTensorPtr>> &GetCachedTensor() const { return tensors; }
private:
std::unordered_map<int, std::vector<ExTensorPtr>> tensors;
int nodeIndex = 0;
};
using TensorCachePtr = std::shared_ptr<TensorCache>;
} // namespace executor
} // namespace mindspore
#endif // MINDSPORE_CCSRC_PREDICT_CONVERTER_EXECUTOR_TENSOR_H_
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MINDSPORE_CCSRC_PREDICT_CONVERTER_KERNEL_TO_MS_H_
#define MINDSPORE_CCSRC_PREDICT_CONVERTER_KERNEL_TO_MS_H_
#include <string>
#include <unordered_map>
#include <memory>
#include <vector>
#include <utility>
#include "backend/session/kernel_graph.h"
#include "predict/converter/executor_tensor.h"
#include "predict/schema/inner/ms_generated.h"
#include "predict/converter/attr_utils/convert_util.h"
static constexpr size_t kTupleGetItemIndex = 2;
namespace mindspore {
namespace executor {
using KernelGraphPtr = std::shared_ptr<mindspore::session::KernelGraph>;
enum ConvertMode { kConvertCpuMode, kConvertAscendMode, kConvertUnused };
enum TargetMode { kCPUTarget, kGPUTarget, kUnknowTarget };
class Kernel2Ms {
public:
static Kernel2Ms &GetInstance();
Kernel2Ms(const Kernel2Ms &) = delete;
Kernel2Ms &operator=(const Kernel2Ms &) = delete;
bool KernelGraph2MsGraph(const KernelGraphPtr &kernel_graph_ptr);
bool KernelInput2MS(const std::vector<TensorPtr> &input_tensors);
ConvertMode convert_mode() const { return convert_mode_; }
void set_convert_mode(ConvertMode convert_mode) { convert_mode_ = convert_mode; }
TargetMode device_target() const { return device_target_; }
void set_device_target(TargetMode device_target) { device_target_ = device_target; }
bool SaveDeviceModel(const std::shared_ptr<GraphDefT> &new_ms_graph_ptr, const std::string &save_path_name);
private:
Kernel2Ms() : graph_index_(0) {}
void ReleaseContextRes();
~Kernel2Ms() = default;
bool SetAllTensors(const TensorCachePtr &tensor_cache, SubGraphDefT *sub_graph_def_t);
bool SetOpInputIdx(const CNodePtr &c_node_ptr, const TensorCachePtr &tensor_cache, OpDefT *ms_node);
bool SetOpOutputIdx(const CNodePtr &c_node_ptr, const TensorPtr &output_tensor, const TensorCachePtr &tensor_cache,
int ref_count, size_t order_index, OpDefT *ms_node);
bool SetGraphOutputIdx(const KernelGraphPtr &kernel_graph_ptr, const TensorCachePtr &tensor_cache,
SubGraphDefT *sub_graph_def_t, AllOutputTensors *all_output_tensors);
void TransformGraphIndx();
void GetRealInpoutsPtr(const AnfNodePtr &node, std::vector<AnfNodePtr> *real_inputs,
std::vector<size_t> *real_output_idx);
bool InitGraphIndx(const KernelGraphPtr &kernel_graph_ptr);
bool InitGraphInputsIndx(const KernelGraphPtr &kernel_graph_ptr);
bool InitGraphValueNodesIndx(const KernelGraphPtr &kernel_graph_ptr);
bool InitGraphOpsIndx(const KernelGraphPtr &kernel_graph_ptr);
bool InitGraphOutputsIndx(const KernelGraphPtr &kernel_graph_ptr);
bool SetGraphInputTensors(const KernelGraphPtr &kernel_graph_ptr, const TensorCachePtr &tensor_cache,
SubGraphDefT *sub_graph_def_t);
bool SetGraphValueTensors(const KernelGraphPtr &kernel_graph_ptr, const TensorCachePtr &tensor_cache);
bool SetGraphOpTensors(const KernelGraphPtr &kernel_graph_ptr, const TensorCachePtr &tensor_cache,
SubGraphDefT *sub_graph_def_t);
std::vector<uint32_t> GetAllInputWeightIdxs() const { return input_weight_idxs_; }
std::vector<uint32_t> GetAllInputIdxs() const { return all_input_idxs_; }
bool CheckInputSizes(const std::vector<TensorPtr> &input_tensors, const std::vector<uint32_t> &all_input_idxs);
bool SetMemResue() const;
SubGraphPtr sub_ms_graph_;
AllOutputTensors all_output_tensors_;
std::vector<OpDefT *> tmp_op_nodes_;
std::unordered_map<MsKernelKey, int> node_indexs_;
std::unordered_map<int, MsKernelKey> index_nodes_;
int graph_index_ = 0;
TensorCachePtr tensor_cache_ptr_ = nullptr;
ConvertMode convert_mode_ = kConvertCpuMode;
TargetMode device_target_ = kCPUTarget;
std::vector<uint32_t> input_weight_idxs_;
std::vector<uint32_t> all_input_idxs_;
};
using Kernel2MsPtr = std::shared_ptr<Kernel2Ms>;
} // namespace executor
} // namespace mindspore
#endif // MINDSPORE_CCSRC_PREDICT_CONVERTER_KERNEL_TO_MS_H_
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "predict/converter/lite_model/op_attr_packer.h"
#include "./securec.h"
namespace mindspore {
namespace predict {
namespace convert {
// forward declare
bool Conv2dPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op);
bool MatMulPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op);
bool BiasAddPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op);
bool ReshapePacker(const CNodePtr &c_node_ptr, OpDefT *ms_op);
bool ActivationPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op);
bool PoolingPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op);
bool FusedBatchNormPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op);
bool AddPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op);
bool CastPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op);
bool MeanPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op);
bool SoftmaxPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op);
bool ScalePacker(const CNodePtr &c_node_ptr, OpDefT *ms_op);
bool AddFoldPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op);
bool ArgMaxPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op);
bool BatchNormFoldPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op);
bool FakeQuantWithMinMaxPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op);
bool FakeQuantWithMinMaxPerChannelPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op);
bool MulPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op);
bool MulFoldPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op);
bool SqueezePacker(const CNodePtr &c_node_ptr, OpDefT *ms_op);
OpAttrFactory::OpAttrFactory() {
pack_funs_ = {{"Conv2D", Conv2dPacker},
{"MatMul", MatMulPacker},
{"BiasAdd", BiasAddPacker},
{"Reshape", ReshapePacker},
{"Activation", ActivationPacker},
{"ReLU", ActivationPacker},
{"ReLU6", ActivationPacker},
{"EReLU", ActivationPacker},
{"LeakyReLU", ActivationPacker},
{"Sigmoid", ActivationPacker},
{"Softsign", ActivationPacker},
{"Softplus", ActivationPacker},
{"Tanh", ActivationPacker},
{"HSwish", ActivationPacker},
{"HSigmoid", ActivationPacker},
{"MaxPool", PoolingPacker},
{"MaxPool2D", PoolingPacker},
{"MeanPool", PoolingPacker},
{"GlobalPool", PoolingPacker},
{"FusedBatchNorm", FusedBatchNormPacker},
{"FusedBatchNormGrad", FusedBatchNormPacker},
{"Cast", CastPacker},
{"TensorAdd", AddPacker},
{"SoftMax", SoftmaxPacker},
{"SimpleMean", MeanPacker},
{"ReduceMean", MeanPacker},
{"AddFold", AddFoldPacker},
{"ArgMax", ArgMaxPacker},
{"BatchNorm", BatchNormFoldPacker},
{"FakeQuantPerLayer", FakeQuantWithMinMaxPacker},
{"FakeQuantPerChannel", FakeQuantWithMinMaxPerChannelPacker},
{"Mul", MulPacker},
{"MulFold", MulFoldPacker},
{"Squeeze", SqueezePacker}};
}
OpAttrPackFun OpAttrFactory::GetPackFun(const std::string &opType) {
if (pack_funs_.find(opType) == pack_funs_.end()) {
MS_LOG(WARNING) << "Op Attr pack fun [" << opType << "] not found.";
return nullptr;
}
return pack_funs_[opType];
}
mindspore::predict::Format GetAttrFormat(const std::string &format) {
if (format == kOpFormat_NCHW) {
return predict::Format::Format_NCHW;
} else if (format == kOpFormat_NHWC) {
return predict::Format::Format_NHWC;
} else {
return predict::Format::Format_NUM_OF_FORMAT;
}
}
mindspore::predict::PadMode GetAttrPadMode(const std::string &pad_mode) {
if (pad_mode == "same") {
return mindspore::predict::PadMode::PadMode_SAME;
} else if (pad_mode == "valid") {
return mindspore::predict::PadMode::PadMode_VALID;
} else {
return mindspore::predict::PadMode::PadMode_NOTSET;
}
}
} // namespace convert
} // namespace predict
} // namespace mindspore
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MINDSPORE_CCSRC_PREDICT_CONVERTER_OP_ATTR_PACKER_H_
#define MINDSPORE_CCSRC_PREDICT_CONVERTER_OP_ATTR_PACKER_H_
#include <utility>
#include <string>
#include <unordered_map>
#include "backend/session/anf_runtime_algorithm.h"
#include "predict/schema/inner/ms_generated.h"
static constexpr size_t kNIndex = 0;
static constexpr size_t kCIndex = 1;
static constexpr size_t kHIndex = 2;
static constexpr size_t kWIndex = 3;
static constexpr size_t kNCHWSize = 4;
namespace mindspore {
namespace predict {
namespace convert {
using OpAttrPackFun = bool (*)(const CNodePtr &c_node_ptr, OpDefT *ms_op);
class OpAttrFactory {
public:
static OpAttrFactory *GetInstance() {
static OpAttrFactory instance;
return &instance;
}
OpAttrFactory(const OpAttrFactory &) = delete;
OpAttrFactory &operator=(const OpAttrFactory &) = delete;
OpAttrPackFun GetPackFun(const std::string &op_type);
~OpAttrFactory() { pack_funs_.clear(); }
OpAttrFactory();
private:
std::unordered_map<std::string, OpAttrPackFun> pack_funs_;
};
mindspore::predict::Format GetAttrFormat(const std::string &format);
mindspore::predict::PadMode GetAttrPadMode(const std::string &pad_mode);
} // namespace convert
} // namespace predict
} // namespace mindspore
#endif // MINDSPORE_CCSRC_PREDICT_CONVERTER_CPU_OP_INFO_OP_ATTR_FACTORY_H_
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "predict/converter/lite_model/op_attr_packer.h"
namespace mindspore {
namespace predict {
namespace convert {
bool ActivationPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op) {
if (c_node_ptr == nullptr || ms_op == nullptr) {
return false;
}
std::unique_ptr<ActivationT> attr(new ActivationT());
MS_EXCEPTION_IF_NULL(attr);
if (AnfAlgo::GetCNodeName(c_node_ptr) == "ReLU") {
attr->type = predict::ActivationType::ActivationType_RELU;
} else if (AnfAlgo::GetCNodeName(c_node_ptr) == "Sigmoid") {
attr->type = predict::ActivationType::ActivationType_SIGMOID;
} else if (AnfAlgo::GetCNodeName(c_node_ptr) == "ReLU6") {
attr->type = predict::ActivationType::ActivationType_RELU6;
} else if (AnfAlgo::GetCNodeName(c_node_ptr) == "ELU") {
attr->type = predict::ActivationType::ActivationType_ELU;
} else if (AnfAlgo::GetCNodeName(c_node_ptr) == "Leaky_ReLU") {
attr->type = predict::ActivationType::ActivationType_LEAKY_RELU;
} else if (AnfAlgo::GetCNodeName(c_node_ptr) == "ABS") {
attr->type = predict::ActivationType::ActivationType_ABS;
} else if (AnfAlgo::GetCNodeName(c_node_ptr) == "ReLU1") {
attr->type = predict::ActivationType::ActivationType_RELU1;
} else if (AnfAlgo::GetCNodeName(c_node_ptr) == "Softsign") {
attr->type = predict::ActivationType::ActivationType_SOFTSIGN;
} else if (AnfAlgo::GetCNodeName(c_node_ptr) == "Softplus") {
attr->type = predict::ActivationType::ActivationType_SOFTPLUS;
} else if (AnfAlgo::GetCNodeName(c_node_ptr) == "Tanh") {
attr->type = predict::ActivationType::ActivationType_TANH;
} else {
attr->type = predict::ActivationType::ActivationType_UNKNOW;
MS_LOG(WARNING) << "unknow Activation";
}
ms_op->name = c_node_ptr->fullname_with_scope();
ms_op->attr.type = OpT_Activation;
ms_op->attr.value = attr.release();
return true;
}
} // namespace convert
} // namespace predict
} // namespace mindspore
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "predict/converter/lite_model/op_attr_packer.h"
namespace mindspore {
namespace predict {
namespace convert {
bool AddPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op) {
if (c_node_ptr == nullptr || ms_op == nullptr) {
return false;
}
std::unique_ptr<AddT> attr(new AddT());
MS_EXCEPTION_IF_NULL(attr);
ms_op->name = c_node_ptr->fullname_with_scope();
ms_op->attr.type = OpT_Add;
ms_op->attr.value = attr.release();
return true;
}
} // namespace convert
} // namespace predict
} // namespace mindspore
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "predict/converter/lite_model/op_attr_packer.h"
namespace mindspore {
namespace predict {
namespace convert {
bool AddFoldPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op) {
if (c_node_ptr == nullptr || ms_op == nullptr) {
return false;
}
std::unique_ptr<AddFoldT> attr(new AddFoldT());
MS_EXCEPTION_IF_NULL(attr);
ms_op->attr.type = OpT_AddFold;
ms_op->attr.value = attr.release();
return true;
}
} // namespace convert
} // namespace predict
} // namespace mindspore
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "predict/converter/lite_model/op_attr_packer.h"
namespace mindspore {
namespace predict {
namespace convert {
bool ArgMaxPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op) {
if (c_node_ptr == nullptr || ms_op == nullptr) {
return false;
}
std::unique_ptr<ArgMaxT> attr(new ArgMaxT());
MS_EXCEPTION_IF_NULL(attr);
ms_op->attr.type = OpT_ArgMax;
ms_op->attr.value = attr.release();
return true;
}
} // namespace convert
} // namespace predict
} // namespace mindspore
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "predict/converter/lite_model/op_attr_packer.h"
namespace mindspore {
namespace predict {
namespace convert {
bool BatchNormFoldPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op) {
if (c_node_ptr == nullptr || ms_op == nullptr) {
return false;
}
std::unique_ptr<BatchNormFoldT> attr(new BatchNormFoldT());
MS_EXCEPTION_IF_NULL(attr);
ms_op->attr.type = OpT_BatchNormFold;
ms_op->attr.value = attr.release();
return true;
}
} // namespace convert
} // namespace predict
} // namespace mindspore
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <memory>
#include "predict/converter/lite_model/op_attr_packer.h"
namespace mindspore {
namespace predict {
namespace convert {
bool BiasAddPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op) {
if (c_node_ptr == nullptr || ms_op == nullptr) {
return false;
}
std::unique_ptr<BiasAddT> attr(new BiasAddT());
MS_EXCEPTION_IF_NULL(attr);
attr->axis = {1};
ms_op->name = c_node_ptr->fullname_with_scope();
ms_op->attr.type = OpT_BiasAdd;
ms_op->attr.value = attr.release();
return true;
}
} // namespace convert
} // namespace predict
} // namespace mindspore
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "predict/converter/lite_model/op_attr_packer.h"
namespace mindspore {
namespace predict {
namespace convert {
bool CastPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op) {
if (c_node_ptr == nullptr || ms_op == nullptr) {
return false;
}
std::unique_ptr<CastT> attr(new CastT());
MS_EXCEPTION_IF_NULL(attr);
attr->srcT = 0;
attr->dstT = 0;
ms_op->name = c_node_ptr->fullname_with_scope();
ms_op->attr.type = OpT_Cast;
ms_op->attr.value = attr.release();
return true;
}
} // namespace convert
} // namespace predict
} // namespace mindspore
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "predict/converter/lite_model/op_attr_packer.h"
namespace mindspore {
namespace predict {
namespace convert {
bool Conv2dPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op) {
if (c_node_ptr == nullptr || ms_op == nullptr) {
return false;
}
int kernel_group_value = AnfAlgo::GetNodeAttr<int>(c_node_ptr, "group");
int kernel_channel_value = AnfAlgo::GetNodeAttr<int>(c_node_ptr, "out_channel");
std::vector<int> kernel_size_value = AnfAlgo::GetNodeAttr<std::vector<int>>(c_node_ptr, "kernel_size");
std::string kernel_pad_mode_value = AnfAlgo::GetNodeAttr<std::string>(c_node_ptr, "pad_mode");
int kernel_pad_value = AnfAlgo::GetNodeAttr<int>(c_node_ptr, "pad");
auto kernel_stride_value = AnfAlgo::GetNodeAttr<std::vector<int>>(c_node_ptr, "stride");
auto kernel_dilation_value = AnfAlgo::GetNodeAttr<std::vector<int>>(c_node_ptr, "dilation");
std::string kernel_data_format_value = AnfAlgo::GetNodeAttr<std::string>(c_node_ptr, "data_format");
std::unique_ptr<Conv2DT> attr(new Conv2DT());
MS_EXCEPTION_IF_NULL(attr);
attr->format = GetAttrFormat(kernel_data_format_value);
attr->group = kernel_group_value;
auto in_shape = AnfAlgo::GetPrevNodeOutputInferShape(c_node_ptr, 1);
if (in_shape.size() != kNCHWSize) {
return false;
}
attr->channelIn = SizeToInt(in_shape[1]);
attr->channelOut = kernel_channel_value;
attr->kernelW = kernel_size_value[0];
attr->kernelH = kernel_size_value[1];
attr->strideW = kernel_stride_value[0];
attr->strideH = kernel_stride_value[1];
attr->padMode = GetAttrPadMode(kernel_pad_mode_value);
attr->padUp = kernel_pad_value;
attr->padDown = kernel_pad_value;
attr->padLeft = kernel_pad_value;
attr->padRight = kernel_pad_value;
attr->dilateW = kernel_dilation_value[0];
attr->dilateH = kernel_dilation_value[1];
attr->hasBias = false;
ms_op->name = c_node_ptr->fullname_with_scope();
ms_op->attr.type = OpT_Conv2D;
ms_op->attr.value = attr.release();
return true;
}
} // namespace convert
} // namespace predict
} // namespace mindspore
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "predict/converter/lite_model/op_attr_packer.h"
namespace mindspore {
namespace predict {
namespace convert {
bool FakeQuantWithMinMaxPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op) {
if (c_node_ptr == nullptr || ms_op == nullptr) {
return false;
}
std::unique_ptr<FakeQuantWithMinMaxT> attr(new FakeQuantWithMinMaxT());
MS_EXCEPTION_IF_NULL(attr);
ms_op->attr.type = OpT_FakeQuantWithMinMax;
ms_op->attr.value = attr.release();
return true;
}
} // namespace convert
} // namespace predict
} // namespace mindspore
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "predict/converter/lite_model/op_attr_packer.h"
namespace mindspore {
namespace predict {
namespace convert {
bool FakeQuantWithMinMaxPerChannelPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op) {
if (c_node_ptr == nullptr || ms_op == nullptr) {
return false;
}
std::unique_ptr<FakeQuantWithMinMaxPerChannelT> attr(new FakeQuantWithMinMaxPerChannelT());
MS_EXCEPTION_IF_NULL(attr);
ms_op->attr.type = OpT_FakeQuantWithMinMaxPerChannel;
ms_op->attr.value = attr.release();
return true;
}
} // namespace convert
} // namespace predict
} // namespace mindspore
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "predict/converter/lite_model/op_attr_packer.h"
namespace mindspore {
namespace predict {
namespace convert {
bool FusedBatchNormPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op) {
if (c_node_ptr == nullptr || ms_op == nullptr) {
return false;
}
std::unique_ptr<FusedBatchNormT> attr(new FusedBatchNormT());
MS_EXCEPTION_IF_NULL(attr);
auto kernel_epsilon = AnfAlgo::GetNodeAttr<float>(c_node_ptr, "epsilon");
attr->epsilon = kernel_epsilon;
ms_op->name = c_node_ptr->fullname_with_scope();
ms_op->attr.type = OpT_FusedBatchNorm;
ms_op->attr.value = attr.release();
return true;
}
} // namespace convert
} // namespace predict
} // namespace mindspore
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "predict/converter/lite_model/op_attr_packer.h"
namespace mindspore {
namespace predict {
namespace convert {
bool MatMulPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op) {
if (c_node_ptr == nullptr || ms_op == nullptr) {
return false;
}
bool kernel_transpore_a = AnfAlgo::GetNodeAttr<bool>(c_node_ptr, "transpose_a");
bool kernel_transpore_b = AnfAlgo::GetNodeAttr<bool>(c_node_ptr, "transpose_b");
std::unique_ptr<MatMulT> attr(new MatMulT());
MS_EXCEPTION_IF_NULL(attr);
attr->transposeA = kernel_transpore_a;
attr->transposeB = kernel_transpore_b;
ms_op->name = c_node_ptr->fullname_with_scope();
ms_op->attr.type = OpT_MatMul;
ms_op->attr.value = attr.release();
return true;
}
} // namespace convert
} // namespace predict
} // namespace mindspore
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "predict/converter/lite_model/op_attr_packer.h"
namespace mindspore {
namespace predict {
namespace convert {
bool MeanPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op) {
if (c_node_ptr == nullptr || ms_op == nullptr) {
return false;
}
std::unique_ptr<MeanT> attr(new MeanT());
MS_EXCEPTION_IF_NULL(attr);
attr->axis = {1};
attr->keepDims = false;
ms_op->name = c_node_ptr->fullname_with_scope();
ms_op->attr.type = OpT_Mean;
ms_op->attr.value = attr.release();
return true;
}
} // namespace convert
} // namespace predict
} // namespace mindspore
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "predict/converter/lite_model/op_attr_packer.h"
namespace mindspore {
namespace predict {
namespace convert {
bool MulPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op) {
if (c_node_ptr == nullptr || ms_op == nullptr) {
return false;
}
std::unique_ptr<MulT> attr(new MulT());
MS_EXCEPTION_IF_NULL(attr);
ms_op->attr.type = OpT_Mul;
ms_op->attr.value = attr.release();
return true;
}
} // namespace convert
} // namespace predict
} // namespace mindspore
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "predict/converter/lite_model/op_attr_packer.h"
namespace mindspore {
namespace predict {
namespace convert {
bool MulFoldPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op) {
if (c_node_ptr == nullptr || ms_op == nullptr) {
return false;
}
std::unique_ptr<MulFoldT> attr(new MulFoldT());
MS_EXCEPTION_IF_NULL(attr);
ms_op->name = c_node_ptr->fullname_with_scope();
ms_op->attr.type = OpT_MulFold;
ms_op->attr.value = attr.release();
return true;
}
} // namespace convert
} // namespace predict
} // namespace mindspore
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "predict/converter/lite_model/op_attr_packer.h"
namespace mindspore {
namespace predict {
namespace convert {
bool PoolingPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op) {
if (c_node_ptr == nullptr || ms_op == nullptr) {
return false;
}
std::unique_ptr<PoolingT> attr(new PoolingT());
MS_EXCEPTION_IF_NULL(attr);
std::string kernel_format_value = AnfAlgo::GetNodeAttr<std::string>(c_node_ptr, "data_format");
attr->format = GetAttrFormat(kernel_format_value);
auto c_name = AnfAlgo::GetCNodeName(c_node_ptr);
if (c_name == "MaxPool") {
ms_op->name = c_node_ptr->fullname_with_scope();
attr->poolingMode = mindspore::predict::PoolMode::PoolMode_MAX_POOLING;
} else if (c_name == "MeanPool") {
ms_op->name = c_node_ptr->fullname_with_scope();
attr->poolingMode = mindspore::predict::PoolMode::PoolMode_MEAN_POOLING;
} else if (c_name == "GlobalPool") {
ms_op->name = c_node_ptr->fullname_with_scope();
} else {
MS_LOG(ERROR) << "unknowed pooling type.";
return false;
}
std::vector<int> kernel_ksize = AnfAlgo::GetNodeAttr<std::vector<int>>(c_node_ptr, "ksize");
attr->windowW = kernel_ksize[kHIndex];
attr->windowH = kernel_ksize[kWIndex];
std::vector<int> kernel_strides = AnfAlgo::GetNodeAttr<std::vector<int>>(c_node_ptr, "strides");
attr->strideW = kernel_strides[kHIndex];
attr->strideH = kernel_strides[kWIndex];
std::string kernel_pad_mode_value = AnfAlgo::GetNodeAttr<std::string>(c_node_ptr, "padding");
attr->padMode = GetAttrPadMode(kernel_pad_mode_value);
attr->padUp = 0;
attr->padDown = 0;
attr->padLeft = 0;
attr->padRight = 0;
ms_op->attr.type = OpT_Pooling;
ms_op->attr.value = attr.release();
return true;
}
} // namespace convert
} // namespace predict
} // namespace mindspore
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "predict/converter/lite_model/op_attr_packer.h"
namespace mindspore {
namespace predict {
namespace convert {
bool ReshapePacker(const CNodePtr &c_node_ptr, OpDefT *ms_op) {
if (c_node_ptr == nullptr || ms_op == nullptr) {
return false;
}
std::unique_ptr<ReshapeT> attr(new ReshapeT());
MS_EXCEPTION_IF_NULL(attr);
attr->format = predict::Format::Format_NCHW;
ms_op->name = c_node_ptr->fullname_with_scope();
ms_op->attr.type = OpT_Reshape;
ms_op->attr.value = attr.release();
return true;
}
} // namespace convert
} // namespace predict
} // namespace mindspore
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "predict/converter/lite_model/op_attr_packer.h"
namespace mindspore {
namespace predict {
namespace convert {
bool ScalePacker(const CNodePtr &c_node_ptr, OpDefT *ms_op) {
if (c_node_ptr == nullptr || ms_op == nullptr) {
return false;
}
std::unique_ptr<ScaleT> attr(new ScaleT());
MS_EXCEPTION_IF_NULL(attr);
attr->format = predict::Format::Format_NCHW;
ms_op->name = c_node_ptr->fullname_with_scope();
ms_op->attr.type = OpT_Scale;
ms_op->attr.value = attr.release();
return true;
}
} // namespace convert
} // namespace predict
} // namespace mindspore
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "predict/converter/lite_model/op_attr_packer.h"
namespace mindspore {
namespace predict {
namespace convert {
bool SoftmaxPacker(const CNodePtr &c_node_ptr, OpDefT *ms_op) {
if (c_node_ptr == nullptr || ms_op == nullptr) {
return false;
}
std::unique_ptr<SoftMaxT> attr(new SoftMaxT());
MS_EXCEPTION_IF_NULL(attr);
attr->axis = {1};
ms_op->name = c_node_ptr->fullname_with_scope();
ms_op->attr.type = OpT_SoftMax;
ms_op->attr.value = attr.release();
return true;
}
} // namespace convert
} // namespace predict
} // namespace mindspore
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "predict/converter/lite_model/op_attr_packer.h"
namespace mindspore {
namespace predict {
namespace convert {
bool SqueezePacker(const CNodePtr &c_node_ptr, OpDefT *ms_op) {
if (c_node_ptr == nullptr || ms_op == nullptr) {
return false;
}
std::unique_ptr<SqueezeT> attr(new SqueezeT());
MS_EXCEPTION_IF_NULL(attr);
std::vector<int> kernel_axis_value = AnfAlgo::GetNodeAttr<std::vector<int>>(c_node_ptr, "axis");
attr->axis = kernel_axis_value;
ms_op->attr.type = OpT_Squeeze;
ms_op->attr.value = attr.release();
return true;
}
} // namespace convert
} // namespace predict
} // namespace mindspore
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "predict/generator/ir/ir_model.h"
#include <utility>
#include <algorithm>
#include "utils/log_adapter.h"
namespace mindspore {
namespace generator {
IRModel::~IRModel() { ir_tasks_.clear(); }
void IRModel::SetIrTaskInfos(const std::vector<IRtaskInfoPtr> &ir_tasks) {
(void)std::copy(ir_tasks.begin(), ir_tasks.end(), std::back_inserter(ir_tasks_));
}
} // namespace generator
} // namespace mindspore
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MINDSPORE_CCSRC_EXECUTOR_GENERATOR_IR_IR_MODEL_H_
#define MINDSPORE_CCSRC_EXECUTOR_GENERATOR_IR_IR_MODEL_H_
#include <string>
#include <vector>
#include <memory>
#include "predict/generator/ir/ir_task_info.h"
namespace mindspore {
namespace generator {
class IRModel {
public:
void SetIrTaskInfos(const std::vector<IRtaskInfoPtr> &ir_tasks);
IRModel() = default;
~IRModel();
private:
std::vector<IRtaskInfoPtr> ir_tasks_;
};
using IrModelPtr = std::shared_ptr<IRModel>;
} // namespace generator
} // namespace mindspore
#endif // MINDSPORE_CCSRC_EXECUTOR_GENERATOR_IR_IR_MODEL_H_
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "predict/generator/ir/ir_task_info.h"
#include "utils/log_adapter.h"
namespace mindspore {
namespace generator {
bool CceIRTaskInfo::SerializeIRToProto() {
auto cce_task_def_ptr = std::unique_ptr<ge::model_runner::CceTaskDef>();
auto kernel_context_ptr = std::unique_ptr<ge::model_runner::KernelContext>();
MS_EXCEPTION_IF_NULL(cce_task_def_ptr);
MS_EXCEPTION_IF_NULL(kernel_context_ptr);
kernel_context_ptr->set_kernel_type(k_ctx_.kernel_type);
kernel_context_ptr->set_op_id(k_ctx_.op_id);
kernel_context_ptr->set_kernel_func_id(k_ctx_.kernel_func_id);
kernel_context_ptr->set_op_index(k_ctx_.op_index);
kernel_context_ptr->set_is_flowtable(k_ctx_.is_flowtable);
kernel_context_ptr->set_args_count(k_ctx_.args_count);
for (unsigned int i : k_ctx_.origin_op_index) {
kernel_context_ptr->add_origin_op_index(i);
}
void *tmp_args_offset = static_cast<void *>((k_ctx_.args_offset).data());
if (tmp_args_offset == nullptr) {
MS_LOG(WARNING) << "tmp_args_offset have no data";
return false;
}
kernel_context_ptr->set_args_offset(tmp_args_offset, k_ctx_.args_offset.size());
cce_task_def_ptr->set_allocated_kernel_context(std::move(kernel_context_ptr).get());
cce_task_def_ptr->set_stub_func(stub_func_);
cce_task_def_ptr->set_block_dim(block_dim_);
cce_task_def_ptr->set_args_size(args_size_);
void *tmp_sm_desc = static_cast<void *>(sm_desc_.data());
if (tmp_sm_desc == nullptr) {
MS_LOG(WARNING) << "tmp_sm_desc have no data";
return false;
}
cce_task_def_ptr->set_sm_desc(tmp_sm_desc, sm_desc_.size());
void *tmp_flow_table = static_cast<void *>(flow_table_.data());
if (tmp_flow_table == nullptr) {
MS_LOG(WARNING) << "tmp_flow_table have no data";
return false;
}
cce_task_def_ptr->set_flow_table(tmp_flow_table, flow_table_.size());
return true;
}
CceIRTaskInfo::~CceIRTaskInfo() {
args_.clear();
sm_desc_.clear();
flow_table_.clear();
}
bool TbeIRTaskInfo::SerializeIRToProto() {
auto tbe_task_def_ptr = std::unique_ptr<ge::model_runner::TbeTaskDef>();
MS_EXCEPTION_IF_NULL(tbe_task_def_ptr);
tbe_task_def_ptr->set_stub_func(stub_func_);
tbe_task_def_ptr->set_block_dim(block_dim_);
tbe_task_def_ptr->set_args_size(args_size_);
void *tmp_args = static_cast<void *>(args_.data());
if (tmp_args == nullptr) {
MS_LOG(WARNING) << "tmp_args have no data";
return false;
}
tbe_task_def_ptr->set_args(tmp_args, args_.size());
void *tmp_sm_desc = static_cast<void *>(sm_desc_.data());
if (tmp_sm_desc == nullptr) {
MS_LOG(WARNING) << "tmp_sm_desc have no data";
return false;
}
tbe_task_def_ptr->set_sm_desc(tmp_sm_desc, sm_desc_.size());
void *tmp_meta_data = static_cast<void *>(meta_data_.data());
if (tmp_meta_data == nullptr) {
MS_LOG(WARNING) << "tmp_meta_data have no data";
return false;
}
tbe_task_def_ptr->set_meta_data(tmp_meta_data, meta_data_.size());
for (auto &in : input_data_addrs_) {
tbe_task_def_ptr->add_input_addrs(in);
}
for (auto &ou : output_data_addrs_) {
tbe_task_def_ptr->add_output_addrs(ou);
}
for (auto &wk : workspace_addrs_) {
tbe_task_def_ptr->add_workspace_addrs(wk);
}
return true;
}
TbeIRTaskInfo::~TbeIRTaskInfo() {
args_.clear();
sm_desc_.clear();
meta_data_.clear();
input_data_addrs_.clear();
output_data_addrs_.clear();
workspace_addrs_.clear();
}
bool AicpuIRTaskInfo::SerializeIRToProto() {
auto aicpu_task_def_ptr = std::unique_ptr<ge::model_runner::AicpuTaskDef>();
MS_EXCEPTION_IF_NULL(aicpu_task_def_ptr);
aicpu_task_def_ptr->set_op_type(op_type_);
aicpu_task_def_ptr->set_flag(flag_);
for (auto &shape : input_data_shapes_) {
auto in_shape_ptr = aicpu_task_def_ptr->add_input_shapes();
for (auto &in_sh : shape) {
in_shape_ptr->add_shape(static_cast<uint32_t>(in_sh));
}
}
for (auto &shape : output_data_shapes_) {
auto ou_shape_ptr = aicpu_task_def_ptr->add_output_shapes();
for (auto &ou_sh : shape) {
ou_shape_ptr->add_shape(static_cast<uint32_t>(ou_sh));
}
}
for (auto &in_type : input_data_types_) {
aicpu_task_def_ptr->add_input_types(in_type);
}
for (auto &ou_type : output_data_types_) {
aicpu_task_def_ptr->add_output_types(ou_type);
}
for (auto &in_addr : input_data_addrs_) {
aicpu_task_def_ptr->add_input_addrs(in_addr);
}
for (auto &ou_addr : output_data_addrs_) {
aicpu_task_def_ptr->add_output_addrs(ou_addr);
}
void *tmp_node_def = static_cast<void *>(node_def_.data());
if (tmp_node_def == nullptr) {
MS_LOG(WARNING) << "tmp_node_def have no data";
return false;
}
aicpu_task_def_ptr->set_node_def(tmp_node_def, node_def_.size());
void *tmp_func_def = static_cast<void *>(func_def_.data());
if (tmp_func_def == nullptr) {
MS_LOG(WARNING) << "tmp_func_def have no data";
return false;
}
aicpu_task_def_ptr->set_func_def(tmp_func_def, func_def_.size());
return true;
}
AicpuIRTaskInfo::~AicpuIRTaskInfo() {
input_data_types_.clear();
input_data_shapes_.clear();
input_data_addrs_.clear();
output_data_types_.clear();
output_data_shapes_.clear();
output_data_addrs_.clear();
node_def_.clear();
func_def_.clear();
}
bool LabelIRTaskInfo::SerializeIRToProto() {
auto label_task_def_ptr = std::unique_ptr<ge::model_runner::LabelTaskDef>();
MS_EXCEPTION_IF_NULL(label_task_def_ptr);
label_task_def_ptr->set_label_id(label_id_);
return true;
}
bool EventIRTaskInfo::SerializeIRToProto() {
auto event_task_def_ptr = std::unique_ptr<ge::model_runner::EventTaskDef>();
MS_EXCEPTION_IF_NULL(event_task_def_ptr);
event_task_def_ptr->set_event_id(event_id_);
return true;
}
bool HcclIRTaskInfo::SerializeIRToProto() {
auto hccl_task_def_ptr = std::unique_ptr<ge::model_runner::HcclTaskDef>();
MS_EXCEPTION_IF_NULL(hccl_task_def_ptr);
hccl_task_def_ptr->set_hccl_type(hccl_type_);
hccl_task_def_ptr->set_input_addr(input_data_addr_);
hccl_task_def_ptr->set_output_addr(output_data_addr_);
auto tmp_wk = static_cast<void *>(workspace_.data());
hccl_task_def_ptr->set_workspace(tmp_wk, workspace_.size());
hccl_task_def_ptr->set_workspace_num(workspace_num_);
auto tmp_pri_def = static_cast<void *>(private_def_.data());
hccl_task_def_ptr->set_private_def(tmp_pri_def, private_def_.size());
hccl_task_def_ptr->set_ops_kernel_store(ops_kernel_store_);
hccl_task_def_ptr->set_count(count_);
hccl_task_def_ptr->set_root_id(root_id_);
hccl_task_def_ptr->set_op_type(op_type_);
hccl_task_def_ptr->set_data_type(data_type_);
return true;
}
HcclIRTaskInfo::~HcclIRTaskInfo() {
workspace_.clear();
private_def_.clear();
}
bool ProfilerIRTaskInfo::SerializeIRToProto() {
auto profiler_task_def_ptr = std::unique_ptr<ge::model_runner::ProfilerTaskDef>();
MS_EXCEPTION_IF_NULL(profiler_task_def_ptr);
profiler_task_def_ptr->set_log_id(log_id_);
profiler_task_def_ptr->set_flat(flat_);
profiler_task_def_ptr->set_notify(notify_);
return true;
}
bool MemcpyAsyncIRTaskInfo::SerializeIRToProto() {
auto mem_task_def_ptr = std::unique_ptr<ge::model_runner::MemcpyAsyncTaskDef>();
MS_EXCEPTION_IF_NULL(mem_task_def_ptr);
mem_task_def_ptr->set_dst(dst_);
mem_task_def_ptr->set_dst_max(dst_max_);
mem_task_def_ptr->set_src(src_);
mem_task_def_ptr->set_count(count_);
mem_task_def_ptr->set_kind(kind_);
return true;
}
bool StreamSwitchIRTaskInfo::SerializeIRToProto() {
auto stream_switch_task_def_ptr = std::unique_ptr<ge::model_runner::StreamSwitchTaskDef>();
MS_EXCEPTION_IF_NULL(stream_switch_task_def_ptr);
stream_switch_task_def_ptr->set_true_stream_id(true_stream_id_);
stream_switch_task_def_ptr->set_input_addr(input_addr_);
stream_switch_task_def_ptr->set_value_addr(value_addr_);
stream_switch_task_def_ptr->set_cond(cond_);
stream_switch_task_def_ptr->set_data_type(data_type_);
return true;
}
bool StreamActiveIRTaskInfo::SerializeIRToProto() {
auto stream_active_task_def_ptr = std::unique_ptr<ge::model_runner::StreamActiveTaskDef>();
MS_EXCEPTION_IF_NULL(stream_active_task_def_ptr);
stream_active_task_def_ptr->set_active_stream_id(active_stream_id_);
return true;
}
} // namespace generator
} // namespace mindspore
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MINDSPORE_CCSRC_EXECUTOR_GENERATOR_IR_IR_TASK_H_
#define MINDSPORE_CCSRC_EXECUTOR_GENERATOR_IR_IR_TASK_H_
#include <cstdint>
#include <utility>
#include <memory>
#include <string>
#include <vector>
#include "proto/ge_runtime_taskinfo.pb.h"
namespace mindspore {
namespace generator {
using TaskType = ::ge::model_runner::TaskDef_TaskType;
enum TaskTmpType {
CCE_TMP_DEF = 0,
TBE_TMP_DEF = 1,
AICPU_TMP_DEF = 2,
LABEL_TMP_DEF = 3,
EVENT_TMP_DEF = 4,
HCCL_TMP_DEF = 5,
PROFILER_TRACE_TMP_DEF = 6,
MEMCPY_ASYNC_TMP_DEF = 7,
STREAM_SWITCH_TMP_DEF = 8,
STREAM_ACTIVE_TMP_DEF = 9
};
struct KernelContext {
uint32_t kernel_type = 0;
uint32_t op_id = 0;
uint32_t kernel_func_id = 0;
uint32_t op_index = 0;
bool is_flowtable = false;
std::vector<uint8_t> args_offset;
uint32_t args_count = 0;
std::vector<uint32_t> origin_op_index;
};
class IRtaskInfo {
public:
virtual ~IRtaskInfo() = default;
virtual bool SerializeIRToProto() = 0;
protected:
IRtaskInfo(TaskType task_type, TaskTmpType task_tmp_type, uint64_t stream_id)
: task_type_(task_type), task_tmp_type_(task_tmp_type), stream_id_(stream_id) {}
public:
uint64_t GetStreamId() const { return stream_id_; }
TaskType GetTaskType() const { return task_type_; }
TaskTmpType GetTaskTmpType() const { return task_tmp_type_; }
private:
TaskType task_type_;
TaskTmpType task_tmp_type_;
uint64_t stream_id_ = 0;
};
using IRtaskInfoPtr = std::shared_ptr<IRtaskInfo>;
class CceIRTaskInfo : public IRtaskInfo {
public:
CceIRTaskInfo(TaskType task_type, uint64_t stream_id, KernelContext k_ctx, std::string stub_func, uint32_t block_dim,
std::vector<uint8_t> args, uint32_t args_size, std::vector<uint8_t> sm_desc,
std::vector<uint8_t> flow_table)
: IRtaskInfo(task_type, CCE_TMP_DEF, stream_id),
k_ctx_(std::move(k_ctx)),
stub_func_(std::move(stub_func)),
block_dim_(block_dim),
args_(std::move(args)),
args_size_(args_size),
sm_desc_(std::move(sm_desc)),
flow_table_(std::move(flow_table)) {}
~CceIRTaskInfo() override;
bool SerializeIRToProto() override;
private:
KernelContext k_ctx_;
std::string stub_func_;
uint32_t block_dim_ = 0;
std::vector<uint8_t> args_;
// uintptr_t args_addr_;
uint32_t args_size_ = 0;
std::vector<uint8_t> sm_desc_;
std::vector<uint8_t> flow_table_;
};
class TbeIRTaskInfo : public IRtaskInfo {
public:
TbeIRTaskInfo(TaskType task_type, uint64_t stream_id, std::string stub_func, uint32_t block_dim,
std::vector<uint8_t> args, uint32_t args_size, std::vector<uint8_t> sm_desc,
std::vector<uint8_t> meta_data, std::vector<uintptr_t> input_data_addrs,
std::vector<uintptr_t> output_data_addrs, std::vector<uintptr_t> workspace_addrs)
: IRtaskInfo(task_type, TBE_TMP_DEF, stream_id),
stub_func_(std::move(stub_func)),
block_dim_(block_dim),
args_(std::move(args)),
args_size_(args_size),
sm_desc_(std::move(sm_desc)),
meta_data_(std::move(meta_data)),
input_data_addrs_(std::move(input_data_addrs)),
output_data_addrs_(std::move(output_data_addrs)),
workspace_addrs_(std::move(workspace_addrs)) {}
~TbeIRTaskInfo() override;
bool SerializeIRToProto() override;
private:
std::string stub_func_;
uint32_t block_dim_ = 0;
std::vector<uint8_t> args_;
uint32_t args_size_ = 0;
std::vector<uint8_t> sm_desc_;
// uintptr_t binary_;
// uint32_t binary_size_;
std::vector<uint8_t> meta_data_;
std::vector<uintptr_t> input_data_addrs_;
std::vector<uintptr_t> output_data_addrs_;
std::vector<uintptr_t> workspace_addrs_;
// std::vector<uint8_t> flow_table_;
};
class AicpuIRTaskInfo : public IRtaskInfo {
public:
AicpuIRTaskInfo(TaskType task_type, uint64_t stream_id, std::string op_type, uint32_t flag,
std::vector<uint32_t> input_data_types, std::vector<std::vector<size_t>> input_data_shapes,
std::vector<uintptr_t> input_data_addrs, std::vector<uint32_t> output_data_types,
std::vector<std::vector<size_t>> output_data_shapes, std::vector<uintptr_t> output_data_addrs,
std::vector<uint8_t> node_def, std::vector<uint8_t> func_def)
: IRtaskInfo(task_type, AICPU_TMP_DEF, stream_id),
op_type_(std::move(op_type)),
flag_(flag),
input_data_types_(std::move(input_data_types)),
input_data_shapes_(std::move(input_data_shapes)),
input_data_addrs_(std::move(input_data_addrs)),
output_data_types_(std::move(output_data_types)),
output_data_shapes_(std::move(output_data_shapes)),
output_data_addrs_(std::move(output_data_addrs)),
node_def_(std::move(node_def)),
func_def_(std::move(func_def)) {}
~AicpuIRTaskInfo() override;
bool SerializeIRToProto() override;
private:
std::string op_type_;
uint32_t flag_ = 0;
std::vector<uint32_t> input_data_types_;
std::vector<std::vector<size_t>> input_data_shapes_;
std::vector<uintptr_t> input_data_addrs_;
std::vector<uint32_t> output_data_types_;
std::vector<std::vector<size_t>> output_data_shapes_;
std::vector<uintptr_t> output_data_addrs_;
std::vector<uint8_t> node_def_;
std::vector<uint8_t> func_def_;
};
class LabelIRTaskInfo : public IRtaskInfo {
public:
LabelIRTaskInfo(TaskType task_type, uint64_t stream_id, uint32_t label_id)
: IRtaskInfo(task_type, LABEL_TMP_DEF, stream_id), label_id_(label_id) {}
~LabelIRTaskInfo() override {}
bool SerializeIRToProto() override;
private:
uint32_t label_id_ = 0;
};
class EventIRTaskInfo : public IRtaskInfo {
public:
EventIRTaskInfo(TaskType task_type, uint64_t stream_id, uint32_t event_id)
: IRtaskInfo(task_type, EVENT_TMP_DEF, stream_id), event_id_(event_id) {}
~EventIRTaskInfo() override {}
bool SerializeIRToProto() override;
private:
uint32_t event_id_ = 0;
};
class HcclIRTaskInfo : public IRtaskInfo {
public:
HcclIRTaskInfo(TaskType task_type, uint64_t stream_id, std::string hccl_type, uintptr_t input_data_addr,
uintptr_t output_data_addr, std::vector<uint8_t> workspace, int64_t workspace_num,
std::vector<uint8_t> private_def, uintptr_t ops_kernel_store, int32_t count, int64_t root_id,
int64_t op_type, int64_t data_type)
: IRtaskInfo(task_type, HCCL_TMP_DEF, stream_id),
hccl_type_(std::move(hccl_type)),
input_data_addr_(input_data_addr),
output_data_addr_(output_data_addr),
workspace_(std::move(workspace)),
workspace_num_(workspace_num),
private_def_(std::move(private_def)),
ops_kernel_store_(ops_kernel_store),
count_(count),
root_id_(root_id),
op_type_(op_type),
data_type_(data_type) {}
~HcclIRTaskInfo() override;
bool SerializeIRToProto() override;
private:
std::string hccl_type_;
uintptr_t input_data_addr_ = 0;
uintptr_t output_data_addr_ = 0;
std::vector<uint8_t> workspace_;
int64_t workspace_num_ = 0;
std::vector<uint8_t> private_def_;
uintptr_t ops_kernel_store_ = 0;
int32_t count_ = 0;
int64_t root_id_ = 0;
int64_t op_type_ = 0;
int64_t data_type_ = 0;
};
class ProfilerIRTaskInfo : public IRtaskInfo {
public:
ProfilerIRTaskInfo(TaskType task_type, uint64_t stream_id, uint64_t log_id, bool notify, uint32_t flat)
: IRtaskInfo(task_type, PROFILER_TRACE_TMP_DEF, stream_id), log_id_(log_id), notify_(notify), flat_(flat) {}
~ProfilerIRTaskInfo() override {}
bool SerializeIRToProto() override;
private:
uint64_t log_id_ = 0;
bool notify_ = false;
uint32_t flat_ = 0;
};
class MemcpyAsyncIRTaskInfo : public IRtaskInfo {
public:
MemcpyAsyncIRTaskInfo(TaskType task_type, uint32_t stream_id, uint64_t dst, uint64_t dst_max, uint64_t src,
uint64_t count, int64_t kind)
: IRtaskInfo(task_type, MEMCPY_ASYNC_TMP_DEF, stream_id),
dst_(dst),
dst_max_(dst_max),
src_(src),
count_(count),
kind_(kind) {}
~MemcpyAsyncIRTaskInfo() override {}
bool SerializeIRToProto() override;
private:
uint64_t dst_ = 0;
uint64_t dst_max_ = 0;
uint64_t src_ = 0;
uint64_t count_ = 0;
uint32_t kind_ = 0;
};
class StreamSwitchIRTaskInfo : public IRtaskInfo {
public:
StreamSwitchIRTaskInfo(TaskType task_type, uint64_t stream_id, uint32_t true_stream_id, uintptr_t input_addr,
uintptr_t value_addr, uint32_t cond, int64_t data_type)
: IRtaskInfo(task_type, STREAM_SWITCH_TMP_DEF, stream_id),
true_stream_id_(true_stream_id),
input_addr_(input_addr),
value_addr_(value_addr),
cond_(cond),
data_type_(data_type) {}
~StreamSwitchIRTaskInfo() override {}
bool SerializeIRToProto() override;
private:
uint32_t true_stream_id_ = 0;
uintptr_t input_addr_ = 0;
uintptr_t value_addr_ = 0;
uint32_t cond_ = 0;
int64_t data_type_ = 0;
};
class StreamActiveIRTaskInfo : public IRtaskInfo {
public:
StreamActiveIRTaskInfo(TaskType task_type, uint64_t stream_id, uint32_t active_stream_id)
: IRtaskInfo(task_type, STREAM_ACTIVE_TMP_DEF, stream_id), active_stream_id_(active_stream_id) {}
~StreamActiveIRTaskInfo() override {}
bool SerializeIRToProto() override;
private:
uint32_t active_stream_id_ = 0;
};
}; // namespace generator
} // namespace mindspore
#endif // MINDSPORE_CCSRC_EXECUTOR_GENERATOR_IR_IR_TASK_H_
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "predict/generator/utils/ir_model_util.h"
namespace mindspore {
namespace generator {
IRModelUtil &IRModelUtil::GetInstance() {
static IRModelUtil instance;
return instance;
}
void IRModelUtil::Init() {
MS_LOG(INFO) << "IRModel init success";
version_ = "defaultVersion";
stream_num_ = 0;
event_num_ = 0;
batch_num_ = 0;
memory_size_ = 0;
weight_size_ = 0;
var_size_ = 0;
logic_mem_base_ = 0;
logic_var_base_ = 0;
logic_var_base_ = 0;
priority_ = 0;
is_enable_save_model_ = false;
min_static_offset_ = 0;
max_dynamic_offset_ = 0;
}
} // namespace generator
} // namespace mindspore
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MINDSPORE_CCSRC_PREDICT_GENERATOR_IR_IR_MODEL_UTIL_H_
#define MINDSPORE_CCSRC_PREDICT_GENERATOR_IR_IR_MODEL_UTIL_H_
#include <string>
#include <vector>
#include <memory>
#include <utility>
#include <algorithm>
#include "utils/log_adapter.h"
namespace mindspore {
namespace generator {
class IRModelUtil {
public:
static IRModelUtil &GetInstance();
IRModelUtil(const IRModelUtil &) = delete;
IRModelUtil &operator=(const IRModelUtil &) = delete;
void Init();
void set_version(const std::string &version) { version_ = version; }
void set_stream_num(uint32_t stream_num) { stream_num_ = stream_num; }
void set_event_num(uint32_t event_num) { event_num_ = event_num; }
void set_batch_num(uint32_t batch_num) { batch_num_ = batch_num; }
void set_memory_size(uint32_t memory_size) { memory_size_ = memory_size; }
void set_weight_size(uint32_t weight_size) { weight_size_ = weight_size; }
void set_var_size(uint32_t var_size) { var_size_ = var_size; }
void set_logic_mem_base(uint32_t logic_mem_base) { logic_mem_base_ = logic_mem_base; }
void set_logic_weight_base(uint32_t logic_weight_base) { logic_weight_base_ = logic_weight_base; }
void set_logic_var_base(uint32_t logic_var_base) { logic_var_base_ = logic_var_base; }
void set_priority(uint32_t priority) { priority_ = priority; }
void set_is_enable_save_model(bool is_enable_save_model) { is_enable_save_model_ = is_enable_save_model; }
void set_min_static_offset(uint64_t min_static_offset) { min_static_offset_ = min_static_offset; }
void set_max_dynamic_offset(uint64_t max_dynamic_offset) { max_dynamic_offset_ = max_dynamic_offset; }
void set_max_mem_size(uint64_t max_mem_size) { max_mem_size_ = max_mem_size; }
void set_irmodel_mem_base(uint8_t irmodel_mem_base) { irmodel_mem_base_ = irmodel_mem_base; }
std::string version() const { return version_; }
uint32_t stream_num() const { return stream_num_; }
uint32_t event_num() const { return event_num_; }
uint32_t batch_num() const { return batch_num_; }
uint64_t memory_size() const { return memory_size_; }
uint64_t weight_size() const { return weight_size_; }
uint64_t var_size() const { return var_size_; }
uint64_t logic_mem_base() const { return logic_mem_base_; }
uint64_t logic_weight_base() const { return logic_weight_base_; }
uint64_t logic_var_base() const { return logic_var_base_; }
uint32_t priority() const { return priority_; }
bool is_enable_save_model() const { return is_enable_save_model_; }
uint64_t min_static_offset() const { return min_static_offset_; }
uint64_t max_dynamic_offset() const { return max_dynamic_offset_; }
uint64_t max_mem_size() const { return max_mem_size_; }
uint8_t irmodel_mem_base() const { return irmodel_mem_base_; }
private:
IRModelUtil() = default;
~IRModelUtil() = default;
std::string version_;
uint32_t stream_num_ = 0;
uint32_t event_num_ = 0;
uint32_t batch_num_ = 0;
uint64_t memory_size_ = 0;
uint64_t weight_size_ = 0;
uint64_t var_size_ = 0;
uint64_t logic_mem_base_ = 0;
uint64_t logic_weight_base_ = 0;
uint64_t logic_var_base_ = 0;
uint32_t priority_ = 0;
bool is_enable_save_model_ = false;
uint64_t min_static_offset_ = 0;
uint64_t max_dynamic_offset_ = 0;
uint64_t max_mem_size_ = 0;
uint8_t irmodel_mem_base_ = 0;
};
} // namespace generator
} // namespace mindspore
#endif // MINDSPORE_CCSRC_PREDICT_GENERATOR_IR_IR_MODEL_UTIL_H_
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "predict/predict.h"
#include <memory>
#include <vector>
#include <string>
namespace mindspore {
namespace predictmodel {
void StepConvertGraph(const KernelGraphPtr &kernel_graph_ptr) {
MS_LOG(INFO) << "start convert_graph step";
// get kernel_graph. this graph can be origin or device, depends on which steps to persistence
MS_EXCEPTION_IF_NULL(kernel_graph_ptr);
bool save_ms_model = MsContext::GetInstance()->save_ms_model_flag();
if (save_ms_model) {
if (kernel_graph_ptr->inputs().empty()) {
return;
}
// set convert_mode: convert cpu info or convert Davnici
executor::Kernel2Ms::GetInstance().set_convert_mode(executor::kConvertCpuMode);
// convert kernel_graph to sub_ms_graph
bool ret = executor::Kernel2Ms::GetInstance().KernelGraph2MsGraph(kernel_graph_ptr);
if (!ret) {
MS_LOG(WARNING) << "convert to mindsporeGraph failed";
} else {
MS_LOG(INFO) << "convert to Graph success";
}
}
}
void StepConvertWeight(const std::vector<tensor::TensorPtr> &inputs) {
MS_LOG(INFO) << "start convert_input step";
// get all inputs tensor
bool save_ms_model = MsContext::GetInstance()->save_ms_model_flag();
std::string save_path = MsContext::GetInstance()->save_ms_model_path();
if (save_ms_model) {
if (inputs.empty()) {
return;
}
MS_LOG(INFO) << "save ms model is true to path " << save_path;
if (!executor::Kernel2Ms::GetInstance().KernelInput2MS(inputs)) {
MS_LOG(WARNING) << "convert mindspore kernel input failed";
}
auto new_ms_graph_ptr = std::make_shared<mindspore::predict::GraphDefT>();
bool ret = executor::Kernel2Ms::GetInstance().SaveDeviceModel(new_ms_graph_ptr, save_path);
if (!ret) {
MS_LOG(WARNING) << "convert to mindsporeGraph failed";
} else {
MS_LOG(INFO) << "save ms model success";
}
}
}
} // namespace predictmodel
} // namespace mindspore
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MINDSPORE_CCSRC_PREDICT_H_
#define MINDSPORE_CCSRC_PREDICT_H_
#include <memory>
#include <vector>
#include "backend/session/session_basic.h"
#include "predict/converter/kernel2ms.h"
namespace mindspore {
namespace predictmodel {
using KernelGraphPtr = std::shared_ptr<mindspore::session::KernelGraph>;
void StepConvertGraph(const KernelGraphPtr &kernel_graph_ptr);
void StepConvertWeight(const std::vector<tensor::TensorPtr> &inputs);
} // namespace predictmodel
} // namespace mindspore
#endif // MINDSPORE_CCSRC_PREDICT_H_
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
syntax = "proto3";
import public "Graph_ir.proto";
import public "ge_runtime_taskinfo.proto";
package ge.model_runner;
option cc_enable_arenas = true;
message ModelTaskDef {
string version = 1;
repeated TaskDef task = 10;
uint32 stream_num = 11;
uint32 event_num = 12;
uint32 batch_num_ = 13;
uint64 memory_size = 14;
uint64 weight_size = 15;
uint64 var_size_ = 16;
uint64 logic_mem_base_ = 17;
uint64 logic_weight_base_ = 18;
uint64 logic_var_base_ = 19;
uint32 priority_ = 20;
}
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
syntax = "proto3";
package mindspore;
// Data type definition
enum DataType {
DT_UNDEFINED = 0;
// Basic types.
DT_BOOL = 1; // bool
DT_INT8 = 2; // int8_t
DT_INT16 = 3; // int16_t
DT_INT32 = 4; // int32_t
DT_INT64 = 5; // int64_t
DT_UINT8 = 6; // uint8_t
DT_UINT16 = 7; // uint16_t
DT_UINT32 = 8; // uint32_t
DT_UINT64 = 9; // uint64_t
DT_FLOAT16 = 10; // float 16
DT_FLOAT32 = 11; // float 32
DT_FLOAT64 = 12; // float 64
DT_STRING = 13; // string
DT_TENSOR = 14; // tensor
DT_GRAPH = 15; // graph
// list type
DT_BOOLS = 16; // list of bool
DT_INTS8 = 17; // list of int8_t
DT_INTS16 = 18; // list of int16_t
DT_INTS32 = 19; // list of int32_t
DT_INTS64 = 20; // list of int64_t
DT_UINTS8 = 21; // list of uint8_t
DT_UINTS16 = 22; // list of uint16_t
DT_UINTS32 = 23; // list of uint32_t
DT_UINTS64 = 24; // list of uint64_t
DT_FLOATS16 = 25; // list of float16
DT_FLOATS32 = 26; // list of float32
DT_FLOATS64 = 27; // list of float64
DT_STRINGS = 28; // list of string
DT_TENSORS = 29; // list of tensor
DT_GRAPHS = 30; // list of graph
DT_TUPLE = 31; // tuple
DT_LIST = 32; // list
DT_DICT = 33; // dictionary
// other types
DT_NONE = 34; // None
DT_SYM_INST = 35; // Symbolic Key Instance
// type related type
DT_BASE_INT = 36; // type generic int
DT_BASE_UINT = 37; // type generate unsigned int
DT_BASE_FLOAT = 38; // type generate float
DT_TYPE = 39; // type type
DT_ANYTHING = 40; // type anything
};
enum MSConst {
DEFAULT_REFCOUNT = 0;
WEIGHT_REFCOUNT = 999;
};
message TensorDef {
DataType data_type = 1;
repeated int64 dims = 2;
string format = 3;
string layout = 4;
uint32 refCount = 5;
uint64 offset = 6;
uint64 size = 7;
uint64 weight_size = 8;
bytes data = 9;
}
message OpDef {
string name = 1;
string type = 2;
string fwk_type = 3;
string opAttr = 4;
repeated int64 input_index = 5;
repeated int64 output_index = 6;
}
message GraphDef {
string name = 1;
repeated int64 input_index = 2;
repeated int64 output_index = 3;
uint64 mempool_size = 4;
repeated OpDef opdefs = 5;
repeated TensorDef alltensors = 6;
}
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
syntax = "proto3";
package ge.model_runner;
option cc_enable_arenas = true;
message TaskDef {
enum TaskType {
CCE = 0;
TBE = 1;
AICPU = 2;
LABEL_SET = 3;
LABEL_SWITCH = 4;
LABEL_GOTO = 5;
EVENT_RECORD = 6;
EVENT_WAIT = 7;
FUSION_START = 8;
FUSION_END = 9;
HCCL = 10;
PROFILER_TRACE = 11;
MEMCPY_ASYNC = 12;
STREAM_SWITCH = 13;
STREAM_ACTIVE = 14;
// insert new task type here
REVSERVED = 23;
};
TaskType task_type = 1;
uint64 stream_id = 2;
oneof subclass {
CceTaskDef cce_task_def = 3;
TbeTaskDef tbe_task_def = 4;
AicpuTaskDef aicpu_task_def = 5;
LabelTaskDef label_task_def = 6;
EventTaskDef event_task_def = 7;
HcclTaskDef hccl_task_def = 8;
ProfilerTaskDef profiler_task_def = 9;
MemcpyAsyncTaskDef memcpy_async_task_def = 10;
StreamSwitchTaskDef stream_switch_task_def = 11;
StreamActiveTaskDef stream_active_task_def = 12;
}
}
message CceTaskDef {
KernelContext kernel_context = 1;
string stub_func = 2;
uint32 block_dim = 3;
bytes args = 4;
uint32 args_size = 5;
bytes sm_desc = 6;
bytes flow_table = 7;
}
message TbeTaskDef {
string stub_func = 1;
uint32 block_dim = 2;
bytes args = 3;
uint32 args_size = 4;
bytes sm_desc = 5;
bytes meta_data = 8;
repeated uint64 input_addrs = 9;
repeated uint64 output_addrs = 10;
repeated uint64 workspace_addrs = 11;
}
message AicpuTaskDef {
string op_type = 1;
uint32 flag = 2;
repeated uint32 input_types = 3;
repeated Shape input_shapes = 4;
repeated uint64 input_addrs = 5;
repeated uint32 output_types = 6;
repeated Shape output_shapes = 7;
repeated uint64 output_addrs = 8;
bytes node_def = 9;
bytes func_def = 10;
}
message Shape {
repeated uint32 shape = 1;
}
message LabelTaskDef {
uint32 label_id = 1;
}
message EventTaskDef {
uint32 event_id = 1;
}
message HcclTaskDef {
string hccl_type = 1;
uint64 input_addr = 2;
uint64 output_addr = 3;
bytes workspace = 4;
int64 workspace_num = 5;
bytes private_def = 6;
uint64 ops_kernel_store = 7;
int32 count = 8;
int64 root_id = 9;
int64 op_type = 10;
int64 data_type = 11;
}
message ProfilerTaskDef {
uint64 log_id = 1;
bool notify = 2;
uint32 flat = 3;
}
message MemcpyAsyncTaskDef {
uint64 dst = 1;
uint64 dst_max = 2;
uint64 src = 3;
uint64 count = 4;
uint32 kind = 5;
}
message StreamSwitchTaskDef {
uint32 true_stream_id = 1;
uint64 input_addr = 2;
uint64 value_addr = 3;
int64 cond = 4;
int64 data_type = 5;
}
message StreamActiveTaskDef {
uint32 active_stream_id = 1;
}
message KernelContext {
uint32 kernel_type = 1;
uint32 op_id = 2;
uint32 kernel_func_id = 3;
uint32 op_index = 4;
bool is_flowtable = 5;
bytes args_offset = 6;
uint32 args_count = 7;
repeated uint32 origin_op_index = 8;
}
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
this is a dictory for predict including saving model &&& saving taskinfos.
this is a dictory for predict to gen fbs headers
\ No newline at end of file
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
include "op.fbs";
namespace mindspore.predict;
enum MSCONST: int {
WEIGHT_REFCOUNT = 999
}
table QuantParam {
scale: double;
zeroPoint: int;
min: double = 0;
max: double = 0;
narrowRange: bool = true;
numBits: int = 8;
}
table QuantParamArray {
param: [QuantParam]; //pre-channel
}
table TensorDef {
// data type
dataType: DataType;
// shape
dims: [int];
format: Format;
refCount: int;
offset: int;
data: [ubyte];
}
union OpT {
Concat,
SoftMax,
Activation,
Conv2D,
FusedBatchNorm,
CaffeBatchNorm,
BiasAdd,
Pooling,
DepthwiseConv2D,
DeDepthwiseConv2D,
Resize,
DetectionPostProcess,
FullConnection,
Mean,
DeConv2D,
Scale,
Reshape,
Eltwise,
NetOutput,
Add,
Sub,
MatMul,
StridedSlice,
Power,
Slice,
Stack,
Mul,
RealDiv,
Pad,
Maximum,
Minimum,
CaffePReLU,
LeakyReLU,
ArgMax,
ArgMin,
Exp,
CaffeCrop,
Range,
Rsqrt,
ExpandDims,
Tile,
Cast,
Shape,
Nchw2Nhwc,
Nhwc2Nchw,
QuantDTypeCast,
Split,
Permute,
FakeQuantWithMinMaxVars,
Equal,
Less,
Greater,
Min,
Floor,
Abs,
Neg,
Cos,
Sin,
Sqrt,
Square,
Constant,
Log,
Tan,
Atan,
Asin,
Clip,
Transpose,
Squeeze,
Unsqueeze,
Upsample,
Dropout,
Broadcast,
Lrn,
Prelu,
ZerosLike,
TopK,
SpaceToDepth,
SpaceToBatch,
SparseToDense,
ReverseSequence,
Rank,
Gather,
GatherNd,
Fill,
Elu,
DepthToSpace,
BatchToSpace,
AddN,
Ceil,
EmbeddingLookup,
EmbeddingLookupSparse,
FloorDiv,
FloorMod,
L2Norm,
LocalResponseNormalization,
MatrixDiag,
Reduce,
Reverse,
Round,
Select,
Scatter,
Unique,
Unstack,
LogicalAnd,
LogicalOr,
LogicalXor,
LogicalNot,
OnnxInt8Quantize,
OnnxInt8Dequantize,
FakeQuantWithMinMax,
FakeQuantWithMinMaxPerChannel,
BatchNormFold,
MulFold,
AddFold,
SquaredDifference
}
enum QuantType: int {
QUANT_NONE,
AwareTrainning,
WeightQuant,
PostTraining
}
enum FmkType: int {
TF,
CAFFE,
ONNX,
MS,
TFLITE
}
table OpDef {
name: string;
fmkType: FmkType;
attr: OpT;
inputIndex: [uint];
outputIndex: [uint];
quantType: QuantType = QUANT_NONE;
quantParam: [QuantParamArray];
}
table SubGraphDef {
name: string;
inputIndex: [uint];
outputIndex: [uint];
mempoolSize: uint;
nodes: [OpDef];
allTensors: [TensorDef]; // weight + input + output
}
table MempoolCfg {
size: uint;
shiftFactor: uint;
}
table GraphDef {
name: string;
mempoolCfg: MempoolCfg;
subgraphs: [SubGraphDef];
}
root_type GraphDef;
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace mindspore.predict;
enum ResizeMethod: byte {
UNKNOW = -1,
BILINEAR = 0,
NEAREST_NEIGHBOR = 1
}
enum DataType : int {
DT_FLOAT = 0,
DT_FLOAT16 = 1,
DT_INT8 = 2,
DT_INT32 = 3,
DT_UINT8 = 4,
DT_INT16 = 5,
DT_UINT32 = 8,
DT_INT64 = 9,
DT_UINT16 = 10,
DT_UNDEFINED = 16
}
enum Format : int {
NCHW = 0,
NHWC,
HWKC,
HWCK,
KCHW,
CKHW,
KHWC,
CHWK,
NC4HW4 = 100,
NUM_OF_FORMAT
}
enum ActivationType : byte {
NO_ACTIVATION = 0,
RELU = 1,
SIGMOID = 2,
RELU6 = 3,
ELU = 4,
LEAKY_RELU = 5,
ABS = 6,
RELU1 = 7,
SOFTSIGN = 8,
SOFTPLUS = 9,
TANH = 10,
SELU = 11,
HSWISH = 12,
HSIGMOID = 13,
THRESHOLDRELU = 14,
LINEAR = 15,
UNKNOW = 16
}
enum ReduceType : byte {
REDUCE_MAX = 0,
REDUCE_MEAN = 1,
REDUCE_ALL = 2,
REDUCE_ANY = 3,
REDUCE_LOG_SUM_EXP = 4,
REDUCE_PROD = 5,
REDUCE_SUM = 6,
UNKNOW = 7
}
enum PoolMode : byte {
MAX_POOLING = 0,
MEAN_POOLING = 1,
}
enum EltwiseMode : byte {
PROD = 0,
SUM = 1,
MAXIMUM = 2,
UNKNOW = 3
}
enum PadMode : byte {
NOTSET = 0,
SAME = 1,
VALID = 2,
CAFFE = 4
}
enum RoundMode : byte {
FLOOR = 0,
CEIL = 1
}
enum PaddingMode : byte {
CONSTANT = 0,
REFLECT = 1,
SYMMETRIC = 2,
MODE_RESERVED = 3
}
table Pad {
paddingmode: PaddingMode;
paddings: [int];
}
table Maximum {
}
table Minimum {
}
table Concat {
axis: int;
n: int;
}
table SoftMax {
axis: [int];
}
table Activation {
type: ActivationType = 0;
}
table Conv2D {
format: Format = 0;
group: int;
channelIn: int;
channelOut: int;
kernelW: int;
kernelH: int;
strideW: int;
strideH: int;
padMode: PadMode;
padUp: int;
padDown: int;
padLeft: int;
padRight: int;
dilateW: int;
dilateH: int;
hasBias: bool = false;
activationType: ActivationType = 0;
}
table FusedBatchNorm {
epsilon: float = 0.00001; // eg. epsilon=0.001
momentum: float = 0.9;
spatial: int = 1;
}
table CaffeBatchNorm {
epsilon: float; // eg. epsilon=0.001
}
table Shape {
}
table Nchw2Nhwc {
}
table Nhwc2Nchw {
}
table FakeQuantWithMinMaxVars {
narrowRange: bool;
numBits: int;
}
table BiasAdd {
axis: [int];
}
table Pooling {
format: Format = 0;
poolingMode: PoolMode;
global: bool = false;
windowW: int;
windowH: int;
strideW: int;
strideH: int;
padMode: PadMode;
padUp: int;
padDown: int;
padLeft: int;
padRight: int;
roundMode: RoundMode;
}
table DepthwiseConv2D {
format: Format = 0;
channelIn: int;
channelMultiplier: int;
kernelW: int;
kernelH: int;
strideW: int;
strideH: int;
padMode: PadMode;
padUp: int;
padDown: int;
padLeft: int;
padRight: int;
dilateW: int;
dilateH: int;
hasBias: bool = false;
activationType: ActivationType = 0;
}
table DeDepthwiseConv2D {
format: Format = 0;
channelIn: int;
channelMultiplier: int;
kernelW: int;
kernelH: int;
strideW: int;
strideH: int;
padMode: PadMode;
padUp: int;
padDown: int;
padLeft: int;
padRight: int;
dilateW: int;
dilateH: int;
hasBias: bool = false;
activationType: ActivationType = 0;
}
table Resize {
format: Format = 0;
method: ResizeMethod;
newHeight: long;
newWidth: long;
alignCorners: bool = false;
preserveAspectRatio: bool = false;
}
table DetectionPostProcess {
format: Format = 0;
inputSize: int;
hScale: float;
wScale: float;
xScale: float;
yScale: float;
NmsIouThreshold: float;
NmsScoreThreshold: float;
MaxDetections: long;
DetectionsPreClass: long;
MaxClassesPreDetection: long;
NumClasses: long;
UseRegularNms: bool;
}
table FullConnection {
hasBias: bool;
axis: int;
}
// Mean(input_tensor, axis, keep_dims)
table Mean {
axis: [int];
keepDims: bool = false;
}
table DeConv2D {
format: Format = 0;
group: int;
channelIn: int;
channelOut: int;
kernelW: int;
kernelH: int;
strideW: int;
strideH: int;
padMode: PadMode;
padUp: int;
padDown: int;
padLeft: int;
padRight: int;
dilateW: int;
dilateH: int;
hasBias: bool = false;
activationType: ActivationType = 0;
}
table Scale {
format: Format = 0;
}
table Eltwise {
mode: EltwiseMode;
}
table Add {
}
table Sub {
}
table Mul {
}
table RealDiv {
}
table Rsqrt {
}
table Equal {
}
table Less {
}
table Greater {
}
table Min {
}
table Slice {
format: Format = 0;
begin: [int];
size: [int];
}
table Floor {
}
table Abs {
}
table Neg {
}
table Exp {
}
table Cos {
}
table Sin {
}
table Sqrt {
}
table Square {
}
table Ceil {
}
table Log {
}
table Tan {
}
table Atan {
}
table Asin {
}
table Reshape {
format: Format = 0;
shape: [long];
}
table Power {
power: float;
scale: float;
shift: float;
}
table ArgMax {
axis: int;
outMaxValue: bool;
topK: int = 1;
keepDims: bool;
axisType: int;
}
table ArgMin {
axis: int;
outMaxValue: bool;
topK: int = 1;
keepDims: bool;
axisType: int;
}
table NetOutput {
}
table MatMul {
transposeA : bool = false;
transposeB : bool = false;
}
table CaffePReLU {
channelShared : bool = false;
}
table LeakyReLU {
negativeSlope: float;
}
table StridedSlice {
beginMask: int;
endMask: int;
ellipsisMask: int;
newAxisMask: int;
shrinkAxisMask: int;
begin: [int];
end: [int];
stride: [int];
isScale: [int];
}
table Stack {
axis: int;
n: int;
isScale: [int];
}
table Range {
dType: DataType;
start: int;
limit: int;
delta: int;
}
table ExpandDims {
dim: int;
}
table Tile {
multiples: [int];
}
table Cast {
srcT: int;
dstT: int;
}
table QuantDTypeCast {
srcT: DataType;
dstT: DataType;
}
table Split {
numberSplit: int;
sizeSplits: [int];
splitDim: int;
}
table CaffeCrop {
axis : long;
offsets : [long];
}
table Permute {
order: [long];
}
table Clip {
max: float;
min: float;
}
table Constant {
}
table Elu {
alpha: float = 1.0;
}
table Broadcast {
}
table Lrn {
alpha: float = 0.0001;
beta: float = 0.75;
bias: float = 1.0;
size: int;
}
enum ReduceMode : byte {
ReduceMean = 0,
ReduceMax = 1,
ReduceMin = 2,
ReduceProd = 3,
ReduceSum = 4,
ReduceSumSquare = 5
}
table Reduce {
axes: [int];
keepDims: int;
mode: ReduceMode;
}
table Prelu {
slope: [float];
}
table Transpose {
perm: [int];
conjugate: bool = false;
}
table Squeeze {
axis: [int];
}
table Unsqueeze {
axis: [int];
}
table Upsample {
mode: string;
scales: [float];
}
table Dropout {
ratio : float = 0.5;
}
table LocalResponseNormalization {
depth_radius: int;
bias: float;
alpha: float;
beta: float;
}
table ZerosLike {
}
table TopK {
k : int;
sorted : bool = true;
}
table SpaceToDepth {
blockSize : int;
format: Format = 0;
}
table SpaceToBatch {
blockShape : [int];
paddings : [int];
}
table SparseToDense {
validateIndices: bool;
}
table ReverseSequence {
seqAxis: int;
batchAxis: int;
}
table Rank {
}
table Gather {
axis: int;
batchDims: int;
}
table GatherNd {
batchDims: int;
}
table Fill {
dims: [int];
}
table DepthToSpace {
blockSize: int;
format: Format = 0;
}
table BatchToSpace {
blockShape: [int];
crops: [int];
}
table AddN {
N: int;
}
table EmbeddingLookup {
ids: [int];
maxNorm: float;
}
table EmbeddingLookupSparse {
spIds: [int];
spWeights: [float];
//combiner: Combiner=0;
maxNortm: float;
}
table FloorDiv {
}
table FloorMod {
}
table L2Norm {
axis: [int];
epsilon: float;
}
table LogicalAnd {
}
table LogicalOr {
}
table LogicalXor {
}
table LogicalNot {
}
table MatrixDiag {
k: int;
numRows: int;
numCols: int;
paddingValue: float;
}
table Select {
}
table TfReduce {
type: ReduceType = 7;
}
table Reverse {
axis: [int];
}
table Round {
}
table Scatter {
}
table Unique {
}
table Unstack {
num: int;
axis: int;
}
table OnnxInt8Quantize {
}
table OnnxInt8Dequantize {
}
table FakeQuantWithMinMax {
}
table FakeQuantWithMinMaxPerChannel {
}
table BatchNormFold {
}
table MulFold {
}
table AddFold {
}
table SquaredDifference {
}
......@@ -24,7 +24,6 @@
#include "common/utils.h"
#include "backend/session/anf_runtime_algorithm.h"
#include "runtime/device/kernel_adjust.h"
#include "predict/generator/utils/ir_model_util.h"
#include "backend/optimizer/common/helper.h"
#include "utils/utils.h"
......@@ -53,13 +52,6 @@ void AscendStreamAssign::AssignStream(const NotNull<KernelGraphPtr> &graph_ptr)
GetStreamRelations();
PrintStreamGroups();
FindEventRelations(graph_ptr);
// Get info for D Model
AscendResourceMng &resource_manager = AscendResourceMng::GetInstance();
generator::IRModelUtil::GetInstance().set_event_num(resource_manager.get_cur_event_num());
generator::IRModelUtil::GetInstance().set_stream_num(resource_manager.get_cur_stream_num());
// Init to 1,temporarily
generator::IRModelUtil::GetInstance().set_batch_num(1);
}
}
......
......@@ -24,7 +24,6 @@
#include "runtime/device/device_address.h"
#include "ir/tensor.h"
#include "utils/convert_utils.h"
#include "predict/generator/utils/ir_model_util.h"
#ifdef ENABLE_DUMP_E2E
#include "debug/e2e_dump.h"
#endif
......
......@@ -50,8 +50,6 @@ std::map<std::string, MsBackendPolicy> MsContext::policy_map_ = {{"ge", kMsBacke
MsContext::MsContext(const std::string &policy, const std::string &target) {
save_graphs_flag_ = false;
save_graphs_path_ = ".";
save_ms_model_flag_ = false;
save_ms_model_path_ = "./model.ms";
enable_dump_ = false;
save_dump_path_ = ".";
tsd_ref_ = 0;
......
......@@ -102,12 +102,6 @@ class MsContext {
void set_enable_mem_reuse(bool enable_mem_reuse) { enable_mem_reuse_ = enable_mem_reuse; }
bool enable_mem_reuse() const { return enable_mem_reuse_; }
bool save_ms_model_flag() const { return save_ms_model_flag_; }
void set_save_ms_model_flag(bool save_ms_model_flag) { save_ms_model_flag_ = save_ms_model_flag; }
std::string save_ms_model_path() const { return save_ms_model_path_; }
void set_save_ms_model_path(const std::string &save_ms_model_path) { save_ms_model_path_ = save_ms_model_path; }
void set_enable_gpu_summary(bool enable_gpu_summary) { enable_gpu_summary_ = enable_gpu_summary; }
bool enable_gpu_summary() const { return enable_gpu_summary_; }
......@@ -190,8 +184,6 @@ class MsContext {
bool enable_reduce_precision_;
bool enable_loop_sink_;
bool enable_mem_reuse_;
std::string save_ms_model_path_;
bool save_ms_model_flag_;
bool enable_gpu_summary_;
bool enable_dump_;
std::string save_dump_path_;
......
......@@ -234,22 +234,6 @@ class _Context:
if not success:
raise RuntimeError("Device id set failed!!!")
@property
def save_ms_model(self):
return self._context_handle.get_save_ms_model_flag()
@save_ms_model.setter
def save_ms_model(self, save_ms_model_flag):
self._context_handle.set_save_ms_model_flag(save_ms_model_flag)
@property
def save_ms_model_path(self):
return self._context_handle.get_save_ms_model_path()
@save_ms_model_path.setter
def save_ms_model_path(self, save_ms_model_path):
self._context_handle.set_save_ms_model_path(save_ms_model_path)
@property
def enable_auto_mixed_precision(self):
return self._context_handle.get_auto_mixed_precision_flag()
......@@ -541,7 +525,7 @@ def reset_auto_parallel_context():
@args_type_check(mode=int, precompile_only=bool, device_target=str, device_id=int, save_graphs=bool,
save_graphs_path=str, save_ms_model=bool, save_ms_model_path=str, enable_dump=bool,
save_graphs_path=str, enable_dump=bool,
save_dump_path=str, enable_reduce_precision=bool, variable_memory_max_size=str,
enable_profiling=bool, profiling_options=str, enable_auto_mixed_precision=bool,
enable_graph_kernel=bool, check_bprop=bool, max_device_memory=str, print_file_path=str,
......@@ -569,8 +553,6 @@ def set_context(**kwargs):
device_id (int): Id of target device, the value must be in [0, device_num_per_host-1],
while device_num_per_host should no more than 4096. Default: 0.
save_graphs (bool): Whether to save graphs. Default: False.
save_ms_model (bool): Whether to save lite model converted by graph. Default: False.
save_ms_model_path (str): Path to save converted lite model. Default: "."
save_graphs_path (str): Path to save graphs. Default: "."
enable_auto_mixed_precision (bool): Whether to enable auto mixed precision. Default: True.
enable_graph_kernel (bool): Whether to enable composition of basic primitives. These primitives would be
......@@ -615,7 +597,6 @@ def set_context(**kwargs):
>>> context.set_context(device_id=0)
>>> context.set_context(save_graphs=True, save_graphs_path="./model.ms")
>>> context.set_context(enable_reduce_precision=True)
>>> context.set_context(save_ms_model=True, save_ms_model_path=".")
>>> context.set_context(enable_dump=True, save_dump_path=".")
>>> context.set_context(reserve_class_name_in_scope=True)
>>> context.set_context(variable_memory_max_size="6GB")
......
......@@ -20,7 +20,6 @@ from threading import Thread, Lock
import numpy as np
import mindspore.nn as nn
import mindspore.context as context
from mindspore import log as logger
from mindspore.train.checkpoint_pb2 import Checkpoint
from mindspore.train.print_pb2 import Print
......@@ -457,18 +456,17 @@ def export(net, *inputs, file_name, file_format='GEIR'):
net (Cell): MindSpore network.
inputs (Tensor): Inputs of the `net`.
file_name (str): File name of model to export.
file_format (str): MindSpore currently supports 'GEIR', 'ONNX' 'LITE' and 'BINARY' format for exported model.
file_format (str): MindSpore currently supports 'GEIR', 'ONNX' and 'BINARY' format for exported model.
- GEIR: Graph Engine Intermidiate Representation. An intermidiate representation format of
Ascend model.
- ONNX: Open Neural Network eXchange. An open format built to represent machine learning models.
- LITE: Huawei model format for mobile. A lite model only for the MindSpore Lite
- BINARY: Binary format for model. An intermidiate representation format for models.
"""
logger.info("exporting model file:%s format:%s.", file_name, file_format)
check_input_data(*inputs, data_class=Tensor)
supported_formats = ['GEIR', 'ONNX', 'LITE', 'BINARY']
supported_formats = ['GEIR', 'ONNX', 'BINARY']
if file_format not in supported_formats:
raise ValueError(f'Illegal file format {file_format}, it must be one of {supported_formats}')
# switch network mode to infer when it is training
......@@ -497,9 +495,6 @@ def export(net, *inputs, file_name, file_format='GEIR'):
with open(file_name, 'wb') as f:
os.chmod(file_name, stat.S_IWUSR | stat.S_IRUSR)
f.write(onnx_stream)
elif file_format == 'LITE': # file_format is 'LITE'
context.set_context(save_ms_model=True, save_ms_model_path=file_name)
net(*inputs)
# restore network training mode
if is_training:
net.set_train(mode=True)
......
# git ignore file for predict
#flatbuf generated file
schema/*_generated.h
schema/inner/*_generated.h
module/tvm_module/lite/include/*_generated.h
#tvm fbs files
module/tvm_module/lite/tune/convert/*.fbs
#doTest dir
test/doTest/
cmake_minimum_required(VERSION 3.12.1)
project (mindspore-predict)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -s")
option(ENABLE_ASAN "Enable Google Sanitizer to find memory bugs" OFF)
option(ENABLE_PREDICT_ARM64 "predict arm64" OFF)
option(ENABLE_PREDICT_ARM32 "predict arm32" OFF)
set(PREDICT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(PREDICT_BUILD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build)
set(3RD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../third_party)
set(DOTEST_DIR ${PREDICT_BUILD_DIR}/test/doTest)
include_directories(${3RD_DIR})
include_directories(${3RD_DIR}/flatbuffers/include/)
include_directories(${3RD_DIR}/protobuf/build/include/)
include_directories(${3RD_DIR}/googletest/googletest/include/)
include_directories(${3RD_DIR}/googletest/googlemock/include/)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/module/tvm_kernel/lite/include/)
include_directories(${PREDICT_DIR}/module/tvm_kernel/incubator-tvm/3rdparty/dlpack/include)
include_directories(common)
if(ENABLE_PREDICT_ARM64 OR ENABLE_PREDICT_ARM32)
message("*********************predict compile arm*********************")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMS_USE_ARM=1")
set(ANDROID_NDK $ENV{ANDROID_NDK})
if(ANDROID_NDK)
add_subdirectory(${3RD_DIR}/googletest ${CMAKE_BINARY_DIR}/googletest)
link_directories(${PREDICT_BUILD_DIR}/googletest/googlemock/gtest)
add_subdirectory(${3RD_DIR}/securec ${CMAKE_BINARY_DIR}/securec)
link_directories(${PREDICT_BUILD_DIR}/securec/src)
else()
message(FATAL_ERROR "please set ANDROID_NDK in environment variable for example: export ANDROID_NDK=/root/usr/android-ndk-r16b/")
endif()
include_directories(${ANDROID_SYSROOT}/usr/include/)
if(${ANDROID_ABI} STREQUAL "armeabi-v7a")
include_directories(${ANDROID_SYSROOT}/usr/include/arm-linux-androideabi)
elseif(${ANDROID_ABI} STREQUAL "arm64-v8a")
include_directories(${ANDROID_SYSROOT}/usr/include/aarch64-linux-android)
else()
include_directories(${ANDROID_SYSROOT}/usr/include/arm-linux-androideabi)
endif()
else()
# include libsecurec.a x86
message("*********************predict compile x86*********************")
if(EXISTS "${PREDICT_DIR}/../build/mindspore/securec/src/libsecurec.a")
link_directories(${PREDICT_DIR}/../build/mindspore/securec/src)
else()
include(${PREDICT_DIR}/../cmake/dependency_securec.cmake)
link_directories(${PREDICT_BUILD_DIR}/securec/src)
endif()
# include libgtest.so x86
if(EXISTS "${PREDICT_DIR}/../build/googletest/googlemock/gtest/libgtest.so")
link_directories(${PREDICT_DIR}/../build/googletest/googlemock/gtest)
else()
include(${PREDICT_DIR}/../cmake/dependency_gtest.cmake)
link_directories(${PREDICT_BUILD_DIR}/googletest/googlemock/gtest)
endif()
endif()
if (CODE_COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -O0")
endif()
add_subdirectory(common)
add_subdirectory(src)
add_subdirectory(benchmark)
add_subdirectory(test)
add_subdirectory(module)
cmake_minimum_required(VERSION 3.12)
project(benchmark)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_BUILD_TYPE "Debug")
#include 3rd
include_directories(${3RD_DIR}/protobuf/build/include)
include_directories(${3RD_DIR}/securec/include)
include_directories(${3RD_DIR}/flatbuffers/include)
include_directories(${3RD_DIR}/googletest/googletest/include)
include_directories(${3RD_DIR}/googletest/googlemock/include)
include_directories(${PREDICT_DIR}/module/tvm_kernel/incubator-tvm/3rdparty/dlpack/include)
include_directories(${3RD_DIR}/flatbuffers/include)
include_directories(${3RD_DIR}/securec/include)
#include ms
include_directories(.)
include_directories(${PREDICT_DIR})
set(COMMON_SRC ${PREDICT_DIR}/common/flag_parser.cc
${PREDICT_DIR}/common/file_utils.cc
${PREDICT_DIR}/common/func_utils.cc
${PREDICT_DIR}/common/mslog.cc
${PREDICT_DIR}/common/utils.cc)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../output/lib/)
add_executable(benchmark main.cc benchmark.cc ${COMMON_SRC})
target_link_libraries(benchmark mspredict libsecurec.a)
add_dependencies(benchmark tvm_kernel)
add_dependencies(benchmark securec)
add_custom_command(TARGET benchmark POST_BUILD
COMMAND mkdir -pv ${DOTEST_DIR}
COMMAND cp ${PREDICT_BUILD_DIR}/benchmark/benchmark ${DOTEST_DIR})
此差异已折叠。
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PREDICT_BENCHMARK_BENCHMARK_H_
#define PREDICT_BENCHMARK_BENCHMARK_H_
#include <getopt.h>
#include <signal.h>
#include <fstream>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <memory>
#include <unordered_map>
#include "common/flag_parser.h"
#include "common/file_utils.h"
#include "common/func_utils.h"
#include "common/mslog.h"
#include "common/utils.h"
#include "include/errorcode.h"
#include "include/session.h"
#include "include/tensor.h"
#include "schema/inner/ms_generated.h"
#include "src/graph.h"
#include "src/graph_execution.h"
#include "src/op.h"
namespace mindspore {
namespace predict {
enum InDataType { kImage = 0, kBinary = 1 };
struct CheckTensor {
CheckTensor(const std::vector<size_t> &shape, const std::vector<float> &data) {
this->shape = shape;
this->data = data;
}
std::vector<size_t> shape;
std::vector<float> data;
};
class BenchmarkFlags : public virtual FlagParser {
public:
BenchmarkFlags() {
// common
AddFlag(&BenchmarkFlags::modelPath, "modelPath", "Input model path", "");
AddFlag(&BenchmarkFlags::tensorDataTypeIn, "tensorDataType", "Data type of input Tensor. float", "float");
AddFlag(&BenchmarkFlags::inDataPath, "inDataPath", "Input data path, if not set, use random input", "");
// MarkPerformance
AddFlag(&BenchmarkFlags::loopCount, "loopCount", "Run loop count", 10);
AddFlag(&BenchmarkFlags::numThreads, "numThreads", "Run threads number", 2);
AddFlag(&BenchmarkFlags::warmUpLoopCount, "warmUpLoopCount", "Run warm up loop", 3);
// MarkAccuracy
AddFlag(&BenchmarkFlags::calibDataPath, "calibDataPath", "Calibration data file path", "");
}
~BenchmarkFlags() override = default;
public:
// common
std::string modelPath;
std::string inDataPath;
InDataType inDataType;
std::string inDataTypeIn;
DataType tensorDataType;
std::string tensorDataTypeIn;
// MarkPerformance
int loopCount;
int numThreads;
int warmUpLoopCount;
// MarkAccuracy
std::string calibDataPath;
};
class Benchmark {
public:
explicit Benchmark(BenchmarkFlags *flags) : _flags(flags) {}
virtual ~Benchmark() = default;
STATUS Init();
STATUS RunBenchmark();
private:
// call GenerateInputData or ReadInputFile to init inputTensors
STATUS LoadInput();
// call GenerateRandomData to fill inputTensors
STATUS GenerateInputData();
STATUS GenerateRandomData(size_t size, void *data);
STATUS ReadInputFile();
STATUS ReadCalibData();
STATUS CleanData();
STATUS CompareOutput(const std::map<NODE_ID, std::vector<Tensor *>> &msOutputs);
float CompareData(const std::string &nodeName, std::vector<int64_t> msShape, float *msTensorData);
STATUS MarkPerformance();
STATUS MarkAccuracy();
private:
BenchmarkFlags *_flags;
std::shared_ptr<Session> session;
Context ctx;
std::vector<Tensor *> msInputs;
std::map<std::string, std::vector<Tensor *>> msOutputs;
std::unordered_map<std::string, CheckTensor *> calibData;
std::string modelName = "";
bool cleanData = true;
const float US2MS = 1000.0f;
const float percentage = 100.0f;
const int printNum = 50;
const float minFloatThr = 0.0000001f;
const uint64_t maxTimeThr = 1000000;
};
int RunBenchmark(int argc, const char **argv);
} // namespace predict
} // namespace mindspore
#endif // PREDICT_BENCHMARK_BENCHMARK_H_
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <random>
#include <limits>
#include "benchmark/benchmark.h"
int main(int argc, const char **argv) {
signal(SIGSEGV, mindspore::predict::CoreDumpTraceFunc);
return mindspore::predict::RunBenchmark(argc, argv);
}
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../third_party)
add_compile_options(-fPIC)
add_library(common_mid OBJECT
${CMAKE_CURRENT_SOURCE_DIR}/common.h
${CMAKE_CURRENT_SOURCE_DIR}/graph_util.cc
${CMAKE_CURRENT_SOURCE_DIR}/file_utils.cc
${CMAKE_CURRENT_SOURCE_DIR}/flag_parser.cc
${CMAKE_CURRENT_SOURCE_DIR}/func_utils.cc
${CMAKE_CURRENT_SOURCE_DIR}/module_registry.cc
${CMAKE_CURRENT_SOURCE_DIR}/mslog.cc
${CMAKE_CURRENT_SOURCE_DIR}/storage.cc
${CMAKE_CURRENT_SOURCE_DIR}/utils.cc)
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PREDICT_COMMON_COMMON_H_
#define PREDICT_COMMON_COMMON_H_
#include <string>
#include "schema/inner/ms_generated.h"
namespace mindspore {
namespace predict {
enum NCHW_SHAPE { NCHW_N = 0, NCHW_C = 1, NCHW_H = 2, NCHW_W = 3 };
enum NHWC_SHAPE { NHWC_N = 0, NHWC_H = 1, NHWC_W = 2, NHWC_C = 3 };
enum HWCK_SHAPE { HWCK_H = 0, HWCK_W = 1, HWCK_C = 2, HWCK_K = 3 };
enum KCHW_SHAPE { KCHW_K = 0, KCHW_C = 1, KCHW_H = 2, KCHW_W = 3 };
enum CHW_SHAPE { CHW_C = 0, CHW_H = 1, CHW_W = 2 };
enum HWC_SHAPE { HWC_H = 0, HWC_W = 1, HWC_C = 2 };
static constexpr int TENSOR_MAX_REFCOUNT = 999;
static const char *DELIM_COLON = ":";
static const char *DELIM_COMMA = ",";
static const char *DELIM_SLASH = "/";
static const char *DELIM_DOUBLE_BACKSLASH = "\\";
// quantization relative
static const char QUANTIZED_UINT8[] = "QUANTIZED_UINT8";
static const char QUANTIZED_INT8[] = "QUANTIZED_INT8";
static const char QUANTIZED_INT16[] = "QUANTIZED_INT16";
static const char QUANTIZED_UINT16[] = "QUANTIZED_UINT16";
static const char QUANTIZED_FLOAT16[] = "FLOAT16";
static const char QUANTIZED_FLOAT32[] = "FLOAT32";
static const char QUANTIZATION_TYPE_DYNAMIC[] = "DYNAMIC";
static const char QUANTIZATION_TYPE_STATIC[] = "STATIC";
static const char CALIB_NORM[] = "NORM";
// dims
static const int32_t DIM_DEFAULT_SIZE = 4;
static const Format DEFAULT_FORMAT = Format_NCHW;
} // namespace predict
} // namespace mindspore
#endif // PREDICT_COMMON_COMMON_H_
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "common/file_utils.h"
#include <climits>
namespace mindspore {
namespace predict {
char *ReadFile(const char *file, size_t *size) {
if (file == nullptr) {
MS_LOGE("file is nullptr");
return nullptr;
}
MS_ASSERT(size != nullptr);
std::ifstream ifs(RealPath(file));
if (!ifs.good()) {
MS_LOGE("file: %s is not exist", file);
return nullptr;
}
if (!ifs.is_open()) {
MS_LOGE("file: %s open failed", file);
return nullptr;
}
ifs.seekg(0, std::ios::end);
*size = ifs.tellg();
std::unique_ptr<char> buf(new (std::nothrow) char[*size]);
if (buf == nullptr) {
MS_LOGE("malloc buf failed, file:%s", file);
ifs.close();
return nullptr;
}
ifs.seekg(0, std::ios::beg);
ifs.read(buf.get(), *size);
ifs.close();
return buf.release();
}
std::string RealPath(const char *path) {
if (path == nullptr) {
MS_LOGE("path is nullptr");
return "";
}
if ((strlen(path)) >= PATH_MAX) {
MS_LOGE("path is too long");
return "";
}
std::shared_ptr<char> resolvedPath(new (std::nothrow) char[PATH_MAX]{0});
if (resolvedPath == nullptr) {
MS_LOGE("new resolvedPath failed");
return "";
}
auto ret = realpath(path, resolvedPath.get());
if (ret == nullptr) {
MS_LOGE("realpath failed");
return "";
}
return resolvedPath.get();
}
} // namespace predict
} // namespace mindspore
/**
* Copyright 2019 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PREDICT_COMMON_FILE_UTILS_H_
#define PREDICT_COMMON_FILE_UTILS_H_
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string>
#include <iostream>
#include <memory>
#include <fstream>
#include "common/utils.h"
#include "common/mslog.h"
#include "include/tensor.h"
namespace mindspore {
namespace predict {
char *ReadFile(const char *file, size_t *size);
std::string RealPath(const char *path);
} // namespace predict
} // namespace mindspore
#endif // PREDICT_COMMON_FILE_UTILS_H_
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
[submodule "3rdparty/incubator-tvm"]
path = 3rdparty/incubator-tvm
url = https://github.com/dmlc/tvm.git
branch = v0.5
此差异已折叠。
此差异已折叠。
# Copyright 2019 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
"""Neural network operators"""
# from . import arm_cpu
# from . import at_ops
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册