Skip to content

Commit 777cd8e

Browse files
committed
Moved PI files to own folder
Removed SYCL detail includes for PI headers Removed SYCL dependencies from CMake Basic CMake setup for plugins Updated OpenCL in CMake Use higher level CMake Independent PIAPI static library Better package Moved headers to `pi` folder Made plugin class public Some clang-format Enable dynamic linking Basic testing Fixed up CUDA plugin CUDA clang-format Simpler CMake for OpenCL plugin Don't link test with plugin Fixed Windows plugin names Proper test dependency tracking Export `piPluginInit` Put all libraries in same folder Made the test more generic Align CMake requirements with LLVM Set up paths for the test Use `CUDA_CUDA_LIBRARY` Updated PI paths in SYCL Structured CMake file Generate basic config package Fixed reference capture bug Removed `piapiConfigVersion.cmake` Packaging improvements Fixed include headers for package Basic level0 plugin Removed SYCL context dependency `contextSetExtendedDeleter` is never used Use `PIAPI_EXPORT` Moved backends enum into `pi.hpp` Compilable `pi.cpp` Build level0 only when SYCL_BUILD_PI_LEVEL_ZERO Removed awkward symbol visibility setting Link threads Doesn't seem to be enough ... Replaced call_once with static initialization Always set CL_TARGET_OPENCL_VERSION Level 0 compiles CUDA plugin compiles Properly include PI Initial attempt at external project Removed extension header External project compiles Full OpenCL include piapi::piapi Basic includes in RT Fix checkPiResult CMake integration done Returned cude_definitions.hpp Set piapi library as a byproduct Moved GlobalPlugin into `plugin.hpp` PI wrapper headers Forward declare `pi::plugin` Include `pi_cuda` Enabled level0 in SYCL Typo fix Returned `__SYCL_EXPORT` Missed `pi.def` include Link `sycl-ls` with `piapi` library Use `pi::backend` Fixed doc headers Reverted some CUDA changes Reverted some namespace changes Moved `pi_sycl.hpp` to detail SYCL Link with CUDA Try __PI_EXPORT__ Missing pi_cuda.h include Reverted removed CUDA includes DPCPP_INTEGRATION Install into LLVM directory `PI_DPCPP_INTEGRATION` Removed PI ld-version-script Better level0 packaging get_link_library_path Level0 fully linked Documentation for get_library_path XPTI support PI configuration hooks Fix for test environment Better options for toggling plugins Bump PI version to 2.0 Use folders in IDEs Install plugins Moved piapi CMake into new file Use RPATH for test Rebase fix Windows fixes for CUDA plugin LLVM copyright header for PI test Use add_subdirectory for piapi
1 parent a4f0924 commit 777cd8e

File tree

103 files changed

+1285
-823
lines changed

Some content is hidden

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

103 files changed

+1285
-823
lines changed

sycl/CMakeLists.txt

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,43 @@ else()
121121
)
122122
endif()
123123

