gemini-code-assist[bot] commented on code in PR #19769:
URL: https://github.com/apache/tvm/pull/19769#discussion_r3410094837


##########
python/tvm/backend/_autoload_backends.py:
##########
@@ -0,0 +1,90 @@
+# 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.
+"""Autoload backend libraries and Python backend registration hooks."""
+
+from __future__ import annotations
+
+import os
+import warnings
+from importlib.metadata import entry_points
+from pathlib import Path
+from typing import Any
+
+from tvm_ffi.libinfo import load_lib_ctypes
+
+_BUILTIN_BACKENDS = (
+    "cuda",
+    "metal",
+    "rocm",
+    "trn",
+    "opencl",
+    "vulkan",
+    "webgpu",
+    "hexagon",
+    "adreno",
+)
+_BACKEND_RUNTIME_LIBS = ("cuda", "vulkan", "opencl", "metal", "rocm", 
"hexagon", "extra")
+
+# Guard so autoload runs at most once per process, even if invoked again.
+_AUTO_LOAD_DONE = False
+
+
+def load_backend_libs(runtime_lib_path: str, loaded_libs: dict[str, Any] | 
None = None) -> None:
+    """Load each known backend runtime DSO into the process-global symbol 
namespace."""
+    if loaded_libs is None:
+        from tvm.base import _LOADED_LIBS  # pylint: 
disable=import-outside-toplevel
+
+        loaded_libs = _LOADED_LIBS
+
+    runtime_dir = Path(runtime_lib_path).resolve().parent

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   If `runtime_lib_path` is a directory rather than a file path, calling 
`.parent` will resolve to its parent directory, which can lead to silent 
failures when searching for backend runtime libraries.
   
   We can make this more robust by checking if the path is a directory and 
using it directly if so.
   
   ```python
       path = Path(runtime_lib_path).resolve()
       runtime_dir = path if path.is_dir() else path.parent
   ```



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