Skip to content

Commit 129c1d2

Browse files
Merge commit '2003685bd0cc15d78d7b0e87e87e856024e26189'
2 parents c35137a + 2003685 commit 129c1d2

File tree

7 files changed

+20
-40
lines changed

7 files changed

+20
-40
lines changed

CMakeLists.txt

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,6 @@ include_directories(${PROJECT_BINARY_DIR}/third_party) # Tablegen'd files
168168
add_subdirectory(include)
169169
add_subdirectory(lib)
170170

171-
# find_package(PythonLibs REQUIRED)
172-
set(TRITON_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
173-
set(TRITON_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
174-
175171
# TODO: Figure out which target is sufficient to fix errors; triton is
176172
# apparently not enough. Currently set linking libstdc++fs for all targets
177173
# to support some old version GCC compilers like 8.3.0.
@@ -188,24 +184,12 @@ if(TRITON_BUILD_PYTHON_MODULE)
188184
set(PYTHON_SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/python/src)
189185
include_directories(${PYTHON_SRC_PATH})
190186

187+
# Python Interpreter is used to run lit tests
188+
find_package(Python3 REQUIRED COMPONENTS Development Interpreter)
189+
find_package(pybind11 CONFIG REQUIRED HINTS "${Python3_SITELIB}")
191190
if(PYTHON_INCLUDE_DIRS)
192-
# We have PYTHON_INCLUDE_DIRS set--this is what we expect when building
193-
# using pip install.
194-
include_directories(${PYTHON_INCLUDE_DIRS})
195-
include_directories(${PYBIND11_INCLUDE_DIR})
196191
message(STATUS "PYTHON_LIB_DIRS ${PYTHON_LIB_DIRS}")
197192
link_directories(${PYTHON_LIB_DIRS})
198-
else()
199-
# Otherwise, we might be building from top CMakeLists.txt directly.
200-
# Try to find Python and pybind11 packages.
201-
find_package(Python3 REQUIRED COMPONENTS Development Interpreter)
202-
find_package(pybind11 CONFIG REQUIRED HINTS "${Python3_SITELIB}")
203-
include_directories(${Python3_INCLUDE_DIRS})
204-
include_directories(${pybind11_INCLUDE_DIR})
205-
link_directories(${Python3_LIBRARY_DIRS})
206-
link_libraries(${Python3_LIBRARIES})
207-
add_link_options(${Python3_LINK_OPTIONS})
208-
endif()
209193

210194
if (DEFINED TRITON_PLUGIN_DIRS)
211195
foreach(PLUGIN_DIR ${TRITON_PLUGIN_DIRS})
@@ -272,6 +256,9 @@ if(TRITON_BUILD_PYTHON_MODULE)
272256
LLVMAMDGPUCodeGen
273257
LLVMAMDGPUAsmParser
274258

259+
Python3::Module
260+
pybind11::headers
261+
275262
)
276263
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" OR # Linux arm64
277264
CMAKE_SYSTEM_PROCESSOR MATCHES "arm64" OR # macOS arm64
@@ -312,7 +299,7 @@ if(TRITON_BUILD_PYTHON_MODULE)
312299
${PYTHON_SRC_PATH}/llvm.cc)
313300

314301
# Link triton with its dependencies
315-
target_link_libraries(triton PUBLIC ${TRITON_LIBRARIES})
302+
target_link_libraries(triton PRIVATE ${TRITON_LIBRARIES})
316303
if(WIN32)
317304
target_link_libraries(triton PRIVATE ${CMAKE_DL_LIBS})
318305
set_target_properties(triton PROPERTIES SUFFIX ".pyd")
@@ -335,7 +322,7 @@ if(TRITON_BUILD_PYTHON_MODULE AND NOT WIN32)
335322
set(PYTHON_LDFLAGS "-undefined dynamic_lookup")
336323
endif()
337324

338-
target_link_libraries(triton PRIVATE ${PYTHON_LDFLAGS})
325+
target_link_options(triton PRIVATE ${PYTHON_LDFLAGS})
339326
endif()
340327

341328
if(NOT TRITON_BUILD_PYTHON_MODULE)

python/setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ def get_pybind11_cmake_args(self):
453453
pybind11_include_dir = os.path.join(pybind11_sys_path, "include")
454454
else:
455455
pybind11_include_dir = pybind11.get_include()
456-
return [f"-DPYBIND11_INCLUDE_DIR={pybind11_include_dir}"]
456+
return [f"-Dpybind11_INCLUDE_DIR='{pybind11_include_dir}'", f"-Dpybind11_DIR='{pybind11.get_cmake_dir()}'"]
457457