124+
if(MSVC)
125+
set(shared_library_dirname "bin")
126+
else()
127+
set(shared_library_dirname "lib${LLVM_LIBDIR_SUFFIX}")
128+
endif()
129+
130+
# Retrieves the name of the library
131+
# For example:
132+
# get_library_path(libname "OpenCL" "external" SHARED)
133+
# would likely produce (depending on the system):
134+
# set(libname "external/libOpenCL.so")
135+
function(get_library_path out name directory library_type)
136+
set(library_prefix "${CMAKE_${library_type}_LIBRARY_PREFIX}")
137+
set(library_suffix "${CMAKE_${library_type}_LIBRARY_SUFFIX}")
138+
if(NOT ("${directory}" STREQUAL ""))
139+
set(directory "${directory}/")
140+
endif()
141+
set(${out}
142+
"${directory}${library_prefix}${name}${library_suffix}" PARENT_SCOPE)
143+
endfunction()
144+
145+
# Retrieves the name of the library needed when linking
146+
# See get_library_path
147+
function(get_link_library_path out name directory)
148+
if(MSVC)
149+
get_library_path(tmp_out "${name}" "${directory}" STATIC)
150+
else()
151+
get_library_path(tmp_out "${name}" "${directory}" SHARED)
152+
endif()
153+
set(${out} "${tmp_out}" PARENT_SCOPE)
154+
endfunction()
155+
124156
if( NOT OpenCL_LIBRARIES )
125157
message(STATUS "OpenCL_LIBRARIES is missing. Will try to download OpenCL ICD Loader from github.com")
158+
get_link_library_path(OpenCL_LIBRARIES "OpenCL" "${LLVM_LIBRARY_OUTPUT_INTDIR}")
126159
if(MSVC)
127-
set(OpenCL_LIBRARIES
128-
"${LLVM_LIBRARY_OUTPUT_INTDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}OpenCL${CMAKE_STATIC_LIBRARY_SUFFIX}")
129160
list(APPEND AUX_CMAKE_FLAGS -DOPENCL_ICD_LOADER_REQUIRE_WDK=OFF)
130-
else()
131-
set(OpenCL_LIBRARIES
132-
"${LLVM_LIBRARY_OUTPUT_INTDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}OpenCL${CMAKE_SHARED_LIBRARY_SUFFIX}")
133161
endif()
134162
if (CMAKE_C_COMPILER)
135163
list(APPEND AUX_CMAKE_FLAGS -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER})
@@ -260,6 +288,9 @@ if (LLVM_ENABLE_ASSERTIONS AND NOT SYCL_DISABLE_STL_ASSERTIONS)
260288
endif()
261289
endif()
262290

291+
include(piapi.cmake)
292+
add_piapi_library()
293+
263294
set(SYCL_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
264295

265296
# SYCL runtime library
@@ -311,9 +342,6 @@ option(SYCL_INCLUDE_TESTS
311342
"Generate build targets for the SYCL unit tests."
312343
${LLVM_INCLUDE_TESTS})
313344

314-
# Plugin Library
315-
add_subdirectory( plugins )
316-
317345
add_subdirectory(tools)
318346

319347
if(SYCL_INCLUDE_TESTS)
@@ -362,6 +390,11 @@ if(SYCL_BUILD_PI_CUDA)
362390
"CUDA support requires adding \"libclc\" to the CMake argument \"LLVM_ENABLE_PROJECTS\"")
363391
endif()
364392

393+
find_package(CUDA 10.1 REQUIRED)
394+
395+
set_target_properties(pi_cuda PROPERTIES
396+
INTERFACE_LINK_LIBRARIES cudadrv
397+
)
365398
add_dependencies(sycl-toolchain libspirv-builtins pi_cuda)
366399
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS libspirv-builtins pi_cuda)
367400
endif()

sycl/cmake/modules/AddSYCLExecutable.cmake

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ macro(add_sycl_executable ARG_TARGET_NAME)
22
cmake_parse_arguments(ARG
33
""
44
""
5-
"OPTIONS;SOURCES;LIBRARIES;DEPENDANTS"
5+
"OPTIONS;SOURCES;LIBRARIES;STATIC_LIBS;DEPENDANTS"
66
${ARGN})
77

88
set(CXX_COMPILER clang++)
@@ -11,13 +11,24 @@ macro(add_sycl_executable ARG_TARGET_NAME)
1111
set(LIB_POSTFIX ".lib")
1212
else()
1313
set(LIB_PREFIX "-l")
14+
set(SPLIT_LINK_PATH ON)
1415
endif()
1516
set(DEVICE_COMPILER_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/${CXX_COMPILER})
1617

1718
# TODO add support for target_link_libraries(... PUBLIC ...)
1819
foreach(_lib ${ARG_LIBRARIES})
1920
list(APPEND LINKED_LIBS "${LIB_PREFIX}${_lib}${LIB_POSTFIX}")
2021
endforeach()
22+
foreach(_lib ${ARG_STATIC_LIBS})
23+
if(SPLIT_LINK_PATH)
24+
# Note this has to be added separately so that CMake doesn't get confused
25+
# by the space in between the two arguments
26+
list(APPEND LINKED_LIBS "-L$<TARGET_FILE_DIR:${_lib}>")
27+
list(APPEND LINKED_LIBS "-l:$<TARGET_FILE_NAME:${_lib}>")
28+
else()
29+
list(APPEND LINKED_LIBS $<TARGET_FILE:${_lib}>)
30+
endif()
31+
endforeach()
2132

