Skip to content

Commit bbd85f2

Browse files
alexeyvoronov-intelvladimirlaz
authored andcommitted
[SYCL] Merge host and device context to impl context.
Move to library. Signed-off-by: Voronov, Alexey <[email protected]> Signed-off-by: Vladimir Lazarev <[email protected]>
1 parent 7a18373 commit bbd85f2

File tree

11 files changed

+258
-226
lines changed

11 files changed

+258
-226
lines changed

sycl/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ set(OPENCL_INCLUDE "${OpenCL_INCLUDE_DIRS}")
7474
add_library("${SYCLLibrary}" SHARED
7575
"${includeRootPath}/CL/sycl.hpp"
7676
"${sourceRootPath}/detail/common.cpp"
77+
"${sourceRootPath}/detail/context_impl.cpp"
7778
"${sourceRootPath}/detail/device_info.cpp"
7879
"${sourceRootPath}/detail/event_impl.cpp"
7980
"${sourceRootPath}/detail/force_device.cpp"

sycl/include/CL/sycl/context.hpp

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,26 @@
88
//===----------------------------------------------------------------------===//
99

1010
#pragma once
11-
#include <CL/sycl/detail/context_host.hpp>
12-
#include <CL/sycl/detail/context_opencl.hpp>
13-
#include <CL/sycl/device.hpp>
14-
#include <CL/sycl/platform.hpp>
11+
#include <CL/sycl/detail/common.hpp>
12+
#include <CL/sycl/detail/context_impl.hpp>
13+
#include <CL/sycl/exception.hpp>
14+
#include <CL/sycl/info/info_desc.hpp>
1515
#include <CL/sycl/stl.hpp>
1616
#include <memory>
17-
#include <utility>
1817
// 4.6.2 Context class
1918

2019
namespace cl {
2120
namespace sycl {
21+
// Forward declarations
22+
class device;
23+
class platform;
2224
class context {
2325
public:
24-
explicit context(const async_handler &asyncHandler = {})
25-
: context(default_selector().select_device(), asyncHandler) {}
26+
explicit context(const async_handler &asyncHandler = {});
2627

27-
context(const device &dev, async_handler asyncHandler = {})
28-
: context(vector_class<device>(1, dev), asyncHandler) {}
28+
context(const device &dev, async_handler asyncHandler = {});
2929

30-
context(const platform &plt, async_handler asyncHandler = {})
31-
: context(plt.get_devices(), asyncHandler) {}
30+
context(const platform &plt, async_handler asyncHandler = {});
3231

3332
context(const vector_class<device> &deviceList,
3433
async_handler asyncHandler = {});
@@ -37,9 +36,7 @@ class context {
3736

3837
template <info::context param>
3938
typename info::param_traits<info::context, param>::return_type
40-
get_info() const {
41-
return impl->get_info<param>();
42-
}
39+
get_info() const;
4340

4441
context(const context &rhs) = default;
4542

@@ -49,17 +46,17 @@ class context {
4946

5047
context &operator=(context &&rhs) = default;
5148

52-
bool operator==(const context &rhs) const { return impl == rhs.impl; }
49+
bool operator==(const context &rhs) const;
5350

54-
bool operator!=(const context &rhs) const { return !(*this == rhs); }
51+
bool operator!=(const context &rhs) const;
5552

56-
cl_context get() const { return impl->get(); }
53+
cl_context get() const;
5754

58-
bool is_host() const { return impl->is_host(); }
55+
bool is_host() const;
5956

60-
platform get_platform() const { return impl->get_platform(); }
57+
platform get_platform() const;
6158

62-
vector_class<device> get_devices() const { return impl->get_devices(); }
59+
vector_class<device> get_devices() const;
6360

6461
private:
6562
std::shared_ptr<detail::context_impl> impl;

sycl/include/CL/sycl/detail/context_host.hpp

Lines changed: 0 additions & 46 deletions
This file was deleted.

sycl/include/CL/sycl/detail/context_impl.hpp

Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//==---------------- context.hpp - SYCL context ----------------------------==//
1+
//==---------------- context_impl.hpp - SYCL context -----------*- C++-*---==//
22
//
33
// The LLVM Compiler Infrastructure
44
//
@@ -13,71 +13,48 @@
1313
#include <CL/sycl/info/info_desc.hpp>
1414
#include <CL/sycl/platform.hpp>
1515
#include <CL/sycl/stl.hpp>
16+
17+
#include <memory>
1618
// 4.6.2 Context class
1719

1820
namespace cl {
1921
namespace sycl {
2022
// Forward declaration
21-
class platform;
2223
class device;
2324
namespace detail {
24-
template <info::context param> struct get_context_info_cl {
25-
using RetType =
26-
typename info::param_traits<info::context, param>::return_type;
27-
28-
static RetType _(cl_context ctx) {
29-
RetType Result = 0;
30-
// TODO catch an exception and put it to list of asynchronous exceptions
31-
CHECK_OCL_CODE(clGetContextInfo(ctx, cl_context_info(param), sizeof(Result),
32-
&Result, nullptr));
33-
return Result;
34-
}
35-
};
36-
3725
class context_impl {
3826
public:
39-
context_impl(async_handler asyncHandler) : m_AsyncHandler(asyncHandler) {}
27+
context_impl(const device &Device, async_handler AsyncHandler);
4028

41-
template <info::context param>
42-
inline typename info::param_traits<info::context, param>::return_type
43-
get_info() const;
29+
context_impl(const vector_class<cl::sycl::device> Devices,
30+
async_handler AsyncHandler);
31+
32+
context_impl(cl_context ClContext, async_handler AsyncHandler);
33+
34+
~context_impl();
4435

45-
const async_handler& get_async_handler() const { return m_AsyncHandler; }
36+
cl_context get() const;
4637

47-
virtual cl_context get() const = 0;
38+
bool is_host() const;
4839

49-
virtual bool is_host() const = 0;
40+
platform get_platform() const;
5041

51-
virtual platform get_platform() const = 0;
42+
vector_class<device> get_devices() const;
5243

53-
virtual vector_class<device> get_devices() const = 0;
44+
const async_handler &get_async_handler() const;
5445

55-
virtual ~context_impl() = default;
46+
template <info::context param>
47+
typename info::param_traits<info::context, param>::return_type
48+
get_info() const;
5649

5750
private:
5851
async_handler m_AsyncHandler;
52+
vector_class<device> m_Devices;
53+
cl_context m_ClContext;
54+
platform m_Platform;
55+
bool m_OpenCLInterop;
56+
bool m_HostContext;
5957
};
60-
template <>
61-
inline typename info::param_traits<info::context,
62-
info::context::reference_count>::return_type
63-
context_impl::get_info<info::context::reference_count>() const {
64-
if (is_host()) {
65-
return 0;
66-
}
67-
return get_context_info_cl<info::context::reference_count>::_(this->get());
68-
}
69-
template <>
70-
inline typename info::param_traits<info::context,
71-
info::context::platform>::return_type
72-
context_impl::get_info<info::context::platform>() const {
73-
return get_platform();
74-
}
75-
template <>
76-
inline typename info::param_traits<info::context,
77-
info::context::devices>::return_type
78-
context_impl::get_info<info::context::devices>() const {
79-
return get_devices();
80-
}
8158

8259
} // namespace detail
8360
} // namespace sycl
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//==---------------- context_info.hpp - SYCL context -----------*- 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/common.hpp>
12+
#include <CL/sycl/info/info_desc.hpp>
13+
14+
namespace cl {
15+
namespace sycl {
16+
namespace detail {
17+
18+
template <info::context param> struct get_context_info_cl {
19+
using RetType =
20+
typename info::param_traits<info::context, param>::return_type;
21+
22+
static RetType _(cl_context ctx) {
23+
RetType Result = 0;
24+
// TODO catch an exception and put it to list of asynchronous exceptions
25+
CHECK_OCL_CODE(clGetContextInfo(ctx, cl_context_info(param), sizeof(Result),
26+
&Result, nullptr));
27+
return Result;
28+
}
29+
};
30+
31+
} // namespace detail
32+
} // namespace sycl
33+
} // namespace cl

sycl/include/CL/sycl/detail/context_opencl.hpp

Lines changed: 0 additions & 90 deletions
This file was deleted.

sycl/include/CL/sycl/detail/event_info.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#pragma once
1111

12+
#include <CL/sycl/detail/common.hpp>
1213
#include <CL/sycl/info/info_desc.hpp>
1314

1415
namespace cl {

sycl/include/CL/sycl/queue.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <CL/sycl/detail/common.hpp>
1313
#include <CL/sycl/detail/queue_impl.hpp>
14+
#include <CL/sycl/device_selector.hpp>
1415
#include <CL/sycl/info/info_desc.hpp>
1516
#include <CL/sycl/property_list.hpp>
1617

0 commit comments

Comments
 (0)