Skip to content

Commit 9674ab1

Browse files
committed
Improve cmake for benchmarks
1 parent 5f5c5c8 commit 9674ab1

File tree

4 files changed

+39
-27
lines changed

4 files changed

+39
-27
lines changed

benchmarks/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ if(NOT WIN32)
1010
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
1111
endif()
1212

13-
find_package(Python3 COMPONENTS Interpreter)
13+
find_package(Python3 REQUIRED
14+
COMPONENTS Development.Module)
1415
find_package(Torch REQUIRED)
1516
find_library(TORCH_PYTHON_LIBRARY torch_python PATH "${TORCH_INSTALL_PREFIX}/lib")
17+
find_package(XeTLALibrary REQUIRED)
1618

1719
if(USE_IPEX)
1820
string(APPEND CMAKE_CXX_FLAGS " -DUSE_IPEX")

benchmarks/cmake/FindXeTLALibrary.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
include(FetchContent)
44

55
if (NOT XeTLALibrary_FOUND)
6+
# TODO: swithc ot FetchContent_MakeAvailable
7+
cmake_policy(SET CMP0169 OLD)
68

79
set(XeTLALibrary_SOURCE_DIR
810
"${CMAKE_CURRENT_BINARY_DIR}/XeTLALibrary")
911
message(STATUS "XeTLALibrary is not specified. Will try to download
1012
XeTLA library from https://github.com/intel/xetla into
1113
${XeTLALibrary_SOURCE_DIR}")
12-
file(READ xetla-library.conf XeTLALibrary_TAG)
14+
file(READ xetla_kernel/xetla-library.conf XeTLALibrary_TAG)
1315
# Strip the potential trailing newline from tag
1416
string(STRIP "${XeTLALibrary_TAG}" XeTLALibrary_TAG)
1517
FetchContent_Declare(xetla-library

benchmarks/setup.py

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import re
33
import shutil
44
import subprocess
5-
import sysconfig
65
import sys
76

87
from setuptools import setup
@@ -37,40 +36,53 @@ def run(self):
3736
self.build_extension()
3837

3938
def build_extension(self):
39+
# configuration
40+
build_type = "Debug"
41+
4042
ninja_dir = shutil.which("ninja")
4143
# create build directories
4244
if not os.path.exists(self.build_temp):
4345
os.makedirs(self.build_temp)
44-
# python directories
45-
python_include_dir = sysconfig.get_path("platinclude")
4646
cmake_args = [
4747
"-G",
4848
"Ninja", # Ninja is much faster than make
4949
"-DCMAKE_MAKE_PROGRAM=" +
5050
ninja_dir, # Pass explicit path to ninja otherwise cmake may cache a temporary path
5151
f"-DCMAKE_PREFIX_PATH={torch.utils.cmake_prefix_path}{ipex_cmake_prefix_path}",
5252
f"-DUSE_IPEX={USE_IPEX_OPTION}",
53-
"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON",
54-
"-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=" + self.extdir,
55-
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=" + self.extdir,
56-
"-DPython3_EXECUTABLE:FILEPATH=" + sys.executable,
57-
"-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON",
58-
"-DPYTHON_INCLUDE_DIRS=" + python_include_dir,
53+
"-DCMAKE_INSTALL_PREFIX=" + self.extdir,
54+
"-DPython3_ROOT_DIR:FILEPATH=" + sys.exec_prefix,
55+
"-DCMAKE_VERBOSE_MAKEFILE=TRUE",
5956
"-DCMAKE_C_COMPILER=icx",
6057
"-DCMAKE_CXX_COMPILER=icpx",
58+
"-DCMAKE_BUILD_TYPE=" + build_type,
59+
"-S",
60+
self.current_dir,
61+
"-B",
62+
self.build_temp,
6163
]
6264

63-
# configuration
64-
build_type = "Debug"
65-
build_args = ["--config", build_type]
66-
cmake_args += ["-DCMAKE_BUILD_TYPE=" + build_type]
6765
max_jobs = os.getenv("MAX_JOBS", str(2 * os.cpu_count()))
68-
build_args += ["-j" + max_jobs]
66+
build_args = [
67+
"--build",
68+
self.build_temp,
69+
"-j" + max_jobs,
70+
]
71+
72+
install_args = [
73+
"--build",
74+
self.build_temp,
75+
"--target",
76+
"install",
77+
]
6978

7079
env = os.environ.copy()
71-
cmake_dir = self.build_temp
72-
subprocess.check_call(["cmake", self.current_dir] + cmake_args, cwd=cmake_dir, env=env)
73-
subprocess.check_call(["cmake", "--build", "."] + build_args, cwd=cmake_dir)
80+
print(" ".join(["cmake"] + cmake_args))
81+
subprocess.check_call(["cmake"] + cmake_args, env=env)
82+
print(" ".join(["cmake"] + build_args))
83+
subprocess.check_call(["cmake"] + build_args)
84+
print(" ".join(["cmake"] + install_args))
85+
subprocess.check_call(["cmake"] + install_args)
7486

7587

7688
cmake = CMakeBuild()
@@ -80,4 +92,4 @@ def build_extension(self):
8092
"triton_kernels_benchmark",
8193
], package_dir={
8294
"triton_kernels_benchmark": "triton_kernels_benchmark",
83-
}, package_data={"triton_kernels_benchmark": ["xetla_kernel.so"]})
95+
}, package_data={"triton_kernels_benchmark": ["xetla_kernel.cpython-*.so"]})

benchmarks/xetla_kernel/CMakeLists.txt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
# XeTLA library is required.
2-
find_package(XeTLALibrary REQUIRED)
3-
set(CMAKE_CXX_STANDARD 20)
4-
51
set(XETLA_KERNEL_FLAGS ${XETLA_KERNEL_FLAGS} -fsycl)
62

73
if (USE_AOT_DEVLIST)
@@ -26,8 +22,7 @@ else()
2622
set(XETLA_KERNEL_FLAGS ${XETLA_KERNEL_FLAGS} "${XETLA_OFFLINE_OPTIONS}")
2723
endif()
2824

29-
add_library(xetla_kernel SHARED python_main.cpp)
30-
set_target_properties(xetla_kernel PROPERTIES PREFIX "")
25+
Python3_add_library(xetla_kernel MODULE WITH_SOABI python_main.cpp)
3126
target_compile_options(xetla_kernel PRIVATE "-fPIC")
3227
if(USE_IPEX)
3328
target_compile_options(xetla_kernel PRIVATE "-fsycl")
@@ -37,7 +32,6 @@ endif()
3732
target_compile_options(xetla_kernel PUBLIC "-DXETPP_NEW_XMAIN")
3833
target_link_options(xetla_kernel PRIVATE ${XETLA_KERNEL_FLAGS})
3934
target_link_libraries(xetla_kernel PUBLIC ${TORCH_LIBRARIES} ${TORCH_PYTHON_LIBRARY})
40-
target_include_directories(xetla_kernel PUBLIC "${PYTHON_INCLUDE_DIRS}")
4135
target_include_directories(xetla_kernel PUBLIC "${XeTLALibrary_INCLUDE_DIR}")
4236

4337
if(USE_IPEX)
@@ -49,3 +43,5 @@ add_subdirectory(softmax)
4943
add_subdirectory(gemm)
5044
add_subdirectory(stream_k_gemm)
5145
add_subdirectory(flash_attention)
46+
47+
install(TARGETS xetla_kernel LIBRARY DESTINATION .)

0 commit comments

Comments
 (0)