Skip to content

Commit 00d80bd

Browse files
dongkyunahn-intelromanovvladkbobrovsbader
authored
[SYCL][ESIMD][EMU] pi_esimd_cpu bringing up with CM library (2nd) (#4430)
* [SYCL][ESIMD][EMU] pi_esimd_cpu bringing up with CM library - This PR is for a change set that invokes CM functionalities for ESIMD_CPU - initializing CM_EMU module, launching kernel, and accessing CM-managed resources like buffer, etc. CM_EMU library is downloaded as pre-built package from open-source CM github repo (https://github.com/intel/cm-cpu-emulation.git) under Linux environment - '--enable-esimd-cpu-emulation' for configure.py enables ESIMD_CPU ESIMD_CPU emulation is disabled in sycl build by default Co-authored-by: Romanov Vlad <17316488+romanovvlad@users.noreply.github.com> Co-authored-by: kbobrovs <Konstantin.S.Bobrovsky@intel.com> Co-authored-by: Alexey Bader <alexey.bader@intel.com>
1 parent 00ce1fa commit 00d80bd

File tree

9 files changed

+1211
-623
lines changed

9 files changed

+1211
-623
lines changed

buildbot/configure.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def do_configure(args):
2929
libclc_targets_to_build = ''
3030
libclc_gen_remangled_variants = 'OFF'
3131
sycl_build_pi_cuda = 'OFF'
32-
sycl_build_pi_esimd_cpu = 'ON'
32+
sycl_build_pi_esimd_cpu = 'OFF'
3333
sycl_build_pi_rocm = 'OFF'
3434
sycl_build_pi_rocm_platform = 'AMD'
3535
sycl_werror = 'ON'
@@ -45,8 +45,8 @@ def do_configure(args):
4545
if args.arm:
4646
llvm_targets_to_build = 'ARM;AArch64'
4747

48-
if args.disable_esimd_cpu:
49-
sycl_build_pi_esimd_cpu = 'OFF'
48+
if args.enable_esimd_cpu_emulation:
49+
sycl_build_pi_esimd_cpu = 'ON'
5050

5151
if args.cuda or args.rocm:
5252
llvm_enable_projects += ';libclc'
@@ -181,7 +181,7 @@ def main():
181181
parser.add_argument("--rocm", action='store_true', help="switch from OpenCL to ROCm")
182182
parser.add_argument("--rocm-platform", type=str, choices=['AMD', 'NVIDIA'], default='AMD', help="choose ROCm backend")
183183
parser.add_argument("--arm", action='store_true', help="build ARM support rather than x86")
184-
parser.add_argument("--disable-esimd-cpu", action='store_true', help="build without ESIMD_CPU support")
184+
parser.add_argument("--enable-esimd-cpu-emulation", action='store_true', help="build with ESIMD_CPU emulation support")
185185
parser.add_argument("--no-assertions", action='store_true', help="build without assertions")
186186
parser.add_argument("--docs", action='store_true', help="build Doxygen documentation")
187187
parser.add_argument("--no-werror", action='store_true', help="Don't treat warnings as errors")

sycl/CMakeLists.txt

+13-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ set( SYCL_TOOLCHAIN_DEPLOY_COMPONENTS
259259
sycl
260260
pi_opencl
261261
pi_level_zero
262-
pi_esimd_cpu
263262
libsycldevice
264263
${XPTIFW_LIBS}
265264
)
@@ -292,6 +291,19 @@ if(SYCL_BUILD_PI_ROCM)
292291
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS libspirv-builtins pi_rocm)
293292
endif()
294293

294+
# TODO : Remove 'if (NOT MSVC)' when CM_EMU supports Windows
295+
# environment
296+
if (NOT MSVC)
297+
if (SYCL_BUILD_PI_ESIMD_CPU)
298+
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS pi_esimd_cpu libcmrt-headers)
299+
if (MSVC)
300+
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS libcmrt-libs libcmrt-dlls)
301+
else()
302+
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS libcmrt-sos)
303+
endif()
304+
endif()
305+
endif()
306+
295307
# Use it as fake dependency in order to force another command(s) to execute.
296308
add_custom_command(OUTPUT __force_it
297309
COMMAND "${CMAKE_COMMAND}" -E echo

sycl/doc/GetStartedGuide.md

+44
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and a wide range of compute accelerators such as GPU and FPGA.
1111
- [Build DPC++ toolchain with support for NVIDIA CUDA](#build-dpc-toolchain-with-support-for-nvidia-cuda)
1212
- [Build DPC++ toolchain with support for AMD ROCm](#build-dpc-toolchain-with-support-for-amd-rocm)
1313
- [Build DPC++ toolchain with support for NVIDIA ROCm](#build-dpc-toolchain-with-support-for-nvidia-rocm)
14+
- [Build DPC++ toolchain with support for ESIMD CPU Emulation](#build-dpc-toolchain-with-support-for-esimd-cpu)
1415
- [Build Doxygen documentation](#build-doxygen-documentation)
1516
- [Deployment](#deployment)
1617
- [Use DPC++ toolchain](#use-dpc-toolchain)
@@ -109,6 +110,7 @@ flags can be found by launching the script with `--help`):
109110
* `--cuda` -> use the cuda backend (see [Nvidia CUDA](#build-dpc-toolchain-with-support-for-nvidia-cuda))
110111
* `--rocm` -> use the rocm backend (see [AMD ROCm](#build-dpc-toolchain-with-support-for-amd-rocm))
111112
* `--rocm-platform` -> select the platform used by the rocm backend, `AMD` or `NVIDIA` (see [AMD ROCm](#build-dpc-toolchain-with-support-for-amd-rocm) or see [NVIDIA ROCm](#build-dpc-toolchain-with-support-for-nvidia-rocm))
113+
* '--enable-esimd-cpu-emulation' -> enable ESIMD CPU emulation (see [ESIMD CPU emulation](#build-dpc-toolchain-with-support-for-esimd-cpu))
112114
* `--shared-libs` -> Build shared libraries
113115
* `-t` -> Build type (debug or release)
114116
* `-o` -> Path to build directory
@@ -206,6 +208,48 @@ as well as CUDA to be installed, see
206208
Currently this was only tested on Linux with ROCm 4.2, CUDA 11 and a GeForce GTX
207209
1060 card.
208210

211+
### Build DPC++ toolchain with support for ESIMD CPU Emulation
212+
213+
There is experimental support for DPC++ for using ESIMD CPU Emulation
214+
215+
This feature supports ESIMD CPU Emulation using CM_EMU library [CM
216+
Emulation
217+
project](https://github.com/intel/cm-cpu-emulation). Pre-built library
218+
package will be downloaded and installed in your deploy directory
219+
during toolchain build.
220+
221+
To enable support for ESIMD CPU emulation, follow the instructions for
222+
the Linux DPC++ toolchain, but add the `--enable-esimd-cpu-emulation'.
223+
224+
Enabling this flag requires following packages installed.
225+
226+
* Ubuntu 20.04
227+
* libva-dev / 2.7.0-2
228+
* libva-drm2 / 2.7.0-2
229+
* libva-glx2 / 2.7.0-2
230+
* libva-wayland2 / 2.7.0-2
231+
* libva-x11-2 / 2.7.0-2
232+
* libva2 / focal 2.7.0-2
233+
* libffi-dev / 3.3-4
234+
* libffi7 / 3.3-4
235+
* libdrm-amdgpu1
236+
* libdrm-common
237+
* libdrm-dev
238+
* libdrm-intel1
239+
* libdrm-nouveau2
240+
* libdrm-radeon1
241+
* libdrm2
242+
* RHEL 8.*
243+
* libffi
244+
* libffi-devel
245+
* libdrm
246+
* libdrm-devel
247+
* libva
248+
* libva-devel
249+
250+
Currently, this feature was tested and verified on Ubuntu 20.04
251+
environment.
252+
209253
### Build Doxygen documentation
210254

211255
Building Doxygen documentation is similar to building the product itself. First,

sycl/include/sycl/ext/intel/experimental/esimd/emu/detail/esimd_emu_functions_v1.h

+4
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,7 @@ void (*cm_fence_ptr)(void);
4444
char *(*sycl_get_surface_base_addr_ptr)(int);
4545
char *(*__cm_emu_get_slm_ptr)(void);
4646
void (*cm_slm_init_ptr)(size_t);
47+
void (*sycl_get_cm_buffer_params_ptr)(void *, char **, uint32_t *,
48+
std::mutex **);
49+
void (*sycl_get_cm_image_params_ptr)(void *, char **, uint32_t *, uint32_t *,
50+
uint32_t *, std::mutex **);

sycl/include/sycl/ext/intel/experimental/esimd/emu/detail/esimdcpu_device_interface.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
// pointer table file ('esimd_emu_functions_v1.h') included in 'struct
2525
// ESIMDDeviceInterface' definition.
2626
#include <cstdint>
27+
#include <mutex>
2728

2829
__SYCL_INLINE_NAMESPACE(cl) {
2930
namespace sycl {

sycl/plugins/CMakeLists.txt

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ endif()
1515
add_subdirectory(opencl)
1616
add_subdirectory(level_zero)
1717

18-
if (SYCL_BUILD_PI_ESIMD_CPU)
19-
add_subdirectory(esimd_cpu)
18+
# TODO : Remove 'if (NOT MSVC)' when CM_EMU supports Windows
19+
# environment
20+
if (NOT MSVC)
21+
if (SYCL_BUILD_PI_ESIMD_CPU)
22+
add_subdirectory(esimd_cpu)
23+
endif()
2024
endif()

sycl/plugins/esimd_cpu/CMakeLists.txt

+123-7
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,99 @@
22
# PI Esimd CPU library
33
# Create Shared library for libpi_esimd_cpu.so.
44

5+
include(ExternalProject)
6+
57
include_directories("${sycl_inc_dir}")
8+
# FIXME/TODO: 'pi.h' is included in 'pi_esimd_cpu.cpp', and CL_*_INTEL
9+
# and CL_*_KHR definitions in 'pi.h' are from
10+
# ${OPENCL_INCLUDE}. Remove build dependency on OpenCL
611
include_directories(${OpenCL_INCLUDE_DIR})
7-
include_directories(${LIBCMRT_INCLUDE})
12+
13+
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_build)
14+
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_install)
15+
16+
if (MSVC)
17+
set(LIBCM ${LLVM_BINARY_DIR}/pi_esimd_cpu_deps/lib/libcm${CMAKE_STATIC_LIBRARY_SUFFIX})
18+
set(LIBIGFXCMRT_EMU ${LLVM_BINARY_DIR}/pi_esimd_cpu_deps/lib/igfxcmrt64_emu${CMAKE_STATIC_LIBRARY_SUFFIX})
19+
else()
20+
set(LIBCM ${LLVM_BINARY_DIR}/pi_esimd_cpu_deps/lib/libcm${CMAKE_SHARED_LIBRARY_SUFFIX})
21+
set(LIBIGFXCMRT_EMU ${LLVM_BINARY_DIR}/pi_esimd_cpu_deps/lib/libigfxcmrt_emu${CMAKE_SHARED_LIBRARY_SUFFIX})
22+
endif()
23+
24+
if (DEFINED CM_LOCAL_SOURCE_DIR)
25+
# Using local CM directory for online building without downloading
26+
if (MSVC)
27+
ExternalProject_Add(cm-emu
28+
DOWNLOAD_COMMAND ""
29+
SOURCE_DIR ${CM_LOCAL_SOURCE_DIR}
30+
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_build
31+
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_install
32+
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
33+
BUILD_BYPRODUCTS ${LIBCM} ${LIBIGFXCMRT_EMU}
34+
)
35+
else()
36+
ExternalProject_Add(cm-emu
37+
DOWNLOAD_COMMAND ""
38+
SOURCE_DIR ${CM_LOCAL_SOURCE_DIR}
39+
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_build
40+
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_install
41+
CMAKE_ARGS -DLIBVA_INSTALL_PATH=/usr
42+
-D__SYCL_EXPLICIT_SIMD_PLUGIN__=true
43+
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
44+
BUILD_BYPRODUCTS ${LIBCM} ${LIBIGFXCMRT_EMU}
45+
)
46+
endif()
47+
else ()
48+
if (DEFINED CM_PACKAGE_URL)
49+
# Downloading pre-built CM Package
50+
file (MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_install)
51+
ExternalProject_Add(cm-emu
52+
URL ${CM_PACKAGE_URL}
53+
CONFIGURE_COMMAND ""
54+
BUILD_COMMAND ""
55+
UPDATE_COMMAND ""
56+
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_install
57+
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/cm-emu-prefix/src/cm-emu/ <INSTALL_DIR>
58+
BUILD_BYPRODUCTS ${LIBCM} ${LIBIGFXCMRT_EMU}
59+
)
60+
else()
61+
# Build from CM source tree fetched from github
62+
if (MSVC)
63+
message(FATAL_ERROR "Online-building of CM_EMU library is not supported under Windows environment")
64+
else()
65+
ExternalProject_Add(cm-emu
66+
GIT_REPOSITORY https://github.com/intel/cm-cpu-emulation.git
67+
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_build
68+
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_install
69+
CMAKE_ARGS -DLIBVA_INSTALL_PATH=/usr
70+
-D__SYCL_EXPLICIT_SIMD_PLUGIN__=true
71+
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
72+
BUILD_BYPRODUCTS ${LIBCM} ${LIBIGFXCMRT_EMU}
73+
)
74+
endif()
75+
endif()
76+
endif ()
77+
ExternalProject_Add_Step(cm-emu llvminstall
78+
COMMAND ${CMAKE_COMMAND} -E make_directory ${LLVM_BINARY_DIR}/pi_esimd_cpu_deps && ${CMAKE_COMMAND} -E copy_directory <INSTALL_DIR>/ ${LLVM_BINARY_DIR}/pi_esimd_cpu_deps
79+
COMMENT "Installing cm-emu into the LLVM binary directory"
80+
DEPENDEES install
81+
)
82+
83+
include_directories(${LLVM_BINARY_DIR}/pi_esimd_cpu_deps/include/igfxcmrt_emu)
84+
include_directories(${LLVM_BINARY_DIR}/pi_esimd_cpu_deps/include/libcm/cm)
85+
86+
# Compilation flag to exclude lines in header files imported from CM
87+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__SYCL_EXPLICIT_SIMD_PLUGIN__")
88+
89+
set(CMAKE_CXX_STANDARD 17)
90+
91+
# Compilation option modification to prevent build termination caused by
92+
# warnings from CM-imported files
93+
if (MSVC)
94+
string(REPLACE "/W4" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
95+
else()
96+
string(REPLACE "-pedantic" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
97+
endif()
898

999
add_library(pi_esimd_cpu SHARED
10100
"${sycl_inc_dir}/CL/sycl/detail/pi.h"
@@ -31,16 +121,42 @@ else()
31121
)
32122
endif()
33123

124+
add_dependencies(pi_esimd_cpu OpenCL-Headers)
125+
add_dependencies(pi_esimd_cpu cm-emu)
34126
add_dependencies(sycl-toolchain pi_esimd_cpu)
35127

36-
add_dependencies(pi_esimd_cpu
37-
OpenCL-Headers)
38-
39-
target_link_libraries(pi_esimd_cpu PRIVATE sycl)
128+
target_link_libraries(pi_esimd_cpu PRIVATE sycl ${LIBCM} ${LIBIGFXCMRT_EMU})
40129
set_target_properties(pi_esimd_cpu PROPERTIES LINKER_LANGUAGE CXX)
41130

42131
add_common_options(pi_esimd_cpu)
43132

44133
install(TARGETS pi_esimd_cpu
45-
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}" COMPONENT pi_esimd_cpu
46-
RUNTIME DESTINATION "bin" COMPONENT pi_esimd_cpu)
134+
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}" COMPONENT pi_esimd_cpu
135+
RUNTIME DESTINATION "bin" COMPONENT pi_esimd_cpu)
136+
137+
# Copy CM Header files to $(INSTALL)/include/sycl/CL/
138+
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_install/include/libcm/cm/
139+
DESTINATION ${SYCL_INCLUDE_DIR}/CL
140+
COMPONENT libcmrt-headers
141+
FILES_MATCHING PATTERN "*.h"
142+
)
143+
144+
# Copy '.so' files to '$(INSTALL)/lib'
145+
if (MSVC)
146+
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_install/lib/
147+
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
148+
COMPONENT libcmrt-libs
149+
FILES_MATCHING PATTERN "*.lib"
150+
)
151+
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_install/bin/
152+
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
153+
COMPONENT libcmrt-dlls
154+
FILES_MATCHING PATTERN "*.dll"
155+
)
156+
else()
157+
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_install/lib/
158+
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
159+
COMPONENT libcmrt-sos
160+
FILES_MATCHING PATTERN "*.so"
161+
)
162+
endif()

0 commit comments

Comments
 (0)