This is an automated email from the ASF dual-hosted git repository. tqchen pushed a commit to branch refactor-s2 in repository https://gitbox.apache.org/repos/asf/tvm.git
commit 2d5791a0e49c454352167c126b97120197ba68da Author: tqchen <[email protected]> AuthorDate: Tue Apr 22 10:18:58 2025 -0400 Update string to make use of the new ffi::String convention --- src/contrib/msc/core/printer/msc_base_printer.cc | 2 +- src/meta_schedule/database/database_utils.cc | 4 ++-- src/node/structural_hash.cc | 10 +++++----- src/runtime/disco/protocol.h | 12 ++++++------ src/runtime/rpc/rpc_local_session.cc | 6 +++--- src/runtime/rpc/rpc_module.cc | 2 +- src/script/printer/doc_printer/python_doc_printer.cc | 2 +- src/tir/schedule/instruction.cc | 2 +- src/tir/schedule/instruction_traits.h | 2 +- src/tir/schedule/trace.cc | 12 ++++++------ 10 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/contrib/msc/core/printer/msc_base_printer.cc b/src/contrib/msc/core/printer/msc_base_printer.cc index 4b70d54e80..dac732aaa6 100644 --- a/src/contrib/msc/core/printer/msc_base_printer.cc +++ b/src/contrib/msc/core/printer/msc_base_printer.cc @@ -114,7 +114,7 @@ void MSCBasePrinter::PrintTypedDoc(const LiteralDoc& doc) { output_ << float_imm->value; } } else if (const auto* string_obj = value.as<StringObj>()) { - output_ << "\"" << tvm::support::StrEscape(string_obj->bytes.data, string_obj->bytes.size) + output_ << "\"" << tvm::support::StrEscape(string_obj->data, string_obj->size) << "\""; } else { LOG(FATAL) << "TypeError: Unsupported literal value type: " << value.GetTypeKey(); diff --git a/src/meta_schedule/database/database_utils.cc b/src/meta_schedule/database/database_utils.cc index e24fd15551..f79e91cefc 100644 --- a/src/meta_schedule/database/database_utils.cc +++ b/src/meta_schedule/database/database_utils.cc @@ -44,7 +44,7 @@ void JSONDumps(Any json_obj, std::ostringstream& os) { FloatImm float_imm = *std::move(opt_float_imm); os << std::setprecision(20) << float_imm->value; } else if (const auto* str = json_obj.as<runtime::StringObj>()) { - os << '"' << support::StrEscape(str->bytes.data, str->bytes.size) << '"'; + os << '"' << support::StrEscape(str->data, str->size) << '"'; } else if (const auto* array = json_obj.as<ffi::ArrayNode>()) { os << "["; int n = array->size(); @@ -75,7 +75,7 @@ void JSONDumps(Any json_obj, std::ostringstream& os) { if (i != 0) { os << ","; } - os << '"' << support::StrEscape(kv.first->bytes.data, kv.first->bytes.size) << '"'; + os << '"' << support::StrEscape(kv.first->data, kv.first->size) << '"'; os << ":"; JSONDumps(kv.second, os); } diff --git a/src/node/structural_hash.cc b/src/node/structural_hash.cc index e81bf66fb9..4c864d6613 100644 --- a/src/node/structural_hash.cc +++ b/src/node/structural_hash.cc @@ -317,15 +317,15 @@ struct StringObjTrait { static void SHashReduce(const runtime::StringObj* key, SHashReducer hash_reduce) { hash_reduce->SHashReduceHashedValue( - ffi::details::StableHashBytes(key->bytes.data, key->bytes.size)); + ffi::details::StableHashBytes(key->data, key->size)); } static bool SEqualReduce(const runtime::StringObj* lhs, const runtime::StringObj* rhs, SEqualReducer equal) { if (lhs == rhs) return true; - if (lhs->bytes.size != rhs->bytes.size) return false; - if (lhs->bytes.data == rhs->bytes.data) return true; - return std::memcmp(lhs->bytes.data, rhs->bytes.data, lhs->bytes.size) == 0; + if (lhs->size != rhs->size) return false; + if (lhs->data == rhs->data) return true; + return std::memcmp(lhs->data, rhs->data, lhs->size) == 0; } }; @@ -348,7 +348,7 @@ TVM_REGISTER_REFLECTION_VTABLE(runtime::StringObj, StringObjTrait) TVM_STATIC_IR_FUNCTOR(ReprPrinter, vtable) .set_dispatch<runtime::StringObj>([](const ObjectRef& node, ReprPrinter* p) { auto* op = static_cast<const runtime::StringObj*>(node.get()); - p->stream << '"' << support::StrEscape(op->bytes.data, op->bytes.size) << '"'; + p->stream << '"' << support::StrEscape(op->data, op->size) << '"'; }); struct ModuleNodeTrait { diff --git a/src/runtime/disco/protocol.h b/src/runtime/disco/protocol.h index 591a690e6e..6bcba6e470 100644 --- a/src/runtime/disco/protocol.h +++ b/src/runtime/disco/protocol.h @@ -125,10 +125,10 @@ inline uint64_t DiscoProtocol<SubClassType>::GetObjectBytes(Object* obj) { if (obj->IsInstance<DRefObj>()) { return sizeof(uint32_t) + sizeof(int64_t); } else if (obj->IsInstance<StringObj>()) { - uint64_t size = static_cast<StringObj*>(obj)->bytes.size; + uint64_t size = static_cast<StringObj*>(obj)->size; return sizeof(uint32_t) + sizeof(uint64_t) + size * sizeof(char); } else if (obj->IsInstance<ffi::BytesObj>()) { - uint64_t size = static_cast<ffi::BytesObj*>(obj)->bytes.size; + uint64_t size = static_cast<ffi::BytesObj*>(obj)->size; return sizeof(uint32_t) + sizeof(uint64_t) + size * sizeof(char); } else if (obj->IsInstance<ShapeTupleObj>()) { uint64_t ndim = static_cast<ShapeTupleObj*>(obj)->size; @@ -150,13 +150,13 @@ inline void DiscoProtocol<SubClassType>::WriteObject(Object* obj) { } else if (obj->IsInstance<StringObj>()) { StringObj* str = static_cast<StringObj*>(obj); self->template Write<uint32_t>(TypeIndex::kRuntimeString); - self->template Write<uint64_t>(str->bytes.size); - self->template WriteArray<char>(str->bytes.data, str->bytes.size); + self->template Write<uint64_t>(str->size); + self->template WriteArray<char>(str->data, str->size); } else if (obj->IsInstance<ffi::BytesObj>()) { ffi::BytesObj* bytes = static_cast<ffi::BytesObj*>(obj); self->template Write<uint32_t>(ffi::TypeIndex::kTVMFFIBytes); - self->template Write<uint64_t>(bytes->bytes.size); - self->template WriteArray<char>(bytes->bytes.data, bytes->bytes.size); + self->template Write<uint64_t>(bytes->size); + self->template WriteArray<char>(bytes->data, bytes->size); } else if (obj->IsInstance<ShapeTupleObj>()) { ShapeTupleObj* shape = static_cast<ShapeTupleObj*>(obj); self->template Write<uint32_t>(TypeIndex::kRuntimeShapeTuple); diff --git a/src/runtime/rpc/rpc_local_session.cc b/src/runtime/rpc/rpc_local_session.cc index 4dfdc957fd..a3bb547eba 100644 --- a/src/runtime/rpc/rpc_local_session.cc +++ b/src/runtime/rpc/rpc_local_session.cc @@ -68,14 +68,14 @@ void LocalSession::EncodeReturn(TVMRetValue rv, const FEncodeReturn& encode_retu // always pass bytes as byte array packed_args[0] = static_cast<int32_t>(kTVMBytes); TVMFFIByteArray byte_arr; - byte_arr.data = bytes->bytes.data; - byte_arr.size = bytes->bytes.size; + byte_arr.data = bytes->data; + byte_arr.size = bytes->size; packed_args[1] = &byte_arr; encode_return(ffi::PackedArgs(packed_args, 2)); } else if (const auto* str = rv.as<ffi::StringObj>()) { // always pass bytes as raw string packed_args[0] = static_cast<int32_t>(kTVMStr); - packed_args[1] = str->bytes.data; + packed_args[1] = str->data; encode_return(ffi::PackedArgs(packed_args, 2)); } else if (rv.as<ffi::ObjectRef>()) { TVMFFIAny ret_any = ffi::details::AnyUnsafe::MoveAnyToTVMFFIAny(std::move(rv)); diff --git a/src/runtime/rpc/rpc_module.cc b/src/runtime/rpc/rpc_module.cc index e6afa711a6..e2a7694c5e 100644 --- a/src/runtime/rpc/rpc_module.cc +++ b/src/runtime/rpc/rpc_module.cc @@ -93,7 +93,7 @@ class RPCWrappedFunc : public Object { // to their remote variant. for (int i = 0; i < args.size(); ++i) { if (const auto* str = args[i].as<ffi::StringObj>()) { - packed_args[i] = str->bytes.data; + packed_args[i] = str->data; continue; } packed_args[i] = args[i]; diff --git a/src/script/printer/doc_printer/python_doc_printer.cc b/src/script/printer/doc_printer/python_doc_printer.cc index 519fced395..2bb8e2a1dc 100644 --- a/src/script/printer/doc_printer/python_doc_printer.cc +++ b/src/script/printer/doc_printer/python_doc_printer.cc @@ -351,7 +351,7 @@ void PythonDocPrinter::PrintTypedDoc(const LiteralDoc& doc) { } } else if (const auto* string_obj = value.as<ffi::StringObj>()) { - output_ << "\"" << support::StrEscape(string_obj->bytes.data, string_obj->bytes.size) << "\""; + output_ << "\"" << support::StrEscape(string_obj->data, string_obj->size) << "\""; } else { LOG(FATAL) << "TypeError: Unsupported literal value type: " << value->GetTypeKey(); } diff --git a/src/tir/schedule/instruction.cc b/src/tir/schedule/instruction.cc index 74f3c443fc..8e1bce285d 100644 --- a/src/tir/schedule/instruction.cc +++ b/src/tir/schedule/instruction.cc @@ -66,7 +66,7 @@ TVM_STATIC_IR_FUNCTOR(ReprPrinter, vtable) } else if (obj.as<BlockRVNode>() || obj.as<LoopRVNode>()) { inputs.push_back(String("_")); } else if (const auto* str_obj = obj.as<StringObj>()) { - inputs.push_back(String('"' + std::string(str_obj->bytes.data) + '"')); + inputs.push_back(String('"' + std::string(str_obj->data) + '"')); } else if (obj.type_index() < ffi::TypeIndex::kTVMFFIStaticObjectBegin) { inputs.push_back(obj); } else if (obj.as<IntImmNode>() || obj.as<FloatImmNode>()) { diff --git a/src/tir/schedule/instruction_traits.h b/src/tir/schedule/instruction_traits.h index fe3158894e..53deb7457c 100644 --- a/src/tir/schedule/instruction_traits.h +++ b/src/tir/schedule/instruction_traits.h @@ -419,7 +419,7 @@ inline void PythonAPICall::AsPythonString(const Any& obj, std::ostream& os) { if (obj == nullptr) { os << "None"; } else if (const auto* str = obj.as<ffi::StringObj>()) { - os << str->bytes.data; + os << str->data; } else if (const auto opt_int_imm = obj.as<IntImm>()) { os << (*opt_int_imm)->value; } else if (const auto opt_float_imm = obj.as<FloatImm>()) { diff --git a/src/tir/schedule/trace.cc b/src/tir/schedule/trace.cc index 199b91d639..4c72ce4d1b 100644 --- a/src/tir/schedule/trace.cc +++ b/src/tir/schedule/trace.cc @@ -122,7 +122,7 @@ Array<Any> TranslateInputRVs( } } else if (const auto* str_obj = input.as<StringObj>()) { // Case 2. string => "content" - results.push_back(String('"' + std::string(str_obj->bytes.data) + '"')); + results.push_back(String('"' + std::string(str_obj->data) + '"')); } else if (input.as<IntImmNode>() || input.as<FloatImmNode>()) { // Case 3. integer or floating-point number results.push_back(input); @@ -177,9 +177,9 @@ Array<Any> TranslateInputRVs(const Array<Any>& inputs, } const auto* str = input.as<ffi::StringObj>(); CHECK(str) << "TypeError: Expect String, but gets: " << input.GetTypeKey(); - CHECK_GT(str->bytes.size, 0) << "ValueError: Empty string is not allowed in input names"; - const char* name = str->bytes.data; - int64_t size = str->bytes.size; + CHECK_GT(str->size, 0) << "ValueError: Empty string is not allowed in input names"; + const char* name = str->data; + int64_t size = str->size; if (name[0] == '{' && name[size - 1] == '}') { Any obj = LoadJSON(name); // Case 6. IndexMap @@ -359,7 +359,7 @@ Array<String> TraceNode::AsPython(bool remove_postproc) const { attrs.reserve(inst->attrs.size()); for (const Any& obj : inst->attrs) { if (const auto* str = obj.as<StringObj>()) { - attrs.push_back(String('"' + std::string(str->bytes.data) + '"')); + attrs.push_back(String('"' + std::string(str->data) + '"')); } else { attrs.push_back(obj); } @@ -424,7 +424,7 @@ void Trace::ApplyJSONToSchedule(ObjectRef json, Schedule sch) { const auto* arr = inst_entry.as<ArrayNode>(); ICHECK(arr && arr->size() == 4); const auto* arr0 = arr->at(0).as<StringObj>(); - kind = InstructionKind::Get(arr0->bytes.data); + kind = InstructionKind::Get(arr0->data); inputs = arr->at(1); attrs = arr->at(2); outputs = arr->at(3);
