Skip to content

[SYCL][ESIMD][EMU] pi_esimd_cpu bringing up with CM library (2nd) #4430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions buildbot/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def do_configure(args):
libclc_targets_to_build = ''
libclc_gen_remangled_variants = 'OFF'
sycl_build_pi_cuda = 'OFF'
sycl_build_pi_esimd_cpu = 'ON'
sycl_build_pi_esimd_cpu = 'OFF'
sycl_build_pi_rocm = 'OFF'
sycl_build_pi_rocm_platform = 'AMD'
sycl_werror = 'ON'
Expand All @@ -45,8 +45,8 @@ def do_configure(args):
if args.arm:
llvm_targets_to_build = 'ARM;AArch64'

if args.disable_esimd_cpu:
sycl_build_pi_esimd_cpu = 'OFF'
if args.enable_esimd_cpu_emulation:
sycl_build_pi_esimd_cpu = 'ON'

if args.cuda or args.rocm:
llvm_enable_projects += ';libclc'
Expand Down Expand Up @@ -181,7 +181,7 @@ def main():
parser.add_argument("--rocm", action='store_true', help="switch from OpenCL to ROCm")
parser.add_argument("--rocm-platform", type=str, choices=['AMD', 'NVIDIA'], default='AMD', help="choose ROCm backend")
parser.add_argument("--arm", action='store_true', help="build ARM support rather than x86")
parser.add_argument("--disable-esimd-cpu", action='store_true', help="build without ESIMD_CPU support")
parser.add_argument("--enable-esimd-cpu-emulation", action='store_true', help="build with ESIMD_CPU emulation support")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it rather be

Suggested change
parser.add_argument("--enable-esimd-cpu-emulation", action='store_true', help="build with ESIMD_CPU emulation support")
parser.add_argument("--enable-esimd-cpu-emulation", action='store_false', help="build with ESIMD_CPU emulation support")

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know, store_true means 'True' will be applied to 'enable-esimd-cpu-emulation' member variable with --enable-esimd-cpu-emuation. store_false means 'False' for the variable. This is same for other plugins that are enabled with similar command line option like CUDA - Line 180.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

store_true will set the variable to true when the option is available, otherwise it will remain default (BTW, default=False might be needed). Isn't that the intent?

Copy link
Contributor Author

@dongkyunahn-intel dongkyunahn-intel Aug 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I verified that current code works as the intent.

  • Without --enable-esimd-cpu-emulation command line argument, libpi_esimd_cpu.so is not generated
  • With the command line argument, libpi_esimd_cpu.so is generated

The store_true option automatically creates a default value of False. - https://stackoverflow.com/questions/8203622/argparse-store-false-if-unspecified

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

parser.add_argument("--no-assertions", action='store_true', help="build without assertions")
parser.add_argument("--docs", action='store_true', help="build Doxygen documentation")
parser.add_argument("--no-werror", action='store_true', help="Don't treat warnings as errors")
Expand Down
14 changes: 13 additions & 1 deletion sycl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ set( SYCL_TOOLCHAIN_DEPLOY_COMPONENTS
sycl
pi_opencl
pi_level_zero
pi_esimd_cpu
libsycldevice
${XPTIFW_LIBS}
)
Expand Down Expand Up @@ -292,6 +291,19 @@ if(SYCL_BUILD_PI_ROCM)
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS libspirv-builtins pi_rocm)
endif()

# TODO : Remove 'if (NOT MSVC)' when CM_EMU supports Windows
# environment
if (NOT MSVC)
if (SYCL_BUILD_PI_ESIMD_CPU)
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS pi_esimd_cpu libcmrt-headers)
if (MSVC)
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS libcmrt-libs libcmrt-dlls)
else()
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS libcmrt-sos)
endif()
endif()
endif()

