Merged
fix(interface): Fix log wording and unify logging interface #5764
HuYiShengAdd on Aug 28
fix(interface): Fix log wording and unify logging interface #5764
Merged
HuYiShengAdd on Aug 28
Total: 13 files changed+91-25
@@ -596,7 +596,7 @@ bool ConfigManagerNg::IsWithinRange(const std::string& properties, std::any& val
596 return impl_->IsWithinRange(properties, AnyCast<int64_t>(value));596 return impl_->IsWithinRange(properties, AnyCast<int64_t>(value));
597 }597 }
598 } catch (const std::out_of_range& e) {598 } catch (const std::out_of_range& e) {
599- FE_LOGE(FeError::INVALID_VAL, "key[%s] has been not loaded form tile_fwk_config_schema.json.",599+ FE_LOGE(FeError::INVALID_VAL, "key[%s] has not been loaded from tile_fwk_config_schema.json.",
600 properties.c_str());600 properties.c_str());
601 return false;601 return false;
602 }602 }
@@ -789,7 +789,7 @@ void RedundantOutCastCheck(std::map<Function*, std::set<size_t>>& removeRecord,
789 std::map<size_t, size_t>& outcasts)789 std::map<size_t, size_t>& outcasts)
790{790{
791 for (auto calleeFunc : func->GetCalleeFunctionList()) {791 for (auto calleeFunc : func->GetCalleeFunctionList()) {
792- FE_ASSERT(FeError::INVALID_PTR, calleeFunc != nullptr) << func->GetMagicName() << "has nullptr calleeFunc";792+ FE_ASSERT(FeError::INVALID_PTR, calleeFunc != nullptr) << func->GetMagicName() << " has nullptr calleeFunc";
793 std::map<size_t, size_t> outcastIdx2parent; // key: callee outcastIdx, value: caller outcastIdx793 std::map<size_t, size_t> outcastIdx2parent; // key: callee outcastIdx, value: caller outcastIdx
794 CalleeSlotNoConsumer(*calleeFunc, *func, outcasts, outcastIdx2parent);794 CalleeSlotNoConsumer(*calleeFunc, *func, outcasts, outcastIdx2parent);
795 if (!outcastIdx2parent.empty()) {795 if (!outcastIdx2parent.empty()) {
@@ -1048,9 +1048,9 @@ void ExecuteOpTri(ExecuteOperationContext* ctx)
1048 1048 
1049 // dynScalar 可能为 RUNTIME_COA_GET_PARAM(idx),需经 callop linearArgList 解析1049 // dynScalar 可能为 RUNTIME_COA_GET_PARAM(idx),需经 callop linearArgList 解析
1050 SymbolicScalar diaSym = ctx->op->GetSymbolicScalarAttribute(OpAttributeKey::dynScalar);1050 SymbolicScalar diaSym = ctx->op->GetSymbolicScalarAttribute(OpAttributeKey::dynScalar);
1051- std::vector<OpImmediate> diaImmList = {OpImmediate::Specified(diaSym)};1051+ std::vector<OpImmediate> diagonalImmList = {OpImmediate::Specified(diaSym)};
1052- int diagonal = static_cast<int>(ctx->opInter->EvaluateOpImmediate(ctx->frame, diaImmList)[0]);1052+ int diagonal = static_cast<int>(ctx->opInter->EvaluateOpImmediate(ctx->frame, diagonalImmList)[0]);
1053- std::cout << "diagonal: " << diagonal << std::endl;1053+ INTERPRETER_LOGI("diagonal: %d", diagonal);
1054 bool isUpper = ctx->op->GetBoolAttribute(OpAttributeKey::isUpper);1054 bool isUpper = ctx->op->GetBoolAttribute(OpAttributeKey::isUpper);
1055 isUpper ? calc::TriU(output, input, diagonal) : calc::TriL(output, input, diagonal);1055 isUpper ? calc::TriU(output, input, diagonal) : calc::TriL(output, input, diagonal);
1056}1056}
@@ -1856,7 +1856,7 @@ void Gather(const TensorData& out, const TensorData& params, const TensorData& i
1856 axis += paramsRank;1856 axis += paramsRank;
1857 }1857 }
1858 ASSERT(CalculatorErrorScene::GATHER_AXIS_OUT_OF_RANGE, axis >= 0 && axis < static_cast<int64_t>(paramsRank))1858 ASSERT(CalculatorErrorScene::GATHER_AXIS_OUT_OF_RANGE, axis >= 0 && axis < static_cast<int64_t>(paramsRank))
1859- << "axis out of range";1859+ << "axis " << axis << " out of range [0, " << paramsRank << ")";
1860 auto idxFlat = tindices.second.to(torch::kLong).reshape({-1});1860 auto idxFlat = tindices.second.to(torch::kLong).reshape({-1});
1861 auto gathered = tparams.second.index_select(/*dim=*/axis, /*index=*/idxFlat);1861 auto gathered = tparams.second.index_select(/*dim=*/axis, /*index=*/idxFlat);
1862 std::vector<int64_t> outSize{};1862 std::vector<int64_t> outSize{};
@@ -312,14 +312,15 @@ bool FlowVerifier::VerifyResult(const std::vector<std::shared_ptr<LogicalTensor>
312 INTERPRETER_LOGE_FULL(VerifyResultScene::VERIFY_RESULT_MISMATCH,312 INTERPRETER_LOGE_FULL(VerifyResultScene::VERIFY_RESULT_MISMATCH,
313 "%s Verify for %zu data view list index %zu result FAILED", key.c_str(),313 "%s Verify for %zu data view list index %zu result FAILED", key.c_str(),
314 goldenDataViewList.size(), k);314 goldenDataViewList.size(), k);
315- fprintf(functionInterpreter_->execDumpErrorFile, "[VERIFY:FAIL] %s, %s, %s, %s, %s\n",315+ INTERPRETER_LOGE_FULL(VerifyResultScene::VERIFY_RESULT_MISMATCH, "[VERIFY:FAIL] %s, %s, %s, %s, %s",
316- functionInterpreter_->execDumpPassName.c_str(), functionInterpreter_->execDumpFunPath.c_str(),316+ functionInterpreter_->execDumpPassName.c_str(),
317- functionInterpreter_->GetLoopSymbolString().c_str(),317+ functionInterpreter_->execDumpFunPath.c_str(),
318- std::to_string(tensorDatalist[k]->GetRawTensor()->GetRawMagic()).c_str(),318+ functionInterpreter_->GetLoopSymbolString().c_str(),
319- tensorDatalist[k]->GetRawTensor()->GetSymbol().c_str());319+ std::to_string(tensorDatalist[k]->GetRawTensor()->GetRawMagic()).c_str(),
320+ tensorDatalist[k]->GetRawTensor()->GetSymbol().c_str());
320 std::ostringstream oss;321 std::ostringstream oss;
321 tensorGraphResult.DumpDataDetail(oss);322 tensorGraphResult.DumpDataDetail(oss);
322- fprintf(functionInterpreter_->execDumpErrorFile, "%s", oss.str().c_str());323+ INTERPRETER_LOGE_FULL(VerifyResultScene::VERIFY_RESULT_MISMATCH, "%s", oss.str().c_str());
323 ProgrameInfo[toIndex(ProgrameInfoCsvHeader::verifyResult)] = "FAIL";324 ProgrameInfo[toIndex(ProgrameInfoCsvHeader::verifyResult)] = "FAIL";
324 result = false;325 result = false;
325 } else {326 } else {
@@ -528,7 +529,7 @@ void FlowVerifier::VerifyTensorGraph(Function* entry,
528 }529 }
529 } catch (std::exception& e) {530 } catch (std::exception& e) {
530 std::string msg = e.what();531 std::string msg = e.what();
531- fprintf(functionInterpreter_->execDumpErrorFile, "%s\n", ParseErrorMsg(msg).c_str());532+ INTERPRETER_LOGE_FULL(VerifyResultScene::VERIFY_RESULT_MISMATCH, "%s", ParseErrorMsg(msg).c_str());
532 WriteException();533 WriteException();
533 throw std::runtime_error(e.what());534 throw std::runtime_error(e.what());
534 }535 }
@@ -615,7 +616,7 @@ void FlowVerifier::VerifyPass(Function* func, int passIndex, const std::string&
615 func->GetMagicName().c_str(), passIdentifier.c_str(), passIndex, captureIndex,616 func->GetMagicName().c_str(), passIdentifier.c_str(), passIndex, captureIndex,
616 e.what());617 e.what());
617 std::string msg = e.what();618 std::string msg = e.what();
618- fprintf(functionInterpreter_->execDumpErrorFile, "%s\n", ParseErrorMsg(msg).c_str());619+ INTERPRETER_LOGE_FULL(VerifyResultScene::VERIFY_RESULT_MISMATCH, "%s", ParseErrorMsg(msg).c_str());
619 WriteException();620 WriteException();
620 checkResult = false;621 checkResult = false;
621 continue;622 continue;
@@ -250,7 +250,7 @@ void FunctionInterpreter::DumpBinary(std::vector<int64_t>& shape, std::vector<in
250 } else {250 } else {
251 size_t res = fwrite(data + offset[0] * dtypeSize, dtypeSize, shape[0], fdata);251 size_t res = fwrite(data + offset[0] * dtypeSize, dtypeSize, shape[0], fdata);
252 if (res != static_cast<size_t>(shape[0])) {252 if (res != static_cast<size_t>(shape[0])) {
253- INTERPRETER_LOGW("Write size is not equal actual size.");253+ INTERPRETER_LOGW("Write size is not equal to actual size.");
254 }254 }
255 }255 }
256}256}
@@ -417,7 +417,7 @@ Operation* Program::FinishCurrentFunction(const std::shared_ptr<TensorSlotScope>
417 std::to_string(currentFunctionPtr_->GetFuncMagic());417 std::to_string(currentFunctionPtr_->GetFuncMagic());
418 FE_ASSERT(FeError::NOT_EXIST, funcMagicName == expectedName)418 FE_ASSERT(FeError::NOT_EXIST, funcMagicName == expectedName)
419 << "currentFunc magicName: " << funcMagicName << ", rawName: " << currentFunctionPtr_->GetRawName()419 << "currentFunc magicName: " << funcMagicName << ", rawName: " << currentFunctionPtr_->GetRawName()
420- << "funcMagic: " << currentFunctionPtr_->GetFuncMagic();420+ << ", funcMagic: " << currentFunctionPtr_->GetFuncMagic();
421 }421 }
422 422 
423 FE_LOGD("func.end.finish: name=%s", funcMagicName.c_str());423 FE_LOGD("func.end.finish: name=%s", funcMagicName.c_str());
@@ -15,6 +15,7 @@
15 15 
16#pragma once16#pragma once
17#include "interface/utils/common.h"17#include "interface/utils/common.h"
18+#include "tilefwk/pypto_fwk_log.h"
18 19 
19#include <stdio.h>20#include <stdio.h>
20#include <stdint.h>21#include <stdint.h>
@@ -231,9 +232,9 @@ class Float {
231 232 
232 static void PrintMetadata()233 static void PrintMetadata()
233 {234 {
234- printf("expBit=%d fracBit=%d expZero=%d fp32ExpBit=%d fp32FracBit=%d fp32ExpZero=%d\n", expBit, fracBit,235+ FE_LOGI("expBit=%u fracBit=%u expZero=%u fp32ExpBit=%u fp32FracBit=%u fp32ExpZero=%u", expBit, fracBit,
235- static_cast<uint32_t>(FloatExp::expZero), static_cast<uint32_t>(FloatExp::fp32ExpBit),236+ static_cast<uint32_t>(FloatExp::expZero), static_cast<uint32_t>(FloatExp::fp32ExpBit),
236- static_cast<uint32_t>(FloatExp::fp32FracBit), static_cast<uint32_t>(FloatExp::fp32ExpZero));237+ static_cast<uint32_t>(FloatExp::fp32FracBit), static_cast<uint32_t>(FloatExp::fp32ExpZero));
237 }238 }
238 239 
239public:240public:
@@ -794,9 +794,9 @@ SymbolicScalar UpdateGetTensorDataIOIndex(size_t currOutcastIdx, size_t newOutca
794 std::vector<RawSymbolicScalarPtr> operandList = call->GetExpressionOperandList();794 std::vector<RawSymbolicScalarPtr> operandList = call->GetExpressionOperandList();
795 auto currIOType = operandList[GET_TENSOR_DATA_OPERAND_INDEX_IOTYPE];795 auto currIOType = operandList[GET_TENSOR_DATA_OPERAND_INDEX_IOTYPE];
796 auto currIOTypeIndex = operandList[GET_TENSOR_DATA_OPERAND_INDEX_IOTYPE_INDEX];796 auto currIOTypeIndex = operandList[GET_TENSOR_DATA_OPERAND_INDEX_IOTYPE_INDEX];
797- FE_ASSERT(currIOType->IsImmediate()) << "its' kind: " << SymbolicScalarKind2Name(currIOType->kind);797+ FE_ASSERT(currIOType->IsImmediate()) << "its kind: " << SymbolicScalarKind2Name(currIOType->kind);
798 FE_ASSERT(currIOTypeIndex->IsImmediate())798 FE_ASSERT(currIOTypeIndex->IsImmediate())
799- << "its' kind: " << SymbolicScalarKind2Name(currIOTypeIndex->kind);799+ << "its kind: " << SymbolicScalarKind2Name(currIOTypeIndex->kind);
800 if (currIOType->GetImmediateValue() != GET_TENSOR_DATA_OPERAND_IOTYPE_OUTCAST)800 if (currIOType->GetImmediateValue() != GET_TENSOR_DATA_OPERAND_IOTYPE_OUTCAST)
801 continue;801 continue;
802 size_t outcastIndex = currIOTypeIndex->GetImmediateValue();802 size_t outcastIndex = currIOTypeIndex->GetImmediateValue();
@@ -833,9 +833,9 @@ SymbolicScalar GetTensorDataFillIO(const GetTensorDataIODescDict& iodescDict, co
833 std::vector<RawSymbolicScalarPtr> operandList = call->GetExpressionOperandList();833 std::vector<RawSymbolicScalarPtr> operandList = call->GetExpressionOperandList();
834 auto currIOType = operandList[GET_TENSOR_DATA_OPERAND_INDEX_IOTYPE];834 auto currIOType = operandList[GET_TENSOR_DATA_OPERAND_INDEX_IOTYPE];
835 auto currIOTypeIndex = operandList[GET_TENSOR_DATA_OPERAND_INDEX_IOTYPE_INDEX];835 auto currIOTypeIndex = operandList[GET_TENSOR_DATA_OPERAND_INDEX_IOTYPE_INDEX];
836- FE_ASSERT(currIOType->IsImmediate()) << "its' kind: " << SymbolicScalarKind2Name(currIOType->kind);836+ FE_ASSERT(currIOType->IsImmediate()) << "its kind: " << SymbolicScalarKind2Name(currIOType->kind);
837 FE_ASSERT(currIOTypeIndex->IsImmediate())837 FE_ASSERT(currIOTypeIndex->IsImmediate())
838- << "its' kind: " << SymbolicScalarKind2Name(currIOTypeIndex->kind);838+ << "its kind: " << SymbolicScalarKind2Name(currIOTypeIndex->kind);
839 if (currIOType->GetImmediateValue() == ioTypeValue &&839 if (currIOType->GetImmediateValue() == ioTypeValue &&
840 currIOTypeIndex->GetImmediateValue() == ioTypeIndexValue) {840 currIOTypeIndex->GetImmediateValue() == ioTypeIndexValue) {
841 continue;841 continue;
@@ -226,7 +226,7 @@ bool Tensor::IsEmpty() const { return storage_ == nullptr; }
226int32_t Tensor::GetShape(int axis) const226int32_t Tensor::GetShape(int axis) const
227{227{
228 const size_t dimCount = storage_->shape.size();228 const size_t dimCount = storage_->shape.size();
229- FE_ASSERT(FeError::INVALID_VAL, dimCount > 0) << "Tensor has no dimensions! disCount: " << dimCount;229+ FE_ASSERT(FeError::INVALID_VAL, dimCount > 0) << "Tensor has no dimensions! dimCount: " << dimCount;
230 if (axis < 0) {230 if (axis < 0) {
231 axis += static_cast<int>(dimCount);231 axis += static_cast<int>(dimCount);
232 }232 }
@@ -16,6 +16,7 @@
16#include <gtest/gtest.h>16#include <gtest/gtest.h>
17#include <atomic>17#include <atomic>
18#include <chrono>18#include <chrono>
19+#include <cstdio>
19#include <future>20#include <future>
20 21 
21#include "interface/inner/tilefwk.h"22#include "interface/inner/tilefwk.h"
@@ -355,5 +356,21 @@ TEST_F(FunctionMixParallelTest, GetInplaceIndexIsInplaceAttr)
355 EXPECT_EQ(op.GetInplaceIndex(0), 0);356 EXPECT_EQ(op.GetInplaceIndex(0), 0);
356}357}
357 358 
359+// FunctionInterpreter::DumpBinary short-write branch:
360+// a read-only FILE* makes fwrite return 0 (not equal to shape[0]),
361+// which triggers the "Write size is not equal to actual size" warning.
362+TEST_F(FunctionMixParallelTest, DumpBinaryShortWriteTriggersWarning)
363+{
364+ FunctionInterpreter interp;
365+ std::vector<int64_t> shape = {4};
366+ std::vector<int64_t> stride = {1};
367+ std::vector<int64_t> offset = {0};
368+ uint8_t data[4] = {1, 2, 3, 4};
369+ FILE* fp = fopen("/dev/null", "r");
370+ ASSERT_NE(fp, nullptr);
371+ interp.DumpBinary(shape, stride, offset, fp, data, 1);
372+ fclose(fp);
373+}
374+ 
358} // namespace375} // namespace
359} // namespace npu::tile_fwk376} // namespace npu::tile_fwk
@@ -13,10 +13,13 @@
13 * \brief Test cases for LogicalTensor class with error codes13 * \brief Test cases for LogicalTensor class with error codes
14 */14 */
15 15 
16+#include <memory>
17+ 
16#include "gtest/gtest.h"18#include "gtest/gtest.h"
17#include "tilefwk/tilefwk.h"19#include "tilefwk/tilefwk.h"
18#include "interface/inner/tilefwk.h"20#include "interface/inner/tilefwk.h"
19#include "interface/tensor/tensormap.h"21#include "interface/tensor/tensormap.h"
22+#include "interface/tensor/logical_tensor.h"
20#include "tilefwk/data_type.h"23#include "tilefwk/data_type.h"
21 24 
22using namespace npu::tile_fwk;25using namespace npu::tile_fwk;
@@ -76,3 +79,46 @@ TEST_F(TestLogicalTensor, PackedDataSize)
76 EXPECT_EQ(storage->GetRawTensor()->GetRawDataSize(), 4);79 EXPECT_EQ(storage->GetRawTensor()->GetRawDataSize(), 4);
77 EXPECT_EQ(storage->MemorySize(), 4);80 EXPECT_EQ(storage->MemorySize(), 4);
78}81}
82+ 
83+// Helper: build a T_MOP_CALL expression that GetTensorDataDict recognises
84+// (callee symbol name starts with "RUNTIME_GetTensorData"). By making the
85+// IOTYPE (operand[2]) or IOTYPE_INDEX (operand[3]) a non-immediate symbol,
86+// the FE_ASSERT inside UpdateGetTensorDataIOIndex fails and throws.
87+static SymbolicScalar MakeGetTensorDataCall(bool ioTypeImmediate, bool ioTypeIndexImmediate)
88+{
89+ auto callee = RawSymbolicSymbol::Create(AddRuntimePrefix("GetTensorDataTest"));
90+ auto index = RawSymbolicImmediate::Create(0); // operand[1] must be immediate for GetImmediateValue
91+ // operand[2] (IOTYPE): use OUTCAST so the "continue" guard is bypassed
92+ RawSymbolicScalarPtr ioType = ioTypeImmediate ?
93+ static_cast<RawSymbolicScalarPtr>(
94+ RawSymbolicImmediate::Create(GET_TENSOR_DATA_OPERAND_IOTYPE_OUTCAST)) :
95+ static_cast<RawSymbolicScalarPtr>(RawSymbolicSymbol::Create("nonImmIOType"));
96+ // operand[3] (IOTYPE_INDEX): non-immediate to trigger the second FE_ASSERT
97+ RawSymbolicScalarPtr ioTypeIndex = ioTypeIndexImmediate ?
98+ static_cast<RawSymbolicScalarPtr>(RawSymbolicImmediate::Create(0)) :
99+ static_cast<RawSymbolicScalarPtr>(
100+ RawSymbolicSymbol::Create("nonImmIOTypeIndex"));
101+ std::vector<RawSymbolicScalarPtr> operands = {callee, index, ioType, ioTypeIndex};
102+ auto expr = std::make_shared<RawSymbolicExpression>(SymbolicOpcode::T_MOP_CALL, operands);
103+ return SymbolicScalar(expr);
104+}
105+ 
106+// FE_ASSERT(currIOType->IsImmediate()) fails because the IOTYPE operand
107+// is a symbol, not an immediate.
108+TEST_F(TestLogicalTensor, UpdateGetTensorDataIOIndexNonImmediateIOTypeThrows)
109+{
110+ // IOTYPE non-immediate triggers the first FE_ASSERT.
111+ SymbolicScalar scalar = MakeGetTensorDataCall(false, true);
112+ EXPECT_THROW(UpdateGetTensorDataIOIndex(0, 1, scalar), std::exception);
113+}
114+ 
115+// FE_ASSERT(currIOTypeIndex->IsImmediate()) fails because IOTYPE is
116+// immediate-OUTCAST (passes the first assert and the continue guard),
117+// but IOTYPE_INDEX is a symbol, triggering the second FE_ASSERT.
118+TEST_F(TestLogicalTensor, UpdateGetTensorDataIOIndexNonImmediateIOTypeIndexThrows)
119+{
120+ // IOTYPE is immediate OUTCAST; IOTYPE_INDEX non-immediate triggers the
121+ // second FE_ASSERT.
122+ SymbolicScalar scalar = MakeGetTensorDataCall(true, false);
123+ EXPECT_THROW(UpdateGetTensorDataIOIndex(0, 1, scalar), std::exception);
124+}
@@ -14,6 +14,7 @@
14 */14 */
15 15 
16#include "pybind_common.h"16#include "pybind_common.h"
17+#include "tilefwk/pypto_fwk_log.h"
17 18 
18#include <utility>19#include <utility>
19#include <vector>20#include <vector>
@@ -544,7 +545,7 @@ void BindControllerScopeClasses(py::module_& m)
544 try {545 try {
545 result[py::str(key)] = AnyToPyObject(val);546 result[py::str(key)] = AnyToPyObject(val);
546 } catch (const py::type_error& e) {547 } catch (const py::type_error& e) {
547- py::print("Warning: Skipping key '", key, "' -", e.what());548+ PYPTO_LOGW("Warning: Skipping key '%s' - %s", key.c_str(), e.what());
548 }549 }
549 }550 }
550 return result;551 return result;