This is an automated email from the ASF dual-hosted git repository. tqchen pushed a commit to branch refactor-s2 in repository https://gitbox.apache.org/repos/asf/tvm.git
commit f798de7193eeaaabbc1f188271fd8643bc5a6487 Author: tqchen <[email protected]> AuthorDate: Mon Apr 21 09:45:12 2025 -0400 Introduce a new ffi path for dev --- python/setup.py | 19 +++++++++++++++++++ python/tvm/ffi/__init__.py | 23 +++++++++++++++++++++++ python/tvm/ffi/cython/.gitignore | 2 ++ python/tvm/ffi/cython/__init__.py | 17 +++++++++++++++++ python/tvm/ffi/cython/core.pyx | 20 ++++++++++++++++++++ 5 files changed, 81 insertions(+) diff --git a/python/setup.py b/python/setup.py index cef26a3e1c..9da4eba2b3 100644 --- a/python/setup.py +++ b/python/setup.py @@ -183,6 +183,25 @@ def config_cython(): language="c++", ) ) + + # the latest ffi source + for fn in os.listdir("tvm/ffi/cython"): + if not fn.endswith(".pyx"): + continue + ret.append( + Extension( + f"tvm.ffi.cython.{fn[:-4]}", + ["tvm/ffi/cython/%s" % fn], + include_dirs=[ + "../ffi/include/", + "../ffi/3rdparty/dlpack/include", + ], + extra_compile_args=extra_compile_args, + library_dirs=library_dirs, + libraries=libraries, + language="c++", + ) + ) return cythonize(ret, compiler_directives={"language_level": 3}) except ImportError as error: raise RuntimeError("Cython is not installed, please pip install cython") diff --git a/python/tvm/ffi/__init__.py b/python/tvm/ffi/__init__.py new file mode 100644 index 0000000000..da0a766de3 --- /dev/null +++ b/python/tvm/ffi/__init__.py @@ -0,0 +1,23 @@ +# 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. +"""TVM FFI binding module. + +This module binds the TVM FFI C API to python. +This is a standalone module that can be +""" + +from .cython.core import test_ffi diff --git a/python/tvm/ffi/cython/.gitignore b/python/tvm/ffi/cython/.gitignore new file mode 100644 index 0000000000..eeb15feab3 --- /dev/null +++ b/python/tvm/ffi/cython/.gitignore @@ -0,0 +1,2 @@ +core.cpp +core.cpython* diff --git a/python/tvm/ffi/cython/__init__.py b/python/tvm/ffi/cython/__init__.py new file mode 100644 index 0000000000..be4a69b43c --- /dev/null +++ b/python/tvm/ffi/cython/__init__.py @@ -0,0 +1,17 @@ +# 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. +"""cython namespace""" diff --git a/python/tvm/ffi/cython/core.pyx b/python/tvm/ffi/cython/core.pyx new file mode 100644 index 0000000000..45f79adae0 --- /dev/null +++ b/python/tvm/ffi/cython/core.pyx @@ -0,0 +1,20 @@ +# 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. + +def test_ffi(): + print("Hello") + pass
