!38 Synchronize with latest Ascend software suite 17 Jun 2020
Merge pull request !38 from yanghaoran/masterpull/38/MERGE
commit
1350673d51
@ -1,61 +0,0 @@
|
||||
/**
|
||||
* 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 INC_FRAMEWORK_DLOG_LOG_H_
|
||||
#define INC_FRAMEWORK_DLOG_LOG_H_
|
||||
|
||||
#include <string>
|
||||
#if !defined(__ANDROID__) && !defined(ANDROID)
|
||||
#include "toolchain/slog.h"
|
||||
#else
|
||||
#include <android/log.h>
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define FUNC_NAME __FUNCTION__
|
||||
#else
|
||||
#define FUNC_NAME __PRETTY_FUNCTION__
|
||||
#endif
|
||||
|
||||
#if !defined(__ANDROID__) && !defined(ANDROID)
|
||||
#define DAV_LOGI(MOD_NAME, fmt, ...) dlog_info(static_cast<int>(GE), "%s:" #fmt, __FUNCTION__, ##__VA_ARGS__)
|
||||
#define DAV_LOGW(MOD_NAME, fmt, ...) dlog_warn(static_cast<int>(GE), "%s:" #fmt, __FUNCTION__, ##__VA_ARGS__)
|
||||
#define DAV_LOGE(MOD_NAME, fmt, ...) dlog_error(static_cast<int>(GE), "%s:" #fmt, __FUNCTION__, ##__VA_ARGS__)
|
||||
#define DAV_LOGD(MOD_NAME, fmt, ...) dlog_debug(static_cast<int>(GE), "%s:" #fmt, __FUNCTION__, ##__VA_ARGS__)
|
||||
#define DAV_EVENT(MOD_NAME, fmt, ...) dlog_event(static_cast<int>(GE), "%s:" #fmt, __FUNCTION__, ##__VA_ARGS__)
|
||||
#else
|
||||
#define DAV_LOGI(MOD_NAME, fmt, ...) \
|
||||
__android_log_print(ANDROID_LOG_INFO, MOD_NAME, "%s %s(%d)::" #fmt, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||
#define DAV_LOGW(MOD_NAME, fmt, ...) \
|
||||
__android_log_print(ANDROID_LOG_WARN, MOD_NAME, "%s %s(%d)::" #fmt, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||
#define DAV_LOGE(MOD_NAME, fmt, ...) \
|
||||
__android_log_print(ANDROID_LOG_ERROR, MOD_NAME, "%s %s(%d)::" #fmt, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||
#define DAV_LOGD(MOD_NAME, fmt, ...) \
|
||||
__android_log_print(ANDROID_LOG_DEBUG, MOD_NAME, "%s %s(%d)::" #fmt, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||
#define DAV_EVENT(MOD_NAME, fmt, ...) \
|
||||
__android_log_print(ANDROID_LOG_DEBUG, MOD_NAME, "%s %s(%d)::" #fmt, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#define DLOG_DECLARE(level) \
|
||||
void Log_##level(const char *mod_name, const char *func, const char *file, int line, const char *format, ...)
|
||||
|
||||
namespace domi {
|
||||
DLOG_DECLARE(INFO);
|
||||
DLOG_DECLARE(WARNING);
|
||||
DLOG_DECLARE(ERROR);
|
||||
} // namespace domi
|
||||
|
||||
#endif // INC_FRAMEWORK_DLOG_LOG_H_
|
@ -0,0 +1,113 @@
|
||||
/**
|
||||
* 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 INC_FRAMEWORK_GE_RUNTIME_DAVINCI_MODEL_H_
|
||||
#define INC_FRAMEWORK_GE_RUNTIME_DAVINCI_MODEL_H_
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "ge_runtime/op_info.h"
|
||||
#include "ge_runtime/task_info.h"
|
||||
|
||||
namespace ge {
|
||||
namespace model_runner {
|
||||
class DavinciModel {
|
||||
public:
|
||||
DavinciModel(const std::vector<std::shared_ptr<TaskInfo>> &task_info_list,
|
||||
const std::vector<std::shared_ptr<OpInfo>> &data_info_list,
|
||||
const std::vector<std::shared_ptr<OpInfo>> &output_info_list,
|
||||
const std::vector<std::shared_ptr<OpInfo>> &constant_info_list,
|
||||
const std::vector<model_runner::OpInfoPtr> &variable_info_list,
|
||||
const std::vector<uint32_t> &wait_active_stream_list,
|
||||
const std::vector<uint32_t> &force_copy_stream_list, uint64_t mem_size = 0, uint64_t weight_size = 0,
|
||||
uint64_t var_size = 0, uintptr_t logic_mem_base = 0, uintptr_t logic_weight_base = 0,
|
||||
uintptr_t logic_var_base = 0, uint32_t stream_num = 0, uint32_t batch_num = 0, uint32_t event_num = 0,
|
||||
int32_t priority = 0)
|
||||
: task_info_list_(task_info_list),
|
||||
data_info_list_(data_info_list),
|
||||
output_info_list_(output_info_list),
|
||||
constant_info_list_(constant_info_list),
|
||||
variable_info_list_(variable_info_list),
|
||||
wait_active_stream_list_(wait_active_stream_list),
|
||||
force_copy_stream_list_(force_copy_stream_list),
|
||||
mem_size_(mem_size),
|
||||
weight_size_(weight_size),
|
||||
var_size_(var_size),
|
||||
logic_mem_base_(logic_mem_base),
|
||||
logic_weight_base_(logic_weight_base),
|
||||
logic_var_base_(logic_var_base),
|
||||
stream_num_(stream_num),
|
||||
batch_num_(batch_num),
|
||||
event_num_(event_num),
|
||||
priority_(priority) {}
|
||||
~DavinciModel() {}
|
||||
|
||||
uint64_t GetMemSize() const { return mem_size_; }
|
||||
uint64_t GetWeightSize() const { return weight_size_; }
|
||||
uint64_t GetVarSize() const { return var_size_; }
|
||||
|
||||
uintptr_t GetLogicMemBase() const { return logic_mem_base_; }
|
||||
uintptr_t GetLogicWeightBase() const { return logic_weight_base_; }
|
||||
uintptr_t GetLogicVarBase() const { return logic_var_base_; }
|
||||
|
||||
uint32_t GetStreamNum() const { return stream_num_; }
|
||||
uint32_t GetBatchNum() const { return batch_num_; }
|
||||
uint32_t GetEventNum() const { return event_num_; }
|
||||
|
||||
const std::vector<uint32_t> &GetWaitActiveStreams() const { return wait_active_stream_list_; }
|
||||
const std::vector<uint32_t> &GetForceCopyStreams() const { return force_copy_stream_list_; }
|
||||
|
||||
int32_t GetPriority() const { return priority_; }
|
||||
|
||||
const std::vector<std::shared_ptr<TaskInfo>> &GetTaskInfoList() const { return task_info_list_; }
|
||||
const std::vector<std::shared_ptr<OpInfo>> &GetDataInfoList() const { return data_info_list_; }
|
||||
const std::vector<std::shared_ptr<OpInfo>> &GetOutputInfoList() const { return output_info_list_; }
|
||||
const std::vector<std::shared_ptr<OpInfo>> &GetConstantInfoList() const { return output_info_list_; }
|
||||
const std::vector<model_runner::OpInfoPtr> &GetVariableInfoList() const { return variable_info_list_; }
|
||||
|
||||
private:
|
||||
std::vector<std::shared_ptr<TaskInfo>> task_info_list_;
|
||||
std::vector<std::shared_ptr<OpInfo>> data_info_list_;
|
||||
std::vector<std::shared_ptr<OpInfo>> output_info_list_;
|
||||
std::vector<std::shared_ptr<OpInfo>> constant_info_list_;
|
||||
std::vector<model_runner::OpInfoPtr> variable_info_list_;
|
||||
|
||||
std::vector<uint32_t> wait_active_stream_list_;
|
||||
std::vector<uint32_t> force_copy_stream_list_;
|
||||
|
||||
uint64_t mem_size_;
|
||||
uint64_t weight_size_;
|
||||
uint64_t var_size_;
|
||||
|
||||
uintptr_t logic_mem_base_;
|
||||
uintptr_t logic_weight_base_;
|
||||
uintptr_t logic_var_base_;
|
||||
|
||||
uint32_t stream_num_;
|
||||
uint32_t batch_num_;
|
||||
uint32_t event_num_;
|
||||
|
||||
int32_t priority_;
|
||||
|
||||
// Disable to copy constructor and assignment operator
|
||||
DavinciModel &operator=(const DavinciModel &) = delete;
|
||||
DavinciModel(const DavinciModel &) = delete;
|
||||
};
|
||||
} // namespace model_runner
|
||||
} // namespace ge
|
||||
|
||||
#endif // INC_FRAMEWORK_GE_RUNTIME_DAVINCI_MODEL_H_
|
@ -0,0 +1,58 @@
|
||||
/**
|
||||
* 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 INC_FRAMEWORK_GE_RUNTIME_MODEL_RUNNER_H_
|
||||
#define INC_FRAMEWORK_GE_RUNTIME_MODEL_RUNNER_H_
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "common/ge_inner_error_codes.h"
|
||||
#include "common/ge_types.h"
|
||||
#include "ge_runtime/davinci_model.h"
|
||||
|
||||
namespace ge {
|
||||
namespace model_runner {
|
||||
class RuntimeModel;
|
||||
|
||||
class ModelRunner {
|
||||
public:
|
||||
static ModelRunner &Instance();
|
||||
|
||||
bool LoadDavinciModel(uint32_t device_id, uint64_t session_id, uint32_t model_id,
|
||||
std::shared_ptr<DavinciModel> davinci_model, std::shared_ptr<ModelListener> listener);
|
||||
|
||||
const std::vector<uint32_t> &GetTaskIdList(uint32_t model_id) const;
|
||||
|
||||
bool UnloadModel(uint32_t model_id);
|
||||
|
||||
bool RunModel(uint32_t model_id, const InputData &input_data, OutputData *output_data);
|
||||
|
||||
bool GetInputOutputDescInfo(uint32_t model_id, bool zero_copy, std::vector<InputOutputDescInfo> *input_desc,
|
||||
std::vector<InputOutputDescInfo> *output_desc, std::vector<uint32_t> *input_format,
|
||||
std::vector<uint32_t> *output_format);
|
||||
|
||||
private:
|
||||
ModelRunner() = default;
|
||||
~ModelRunner() = default;
|
||||
|
||||
std::unordered_map<uint32_t, std::shared_ptr<RuntimeModel>> runtime_models_;
|
||||
};
|
||||
} // namespace model_runner
|
||||
} // namespace ge
|
||||
|
||||
#endif // INC_FRAMEWORK_GE_RUNTIME_MODEL_RUNNER_H_
|
@ -0,0 +1,72 @@
|
||||
/**
|
||||
* 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 INC_FRAMEWORK_GE_RUNTIME_OP_INFO_H_
|
||||
#define INC_FRAMEWORK_GE_RUNTIME_OP_INFO_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace ge {
|
||||
namespace model_runner {
|
||||
struct TensorInfo {
|
||||
int64_t GetShapeSize() const {
|
||||
int64_t res = 1;
|
||||
if (dims.empty()) {
|
||||
return 0;
|
||||
}
|
||||
for (auto dim : dims) {
|
||||
res *= dim;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int64_t GetDim(uint32_t index) {
|
||||
if (index >= dims.size()) {
|
||||
return 0;
|
||||
}
|
||||
return dims[index];
|
||||
}
|
||||
|
||||
std::vector<int64_t> dims;
|
||||
uint32_t datatype;
|
||||
uint32_t format;
|
||||
uint32_t real_dim_cnt;
|
||||
uint32_t size;
|
||||
bool is_output;
|
||||
};
|
||||
|
||||
struct OpInfo {
|
||||
uint32_t index;
|
||||
std::string name;
|
||||
std::string type;
|
||||
bool var_is_broadcast;
|
||||
std::vector<uintptr_t> input_addrs;
|
||||
std::vector<uintptr_t> output_addrs;
|
||||
std::vector<TensorInfo> input_tensors;
|
||||
std::vector<TensorInfo> output_tensors;
|
||||
std::vector<TensorInfo> weight_tensors;
|
||||
std::vector<std::string> src_name;
|
||||
std::vector<int64_t> src_index;
|
||||
std::string weight_data;
|
||||
};
|
||||
|
||||
using TensorInfoPtr = std::shared_ptr<TensorInfo>;
|
||||
using OpInfoPtr = std::shared_ptr<OpInfo>;
|
||||
} // namespace model_runner
|
||||
} // namespace ge
|
||||
#endif // INC_FRAMEWORK_GE_RUNTIME_OP_INFO_H_
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,113 @@
|
||||
/**
|
||||
* 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 INC_FRAMEWORK_OMG_OMG_H_
|
||||
#define INC_FRAMEWORK_OMG_OMG_H_
|
||||
|
||||
#include <google/protobuf/message.h>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include "framework/common/types.h"
|
||||
#include "framework/omg/omg_inner_types.h"
|
||||
#include "proto/ge_ir.pb.h"
|
||||
#include "proto/om.pb.h"
|
||||
|
||||
#include "graph/compute_graph.h"
|
||||
#include "graph/graph.h"
|
||||
#include "graph/model.h"
|
||||
#include "runtime/kernel.h"
|
||||
|
||||
using domi::Status;
|
||||
using std::pair;
|
||||
using std::string;
|
||||
using std::unordered_map;
|
||||
using std::vector;
|
||||
|
||||
namespace ge {
|
||||
/**
|
||||
* @ingroup domi_omg
|
||||
* @brief init omg context
|
||||
* @return void
|
||||
*/
|
||||
Status InitDomiOmgContext(const string &input_shape, const string &input_format, const string &net_format,
|
||||
bool is_dynamic_input);
|
||||
|
||||
/**
|
||||
* @ingroup domi_omg
|
||||
* @brief generate graph based on the input model file and weight file
|
||||
* @param [out] graph graph
|
||||
* @param [in] model_file path of model file
|
||||
* @param [in] weights_file path of weight file
|
||||
* @param [in] type type of the input model
|
||||
* @param [in] op_conf op mapping configuration
|
||||
* @param [in] target type of platform. If a tiny model is generated, set target to tiny
|
||||
* @param [in] run_mode run model
|
||||
* @param [in] enable_l2dynamic enable l2dynamic
|
||||
* @param [in] is_dynamic_input dynamic input, true of false
|
||||
* @param [in] atc_params multiply atc params
|
||||
* @return Status result code
|
||||
*/
|
||||
Status ParseGraph(ge::Graph &graph, const std::map<string, string> &atc_params, const char *model_file,
|
||||
const char *weights_file, domi::FrameworkType type, const char *op_conf = nullptr,
|
||||
const char *target = nullptr, RunMode run_mode = GEN_OM_MODEL, bool is_dynamic_input = false);
|
||||
|
||||
/**
|
||||
* @ingroup domi_omg
|
||||
* @brief generates a simplified JSON file based on the key value of the offline model file in protobuf format
|
||||
* @param [in] model_file path of offline model file
|
||||
* @param [out] json_file path of json file
|
||||
* @param [key] encrypted key
|
||||
* @return Status result code
|
||||
*/
|
||||
Status ConvertOmModelToJson(const char *model_file, const char *json_file);
|
||||
|
||||
Status ConvertPbtxtToJson(const char *model_file, const char *json_file);
|
||||
/**
|
||||
* @ingroup domi_omg
|
||||
* @brief convert the model file in protobuf format into a JSON file.
|
||||
* @param [in] framework type of model
|
||||
* @param [in] om model_file path of offline model file
|
||||
* @param [out] json_file path of json file
|
||||
* @param [key] encrypted key
|
||||
* @return Status result code
|
||||
*/
|
||||
Status ConvertFwkModelToJson(domi::FrameworkType framework, const char *model_file, const char *json_file);
|
||||
|
||||
void GetGroupName(ge::proto::ModelDef &model);
|
||||
|
||||
void FindParserSo(const string &path, vector<string> &fileList, string &caffe_parser_path);
|
||||
|
||||
Status CheckCustomAiCpuOpLib();
|
||||
|
||||
Status DumpInfershapeJson(const ge::Graph &graph, const char *json_file);
|
||||
|
||||
Status SetOutputNodeInfo(ge::Graph &graph, const std::string &output_type, const std::string &output_format);
|
||||
|
||||
Status GetOutputLeaf(ge::NodePtr node, std::vector<std::pair<ge::NodePtr, int32_t>> &output_nodes_info,
|
||||
std::vector<std::string> &output_nodes_name);
|
||||
} // namespace ge
|
||||
|
||||
namespace domi {
|
||||
/**
|
||||
* @ingroup domi_omg
|
||||
* @brief get omg context
|
||||
* @return reference of OmgContext
|
||||
*/
|
||||
ge::OmgContext &GetContext();
|
||||
} // namespace domi
|
||||
|
||||
#endif // INC_FRAMEWORK_OMG_OMG_H_
|
@ -0,0 +1,46 @@
|
||||
/**
|
||||
* 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 INC_GRAPH_RUNTIME_INFERENCE_CONTEXT_H_
|
||||
#define INC_GRAPH_RUNTIME_INFERENCE_CONTEXT_H_
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include "external/graph/ge_error_codes.h"
|
||||
#include "external/graph/tensor.h"
|
||||
|
||||
namespace ge {
|
||||
class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY RuntimeInferenceContext {
|
||||
public:
|
||||
static graphStatus GetContext(const std::string &context_id, RuntimeInferenceContext **ctx);
|
||||
static graphStatus CreateContext(const std::string &context_id);
|
||||
static void DestroyContext(const std::string &context_id);
|
||||
|
||||
graphStatus SetTensor(int64_t node_id, int output_id, Tensor &&tensor);
|
||||
graphStatus GetTensor(int64_t node_id, int output_id, Tensor &tensor);
|
||||
|
||||
private:
|
||||
std::map<int64_t, std::vector<Tensor>> tensors_;
|
||||
std::mutex mu_;
|
||||
|
||||
static std::map<std::string, std::unique_ptr<RuntimeInferenceContext>> contexts_;
|
||||
static std::mutex ctx_mu_;
|
||||
};
|
||||
} // namespace ge
|
||||
|
||||
#endif // INC_GRAPH_RUNTIME_INFERENCE_CONTEXT_H_
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue