Skip to content

Commit 729e7b5

Browse files
committed
[NATIVE_CPU][SYCL] Switch to using native_cpu compiler pipeline inline from OCK fetch
This brings the native cpu compiler pipeline files directly under the ownership of intel/llvm. This removes the direct dependence on the oneAPI Construction Kit, although the history of those files still exists under intel/llvm and the originals still exist at https://github.com/uxlfoundation/oneapi-construction-kit. This is the post merge update to the the oneAPI Construction Kit move of the compiler pipeline files for Native CPU and replaces the original FetchContent method. This updates the CMakeLists.txt to be appropriate for llvm components, rather in the style of oneAPI Construction Kit. It also applies clang-format-20 to all the .h and .cpp files brought in. Other than that the .cpp and .h files are unchanged. A brief explanation and limitations of the importing of the files are under l lvm/lib/SYCLNativeCPUUtils/compiler_passes/compiler_passes.rst. It also updates the NATIVECPU_USE_OCK to be on in sycl-linux-build.yml.
1 parent 76f16d1 commit 729e7b5

File tree

143 files changed

+4624
-4446
lines changed

Some content is hidden

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

143 files changed

+4624
-4446
lines changed

.github/workflows/sycl-linux-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ jobs:
203203
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
204204
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
205205
-DLLVM_INSTALL_UTILS=ON \
206-
-DNATIVECPU_USE_OCK=Off
206+
-DNATIVECPU_USE_OCK=ON
207207
- name: Compile
208208
id: build
209209
# Emulate default value for manual dispatch as we've run out of available arguments.
Lines changed: 18 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
set(OCK_LIBS)
2+
option(NATIVECPU_USE_OCK "Use the oneAPI Construction Kit for Native CPU" ON)
3+
4+
# Don't use OCK compiler_passes if Native CPU is not enabled.
5+
if(NOT "native_cpu" IN_LIST SYCL_ENABLE_BACKENDS)
6+
set(NATIVECPU_USE_OCK Off CACHE BOOL "Use the oneAPI Construction Kit for Native CPU" FORCE)
7+
endif()
8+
9+
if(NATIVECPU_USE_OCK)
10+
add_subdirectory(compiler_passes EXCLUDE_FROM_ALL)
11+
set(OCK_LIBS NativeCPUPipeline NativeCPUVecz)
12+
endif()
13+
114
add_llvm_component_library(LLVMSYCLNativeCPUUtils
215
PipelineSYCLNativeCPU.cpp
316
PrepareSYCLNativeCPU.cpp
@@ -17,80 +30,13 @@ add_llvm_component_library(LLVMSYCLNativeCPUUtils
1730
TargetParser
1831
TransformUtils
1932
ipo
20-
)
33+
${OCK_LIBS}
34+
)
2135

22-
option(NATIVECPU_USE_OCK "Use the oneAPI Construction Kit for Native CPU" ON)
23-
24-
# Don't fetch OCK if Native CPU is not enabled.
25-
if(NOT "native_cpu" IN_LIST SYCL_ENABLE_BACKENDS)
26-
set(NATIVECPU_USE_OCK Off CACHE BOOL "Use the oneAPI Construction Kit for Native CPU" FORCE)
27-
endif()
2836

2937
if(NATIVECPU_USE_OCK)
30-
set(OCK_SEARCH_LOC "oneapi-construction-kit/compiler_passes")
31-
if(NOT FETCHCONTENT_SOURCE_DIR_ONEAPI-CK)
32-
find_path(OCK_SOURCE_DIR ${OCK_SEARCH_LOC} PATHS ${CMAKE_PREFIX_PATH})
33-
endif()
34-
if(OCK_SOURCE_DIR)
35-
message(STATUS "Found system source location of oneAPI Construction Kit in ${OCK_SOURCE_DIR}")
36-
set(OCK_SOURCE_DIR "${OCK_SOURCE_DIR}/${OCK_SEARCH_LOC}")
37-
set(OCK_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/oneapi-construction-kit")
38-
else()
39-
set(OCK_GIT_REPO "https://github.com/uxlfoundation/oneapi-construction-kit.git")
40-
# commit d0a32d701e34b3285de7ce776ea36abfec673df7
41-
# Merge: a9f848e0e8 56473a8c25
42-
# Author: Harald van Dijk <[email protected]>
43-
# Date: Mon Jun 30 12:24:46 2025 +0100
44-
#
45-
# Merge pull request #878 from hvdijk/specify-fuse-ld-lld
46-
#
47-
# [RefSi] Explicitly specify -fuse-ld=lld.
48-
set(OCK_GIT_TAG d0a32d701e34b3285de7ce776ea36abfec673df7)
49-
50-
include(FetchContent)
51-
FetchContent_Declare(oneapi-ck
52-
GIT_REPOSITORY "${OCK_GIT_REPO}"
53-
GIT_TAG "${OCK_GIT_TAG}"
54-
)
55-
FetchContent_GetProperties(oneapi-ck)
56-
if(NOT oneapi-ck_POPULATED)
57-
if(FETCHCONTENT_SOURCE_DIR_ONEAPI-CK)
58-
message(STATUS "Using specified oneAPI Construction Kit repo location at ${FETCHCONTENT_SOURCE_DIR_ONEAPI-CK}")
59-
else()
60-
message(STATUS "Cloning oneAPI Construction Kit from ${OCK_GIT_REPO}, tag ${OCK_GIT_TAG}")
61-
endif()
62-
FetchContent_Populate(oneapi-ck)
63-
message(STATUS "oneAPI Construction Kit cloned in ${oneapi-ck_SOURCE_DIR}")
64-
set(OCK_SOURCE_DIR ${oneapi-ck_SOURCE_DIR}/compiler_passes)
65-
set(OCK_BINARY_DIR ${oneapi-ck_BINARY_DIR})
66-
endif()
67-
endif()
68-
69-
set(CA_ENABLE_API "cl" CACHE STRING "" FORCE)
70-
add_subdirectory(
71-
${OCK_SOURCE_DIR}
72-
${OCK_BINARY_DIR} EXCLUDE_FROM_ALL)
73-
74-
install(TARGETS compiler-pipeline
75-
EXPORT;LLVMExports
76-
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT compiler-pipeline
77-
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT compiler-pipeline
78-
RUNTIME DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT compiler-pipeline)
79-
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS compiler-pipeline)
80-
install(TARGETS vecz
81-
EXPORT;LLVMExports
82-
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT vecz
83-
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT vecz
84-
RUNTIME DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT vecz)
85-
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS vecz)
86-
install(TARGETS multi_llvm EXPORT;LLVMExports)
87-
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS multi_llvm)
8838
target_compile_definitions(LLVMSYCLNativeCPUUtils PRIVATE NATIVECPU_USE_OCK)
8939
target_include_directories(LLVMSYCLNativeCPUUtils PRIVATE
90-
${oneapi-ck_SOURCE_DIR}/modules/compiler/multi_llvm/include
91-
${oneapi-ck_SOURCE_DIR}/modules/cargo/include
92-
${oneapi-ck_SOURCE_DIR}/modules/compiler/vecz/include
93-
${oneapi-ck_SOURCE_DIR}/modules/compiler/utils/include)
94-
target_link_libraries(LLVMSYCLNativeCPUUtils PRIVATE compiler-pipeline vecz)
95-
96-
endif()
40+
${CMAKE_CURRENT_SOURCE_DIR}/compiler_passes/compiler_pipeline/include
41+
${CMAKE_CURRENT_SOURCE_DIR}/compiler_passes/vecz/include)
42+
endif()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/compiler_pipeline)
2+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/vecz)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
Compiler passes
2+
===============
3+
4+
Introduction
5+
------------
6+
7+
Files under this directory are ported from the [oneAPI Construction
8+
Kit](https://github.com/uxlfoundation/oneapi-construction-kit). They are used by
9+
NativeCPU to help create a pipeline for turning a base kernel into something
10+
which can be executed across multiple work items, including auto-vectorization.
11+
12+
These files are largely from the sub-directories
13+
**modules/compiler/compiler_pipeline**, **modules/compiler/vecz** and
14+
**modules/compiler/multi_llvm**. Only files that are used have been copied and
15+
the **Cmake** files have been updated to fit in with LLVM components.
16+
17+
These sub-directories are used as follows:
18+
19+
* **compiler_pipeline** provides the passes to build a pipeline from the initial
20+
kernel, including generating working item loops, handling local memory,
21+
handling metadata and calling the vectorizer **vecz**.
22+
23+
* **vecz** provides a full function vectorizer, which generates a copy of the
24+
original function but vectorized across the work group, taking into account
25+
subgroups.
26+
27+
* **multi_llvm**. This provides some support for these functions to work across
28+
multiple LLVM versions. Although this is not strictly needed in LLVM, it has
29+
been ported across to allow the port to go smoothly, without changing files
30+
directly. Note this is header only and exists under
31+
**compiler_pipeline/include/multi_llvm**.
32+
33+
**compiler_pipeline** is documented in :doc:`/compiler_pipeline/docs/compiler`
34+
and **vecz** is documented in :doc:`/vecz/vecz`. Note that there are several
35+
limitations both in the documentation and in the code that are a result of the
36+
initial port. These should be addressed.
37+
38+
General limitations
39+
-------------------
40+
41+
There is the following limitations in the current port:
42+
43+
* The documentation makes a lot of references to **oneAPI Construction Kit**
44+
constructs such as ComputeMux. It also references files that have not been
45+
copied across.
46+
* The namespace in **compiler_pipeline** is **compiler/utils**, the namespace in
47+
multi_llvm is **multi_llvm** and the namespace in **vecz** is **vecz**. These should
48+
be updated to reflect being under **LLVM**.
49+
* include files should ideally be moved to under **llvm/include** but remain under
50+
these directories after the port.
51+
* **vecz** has a test tool **veczc** and associated **lit** tests. This tool if
52+
required should be moved under **llvm/tools** or **llvm/test**. This is also not
53+
built by default. It also refers to **@CA_COMMON_LIT_BINARY_PATH@** which is not
54+
defined.
55+
* **compiler_pipeline** has lit tests for the passes which have not been ported
56+
across. This is because they use a tool **muxc**, but these passes should be
57+
able to be tested using opt. These lit tests can be found
58+
[here](https://github.com/uxlfoundation/oneapi-construction-kit/tree/main/modules/compiler/test/lit/passes).
59+
* There are many files that are unlikely to have any code coverage but because
60+
there are referred to in other files which we do need, they exist here. These
61+
should be pruned over time as a better understanding is made of what is
62+
required.
63+
64+
.. _oneAPI Construction Kit: https://github.com/uxlfoundation/oneapi-construction-kit
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
add_llvm_component_library(LLVMNativeCPUPipeline
2+
${CMAKE_CURRENT_SOURCE_DIR}/source/attributes.cpp
3+
${CMAKE_CURRENT_SOURCE_DIR}/source/barrier_regions.cpp
4+
${CMAKE_CURRENT_SOURCE_DIR}/source/builtin_info.cpp
5+
${CMAKE_CURRENT_SOURCE_DIR}/source/cl_builtin_info.cpp
6+
${CMAKE_CURRENT_SOURCE_DIR}/source/define_mux_builtins_pass.cpp
7+
${CMAKE_CURRENT_SOURCE_DIR}/source/dma.cpp
8+
${CMAKE_CURRENT_SOURCE_DIR}/source/encode_kernel_metadata_pass.cpp
9+
${CMAKE_CURRENT_SOURCE_DIR}/source/group_collective_helpers.cpp
10+
${CMAKE_CURRENT_SOURCE_DIR}/source/mangling.cpp
11+
${CMAKE_CURRENT_SOURCE_DIR}/source/metadata.cpp
12+
${CMAKE_CURRENT_SOURCE_DIR}/source/mux_builtin_info.cpp
13+
${CMAKE_CURRENT_SOURCE_DIR}/source/pass_functions.cpp
14+
${CMAKE_CURRENT_SOURCE_DIR}/source/pass_machinery.cpp
15+
${CMAKE_CURRENT_SOURCE_DIR}/source/prepare_barriers_pass.cpp
16+
${CMAKE_CURRENT_SOURCE_DIR}/source/replace_local_module_scope_variables_pass.cpp
17+
${CMAKE_CURRENT_SOURCE_DIR}/source/scheduling.cpp
18+
${CMAKE_CURRENT_SOURCE_DIR}/source/sub_group_analysis.cpp
19+
${CMAKE_CURRENT_SOURCE_DIR}/source/target_extension_types.cpp
20+
${CMAKE_CURRENT_SOURCE_DIR}/source/work_item_loops_pass.cpp
21+
22+
LINK_COMPONENTS
23+
Passes
24+
Core
25+
)
26+
27+
# TODO: Move to under LLVM include and work out why ADDITIONAL_HEADER_DIRS
28+
# does not capture it.
29+
target_include_directories(LLVMNativeCPUPipeline PUBLIC
30+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
31+
)

llvm/lib/SYCLNativeCPUUtils/compiler_passes/compiler_pipeline/include/compiler/utils/address_spaces.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ enum {
3232
Generic = 4,
3333
};
3434
}
35-
} // namespace utils
36-
} // namespace compiler
35+
} // namespace utils
36+
} // namespace compiler
3737

38-
#endif // COMPILER_UTILS_ADDRESS_SPACES_H_INCLUDED
38+
#endif // COMPILER_UTILS_ADDRESS_SPACES_H_INCLUDED

llvm/lib/SYCLNativeCPUUtils/compiler_passes/compiler_pipeline/include/compiler/utils/attributes.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
namespace llvm {
2525
class CallInst;
2626
class Function;
27-
} // namespace llvm
27+
} // namespace llvm
2828

2929
namespace compiler {
3030
namespace utils {
@@ -180,7 +180,7 @@ bool hasNoExplicitSubgroups(const llvm::Function &F);
180180
/// Currently always returns 1!
181181
unsigned getMuxSubgroupSize(const llvm::Function &F);
182182

183-
} // namespace utils
184-
} // namespace compiler
183+
} // namespace utils
184+
} // namespace compiler
185185

186-
#endif // COMPILER_UTILS_ATTRIBUTES_H_INCLUDED
186+
#endif // COMPILER_UTILS_ATTRIBUTES_H_INCLUDED

llvm/lib/SYCLNativeCPUUtils/compiler_passes/compiler_pipeline/include/compiler/utils/barrier_regions.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Module;
4545
class StructType;
4646
class Type;
4747
class Value;
48-
} // namespace llvm
48+
} // namespace llvm
4949

5050
namespace compiler {
5151
namespace utils {
@@ -84,17 +84,14 @@ struct BarrierRegion {
8484
};
8585

8686
class Barrier {
87-
public:
87+
public:
8888
/// @brief Type for ids of new kernel functions
8989
using kernel_id_map_t = std::map<unsigned, llvm::Function *>;
9090

9191
Barrier(llvm::Module &m, llvm::Function &f, bool IsDebug)
9292
: live_var_mem_ty_(nullptr),
93-
size_t_bytes(compiler::utils::getSizeTypeBytes(m)),
94-
module_(m),
95-
func_(f),
96-
is_debug_(IsDebug),
97-
max_live_var_alignment(0) {}
93+
size_t_bytes(compiler::utils::getSizeTypeBytes(m)), module_(m),
94+
func_(f), is_debug_(IsDebug), max_live_var_alignment(0) {}
9895

9996
/// @brief perform the Barrier Region analysis and kernel splitting
10097
void Run(llvm::ModuleAnalysisManager &mam);
@@ -204,7 +201,7 @@ class Barrier {
204201
const char *name, bool reuse = false);
205202
};
206203

207-
private:
204+
private:
208205
/// @brief The first is set for livein and the second is set for liveout
209206
using live_in_out_t =
210207
std::pair<llvm::DenseSet<llvm::Value *>, llvm::DenseSet<llvm::Value *>>;
@@ -362,7 +359,7 @@ class Barrier {
362359
void SeperateKernelWithBarrier();
363360
};
364361

365-
} // namespace utils
366-
} // namespace compiler
362+
} // namespace utils
363+
} // namespace compiler
367364

368-
#endif // COMPILER_UTILS_BARRIER_REGIONS_H_INCLUDED
365+
#endif // COMPILER_UTILS_BARRIER_REGIONS_H_INCLUDED

0 commit comments

Comments
 (0)