2233
if (LLVM_ENABLE_ASSERTIONS AND NOT SYCL_DISABLE_STL_ASSERTIONS)
2334
if(SYCL_USE_LIBCXX)

sycl/cmake/modules/AddSYCLUnitTest.cmake

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,19 @@ macro(add_sycl_unittest_with_device test_dirname link_variant)
9090
endif()
9191

9292
if ("${link_variant}" MATCHES "OBJECT")
93+
# TODO piapi integration should be fixed,
94+
# replace it with target_link_libraries(${test_dirname} PRIVATE piapi::piapi)
95+
# once add_sycl_executable supports that
96+
set(pi_include_dir "${sycl_inc_dir}/../piapi/include")
9397
add_sycl_executable(${test_dirname}
94-
OPTIONS -nolibsycl ${COMMON_OPTS} ${LLVM_PTHREAD_LIB} ${TERMINFO_LIB}
98+
OPTIONS -nolibsycl ${COMMON_OPTS} ${LLVM_PTHREAD_LIB} ${TERMINFO_LIB} ${piapi_options} -I "${pi_include_dir}" -DPI_DPCPP_INTEGRATION
9599
SOURCES ${ARGN} $<TARGET_OBJECTS:${sycl_obj_target}>
96100
LIBRARIES gtest_main gtest LLVMSupport LLVMTestingSupport OpenCL ${EXTRA_LIBS}
101+
STATIC_LIBS piapi
97102
DEPENDANTS SYCLUnitTests)
103+
add_dependencies(${test_dirname}_exec piapi)
98104
else()
99105
# TODO support shared library case.
100106
endif()
107+
#target_link_libraries(${test_dirname}_exec PRIVATE piapi::piapi)
101108
endmacro()

sycl/doc/PluginInterface.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ SYCL_PI_TRACE=-1 lists all PI Traces above and more debug messages.
7272

7373
#### Plugin binary interface
7474
Plugins should implement all the Interface APIs required for the PI Version
75-
it supports. There is [pi.def](../include/CL/sycl/detail/pi.def)/
76-
[pi.h](../include/CL/sycl/detail/pi.h) file listing all PI API names that can be
75+
it supports. There is [pi.def](../piapi/include/pi/pi.def)/
76+
[pi.h](../piapi/include/pi/pi.h) file listing all PI API names that can be
7777
called by the specific version of Plugin Interface.
7878
It exports a function - "piPluginInit" that returns the plugin details and
7979
function pointer table containing the list of pointers to implemented Interface
@@ -136,7 +136,7 @@ into
136136
- **Interoperability API** which allows interoperability with underlying
137137
runtimes such as OpenCL.
138138

139-
See [pi.h](../include/CL/sycl/detail/pi.h) header for the full list and
139+
See [pi.h](../piapi/include/pi/pi.h) header for the full list and
140140
descriptions of PI APIs.
141141

142142
### The Core OpenCL-based PI APIs

sycl/include/CL/sycl/backend/cuda.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <CL/sycl/backend_types.hpp>
1414
#include <CL/sycl/context.hpp>
1515
#include <CL/sycl/detail/defines.hpp>
16+
#include <CL/sycl/detail/pi_sycl.hpp>
1617
#include <CL/sycl/device.hpp>
1718
#include <CL/sycl/event.hpp>
1819
#include <CL/sycl/queue.hpp>
@@ -58,4 +59,4 @@ struct interop<backend::cuda, accessor<DataT, Dimensions, AccessMode,
5859
};
5960

6061
} // namespace sycl
61-
} // namespace cl
62+
} // __SYCL_INLINE_NAMESPACE(cl)

sycl/include/CL/sycl/backend_types.hpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,14 @@
99
#pragma once
1010

1111
#include <CL/sycl/detail/defines.hpp>
12+
#include <CL/sycl/detail/pi_sycl.hpp>
1213

