Skip to content

Commit 1280554

Browse files
author
Alexander Batashev
authored
[SYCL] Only export public API (#1456)
To enable better control over ABI compatibility, only export functions that users are expected to use. A public API is the part of SYCL Runtime that is implemented in the dynamic Runtime library and is expected to be accessed by the user. That is all public SYCL API (as defined by the spec), implemented in *.cpp files and all routines accessed by these APIs (also implemented in *.cpp). Signed-off-by: Alexander Batashev <[email protected]>
1 parent 3c0a0f1 commit 1280554

Some content is hidden

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

72 files changed

+1214
-848
lines changed

sycl/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ project(sycl-solution)
55
set(CMAKE_CXX_STANDARD 11)
66
set(CMAKE_CXX_STANDARD_REQUIRED ON)
77
set(CMAKE_CXX_EXTENSIONS OFF)
8-
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
98
option(SYCL_ENABLE_WERROR "Treat all warnings as errors in SYCL project" OFF)
109

1110
# enable all warnings by default

sycl/include/CL/__spirv/spirv_ops.hpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#pragma once
1010
#include <CL/__spirv/spirv_types.hpp>
1111
#include <CL/sycl/detail/defines.hpp>
12+
#include <CL/sycl/detail/export.hpp>
1213
#include <cstddef>
1314
#include <cstdint>
1415
#include <type_traits>
@@ -256,16 +257,17 @@ OpGroupAsyncCopyLocalToGlobal(__spv::Scope::Flag Execution, dataT *Dest,
256257
return nullptr;
257258
}
258259

259-
extern void __spirv_ocl_prefetch(const char *Ptr, size_t NumBytes) noexcept;
260+
extern __SYCL_EXPORT void __spirv_ocl_prefetch(const char *Ptr,
261+
size_t NumBytes) noexcept;
260262

261-
__SYCL_CONVERGENT__ extern SYCL_EXTERNAL void
263+
__SYCL_CONVERGENT__ extern SYCL_EXTERNAL __SYCL_EXPORT void
262264
__spirv_ControlBarrier(__spv::Scope Execution, __spv::Scope Memory,
263265
uint32_t Semantics) noexcept;
264266

265-
__SYCL_CONVERGENT__ extern SYCL_EXTERNAL void
267+
__SYCL_CONVERGENT__ extern SYCL_EXTERNAL __SYCL_EXPORT void
266268
__spirv_MemoryBarrier(__spv::Scope Memory, uint32_t Semantics) noexcept;
267269

268-
__SYCL_CONVERGENT__ extern SYCL_EXTERNAL void
270+
__SYCL_CONVERGENT__ extern SYCL_EXTERNAL __SYCL_EXPORT void
269271
__spirv_GroupWaitEvents(__spv::Scope Execution, uint32_t NumEvents,
270272
__ocl_event_t *WaitEvents) noexcept;
271273

sycl/include/CL/sycl/context.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88

99
#pragma once
1010
#include <CL/sycl/detail/common.hpp>
11+
#include <CL/sycl/detail/export.hpp>
1112
#include <CL/sycl/exception_list.hpp>
1213
#include <CL/sycl/info/info_desc.hpp>
1314
#include <CL/sycl/stl.hpp>
15+
1416
#include <type_traits>
1517
// 4.6.2 Context class
1618

@@ -23,7 +25,7 @@ namespace detail {
2325
class context_impl;
2426
}
2527

26-
class context {
28+
class __SYCL_EXPORT context {
2729
public:
2830
/// Constructs a SYCL context instance using an instance of default_selector.
2931
///

sycl/include/CL/sycl/detail/accessor_impl.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#pragma once
1010

1111
#include <CL/sycl/access/access.hpp>
12+
#include <CL/sycl/detail/export.hpp>
1213
#include <CL/sycl/detail/sycl_mem_obj_i.hpp>
1314
#include <CL/sycl/id.hpp>
1415
#include <CL/sycl/range.hpp>
@@ -37,8 +38,7 @@ template <int Dims> class AccessorImplDevice {
3738
range<Dims> MemRange;
3839

3940
bool operator==(const AccessorImplDevice &Rhs) const {
40-
return (Offset == Rhs.Offset &&
41-
AccessRange == Rhs.AccessRange &&
41+
return (Offset == Rhs.Offset && AccessRange == Rhs.AccessRange &&
4242
MemRange == Rhs.MemRange);
4343
}
4444
};
@@ -59,7 +59,7 @@ template <int Dims> class LocalAccessorBaseDevice {
5959
}
6060
};
6161

62-
class AccessorImplHost {
62+
class __SYCL_EXPORT AccessorImplHost {
6363
public:
6464
AccessorImplHost(id<3> Offset, range<3> AccessRange, range<3> MemoryRange,
6565
access::mode AccessMode, detail::SYCLMemObjI *SYCLMemObject,
@@ -129,7 +129,7 @@ class AccessorBaseHost {
129129
AccessorImplPtr impl;
130130
};
131131

132-
class LocalAccessorImplHost {
132+
class __SYCL_EXPORT LocalAccessorImplHost {
133133
public:
134134
LocalAccessorImplHost(sycl::range<3> Size, int Dims, int ElemSize)
135135
: MSize(Size), MDims(Dims), MElemSize(ElemSize),
@@ -185,7 +185,7 @@ class LocalAccessorBaseHost {
185185

186186
using Requirement = AccessorImplHost;
187187

188-
void addHostAccessorAndWait(Requirement *Req);
188+
void __SYCL_EXPORT addHostAccessorAndWait(Requirement *Req);
189189

190190
} // namespace detail
191191
} // namespace sycl

sycl/include/CL/sycl/detail/buffer_impl.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <CL/sycl/access/access.hpp>
1313
#include <CL/sycl/context.hpp>
1414
#include <CL/sycl/detail/common.hpp>
15+
#include <CL/sycl/detail/export.hpp>
1516
#include <CL/sycl/detail/helpers.hpp>
1617
#include <CL/sycl/detail/sycl_mem_obj_t.hpp>
1718
#include <CL/sycl/handler.hpp>
@@ -38,7 +39,7 @@ using buffer_allocator = detail::sycl_memory_object_allocator;
3839

3940
namespace detail {
4041

41-
class buffer_impl final : public SYCLMemObjT {
42+
class __SYCL_EXPORT buffer_impl final : public SYCLMemObjT {
4243
using BaseT = SYCLMemObjT;
4344
using typename BaseT::MemObjType;
4445

@@ -104,7 +105,7 @@ class buffer_impl final : public SYCLMemObjT {
104105
std::move(Allocator)) {}
105106

106107
void *allocateMem(ContextImplPtr Context, bool InitFromUserData,
107-
void *HostPtr, RT::PiEvent &OutEventToWait) override;
108+
void *HostPtr, RT::PiEvent &OutEventToWait) override;
108109

109110
MemObjType getType() const override { return MemObjType::BUFFER; }
110111

sycl/include/CL/sycl/detail/cg.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <CL/sycl/detail/accessor_impl.hpp>
1212
#include <CL/sycl/detail/common.hpp>
13+
#include <CL/sycl/detail/export.hpp>
1314
#include <CL/sycl/detail/helpers.hpp>
1415
#include <CL/sycl/detail/host_profiling_info.hpp>
1516
#include <CL/sycl/detail/kernel_desc.hpp>
@@ -55,7 +56,7 @@ class interop_handler {
5556
private:
5657
cl_command_queue MQueue;
5758
std::vector<ReqToMem> MMemObjs;
58-
cl_mem getMemImpl(detail::Requirement* Req) const;
59+
__SYCL_EXPORT cl_mem getMemImpl(detail::Requirement *Req) const;
5960
};
6061

6162
namespace detail {

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#pragma once
1010

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

1314
// Suppress a compiler warning about undefined CL_TARGET_OPENCL_VERSION
1415
// Khronos ICD supports only latest OpenCL version
@@ -84,7 +85,7 @@ __SYCL_INLINE_NAMESPACE(cl) {
8485
namespace sycl {
8586
namespace detail {
8687

87-
const char *stringifyErrorCode(cl_int error);
88+
__SYCL_EXPORT const char *stringifyErrorCode(cl_int error);
8889

8990
static inline std::string codeToString(cl_int code) {
9091
return std::string(std::to_string(code) + " (" + stringifyErrorCode(code) +

sycl/include/CL/sycl/detail/common_info.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
//===----------------------------------------------------------------------===//
88

99
#pragma once
10+
#include <CL/sycl/detail/export.hpp>
1011
#include <CL/sycl/stl.hpp>
1112

1213
__SYCL_INLINE_NAMESPACE(cl) {
1314
namespace sycl {
1415
namespace detail {
1516

16-
vector_class<string_class> split_string(const string_class &str,
17-
char delimeter);
17+
vector_class<string_class> __SYCL_EXPORT split_string(const string_class &str,
18+
char delimeter);
1819

1920
} // namespace detail
2021
} // namespace sycl

sycl/include/CL/sycl/detail/defines.hpp

-8
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,3 @@
3131
#ifndef SYCL_EXTERNAL
3232
#define SYCL_EXTERNAL
3333
#endif
34-
35-
#if __cplusplus >= 201402
36-
#define __SYCL_DEPRECATED__(message) [[deprecated(message)]]
37-
#elif !defined _MSC_VER
38-
#define __SYCL_DEPRECATED__(message) __attribute__((deprecated(message)))
39-
#else
40-
#define __SYCL_DEPRECATED__(message)
41-
#endif
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//==---------------- export.hpp - SYCL standard header file ----------------==//
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+
#ifndef SYCL_DEVICE_ONLY
12+
#ifndef __SYCL_EXPORT
13+
#ifdef _WIN32
14+
15+
// MSVC discourages export of classes, that use STL class in API. This
16+
// results in a warning, treated as compile error. Silence C4251 to workaround.
17+
#pragma warning(disable : 4251)
18+
#pragma warning(disable : 4275)
19+
20+
#define DLL_LOCAL
21+
22+
#if __SYCL_BUILD_SYCL_DLL
23+
#define __SYCL_EXPORT __declspec(dllexport)
24+
#define __SYCL_EXPORT_DEPRECATED(x) __declspec(dllexport, deprecated(x))
25+
#else
26+
#define __SYCL_EXPORT __declspec(dllimport)
27+
#define __SYCL_EXPORT_DEPRECATED(x) __declspec(dllimport, deprecated(x))
28+
#endif
29+
#else
30+
31+
#define DLL_LOCAL __attribute__((visibility("hidden")))
32+
33+
#define __SYCL_EXPORT __attribute__((visibility("default")))
34+
#define __SYCL_EXPORT_DEPRECATED(x) \
35+
__attribute__((visibility("default"), deprecated(x)))
36+
#endif
37+
#endif
38+
#endif

sycl/include/CL/sycl/detail/generic_type_traits.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -604,8 +604,7 @@ class is_same_vector_size_impl<FirstSize, T, Args...> {
604604

605605
public:
606606
static constexpr bool value =
607-
IsSizeEqual ? is_same_vector_size_impl<FirstSize, Args...>::value
608-
: false;
607+
IsSizeEqual ? is_same_vector_size_impl<FirstSize, Args...>::value : false;
609608
};
610609

611610
template <int FirstSize>

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <CL/__spirv/spirv_vars.hpp>
1313
#include <CL/sycl/access/access.hpp>
1414
#include <CL/sycl/detail/common.hpp>
15+
#include <CL/sycl/detail/export.hpp>
1516
#include <CL/sycl/detail/pi.hpp>
1617
#include <CL/sycl/detail/type_traits.hpp>
1718

@@ -44,11 +45,11 @@ inline void memcpy(void *Dst, const void *Src, size_t Size) {
4445
class context_impl;
4546
// The function returns list of events that can be passed to OpenCL API as
4647
// dependency list and waits for others.
47-
std::vector<RT::PiEvent>
48+
__SYCL_EXPORT std::vector<RT::PiEvent>
4849
getOrWaitEvents(std::vector<cl::sycl::event> DepEvents,
4950
std::shared_ptr<cl::sycl::detail::context_impl> Context);
5051

51-
void waitEvents(std::vector<cl::sycl::event> DepEvents);
52+
__SYCL_EXPORT void waitEvents(std::vector<cl::sycl::event> DepEvents);
5253

5354
class Builder {
5455
public:

sycl/include/CL/sycl/detail/host_profiling_info.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
#pragma once
1010

1111
#include <CL/sycl/detail/common.hpp>
12+
#include <CL/sycl/detail/export.hpp>
1213

1314
__SYCL_INLINE_NAMESPACE(cl) {
1415
namespace sycl {
1516
namespace detail {
1617

1718
/// Profiling info for the host execution.
18-
class HostProfilingInfo {
19+
class __SYCL_EXPORT HostProfilingInfo {
1920
cl_ulong StartTime = 0;
2021
cl_ulong EndTime = 0;
2122

sycl/include/CL/sycl/detail/image_accessor_util.hpp

+12-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#ifndef __SYCL_DEVICE_ONLY__
1515
#include <CL/sycl/builtins.hpp>
16+
#include <CL/sycl/detail/export.hpp>
1617
#include <CL/sycl/detail/generic_type_traits.hpp>
1718
#include <CL/sycl/image.hpp>
1819
#include <CL/sycl/sampler.hpp>
@@ -99,21 +100,25 @@ getImageOffset(const vec<T, 4> &Coords, const id<3> ImgPitch,
99100

100101
// Process cl_float4 Coordinates and return the appropriate Pixel Coordinates to
101102
// read from based on Addressing Mode for Nearest filter mode.
102-
cl_int4 getPixelCoordNearestFiltMode(cl_float4, const addressing_mode,
103-
const range<3>);
103+
__SYCL_EXPORT cl_int4 getPixelCoordNearestFiltMode(cl_float4,
104+
const addressing_mode,
105+
const range<3>);
104106

105107
// Process cl_float4 Coordinates and return the appropriate Pixel Coordinates to
106108
// read from based on Addressing Mode for Linear filter mode.
107-
cl_int8 getPixelCoordLinearFiltMode(cl_float4, const addressing_mode,
108-
const range<3>, cl_float4 &);
109+
__SYCL_EXPORT cl_int8 getPixelCoordLinearFiltMode(cl_float4,
110+
const addressing_mode,
111+
const range<3>, cl_float4 &);
109112

110113
// Check if PixelCoord are out of range for Sampler with clamp adressing mode.
111-
bool isOutOfRange(const cl_int4 PixelCoord, const addressing_mode SmplAddrMode,
112-
const range<3> ImgRange);
114+
__SYCL_EXPORT bool isOutOfRange(const cl_int4 PixelCoord,
115+
const addressing_mode SmplAddrMode,
116+
const range<3> ImgRange);
113117

114118
// Get Border Color for the image_channel_order, the border color values are
115119
// only used when the sampler has clamp addressing mode.
116-
cl_float4 getBorderColor(const image_channel_order ImgChannelOrder);
120+
__SYCL_EXPORT cl_float4
121+
getBorderColor(const image_channel_order ImgChannelOrder);
117122

118123
// Reads data from a pixel at Ptr location, based on the number of Channels in
119124
// Order and returns the data.

sycl/include/CL/sycl/detail/image_impl.hpp

+14-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <CL/sycl/detail/aligned_allocator.hpp>
1212
#include <CL/sycl/detail/common.hpp>
13+
#include <CL/sycl/detail/export.hpp>
1314
#include <CL/sycl/detail/generic_type_traits.hpp>
1415
#include <CL/sycl/detail/sycl_mem_obj_t.hpp>
1516
#include <CL/sycl/device.hpp>
@@ -37,18 +38,23 @@ namespace detail {
3738
using image_allocator = aligned_allocator<byte>;
3839

3940
// utility function: Returns the Number of Channels for a given Order.
40-
uint8_t getImageNumberChannels(image_channel_order Order);
41+
__SYCL_EXPORT uint8_t getImageNumberChannels(image_channel_order Order);
4142

4243
// utility function: Returns the number of bytes per image element
43-
uint8_t getImageElementSize(uint8_t NumChannels, image_channel_type Type);
44+
__SYCL_EXPORT uint8_t getImageElementSize(uint8_t NumChannels,
45+
image_channel_type Type);
4446

45-
RT::PiMemImageChannelOrder convertChannelOrder(image_channel_order Order);
47+
__SYCL_EXPORT RT::PiMemImageChannelOrder
48+
convertChannelOrder(image_channel_order Order);
4649

47-
image_channel_order convertChannelOrder(RT::PiMemImageChannelOrder Order);
50+
__SYCL_EXPORT image_channel_order
51+
convertChannelOrder(RT::PiMemImageChannelOrder Order);
4852

49-
RT::PiMemImageChannelType convertChannelType(image_channel_type Type);
53+
__SYCL_EXPORT RT::PiMemImageChannelType
54+
convertChannelType(image_channel_type Type);
5055

51-
image_channel_type convertChannelType(RT::PiMemImageChannelType Type);
56+
__SYCL_EXPORT image_channel_type
57+
convertChannelType(RT::PiMemImageChannelType Type);
5258

5359
// validImageDataT: cl_int4, cl_uint4, cl_float4, cl_half4
5460
template <typename T>
@@ -59,7 +65,8 @@ template <typename DataT>
5965
using EnableIfImgAccDataT =
6066
typename std::enable_if<is_validImageDataT<DataT>::value, DataT>::type;
6167

62-
template <int Dimensions> class image_impl final : public SYCLMemObjT {
68+
template <int Dimensions>
69+
class __SYCL_EXPORT image_impl final : public SYCLMemObjT {
6370
using BaseT = SYCLMemObjT;
6471
using typename BaseT::MemObjType;
6572

sycl/include/CL/sycl/detail/kernel_desc.hpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
#pragma once
1010

1111
#include <CL/sycl/access/access.hpp>
12-
#include <CL/sycl/detail/os_util.hpp> // for DLL_LOCAL used in int. header
12+
#include <CL/sycl/detail/defines.hpp>
13+
#include <CL/sycl/detail/export.hpp> // for DLL_LOCAL used in int. header
14+
15+
#include <cstddef>
1316

1417
__SYCL_INLINE_NAMESPACE(cl) {
1518
namespace sycl {

0 commit comments

Comments
 (0)