Skip to content

Commit 60e9c7e

Browse files
authored
[Refactor] Rename cython output to tilelang_cython and relocate its path (#1086)
* refactor cython wrapper * optimize * fix installations
1 parent 1d4b718 commit 60e9c7e

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

CMakeLists.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,22 +158,26 @@ endif()
158158
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module ${SKBUILD_SABI_COMPONENT})
159159

160160
add_custom_command(
161-
OUTPUT "${CMAKE_BINARY_DIR}/cython_wrapper.cpp"
161+
OUTPUT "${CMAKE_BINARY_DIR}/tilelang_cython_wrapper.cpp"
162162
COMMENT
163163
"Cythoning tilelang/jit/adapter/cython/cython_wrapper.pyx"
164164
COMMAND Python::Interpreter -m cython
165165
"${CMAKE_CURRENT_SOURCE_DIR}/tilelang/jit/adapter/cython/cython_wrapper.pyx"
166-
--cplus --output-file "${CMAKE_BINARY_DIR}/cython_wrapper.cpp"
166+
--module-name tilelang_cython_wrapper
167+
--cplus --output-file "${CMAKE_BINARY_DIR}/tilelang_cython_wrapper.cpp"
167168
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/tilelang/jit/adapter/cython/cython_wrapper.pyx"
168169
VERBATIM)
169170

170171
if(NOT "${SKBUILD_SABI_VERSION}" STREQUAL "")
171172
set(USE_SABI USE_SABI ${SKBUILD_SABI_VERSION})
172173
endif()
173174

174-
python_add_library(cython_wrapper MODULE "${CMAKE_BINARY_DIR}/cython_wrapper.cpp" ${USE_SABI} WITH_SOABI)
175-
# Install to site dir to support direct import
176-
install(TARGETS cython_wrapper LIBRARY DESTINATION .)
175+
python_add_library(tilelang_cython_wrapper MODULE "${CMAKE_BINARY_DIR}/tilelang_cython_wrapper.cpp" ${USE_SABI} WITH_SOABI)
176+
# Install extension into the tilelang package directory
177+
install(TARGETS tilelang_cython_wrapper
178+
LIBRARY DESTINATION tilelang
179+
RUNTIME DESTINATION tilelang
180+
ARCHIVE DESTINATION tilelang)
177181

178182
# let libtilelang to search tvm/tvm_runtime in same dir
179183
if(APPLE)

tilelang/env.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
TVM_LIBRARY_NOT_FOUND_MESSAGE = ("TVM is not installed or found in the expected path")
2121

2222
TL_ROOT = os.path.dirname(os.path.abspath(__file__))
23-
TL_LIBS = [os.path.join(i, 'lib') for i in [TL_ROOT]]
23+
TL_LIBS = [TL_ROOT, os.path.join(TL_ROOT, 'lib')]
2424
TL_LIBS = [i for i in TL_LIBS if os.path.exists(i)]
2525

2626
DEV = False
@@ -37,6 +37,10 @@
3737
assert TL_LIBS and all(
3838
os.path.exists(i) for i in TL_LIBS), f'tilelang lib root do not exists: {TL_LIBS}'
3939

40+
for lib in TL_LIBS:
41+
if lib not in sys.path:
42+
sys.path.insert(0, lib)
43+
4044

4145
def _find_cuda_home() -> str:
4246
"""Find the CUDA install path.

tilelang/jit/adapter/cython/adapter.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@
2222
logger = logging.getLogger(__name__)
2323

2424
try:
25-
# Load cython_wrapper.api3.so in env.py
26-
from cython_wrapper import CythonKernelWrapper
25+
from tilelang_cython_wrapper import CythonKernelWrapper
2726
except ImportError:
28-
# TODO: tolerance a build without cython backend
2927
raise
3028

3129

0 commit comments

Comments
 (0)