tqchen commented on code in PR #663:
URL: https://github.com/apache/tvm-ffi/pull/663#discussion_r3576232313


##########
python/tvm_ffi/utils/descriptors.py:
##########
@@ -0,0 +1,80 @@
+# 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.
+"""Descriptor utilities for the tvm_ffi Python package."""
+
+from __future__ import annotations
+
+import importlib
+import sys
+from typing import Any, Callable, Generic, TypeVar, overload
+
+_T = TypeVar("_T")
+
+
+def _get_forward_annotations(obj: Any) -> dict[str, Any]:
+    """Return Python 3.14+ annotations without forcing unresolved names."""
+    annotationlib: Any = importlib.import_module("annotationlib")
+    return annotationlib.get_annotations(obj, 
format=annotationlib.Format.FORWARDREF)
+
+
+class init_property(Generic[_T]):
+    """Auto-registered C++ field with eager computation at ``__init__`` time.

Review Comment:
   this seems should belong to dataclass category as utils is generic thing 
that do not depend on tvm ffi constructs like filelock



##########
tests/cpp/test_device.cc:
##########
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ */
+#include <gtest/gtest.h>
+#include <tvm/ffi/any.h>
+#include <tvm/ffi/device.h>
+
+namespace {
+
+using namespace tvm::ffi;
+
+TEST(Device, AnyConversion) {
+  DLDevice device{kDLCUDA, 1};
+  AnyView view = device;
+
+  DLDevice converted = view.cast<DLDevice>();
+  EXPECT_EQ(converted.device_type, kDLCUDA);
+  EXPECT_EQ(converted.device_id, 1);
+}
+
+TEST(Device, AnyConversionWithString) {
+  AnyView cpu_view = "cpu";
+  DLDevice cpu = cpu_view.cast<DLDevice>();
+  EXPECT_EQ(cpu.device_type, kDLCPU);
+  EXPECT_EQ(cpu.device_id, 0);
+
+  Any cuda_any = String("cuda:3");
+  DLDevice cuda = cuda_any.cast<DLDevice>();
+  EXPECT_EQ(cuda.device_type, kDLCUDA);
+  EXPECT_EQ(cuda.device_id, 3);
+
+  AnyView opencl_view = "opencl:-2";

Review Comment:
   is negative value allowed? i think we should reject negative value? also 
simplifies parser



##########
include/tvm/ffi/device.h:
##########
@@ -0,0 +1,155 @@
+/*
+ * 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/ffi/device.h
+ * \brief Device handling.
+ */
+#ifndef TVM_FFI_DEVICE_H_
+#define TVM_FFI_DEVICE_H_
+
+#include <dlpack/dlpack.h>
+#include <tvm/ffi/string.h>
+#include <tvm/ffi/type_traits.h>
+
+#include <cstdint>
+#include <limits>
+#include <optional>
+#include <string>
+#include <string_view>
+
+namespace tvm {
+namespace ffi {
+namespace details {
+
+TVM_FFI_INLINE static std::optional<DLDeviceType> 
TryParseDLDeviceType(std::string_view name) {
+  if (name == "llvm" || name == "cpu" || name == "c" || name == "test") return 
kDLCPU;

Review Comment:
   i know that we had some broad translation on python side which tries to be 
compact with some compiler target, as part of core i think it does not makes 
sense likely, let us only keep cpu, cuda, opencl here.
   
   i will followup with downstream changes so they do not directly rely on 
target name like llvm maps to cpu



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to