Lunderberg commented on code in PR #16183: URL: https://github.com/apache/tvm/pull/16183#discussion_r1409810745
########## include/tvm/runtime/container/boxed_primitive.h: ########## @@ -0,0 +1,121 @@ +/* + * 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/runtime/container/boxed_primitive.h + * \brief Runtime container types for primitives stored as ObjectRef. + */ +#ifndef TVM_RUNTIME_CONTAINER_BOXED_PRIMITIVE_H_ +#define TVM_RUNTIME_CONTAINER_BOXED_PRIMITIVE_H_ + +#include <tvm/runtime/memory.h> +#include <tvm/runtime/object.h> + +namespace tvm { +namespace runtime { + +namespace detail { +/* \brief Provide the BoxNode<T> type key in templated contexts + * + * The Box<T> class is used in many templated contexts, and is easier + * to have templated over the primitive type. However, much of the + * TVM type system depends on classes having a unique name. For + * example, the use of `Object::IsInstance` depends on + * `Object::GetOrAllocRuntimeTypeIndex`. Any duplicate names will + * result in duplicate indices, and invalid downcasting. + * + * Furthermore, the name must be specified in the Python FFI using + * `tvm._ffi.register_object`. This prevents use of + * `typeid(T)::name()` to build a unique name, as the name is not + * required to be human-readable or consistent across compilers. + * + * This utility struct exists to bridge that gap, providing a unique + * name where required. + */ +template <typename Prim> +struct BoxNodeTypeKey; Review Comment: I like the naming for future extensions, though naming it `BoxNodeTrait` might cause confusion with the `BoxNodeTrait` defined [here](https://github.com/apache/tvm/pull/16183/files#diff-22a23c986d23dd8dc15c9233c738505aa04ad2626c0cb24828b7e672d1f56702R48). I've renamed this instance to `BoxNodeRuntimeTraits` and the other to `BoxNodeCompileTimeTraits` to make a clear distinction between the two cases, and documented the intended usage for each. ########## include/tvm/runtime/container/boxed_primitive.h: ########## @@ -0,0 +1,121 @@ +/* + * 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/runtime/container/boxed_primitive.h + * \brief Runtime container types for primitives stored as ObjectRef. + */ +#ifndef TVM_RUNTIME_CONTAINER_BOXED_PRIMITIVE_H_ +#define TVM_RUNTIME_CONTAINER_BOXED_PRIMITIVE_H_ + +#include <tvm/runtime/memory.h> +#include <tvm/runtime/object.h> + +namespace tvm { +namespace runtime { + +namespace detail { +/* \brief Provide the BoxNode<T> type key in templated contexts + * + * The Box<T> class is used in many templated contexts, and is easier + * to have templated over the primitive type. However, much of the + * TVM type system depends on classes having a unique name. For + * example, the use of `Object::IsInstance` depends on + * `Object::GetOrAllocRuntimeTypeIndex`. Any duplicate names will + * result in duplicate indices, and invalid downcasting. + * + * Furthermore, the name must be specified in the Python FFI using + * `tvm._ffi.register_object`. This prevents use of + * `typeid(T)::name()` to build a unique name, as the name is not + * required to be human-readable or consistent across compilers. + * + * This utility struct exists to bridge that gap, providing a unique + * name where required. + */ +template <typename Prim> +struct BoxNodeTypeKey; + +template <> +struct BoxNodeTypeKey<int64_t> { + static constexpr const char* _type_key = "runtime.BoxInt"; +}; + Review Comment: I like the readability improvements, and 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]