# Use it as fake dependency in order to force another command(s) to execute.
add_custom_command(OUTPUT __force_it
COMMAND "${CMAKE_COMMAND}" -E echo
Expand Down
44 changes: 44 additions & 0 deletions sycl/doc/GetStartedGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and a wide range of compute accelerators such as GPU and FPGA.
- [Build DPC++ toolchain with support for NVIDIA CUDA](#build-dpc-toolchain-with-support-for-nvidia-cuda)
- [Build DPC++ toolchain with support for AMD ROCm](#build-dpc-toolchain-with-support-for-amd-rocm)
- [Build DPC++ toolchain with support for NVIDIA ROCm](#build-dpc-toolchain-with-support-for-nvidia-rocm)
- [Build DPC++ toolchain with support for ESIMD CPU Emulation](#build-dpc-toolchain-with-support-for-esimd-cpu)
- [Build Doxygen documentation](#build-doxygen-documentation)
- [Deployment](#deployment)
- [Use DPC++ toolchain](#use-dpc-toolchain)
Expand Down Expand Up @@ -109,6 +110,7 @@ flags can be found by launching the script with `--help`):
* `--cuda` -> use the cuda backend (see [Nvidia CUDA](#build-dpc-toolchain-with-support-for-nvidia-cuda))
* `--rocm` -> use the rocm backend (see [AMD ROCm](#build-dpc-toolchain-with-support-for-amd-rocm))
* `--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))
* '--enable-esimd-cpu-emulation' -> enable ESIMD CPU emulation (see [ESIMD CPU emulation](#build-dpc-toolchain-with-support-for-esimd-cpu))
* `--shared-libs` -> Build shared libraries
* `-t` -> Build type (debug or release)
* `-o` -> Path to build directory
Expand Down Expand Up @@ -206,6 +208,48 @@ as well as CUDA to be installed, see
Currently this was only tested on Linux with ROCm 4.2, CUDA 11 and a GeForce GTX
1060 card.

### Build DPC++ toolchain with support for ESIMD CPU Emulation

There is experimental support for DPC++ for using ESIMD CPU Emulation

This feature supports ESIMD CPU Emulation using CM_EMU library [CM
Emulation
project](https://github.com/intel/cm-cpu-emulation). Pre-built library
package will be downloaded and installed in your deploy directory
during toolchain build.

To enable support for ESIMD CPU emulation, follow the instructions for
the Linux DPC++ toolchain, but add the `--enable-esimd-cpu-emulation'.

Enabling this flag requires following packages installed.

* Ubuntu 20.04
* libva-dev / 2.7.0-2
* libva-drm2 / 2.7.0-2
* libva-glx2 / 2.7.0-2
* libva-wayland2 / 2.7.0-2
* libva-x11-2 / 2.7.0-2
* libva2 / focal 2.7.0-2
* libffi-dev / 3.3-4
* libffi7 / 3.3-4
* libdrm-amdgpu1
* libdrm-common
* libdrm-dev
* libdrm-intel1
* libdrm-nouveau2
* libdrm-radeon1
* libdrm2
* RHEL 8.*
* libffi
* libffi-devel
* libdrm
* libdrm-devel
* libva
* libva-devel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be good to specify which of those are needed to run emulation. I suppose *dev are not needed?


Currently, this feature was tested and verified on Ubuntu 20.04
environment.

### Build Doxygen documentation

Building Doxygen documentation is similar to building the product itself. First,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ void (*cm_fence_ptr)(void);
char *(*sycl_get_surface_base_addr_ptr)(int);
char *(*__cm_emu_get_slm_ptr)(void);
void (*cm_slm_init_ptr)(size_t);
void (*sycl_get_cm_buffer_params_ptr)(void *, char **, uint32_t *,
std::mutex **);
void (*sycl_get_cm_image_params_ptr)(void *, char **, uint32_t *, uint32_t *,
uint32_t *, std::mutex **);
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
// pointer table file ('esimd_emu_functions_v1.h') included in 'struct
// ESIMDDeviceInterface' definition.
#include <cstdint>
#include <mutex>

__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {
Expand Down
8 changes: 6 additions & 2 deletions sycl/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ endif()
add_subdirectory(opencl)
add_subdirectory(level_zero)

if (SYCL_BUILD_PI_ESIMD_CPU)
add_subdirectory(esimd_cpu)
# TODO : Remove 'if (NOT MSVC)' when CM_EMU supports Windows
# environment
if (NOT MSVC)
if (SYCL_BUILD_PI_ESIMD_CPU)
add_subdirectory(esimd_cpu)
endif()
endif()
130 changes: 123 additions & 7 deletions sycl/plugins/esimd_cpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,99 @@
# PI Esimd CPU library
# Create Shared library for libpi_esimd_cpu.so.

include(ExternalProject)

include_directories("${sycl_inc_dir}")
# FIXME/TODO: 'pi.h' is included in 'pi_esimd_cpu.cpp', and CL_*_INTEL
# and CL_*_KHR definitions in 'pi.h' are from
# ${OPENCL_INCLUDE}. Remove build dependency on OpenCL
include_directories(${OpenCL_INCLUDE_DIR})
include_directories(${LIBCMRT_INCLUDE})

file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_build)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_install)

if (MSVC)
set(LIBCM ${LLVM_BINARY_DIR}/pi_esimd_cpu_deps/lib/libcm${CMAKE_STATIC_LIBRARY_SUFFIX})
set(LIBIGFXCMRT_EMU ${LLVM_BINARY_DIR}/pi_esimd_cpu_deps/lib/igfxcmrt64_emu${CMAKE_STATIC_LIBRARY_SUFFIX})
else()
set(LIBCM ${LLVM_BINARY_DIR}/pi_esimd_cpu_deps/lib/libcm${CMAKE_SHARED_LIBRARY_SUFFIX})
set(LIBIGFXCMRT_EMU ${LLVM_BINARY_DIR}/pi_esimd_cpu_deps/lib/libigfxcmrt_emu${CMAKE_SHARED_LIBRARY_SUFFIX})
endif()

if (DEFINED CM_LOCAL_SOURCE_DIR)
# Using local CM directory for online building without downloading
if (MSVC)
ExternalProject_Add(cm-emu
DOWNLOAD_COMMAND ""
SOURCE_DIR ${CM_LOCAL_SOURCE_DIR}
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_build
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_install
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
BUILD_BYPRODUCTS ${LIBCM} ${LIBIGFXCMRT_EMU}
)
else()
ExternalProject_Add(cm-emu
DOWNLOAD_COMMAND ""
SOURCE_DIR ${CM_LOCAL_SOURCE_DIR}
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_build
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_install
CMAKE_ARGS -DLIBVA_INSTALL_PATH=/usr
-D__SYCL_EXPLICIT_SIMD_PLUGIN__=true
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
BUILD_BYPRODUCTS ${LIBCM} ${LIBIGFXCMRT_EMU}
)
endif()
else ()
if (DEFINED CM_PACKAGE_URL)
# Downloading pre-built CM Package
file (MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_install)
ExternalProject_Add(cm-emu
URL ${CM_PACKAGE_URL}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
UPDATE_COMMAND ""
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_install
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/cm-emu-prefix/src/cm-emu/ <INSTALL_DIR>
BUILD_BYPRODUCTS ${LIBCM} ${LIBIGFXCMRT_EMU}
)
else()
# Build from CM source tree fetched from github
if (MSVC)
message(FATAL_ERROR "Online-building of CM_EMU library is not supported under Windows environment")
else()
ExternalProject_Add(cm-emu
GIT_REPOSITORY https://github.com/intel/cm-cpu-emulation.git
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_build
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_install
CMAKE_ARGS -DLIBVA_INSTALL_PATH=/usr
-D__SYCL_EXPLICIT_SIMD_PLUGIN__=true
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
BUILD_BYPRODUCTS ${LIBCM} ${LIBIGFXCMRT_EMU}
)
endif()
endif()
endif ()
ExternalProject_Add_Step(cm-emu llvminstall
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
COMMENT "Installing cm-emu into the LLVM binary directory"
DEPENDEES install
)

include_directories(${LLVM_BINARY_DIR}/pi_esimd_cpu_deps/include/igfxcmrt_emu)
include_directories(${LLVM_BINARY_DIR}/pi_esimd_cpu_deps/include/libcm/cm)

# Compilation flag to exclude lines in header files imported from CM
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__SYCL_EXPLICIT_SIMD_PLUGIN__")

set(CMAKE_CXX_STANDARD 17)

# Compilation option modification to prevent build termination caused by
# warnings from CM-imported files
if (MSVC)
string(REPLACE "/W4" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
string(REPLACE "-pedantic" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif()

add_library(pi_esimd_cpu SHARED
"${sycl_inc_dir}/CL/sycl/detail/pi.h"
Expand All @@ -31,16 +121,42 @@ else()
)
endif()

add_dependencies(pi_esimd_cpu OpenCL-Headers)
add_dependencies(pi_esimd_cpu cm-emu)
add_dependencies(sycl-toolchain pi_esimd_cpu)

add_dependencies(pi_esimd_cpu
OpenCL-Headers)

target_link_libraries(pi_esimd_cpu PRIVATE sycl)
target_link_libraries(pi_esimd_cpu PRIVATE sycl ${LIBCM} ${LIBIGFXCMRT_EMU})
set_target_properties(pi_esimd_cpu PROPERTIES LINKER_LANGUAGE CXX)

add_common_options(pi_esimd_cpu)

install(TARGETS pi_esimd_cpu
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}" COMPONENT pi_esimd_cpu
RUNTIME DESTINATION "bin" COMPONENT pi_esimd_cpu)
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}" COMPONENT pi_esimd_cpu
RUNTIME DESTINATION "bin" COMPONENT pi_esimd_cpu)

# Copy CM Header files to $(INSTALL)/include/sycl/CL/
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_install/include/libcm/cm/
DESTINATION ${SYCL_INCLUDE_DIR}/CL
COMPONENT libcmrt-headers
FILES_MATCHING PATTERN "*.h"
)

# Copy '.so' files to '$(INSTALL)/lib'
if (MSVC)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_install/lib/
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
COMPONENT libcmrt-libs
FILES_MATCHING PATTERN "*.lib"
)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_install/bin/
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
COMPONENT libcmrt-dlls
FILES_MATCHING PATTERN "*.dll"
)
else()
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cm-emu_install/lib/
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
COMPONENT libcmrt-sos
FILES_MATCHING PATTERN "*.so"
)
endif()
Loading