Skip to content

Commit 84e0657

Browse files
author
Alexander Batashev
authored
[SYCL] Move internal headers to source dir (#1136)
Move internal headers from include/CL/sycl to source directory to prevent implementation details leak to user application and enforce stable ABI. A few more changes were applied to make the movement possible: - addHostAccessorAndWait functions in accessor to avoid calls to RT internals from header file - Removed getImageInfo - Move buffer size acquisition from buffer constructor to SYCLMemObjT cpp to avoid calls to PI - getPluginFromContext function in context - Standard containers replaced with SYCL variants in sycl_mem_obj_i.hpp. Unique ptr replaced with shared - A few implementations moved from queue.hpp to queue.cpp - Some LIT tests temporarily include implementaion specific headers. They will be converted to unit tests later. Signed-off-by: Alexander Batashev <[email protected]>
1 parent 7743e86 commit 84e0657

File tree

96 files changed

+422
-362
lines changed

Some content is hidden

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

96 files changed

+422
-362
lines changed

sycl/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ function( add_common_options LIB_NAME)
185185
endif()
186186
endfunction(add_common_options)
187187

188+
set(SYCL_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
189+
188190
# SYCL runtime library
189191
add_subdirectory( source )
190192

sycl/include/CL/sycl/accessor.hpp

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <CL/sycl/detail/generic_type_traits.hpp>
1717
#include <CL/sycl/detail/image_accessor_util.hpp>
1818
#include <CL/sycl/detail/image_ocl_types.hpp>
19-
#include <CL/sycl/detail/queue_impl.hpp>
2019
#include <CL/sycl/exception.hpp>
2120
#include <CL/sycl/handler.hpp>
2221
#include <CL/sycl/id.hpp>
@@ -167,6 +166,8 @@ static T<NewDim> convertToArrayOfN(T<OldDim> OldObj) {
167166
return NewObj;
168167
}
169168

169+
device getDeviceFromHandler(handler &CommandGroupHandlerRef);
170+
170171
template <typename DataT, int Dimensions, access::mode AccessMode,
171172
access::target AccessTarget, access::placeholder IsPlaceholder>
172173
class accessor_common {
@@ -397,10 +398,7 @@ class image_accessor
397398
MImageCount(ImageRef.get_count()),
398399
MImgChannelOrder(detail::getSyclObjImpl(ImageRef)->getChannelOrder()),
399400
MImgChannelType(detail::getSyclObjImpl(ImageRef)->getChannelType()) {
400-
detail::EventImplPtr Event =
401-
detail::Scheduler::getInstance().addHostAccessor(
402-
AccessorBaseHost::impl.get());
403-
Event->wait(Event);
401+
addHostAccessorAndWait(AccessorBaseHost::impl.get());
404402
}
405403
#endif
406404

@@ -429,7 +427,7 @@ class image_accessor
429427
MImgChannelOrder(detail::getSyclObjImpl(ImageRef)->getChannelOrder()),
430428
MImgChannelType(detail::getSyclObjImpl(ImageRef)->getChannelType()) {
431429
checkDeviceFeatureSupported<info::device::image_support>(
432-
CommandGroupHandlerRef.MQueue->get_device());
430+
getDeviceFromHandler(CommandGroupHandlerRef));
433431
}
434432
#endif
435433

@@ -770,12 +768,8 @@ class accessor :
770768
detail::convertToArrayOfN<3, 1>(BufferRef.get_range()), AccessMode,
771769
detail::getSyclObjImpl(BufferRef).get(), AdjustedDim, sizeof(DataT),
772770
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer) {
773-
if (!IsPlaceH) {
774-
detail::EventImplPtr Event =
775-
detail::Scheduler::getInstance().addHostAccessor(
776-
AccessorBaseHost::impl.get());
777-
Event->wait(Event);
778-
}
771+
if (!IsPlaceH)
772+
addHostAccessorAndWait(AccessorBaseHost::impl.get());
779773
#endif
780774
}
781775

@@ -814,12 +808,8 @@ class accessor :
814808
detail::convertToArrayOfN<3, 1>(BufferRef.get_range()), AccessMode,
815809
detail::getSyclObjImpl(BufferRef).get(), Dimensions, sizeof(DataT),
816810
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer) {
817-
if (!IsPlaceH) {
818-
detail::EventImplPtr Event =
819-
detail::Scheduler::getInstance().addHostAccessor(
820-
AccessorBaseHost::impl.get());
821-
Event->wait(Event);
822-
}
811+
if (!IsPlaceH)
812+
addHostAccessorAndWait(AccessorBaseHost::impl.get());
823813
}
824814
#endif
825815

