|
- /**
- * 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 "framework/common/profiling/ge_profiling.h"
- #include "runtime/base.h"
- #include "common/profiling/profiling_manager.h"
- #include "framework/common/debug/ge_log.h"
- #include "framework/common/debug/log.h"
- #include "framework/common/ge_inner_error_codes.h"
- #include "common/model/ge_model.h"
-
- namespace {
- const uint64_t kModelId = ge::INVALID_MODEL_ID;
- const uint16_t kStepStart = 0;
- const uint16_t kStepEnd = 1;
- } // namespace
-
- ge::Status ProfSetStepInfo(uint64_t index_id, uint16_t tag_id, rtStream_t stream) {
- static bool is_first_run = true;
- int32_t device_id = 0;
- rtError_t rt_ret = rtGetDevice(&device_id);
- if (rt_ret != RT_ERROR_NONE) {
- GELOGE(rt_ret, "[Get][LogicDeviceId]Failed, ret 0x%X", rt_ret);
- REPORT_CALL_ERROR("E19999", "Get logic device id failed, ret 0x%X", rt_ret);
- return ge::FAILED;
- }
- auto &profiling_manager = ge::ProfilingManager::Instance();
- profiling_manager.SetStepInfoIndex(index_id);
- if (is_first_run && tag_id == kStepStart) {
- GE_CHK_STATUS_RET_NOLOG(profiling_manager.ProfileStepInfo(index_id, kModelId, tag_id, stream, device_id));
- is_first_run = false;
- return ge::SUCCESS;
- }
- if (!is_first_run && tag_id == kStepEnd) {
- GE_CHK_STATUS_RET_NOLOG(profiling_manager.ProfileStepInfo(index_id, kModelId, tag_id, stream, device_id));
- is_first_run = true;
- return ge::SUCCESS;
- }
- GELOGE(ge::FAILED, "Param tag_id:%u invalid when is_first_run is %d", tag_id, is_first_run);
- REPORT_INPUT_ERROR("E10001", std::vector<std::string>({"value", "parameter", "reason"}),
- std::vector<std::string>({std::to_string(tag_id), "tag_id",
- "tag id must be 0 when first run, must be 1 when second run"}));
- return ge::FAILED;
- }
-
- ge::Status ProfGetDeviceFormGraphId(uint32_t graph_id, uint32_t &device_id) {
- return ge::ProfilingManager::Instance().GetDeviceIdFromGraph(graph_id, device_id);
- }
|