Skip to content

Commit 0a78d51

Browse files
committed
[Release] CUDA Tile IR 13.1 - Initial open-source release
CUDA Tile IR is an MLIR-based intermediate representation and compiler infrastructure for tile-based GPU programming targeting NVIDIA Tensor Cores. This release is aligned with the CUDA Tile IR specification included in CUDA Toolkit 13.1. Core components: * CUDA Tile Dialect: MLIR dialect for tile-based computations * Python Bindings: Python API for IR construction and manipulation * Bytecode: Binary serialization/deserialization support * Conformance Test Suite: Specification compliance tests For more information: * NVIDIA Developer: https://developer.nvidia.com/cuda/tile * CUDA Tile IR Spec 13.1: https://docs.nvidia.com/cuda/tile-ir/13.1/index.html
0 parents  commit 0a78d51

145 files changed

Lines changed: 45213 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*.swp
2+
.cache
3+
.clangd
4+
.cursorignore
5+
.venv
6+
.vscode
7+
build*/
8+
compile_commands.json
9+
doxygen
10+
media/

CMakeLists.txt

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
# ------------------------------------------------------------------------------
2+
# Project Configuration and Requirements
3+
# ------------------------------------------------------------------------------
4+
cmake_minimum_required(VERSION 3.20.0)
5+
6+
project(CUDA_TILE)
7+
8+
set(CMAKE_CXX_STANDARD 17)
9+
set(CMAKE_CXX_STANDARD_REQUIRED True)
10+
11+
include(cmake/IncludeCompilerChecks.cmake)
12+
include(cmake/IncludeCudaTileUtils.cmake)
13+
14+
set_cuda_tile_build_type()
15+
16+
set(CUDA_TILE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE PATH
17+
"Path to CUDA Tile source directory")
18+
set(CUDA_TILE_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH
19+
"Path to CUDA Tile binary directory")
20+
set(CUDA_TILE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX} CACHE PATH
21+
"Path to CUDA Tile install directory")
22+
option(CUDA_TILE_ENABLE_TESTING "Enable CUDA Tile testing" OFF)
23+
option(CUDA_TILE_ENABLE_CCACHE "Enable ccache for faster rebuilds" OFF)
24+
25+
message(STATUS "CUDA Tile source directory: ${CUDA_TILE_SOURCE_DIR}")
26+
message(STATUS "CUDA Tile binary directory: ${CUDA_TILE_BINARY_DIR}")
27+
message(STATUS "CUDA Tile install directory: ${CUDA_TILE_INSTALL_DIR}")
28+
message(STATUS "CUDA Tile testing: ${CUDA_TILE_ENABLE_TESTING}")
29+
message(STATUS "CUDA Tile ccache: ${CUDA_TILE_ENABLE_CCACHE}")
30+
31+
# Configure ccache if enabled.
32+
if(CUDA_TILE_ENABLE_CCACHE)
33+
find_program(CCACHE_PROGRAM ccache)
34+
if(CCACHE_PROGRAM)
35+
message(STATUS "Found ccache: ${CCACHE_PROGRAM}")
36+
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
37+
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
38+
else()
39+
message(WARNING "ccache enabled but not found in PATH")
40+
endif()
41+
endif()
42+
43+
# Project-level compilation flags.
44+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
45+
46+
# ------------------------------------------------------------------------------
47+
# TEMPORARY HACKS!
48+
# ------------------------------------------------------------------------------
49+
add_definitions(-DUSE_12_9_COMPATIBLE_LLVM=0)
50+
51+
# ------------------------------------------------------------------------------
52+
# LLVM/MLIR Configuration
53+
# ------------------------------------------------------------------------------
54+
include(cmake/IncludeLLVM.cmake)
55+
56+
# Check that none or either CUDA_TILE_USE_LLVM_INSTALL_DIR or
57+
# CUDA_TILE_USE_LLVM_SOURCE_DIR is set.
58+
if (DEFINED CUDA_TILE_USE_LLVM_INSTALL_DIR AND
59+
DEFINED CUDA_TILE_USE_LLVM_SOURCE_DIR)
60+
message(FATAL_ERROR "Either CUDA_TILE_USE_LLVM_INSTALL_DIR or "
61+
"CUDA_TILE_USE_LLVM_SOURCE_DIR may be set, but not both")
62+
endif()
63+
64+
# Configure build to use a pre-installed version of LLVM or build it from
65+
# source by downloading them or using the ones provided by the user.
66+
if (CUDA_TILE_USE_LLVM_INSTALL_DIR)
67+
configure_pre_installed_llvm()
68+
else()
69+
configure_llvm_from_sources()
70+
endif()
71+
72+
# Search for the MLIR package based on the previous cmake configuration.
73+
message(STATUS "LLVM_CMAKE_DIR: ${LLVM_CMAKE_DIR}")
74+
message(STATUS "MLIR_CMAKE_DIR: ${MLIR_CMAKE_DIR}")
75+
list(APPEND CMAKE_MODULE_PATH ${LLVM_CMAKE_DIR})
76+
list(APPEND CMAKE_MODULE_PATH ${MLIR_CMAKE_DIR})
77+
find_package(MLIR REQUIRED CONFIG PATHS ${MLIR_CMAKE_DIR} NO_DEFAULT_PATH)
78+
79+
# Configure CUDA Tile and MLIR python bindings. These checks need to happen after
80+
# `find_package(MLIR)` as some MLIR CMake variables can be overridden.
81+
option(CUDA_TILE_ENABLE_BINDINGS_PYTHON "Enable CUDA Tile Python bindings" OFF)
82+
message(STATUS "CUDA Tile Python bindings: ${CUDA_TILE_ENABLE_BINDINGS_PYTHON}")
83+
if (CUDA_TILE_ENABLE_BINDINGS_PYTHON)
84+
message(STATUS "MLIR python bindings: ${MLIR_ENABLE_BINDINGS_PYTHON}")
85+
# If this check fails and `MLIR_ENABLE_BINDINGS_PYTHON` was set to `ON` before the
86+
# `find_package(MLIR)` above, make sure that `find_package(MLIR)` is picking up
87+
# the correct MLIR project and not the one from an unexpected location.
88+
if(NOT MLIR_ENABLE_BINDINGS_PYTHON)
89+
message(FATAL_ERROR "CUDA Tile IR Python bindings require MLIR Python bindings enabled")
90+
endif()
91+
92+
# Configure MLIR python dev packages.
93+
include(MLIRDetectPythonEnv)
94+
mlir_configure_python_dev_packages()
95+
endif()
96+
97+
# Components needed from LLVM and MLIR.
98+
99+
include(TableGen)
100+
include(AddLLVM)
101+
include(AddMLIR)
102+
103+
# Include directories for LLVM and MLIR.
104+
include_directories(${LLVM_INCLUDE_DIRS})
105+
include_directories(${MLIR_INCLUDE_DIRS})
106+
107+
# Create a cross-compilation target for CUDA Tile. This is mostly required by
108+
# cuda-tile-tblgen as we need to use the host's tablegen executable.
109+
if(CMAKE_CROSSCOMPILING)
110+
include(CrossCompile)
111+
set(LLVM_USE_HOST_TOOLS ON)
112+
113+
if (NOT DEFINED CUDA_TILE_USE_NATIVE_LLVM_INSTALL_DIR)
114+
message(FATAL_ERROR "CUDA_TILE_USE_NATIVE_LLVM_INSTALL_DIR is not defined")
115+
endif()
116+
117+
llvm_create_cross_target(CUDA_TILE NATIVE "" Release
118+
-DCUDA_TILE_USE_LLVM_INSTALL_DIR=${CUDA_TILE_USE_NATIVE_LLVM_INSTALL_DIR}
119+
-DCUDA_TILE_ENABLE_TESTING=OFF
120+
-DCUDA_TILE_ENABLE_BINDINGS_PYTHON=OFF
121+
-DCMAKE_C_COMPILER=${NATIVE_C_COMPILER}
122+
-DCMAKE_CXX_COMPILER=${NATIVE_CXX_COMPILER}
123+
-DPython3_EXECUTABLE=${Python3_EXECUTABLE}
124+
)
125+
endif()
126+
127+
print_llvm_config()
128+
129+
#-------------------------------------------------------------------------------
130+
# CUDA Tile Configuration
131+
#-------------------------------------------------------------------------------
132+
133+
# Include directories for CUDA Tile IR.
134+
include_directories(${CUDA_TILE_SOURCE_DIR}/include)
135+
include_directories(${CUDA_TILE_BINARY_DIR}/include)
136+
137+
# Place generated executables (and libraries) in bin (or lib), instead of
138+
# tools/<tool_name>/.
139+
set(LLVM_RUNTIME_OUTPUT_INTDIR ${CUDA_TILE_BINARY_DIR}/bin)
140+
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CUDA_TILE_BINARY_DIR}/lib)
141+
142+
# Used by lit test configuration
143+
set(CUDA_TILE_TOOL_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
144+
set(CUDA_TILE_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
145+
146+
#-------------------------------------------------------------------------------
147+
# CUDA Tile Subdirectories
148+
#-------------------------------------------------------------------------------
149+
150+
# 'cuda-tile-tblgen' is part of the build process and must be built before
151+
# anything else.
152+
add_subdirectory(tools/cuda-tile-tblgen)
153+
154+
# The CMake in 'tools/cuda-tile-tblgen' defines CUDA_TILE_TABLEGEN_EXE to a
155+
# default 'cuda-tile-tblgen'. We need to include the full path of the host
156+
# executable.
157+
if(CMAKE_CROSSCOMPILING)
158+
get_native_tool_path(cuda-tile-tblgen CUDA_TILE_TABLEGEN_EXE)
159+
set(MLIR_TABLEGEN_EXE "${CUDA_TILE_USE_NATIVE_LLVM_INSTALL_DIR}/bin/${MLIR_TABLEGEN_EXE}")
160+
else()
161+
set(CUDA_TILE_TABLEGEN_EXE ${CUDA_TILE_BINARY_DIR}/bin/cuda-tile-tblgen)
162+
endif()
163+
164+
message(STATUS "CUDA_TILE_TABLEGEN_EXE: ${CUDA_TILE_TABLEGEN_EXE}")
165+
166+
# Pass testing flag to both TableGen and C++ compilation for conditional operation generation.
167+
if (CUDA_TILE_ENABLE_TESTING)
168+
list(APPEND LLVM_TABLEGEN_FLAGS -DTILE_IR_INCLUDE_TESTS)
169+
add_compile_definitions(TILE_IR_INCLUDE_TESTS=1)
170+
endif()
171+
172+
add_subdirectory(include)
173+
add_subdirectory(lib)
174+
add_subdirectory(tools)
175+
if (CUDA_TILE_ENABLE_BINDINGS_PYTHON)
176+
add_subdirectory(python)
177+
endif()
178+
179+
if(CUDA_TILE_ENABLE_TESTING)
180+
add_subdirectory(test)
181+
endif()
182+
183+
# ------------------------------------------------------------------------------
184+
# Install CUDA Tile headers
185+
#-------------------------------------------------------------------------------
186+
187+
# TODO: Use custom targets to install the headers instead of installing the
188+
# whole directory?
189+
install(DIRECTORY ${CUDA_TILE_SOURCE_DIR}/include
190+
DESTINATION ${CUDA_TILE_INSTALL_DIR}/include
191+
FILES_MATCHING
192+
PATTERN "*.def"
193+
PATTERN "*.h"
194+
PATTERN "*.inc"
195+
PATTERN "*.td")
196+

0 commit comments

Comments
 (0)