You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
graphengine/ge/hybrid/executor/hybrid_execution_context.h

110 lines
4.2 KiB

/**
* 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 GE_HYBRID_EXECUTOR_HYBRID_EXECUTION_CONTEXT_H_
#define GE_HYBRID_EXECUTOR_HYBRID_EXECUTION_CONTEXT_H_
#include <atomic>
#include <unordered_map>
#include "common/blocking_queue.h"
#include "common/properties_manager.h"
#include "framework/common/debug/ge_log.h"
#include "graph/ge_local_context.h"
#include "hybrid/common/npu_memory_allocator.h"
#include "hybrid/common/tensor_value.h"
#include "hybrid/executor/hybrid_profiler.h"
#include "hybrid/executor/node_done_manager.h"
#include "hybrid/executor/node_state.h"
#include "hybrid/executor/rt_callback_manager.h"
#include "hybrid/model/hybrid_model.h"
4 years ago
// If expr is not SUCCESS, print the log and return the same value
#define HYBRID_CHK_STATUS_RET(expr, ...) \
do { \
const ge::Status _status = (expr); \
if (_status != ge::SUCCESS) { \
if (_status == ge::END_OF_SEQUENCE) { \
GELOGD("Got end of sequence"); \
} else { \
GELOGE(_status, __VA_ARGS__); \
} \
return _status; \
} \
} while (0)
namespace ge {
namespace hybrid {
struct GraphExecutionContext {
GraphExecutionContext();
~GraphExecutionContext() = default;
void SetErrorCode(Status error_code);
Status GetStatus() const;
Status Synchronize(rtStream_t rt_stream);
uint64_t session_id = 0;
uint64_t context_id = 0;
const HybridModel *model = nullptr;
const GEThreadLocalContext *ge_context = nullptr;
rtStream_t stream = nullptr;
rtContext_t rt_context = nullptr;
rtContext_t rt_gen_context = nullptr;
4 years ago
std::unique_ptr<CallbackManager> callback_manager = nullptr;
NpuMemoryAllocator *allocator = nullptr;
4 years ago
mutable std::unique_ptr<HybridProfiler> profiler = nullptr;
DumpProperties dump_properties;
bool trace_enabled = false;
bool dump_enabled = false;
std::atomic_bool is_eos_;
long profiling_level = 0;
long iteration = 0;
private:
Status status = SUCCESS;
mutable std::mutex mu;
};
4 years ago
#define RECORD_PROFILING_EVENT(context, evt_type, fmt, category, node_name, ...) \
do { \
if ((context != nullptr) && (context)->profiler != nullptr) { \
if (node_name != nullptr) { \
context->profiler->RecordEvent(evt_type, "tid:%lu [%s@%ld] [%s] " fmt, \
GeLog::GetTid(), node_name, context->iteration, category, \
4 years ago
##__VA_ARGS__); \
4 years ago
} else { \
context->profiler->RecordEvent(evt_type, "tid:%lu [%s] " fmt, GeLog::GetTid(), category, ##__VA_ARGS__); \
4 years ago
}\
} \
} while (0)
#define RECORD_MODEL_EXECUTION_EVENT(context, fmt, ...) \
RECORD_PROFILING_EVENT((context), HybridProfiler::GENERAL, fmt, "ModelExecutor", nullptr, ##__VA_ARGS__)
#define RECORD_SHAPE_INFERENCE_EVENT(context, name, fmt, ...) \
4 years ago
RECORD_PROFILING_EVENT((context), HybridProfiler::SHAPE_INFERENCE, fmt, "ShapeInference", name, ##__VA_ARGS__)
#define RECORD_COMPILE_EVENT(context, name, fmt, ...) \
4 years ago
RECORD_PROFILING_EVENT((context), HybridProfiler::COMPILE, fmt, "Compilation", name, ##__VA_ARGS__)
#define RECORD_EXECUTION_EVENT(context, name, fmt, ...) \
4 years ago
RECORD_PROFILING_EVENT((context), HybridProfiler::EXECUTION, fmt, "Execution", name, ##__VA_ARGS__)
#define RECORD_CALLBACK_EVENT(context, name, fmt, ...) \
RECORD_PROFILING_EVENT((context), HybridProfiler::CALLBACKS, fmt, "Callback", name, ##__VA_ARGS__)
} // namespace hybrid
} // namespace ge
4 years ago
#endif // GE_HYBRID_EXECUTOR_HYBRID_EXECUTION_CONTEXT_H_