1314
#include <fstream>
1415
#include <iostream>
1516
#include <istream>
1617
#include <string>
1718

18-
__SYCL_INLINE_NAMESPACE(cl) {
19-
namespace sycl {
20-
21-
enum class backend : char { host, opencl, level_zero, cuda, all };
22-
23-
template <backend name, typename SYCLObjectT> struct interop;
24-
19+
namespace pi {
2520
inline std::ostream &operator<<(std::ostream &Out, backend be) {
2621
switch (be) {
2722
case backend::host:
@@ -41,6 +36,18 @@ inline std::ostream &operator<<(std::ostream &Out, backend be) {
4136
}
4237
return Out;
4338
}
39+
} // namespace pi
40+
41+
__SYCL_INLINE_NAMESPACE(cl) {
42+
namespace sycl {
43+
44+
using backend = pi::backend;
45+
46+
template <backend name, typename SYCLObjectT> struct interop;
47+
48+
inline std::ostream &operator<<(std::ostream &Out, backend be) {
49+
return pi::operator<<(Out, be);
50+
}
4451

4552
} // namespace sycl
4653
} // __SYCL_INLINE_NAMESPACE(cl)

sycl/include/CL/sycl/detail/common.hpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,26 @@
2020
#define __SYCL_STRINGIFY_LINE_HELP(s) #s
2121
#define __SYCL_STRINGIFY_LINE(s) __SYCL_STRINGIFY_LINE_HELP(s)
2222

23+
#ifdef XPTI_ENABLE_INSTRUMENTATION
24+
namespace pi {
25+
// We define a sycl stream name and this will be used by the instrumentation
26+
// framework
27+
extern const char *SYCL_STREAM_NAME;
28+
} // namespace pi
29+
#endif // XPTI_ENABLE_INSTRUMENTATION
30+
2331
// Default signature enables the passing of user code location information to
2432
// public methods as a default argument. If the end-user wants to disable the
2533
// code location information, they must compile the code with
2634
// -DDISABLE_SYCL_INSTRUMENTATION_METADATA flag
2735
__SYCL_INLINE_NAMESPACE(cl) {
2836
namespace sycl {
2937
namespace detail {
30-
// We define a sycl stream name and this will be used by the instrumentation
31-
// framework
32-
constexpr const char *SYCL_STREAM_NAME = "sycl";
33-
// Stream name being used for traces generated from the SYCL plugin layer
34-
constexpr const char *SYCL_PICALL_STREAM_NAME = "sycl.pi";
38+
39+
#ifdef XPTI_ENABLE_INSTRUMENTATION
40+
using pi::SYCL_STREAM_NAME;
41+
#endif // XPTI_ENABLE_INSTRUMENTATION
42+
3543
// Data structure that captures the user code location information using the
3644
// builtin capabilities of the compiler
3745
struct code_location {

sycl/include/CL/sycl/detail/device_binary_image.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#pragma once
99

1010
#include <CL/sycl/detail/os_util.hpp>
11-
#include <CL/sycl/detail/pi.hpp>
11+
#include <CL/sycl/detail/pi_sycl.hpp>
1212

1313
#include <memory>
1414

sycl/include/CL/sycl/detail/device_filter.hpp

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,16 @@
1111
#include <CL/sycl/backend_types.hpp>
1212
#include <CL/sycl/detail/defines.hpp>
1313
#include <CL/sycl/info/info_desc.hpp>
14+
#include <pi/device_filter.hpp>
1415

1516
#include <iostream>
1617
#include <string>
1718

18-
__SYCL_INLINE_NAMESPACE(cl) {
19-
namespace sycl {
20-
namespace detail {
21-
22-
struct device_filter {
23-
backend Backend = backend::all;
24-
info::device_type DeviceType = info::device_type::all;
25-
int DeviceNum = 0;
26-
bool HasBackend = false;
27-
bool HasDeviceType = false;
28-
bool HasDeviceNum = false;
29-
int MatchesSeen = 0;
30-
31-
device_filter(){};
32-
device_filter(const std::string &FilterString);
33-
friend std::ostream &operator<<(std::ostream &Out,
34-
const device_filter &Filter);
35-
};
36-
37-
class device_filter_list {
38-
std::vector<device_filter> FilterList;
39-
40-
public:
41-
device_filter_list() {}
42-
device_filter_list(const std::string &FilterString);
43-
device_filter_list(device_filter &Filter);
44-
void addFilter(device_filter &Filter);
45-
std::vector<device_filter> &get() { return FilterList; }
46-
friend std::ostream &operator<<(std::ostream &Out,
47-
const device_filter_list &List);
48-
};
19+
namespace pi {
4920

5021
inline std::ostream &operator<<(std::ostream &Out,
5122
const device_filter &Filter) {
23+
namespace info = cl::sycl::info;
5224
Out << Filter.Backend << ":";
5325
if (Filter.DeviceType == info::device_type::host) {
5426
Out << "host";
@@ -78,6 +50,15 @@ inline std::ostream &operator<<(std::ostream &Out,
7850
return Out;
7951
}
8052

53+
} // namespace pi
54+
55+
__SYCL_INLINE_NAMESPACE(cl) {
56+
namespace sycl {
57+
namespace detail {
58+
59+
using pi::device_filter;
60+
using pi::device_filter_list;
61+
8162
} // namespace detail
8263
} // namespace sycl
8364
} // __SYCL_INLINE_NAMESPACE(cl)

sycl/include/CL/sycl/detail/helpers.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <CL/sycl/access/access.hpp>
1414
#include <CL/sycl/detail/common.hpp>
1515
#include <CL/sycl/detail/export.hpp>
16-
#include <CL/sycl/detail/pi.hpp>
16+
#include <CL/sycl/detail/pi_sycl.hpp>
1717
#include <CL/sycl/detail/type_traits.hpp>
1818

1919
#if __cpp_lib_bit_cast
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//==---------------- pi_sycl.hpp - SYCL wrapper for PI ---------*- C++ -*---==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
// ===--------------------------------------------------------------------=== //
8+
9+
#pragma once
10+
11+
#include <CL/sycl/detail/defines.hpp>
12+
#include <pi/pi.hpp>
13+
14+
__SYCL_INLINE_NAMESPACE(cl) {
15+
namespace sycl {
16+
17+
namespace RT = ::pi;
18+
19+
namespace detail {
20+
21+
namespace RT = ::pi;
22+
using PiApiKind = ::PiApiKind;
23+
namespace pi {
24+
using namespace ::pi;
25+
}
26+
27+
} // namespace detail
28+
} // namespace sycl
29+
} // __SYCL_INLINE_NAMESPACE(cl)

sycl/include/CL/sycl/detail/sycl_mem_obj_i.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#pragma once
1010

11-
#include <CL/sycl/detail/pi.hpp>
11+
#include <CL/sycl/detail/pi_sycl.hpp>
1212
#include <CL/sycl/stl.hpp>
1313

1414
__SYCL_INLINE_NAMESPACE(cl) {

sycl/include/CL/sycl/detail/sycl_mem_obj_t.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@
2222
#include <cstring>
2323
#include <type_traits>
2424

25+
namespace pi {
26+
class plugin;
27+
}
28+
2529
__SYCL_INLINE_NAMESPACE(cl) {
2630
namespace sycl {
2731
namespace detail {
2832

2933
// Forward declarations
3034
class context_impl;
3135
class event_impl;
32-
class plugin;
3336

3437
using ContextImplPtr = shared_ptr_class<context_impl>;
3538
using EventImplPtr = shared_ptr_class<event_impl>;
@@ -86,7 +89,7 @@ class __SYCL_EXPORT SYCLMemObjT : public SYCLMemObjI {
8689

8790
virtual ~SYCLMemObjT() = default;
8891

89-
const plugin &getPlugin() const;
92+
const pi::plugin &getPlugin() const;
9093

9194
__SYCL_DLL_LOCAL size_t getSize() const override { return MSizeInBytes; }
9295
__SYCL_DLL_LOCAL size_t get_count() const {

0 commit comments

Comments
 (0)