mbs-octoml commented on a change in pull request #9313: URL: https://github.com/apache/tvm/pull/9313#discussion_r737916988
########## File path: src/target/se_scope.cc ########## @@ -0,0 +1,225 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +/*! + * \file tvm/target/se_scope.cc + * \brief Implementation of \p SEScope for representing a Storage or Execution scope. + */ +#include <tvm/node/reflection.h> +#include <tvm/runtime/device_api.h> +#include <tvm/target/se_scope.h> + +namespace tvm { + +TVM_REGISTER_NODE_TYPE(SEScopeNode); + +void SEScopeNode::VisitAttrs(AttrVisitor* v) { + int i = static_cast<int>(device_type_); + v->Visit("device_type", &i); + device_type_ = static_cast<DLDeviceType>(i); + v->Visit("virtual_device_id", &virtual_device_id_); + v->Visit("target", &target_); + v->Visit("memory_scope", &memory_scope_); +} + +bool SEScopeNode::SEqualReduce(const SEScopeNode* other, SEqualReducer equal) const { + return device_type_ == other->device_type_ && virtual_device_id_ == other->virtual_device_id_ && + // NOTE: Comparing targets by their str representations + target_->str() == other->target_->str() && memory_scope_ == other->memory_scope_; +} + +void SEScopeNode::SHashReduce(SHashReducer hash_reduce) const { + hash_reduce(device_type_); + hash_reduce(virtual_device_id_); + // NOTE: Reducing target to its str representation + hash_reduce(target_->str()); + hash_reduce(memory_scope_); +} + +TVM_STATIC_IR_FUNCTOR(ReprPrinter, vtable) + .set_dispatch<SEScopeNode>([](const ObjectRef& ref, ReprPrinter* p) { + auto* node = ref.as<SEScopeNode>(); + p->stream << "SEScopeNode("; + if (node->is_fully_unconstrained()) { + p->stream << "?"; + } else { + bool need_sep = false; + if (node->device_type() != kInvalidDeviceType) { + p->stream << "device_type=" << node->device_type(); + need_sep = true; + } + if (node->virtual_device_id() >= 0) { + if (need_sep) { + p->stream << ", "; + } + p->stream << "virtual_device_id=" << node->virtual_device_id(); + need_sep = true; + } + if (node->target().defined()) { + if (need_sep) { + p->stream << ", "; + } + p->stream << "target='" << node->target()->str() << "'"; + need_sep = true; + } + if (!node->memory_scope().empty()) { + if (need_sep) { + p->stream << ", "; + } + p->stream << "memory_scope='" << node->memory_scope() << "'"; + } + } + p->stream << ")"; + }); + +SEScope::SEScope(DLDeviceType device_type, int virtual_device_id, Target target, + String memory_scope) { + ICHECK(!target.defined() || device_type == target->kind->device_type) Review comment: done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
