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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 6 additions & 4 deletions
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 0 additions & 8 deletions
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
Lines changed: 38 additions & 0 deletions
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

0 commit comments

Comments
 (0)