@@ -858,12 +848,8 @@ class accessor :
858848
AccessMode, detail::getSyclObjImpl(BufferRef).get(),
859849
Dimensions, sizeof(DataT), BufferRef.OffsetInBytes,
860850
BufferRef.IsSubBuffer) {
861-
if (!IsPlaceH) {
862-
detail::EventImplPtr Event =
863-
detail::Scheduler::getInstance().addHostAccessor(
864-
AccessorBaseHost::impl.get());
865-
Event->wait(Event);
866-
}
851+
if (!IsPlaceH)
852+
addHostAccessorAndWait(AccessorBaseHost::impl.get());
867853
}
868854
#endif
869855

sycl/include/CL/sycl/buffer.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,8 @@ class buffer {
194194
event AvailableEvent = {})
195195
: Range{0} {
196196

197-
size_t BufSize = 0;
198-
const detail::plugin &Plugin = detail::getSyclObjImpl(SyclContext)->getPlugin();
199-
Plugin.call<detail::PiApiKind::piMemGetInfo>(
200-
detail::pi::cast<detail::RT::PiMem>(MemObject), CL_MEM_SIZE,
201-
sizeof(size_t), &BufSize, nullptr);
197+
size_t BufSize = detail::SYCLMemObjT::getBufSizeForContext(
198+
detail::getSyclObjImpl(SyclContext), MemObject);
202199

203200
Range[0] = BufSize / sizeof(T);
204201
impl = std::make_shared<detail::buffer_impl>(

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ class LocalAccessorBaseHost {
185185

186186
using Requirement = AccessorImplHost;
187187

188+
void addHostAccessorAndWait(Requirement *Req);
189+
188190
} // namespace detail
189191
} // namespace sycl
190192
} // __SYCL_INLINE_NAMESPACE(cl)

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,6 @@ template <int Dimensions> class image_impl final : public SYCLMemObjT {
219219
~image_impl() { BaseT::updateHostMemory(); }
220220

221221
private:
222-
template <typename T>
223-
void getImageInfo(const ContextImplPtr Context, RT::PiMemImageInfo Info,
224-
T &Dest) {
225-
const detail::plugin &Plugin = Context->getPlugin();
226-
RT::PiMem Mem = pi::cast<RT::PiMem>(BaseT::MInteropMemObject);
227-
Plugin.call<PiApiKind::piMemImageGetInfo>(Mem, Info, sizeof(T), &Dest,
228-
nullptr);
229-
}
230-
231222
vector_class<device> getDevices(const ContextImplPtr Context);
232223

233224
template <info::device Param>

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

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

1111
#include <CL/sycl/detail/pi.hpp>
12-
#include <memory>
12+
#include <CL/sycl/stl.hpp>
1313

1414
__SYCL_INLINE_NAMESPACE(cl) {
1515
namespace sycl {
@@ -20,8 +20,8 @@ class event_impl;
2020
class context_impl;
2121
struct MemObjRecord;
2222

23-
using EventImplPtr = std::shared_ptr<detail::event_impl>;
24-
using ContextImplPtr = std::shared_ptr<detail::context_impl>;
23+
using EventImplPtr = shared_ptr_class<detail::event_impl>;
24+
using ContextImplPtr = shared_ptr_class<detail::context_impl>;
2525

2626
// The class serves as an interface in the scheduler for all SYCL memory
2727
// objects.
@@ -64,7 +64,10 @@ class SYCLMemObjI {
6464
protected:
6565
// Pointer to the record that contains the memory commands. This is managed
6666
// by the scheduler.
67-
std::unique_ptr<MemObjRecord> MRecord;
67+
// fixme replace with unique_ptr_class once it is implemented. Standard
68+
// unique_ptr requires knowlege of sizeof(MemObjRecord) at compile time
69+
// which is unavailable.
70+
shared_ptr_class<MemObjRecord> MRecord;
6871
friend class Scheduler;
6972
};
7073

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

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

1111
#include <CL/sycl/detail/common.hpp>
12-
#include <CL/sycl/detail/context_impl.hpp>
1312
#include <CL/sycl/detail/sycl_mem_obj_allocator.hpp>
14-
#include <CL/sycl/detail/plugin.hpp>
1513
#include <CL/sycl/detail/sycl_mem_obj_i.hpp>
1614
#include <CL/sycl/detail/type_traits.hpp>
1715
#include <CL/sycl/event.hpp>
@@ -26,7 +24,9 @@ namespace sycl {
2624
namespace detail {
2725

2826
// Forward declarations
27+
class context_impl;
2928
class event_impl;
29+
class plugin;
3030

3131
using ContextImplPtr = shared_ptr_class<context_impl>;
3232
using EventImplPtr = shared_ptr_class<event_impl>;
@@ -83,11 +83,8 @@ class SYCLMemObjT : public SYCLMemObjI {
8383

8484
virtual ~SYCLMemObjT() = default;
8585

86-
const plugin &getPlugin() const {
87-
assert((MInteropContext != nullptr) &&
88-
"Trying to get Plugin from SYCLMemObjT with nullptr ContextImpl.");
89-
return (MInteropContext->getPlugin());
90-
}
86+
const plugin &getPlugin() const;
87+
9188
size_t getSize() const override { return MSizeInBytes; }
9289
size_t get_count() const {
9390
size_t AllocatorValueSize = MAllocator->getValueSize();
@@ -259,6 +256,9 @@ class SYCLMemObjT : public SYCLMemObjI {
259256
MAllocator->setAlignment(RequiredAlign);
260257
}
261258

259+
static size_t getBufSizeForContext(const ContextImplPtr &Context,
260+
cl_mem MemObject);
261+
262262
protected:
263263
// Allocator used for allocation memory on host.
264264
unique_ptr_class<SYCLMemObjAllocator> MAllocator;

sycl/include/CL/sycl/handler.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ namespace sycl {
5959

6060
// Forward declaration
6161

62+
class handler;
6263
template <typename T, int Dimensions, typename AllocatorT> class buffer;
6364
namespace detail {
6465

@@ -104,6 +105,7 @@ template <typename Type> struct get_kernel_name_t<detail::auto_name, Type> {
104105
using name = Type;
105106
};
106107

108+
device getDeviceFromHandler(handler &);
107109
} // namespace detail
108110

109111
/// 4.8.3 Command group handler class
@@ -1278,6 +1280,7 @@ class handler {
12781280
template <typename DataT, int Dims, access::mode AccMode,
12791281
access::target AccTarget, access::placeholder isPlaceholder>
12801282
friend class accessor;
1283+
friend device detail::getDeviceFromHandler(handler &);
12811284

12821285
template <typename DataT, int Dimensions, access::mode AccessMode,
12831286
access::target AccessTarget, access::placeholder IsPlaceholder>

sycl/include/CL/sycl/intel/function_pointer.hpp

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

99
#pragma once
1010

11-
#include <CL/sycl/detail/plugin.hpp>
1211
#include <CL/sycl/device.hpp>
1312
#include <CL/sycl/program.hpp>
1413
#include <CL/sycl/stl.hpp>

sycl/include/CL/sycl/platform.hpp

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

99
#pragma once
1010
#include <CL/sycl/detail/common.hpp>
11-
#include <CL/sycl/detail/platform_info.hpp>
1211
#include <CL/sycl/stl.hpp>
1312

1413
// 4.6.2 Platform class

sycl/include/CL/sycl/queue.hpp

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

1111
#include <CL/sycl/detail/common.hpp>
12+
#include <CL/sycl/device.hpp>
1213
#include <CL/sycl/device_selector.hpp>
1314
#include <CL/sycl/event.hpp>
1415
#include <CL/sycl/exception_list.hpp>
16+
#include <CL/sycl/handler.hpp>
1517
#include <CL/sycl/info/info_desc.hpp>
1618
#include <CL/sycl/property_list.hpp>
1719
#include <CL/sycl/stl.hpp>
@@ -107,10 +109,7 @@ class queue {
107109
/// @param SyclDevice is an instance of SYCL device.
108110
/// @param PropList is a list of properties for queue construction.
109111
queue(const context &SyclContext, const device &SyclDevice,
110-
const property_list &PropList = {})
111-
: queue(SyclContext, SyclDevice,
112-
detail::getSyclObjImpl(SyclContext)->get_async_handler(),
113-
PropList) {};
112+
const property_list &PropList = {});
114113

115114
/// Constructs a SYCL queue associated with the given context, device,
116115
/// asynchronous exception handler and optional properties list.
@@ -447,9 +446,7 @@ class queue {
447446
/// Returns whether the queue is in order or OoO
448447
///
449448
/// Equivalent to has_property<property::queue::in_order>()
450-
bool is_in_order() const {
451-
return impl->has_property<property::queue::in_order>();
452-
}
449+
bool is_in_order() const;
453450

454451
private:
455452
shared_ptr_class<detail::queue_impl> impl;

sycl/source/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ set(SYCL_SOURCES
8282
"detail/usm/usm_dispatch.cpp"
8383
"detail/usm/usm_impl.cpp"
8484
"detail/util.cpp"
85+
"accessor.cpp"
8586
"context.cpp"
8687
"device.cpp"
8788
"device_selector.cpp"

sycl/source/accessor.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//==------------ accessor.cpp - SYCL standard source 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+
#include <CL/sycl/accessor.hpp>
10+
#include <detail/queue_impl.hpp>
11+
12+
__SYCL_INLINE_NAMESPACE(cl) {
13+
namespace sycl {
14+
namespace detail {
15+
device getDeviceFromHandler(handler &CommandGroupHandlerRef) {
16+
return CommandGroupHandlerRef.MQueue->get_device();
17+
}
18+
} // namespace detail
19+
} // namespace sycl
20+
} // __SYCL_INLINE_NAMESPACE(cl)

sycl/source/context.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88

99
#include <CL/sycl/context.hpp>
1010
#include <CL/sycl/detail/common.hpp>
11-
#include <CL/sycl/detail/context_impl.hpp>
1211
#include <CL/sycl/device.hpp>
1312
#include <CL/sycl/device_selector.hpp>
1413
#include <CL/sycl/exception.hpp>
1514
#include <CL/sycl/exception_list.hpp>
1615
#include <CL/sycl/platform.hpp>
1716
#include <CL/sycl/stl.hpp>
17+
#include <detail/context_impl.hpp>
18+
1819
#include <algorithm>
1920
#include <memory>
2021
#include <utility>

sycl/source/detail/accessor_impl.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
//===----------------------------------------------------------------------===//
88

99
#include <CL/sycl/detail/accessor_impl.hpp>
10-
#include <CL/sycl/detail/scheduler/scheduler.hpp>
10+
#include <detail/event_impl.hpp>
11+
#include <detail/scheduler/scheduler.hpp>
1112

1213
__SYCL_INLINE_NAMESPACE(cl) {
1314
namespace sycl {
@@ -17,6 +18,12 @@ AccessorImplHost::~AccessorImplHost() {
1718
if (MBlockedCmd)
1819
detail::Scheduler::getInstance().releaseHostAccessor(this);
1920
}
21+
22+
void addHostAccessorAndWait(Requirement *Req) {
23+
detail::EventImplPtr Event =
24+
detail::Scheduler::getInstance().addHostAccessor(Req);
25+
Event->wait(Event);
26+
}
2027
}
2128
}
2229
}

sycl/source/detail/buffer_impl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
//===----------------------------------------------------------------------===//
88

99
#include <CL/sycl/detail/buffer_impl.hpp>
10-
#include <CL/sycl/detail/context_impl.hpp>
1110
#include <CL/sycl/detail/memory_manager.hpp>
12-
#include <CL/sycl/detail/scheduler/scheduler.hpp>
11+
#include <detail/context_impl.hpp>
12+
#include <detail/scheduler/scheduler.hpp>
1313

1414
__SYCL_INLINE_NAMESPACE(cl) {
1515
namespace sycl {

sycl/source/detail/config.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#pragma once
1010

11+
#include <CL/sycl/detail/defines.hpp>
12+
1113
#include <cstdlib>
1214

1315
__SYCL_INLINE_NAMESPACE(cl) {

sycl/source/detail/context_impl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
#include <CL/sycl/detail/clusm.hpp>
1010
#include <CL/sycl/detail/common.hpp>
11-
#include <CL/sycl/detail/context_impl.hpp>
12-
#include <CL/sycl/detail/context_info.hpp>
1311
#include <CL/sycl/device.hpp>
1412
#include <CL/sycl/exception.hpp>
1513
#include <CL/sycl/exception_list.hpp>
1614
#include <CL/sycl/info/info_desc.hpp>
1715
#include <CL/sycl/platform.hpp>
1816
#include <CL/sycl/stl.hpp>
17+
#include <detail/context_impl.hpp>
18+
#include <detail/context_info.hpp>
1919

2020
__SYCL_INLINE_NAMESPACE(cl) {
2121
namespace sycl {

0 commit comments

Comments
 (0)