458458
def get_proton_cmake_args(self):
459459
cmake_args = get_thirdparty_packages([get_json_package_info()])
@@ -493,7 +493,7 @@ def build_extension(self, ext):
493493
"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON", "-DLLVM_ENABLE_WERROR=ON",
494494
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=" + extdir, "-DTRITON_BUILD_TUTORIALS=OFF",
495495
"-DTRITON_BUILD_PYTHON_MODULE=ON", "-DPython3_EXECUTABLE:FILEPATH=" + sys.executable,
496-
"-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON", "-DPYTHON_INCLUDE_DIRS=" + python_include_dir,
496+
"-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON", "-DPython3_INCLUDE_DIR=" + python_include_dir,
497497
"-DTRITON_CODEGEN_BACKENDS=" + ';'.join([b.name for b in backends if not b.is_external]),
498498
"-DTRITON_PLUGIN_DIRS=" + ';'.join([b.src_dir for b in backends if b.is_external])
499499
]

test/lit.site.cfg.py.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import sys
44

5-
config.triton_obj_root = "@TRITON_BINARY_DIR@"
5+
config.triton_obj_root = "@triton_BINARY_DIR@"
66
config.llvm_src_root = "@LLVM_SOURCE_DIR@"
77
config.llvm_obj_root = "@LLVM_BINARY_DIR@"
88
config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
@@ -20,4 +20,4 @@ import lit.llvm
2020
lit.llvm.initialize(lit_config, config)
2121

2222
# Let the main config do the real work
23-
lit_config.load_config(config, "@TRITON_SOURCE_DIR@/test/lit.cfg.py")
23+
lit_config.load_config(config, "@triton_SOURCE_DIR@/test/lit.cfg.py")

third_party/amd/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ add_subdirectory(include)
44
add_subdirectory(lib)
55
if(TRITON_BUILD_PYTHON_MODULE)
66
add_triton_plugin(TritonAMD ${CMAKE_CURRENT_SOURCE_DIR}/python/triton_amd.cc LINK_LIBS TritonAMDGPUToLLVM TritonAMDGPUTransforms TritonAMDGPUDialectToLLVM)
7+
target_link_libraries(TritonAMD PRIVATE Python3::Module pybind11::headers)
78
endif()
89
if(TRITON_BUILD_UT)
910
add_subdirectory(unittest)

third_party/nvidia/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ add_subdirectory(include)
44
add_subdirectory(lib)
55
if(TRITON_BUILD_PYTHON_MODULE)
66
add_triton_plugin(TritonNVIDIA ${CMAKE_CURRENT_SOURCE_DIR}/triton_nvidia.cc LINK_LIBS TritonNVIDIAGPUToLLVM NVGPUToLLVM)
7+
target_link_libraries(TritonNVIDIA PRIVATE Python3::Module pybind11::headers)
78
endif()
89
if(TRITON_BUILD_UT)
910
add_subdirectory(unittest)

third_party/proton/CMakeLists.txt

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,8 @@ include_directories(${JSON_INCLUDE_DIR})
1919
include_directories(${PROTON_SRC_DIR}/include)
2020
include_directories(${PROTON_EXTERN_DIR})
2121

22-
if(PYTHON_INCLUDE_DIRS)
23-
# We have PYTHON_INCLUDE_DIRS set--this is what we expect when building
24-
# using pip install.
25-
include_directories(${PYTHON_INCLUDE_DIRS})
26-
include_directories(${PYBIND11_INCLUDE_DIR})
27-
else()
28-
# Otherwise, we might be building from top CMakeLists.txt directly.
29-
# Try to find Python and pybind11 packages.
30-
find_package(Python3 REQUIRED Interpreter Development)
31-
find_package(pybind11 CONFIG REQUIRED HINTS "${Python3_SITELIB}")
32-
include_directories(${Python3_INCLUDE_DIRS})
33-
include_directories(${pybind11_INCLUDE_DIR})
34-
endif()
22+
find_package(Python3 REQUIRED Interpreter Development)
23+
find_package(pybind11 CONFIG REQUIRED HINTS "${Python3_SITELIB}")
3524

3625
# Check if the platform is MacOS
3726
if(APPLE)
@@ -49,4 +38,5 @@ include_directories(${CUPTI_INCLUDE_DIR})
4938
include_directories(SYSTEM ${ROCTRACER_INCLUDE_DIR})
5039
target_compile_definitions(proton PRIVATE __HIP_PLATFORM_AMD__)
5140

52-
target_link_libraries(proton PRIVATE ${Python_LIBRARIES} ${PROTON_PYTHON_LDFLAGS})
41+
target_link_libraries(proton PRIVATE Python3::Module pybind11::headers)
42+
target_link_options(proton PRIVATE ${PROTON_PYTHON_LDFLAGS})

third_party/proton/dialect/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
33
add_subdirectory(include)
44
add_subdirectory(lib)
55
if(TRITON_BUILD_PYTHON_MODULE)
6-
add_triton_plugin(TritonProton ${CMAKE_CURRENT_SOURCE_DIR}/triton_proton.cc LINK_LIBS ProtonIR)
6+
add_triton_plugin(TritonProton ${CMAKE_CURRENT_SOURCE_DIR}/triton_proton.cc)
7+
target_link_libraries(TritonProton PRIVATE ProtonIR Python3::Module pybind11::headers)
78
endif()

0 commit comments

Comments
 (0)