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


##########
addons/tvm-ffi-orcjit/MANIFEST.in:
##########
@@ -0,0 +1,7 @@
+include README.md
+include LICENSE
+include pyproject.toml
+include CMakeLists.txt
+recursive-include include *.h

Review Comment:
   manifest is not needed and only need in pyproject



##########
addons/tvm-ffi-orcjit/python/tvm_ffi_orcjit/dylib.py:
##########
@@ -0,0 +1,133 @@
+# 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.
+"""ORC JIT Dynamic Library."""
+
+from __future__ import annotations
+
+from pathlib import Path
+from typing import TYPE_CHECKING, Any
+
+from tvm_ffi import Function, get_global_func
+from tvm_ffi._ffi_api import ModuleGetFunction
+
+if TYPE_CHECKING:
+    from .session import ExecutionSession
+
+
+class DynamicLibrary:

Review Comment:
   Make it wrap ffi.Module, so we can directly do lib.foo



##########
addons/tvm-ffi-orcjit/python/tvm_ffi_orcjit/dylib.py:
##########
@@ -0,0 +1,133 @@
+# 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.
+"""ORC JIT Dynamic Library."""
+
+from __future__ import annotations
+
+from pathlib import Path
+from typing import TYPE_CHECKING, Any
+
+from tvm_ffi import Function, get_global_func
+from tvm_ffi._ffi_api import ModuleGetFunction
+
+if TYPE_CHECKING:
+    from .session import ExecutionSession
+
+
+class DynamicLibrary:
+    """ORC JIT Dynamic Library (JITDylib).
+
+    Represents a collection of symbols that can be loaded from object files 
and linked
+    against other dynamic libraries. Supports JIT compilation and symbol 
resolution.
+
+    Examples
+    --------
+    >>> session = create_session()
+    >>> lib = session.create_library()
+    >>> lib.add("add.o")
+    >>> lib.add("multiply.o")
+    >>> add_func = lib.get_function("add")
+    >>> result = add_func(1, 2)
+
+    """
+
+    def __init__(self, handle: Any, session: ExecutionSession) -> None:
+        """Initialize DynamicLibrary from a handle.
+
+        Parameters
+        ----------
+        handle : object
+            The underlying C++ ORCJITDynamicLibrary object.
+        session : ExecutionSession
+            The parent execution session (kept alive for the library's 
lifetime).
+
+        """
+        self._handle = handle
+        self._session = session  # Keep session alive
+        self._add_func = get_global_func("orcjit.DynamicLibraryAdd")
+        self._link_func = get_global_func("orcjit.DynamicLibraryLinkAgainst")
+        self._to_module_func = get_global_func("orcjit.DynamicLibraryToModule")
+
+    def add(self, object_file: str | Path) -> None:
+        """Add an object file to this dynamic library.
+
+        Parameters
+        ----------
+        object_file : str or Path
+            Path to the object file to load.
+
+        Examples
+        --------
+        >>> lib.add("add.o")
+        >>> lib.add(Path("multiply.o"))
+
+        """
+        if isinstance(object_file, Path):
+            object_file = str(object_file)
+        self._add_func(self._handle, object_file)
+
+    def link_against(self, *libraries: DynamicLibrary) -> None:

Review Comment:
   lib.set_link_order(list[libraries])



##########
addons/tvm-ffi-orcjit/python/tvm_ffi_orcjit/dylib.py:
##########
@@ -0,0 +1,133 @@
+# 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.
+"""ORC JIT Dynamic Library."""
+
+from __future__ import annotations
+
+from pathlib import Path
+from typing import TYPE_CHECKING, Any
+
+from tvm_ffi import Function, get_global_func
+from tvm_ffi._ffi_api import ModuleGetFunction
+
+if TYPE_CHECKING:
+    from .session import ExecutionSession
+
+
+class DynamicLibrary:
+    """ORC JIT Dynamic Library (JITDylib).
+
+    Represents a collection of symbols that can be loaded from object files 
and linked
+    against other dynamic libraries. Supports JIT compilation and symbol 
resolution.
+
+    Examples
+    --------
+    >>> session = create_session()
+    >>> lib = session.create_library()
+    >>> lib.add("add.o")
+    >>> lib.add("multiply.o")
+    >>> add_func = lib.get_function("add")
+    >>> result = add_func(1, 2)
+
+    """
+
+    def __init__(self, handle: Any, session: ExecutionSession) -> None:
+        """Initialize DynamicLibrary from a handle.
+
+        Parameters
+        ----------
+        handle : object
+            The underlying C++ ORCJITDynamicLibrary object.
+        session : ExecutionSession
+            The parent execution session (kept alive for the library's 
lifetime).
+
+        """
+        self._handle = handle
+        self._session = session  # Keep session alive
+        self._add_func = get_global_func("orcjit.DynamicLibraryAdd")
+        self._link_func = get_global_func("orcjit.DynamicLibraryLinkAgainst")
+        self._to_module_func = get_global_func("orcjit.DynamicLibraryToModule")
+
+    def add(self, object_file: str | Path) -> None:

Review Comment:
   `lib.add_object_file(path) => lib.mod["__add_object_file__"](path)`
   
   `lib.foo`
   
   `lib.function`



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