Skip to content

Commit a4543c6

Browse files
committed
Fix contradiction with context constructors
The context constructor overloads in the `context` synopsis did not match the description in the text of the specification. We decided that the overloads in the synopsis were what we intended, so change the text to match. We also discovered that two constructor overloads taking a `platform` argument were present in SYCL 1.2.1 and were inadvertently dropped from the SYCL 2020 specification. Add them back. Clarify the behavior of the constructors when the set of devices is empty. We decided that this should throw an exception, which is consistent with OpenCL's `clCreateContext`. Closes #470 Closes #474
1 parent 51bfc4b commit a4543c6

2 files changed

Lines changed: 118 additions & 27 deletions

File tree

adoc/chapters/programming_interface.adoc

Lines changed: 113 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,56 +1227,141 @@ include::{header_dir}/context.h[lines=4..-1]
12271227
[[sec:context-ctors]]
12281228
==== Constructors
12291229

1230+
All context constructors take a parameter named [code]#propList# which allows
1231+
the application to pass zero or more properties.
1232+
These properties may specify additional effects of the constructor and may also
1233+
specify exceptions that the constructor throws.
1234+
See <<sec:context-properties>> for the context properties that are defined by
1235+
the <<core-spec>>.
1236+
1237+
'''
1238+
12301239
.[apititle]#Default constructor#
12311240
[source,role=synopsis,id=api:context-ctor]
12321241
----
1233-
explicit context(async_handler asyncHandler = {})
1242+
explicit context(const property_list& propList = {})
12341243
----
12351244

1236-
_Effects:_ Constructs a [code]#context# object using the
1237-
[code]#default_selector_v# to determine the associated platform and devices.
1238-
The associated platform is the platform which contains the device selected by
1245+
_Effects:_ Constructs a [code]#context# object using the device selected by
12391246
[code]#default_selector_v#.
1240-
The <<device,devices>> that are associated with the constructed context are
1241-
implementation-defined but must contain the device that is selected by
1247+
The context's platform is the platform that contains this device.
1248+
The context contains the selected device.
1249+
The context may also contain other devices from the same platform.
1250+
Whether this happens is implementation defined.
1251+
1252+
'''
1253+
1254+
.[apititle]#Constructor with async handler#
1255+
[source,role=synopsis,id=api:context-ctor-async-handler]
1256+
----
1257+
explicit context(async_handler asyncHandler, const property_list& propList = {})
1258+
----
1259+
1260+
_Effects:_ Constructs a [code]#context# object using the device selected by
12421261
[code]#default_selector_v#.
1243-
The constructed context uses the [code]#asyncHandler# parameter to handle
1244-
exceptions.
1262+
The context's platform is the platform that contains this device.
1263+
The context contains the selected device.
1264+
The context may also contain other devices from the same platform.
1265+
Whether this happens is implementation defined.
1266+
The context has the asynchronous error handler [code]#asyncHandler#.
1267+
1268+
'''
1269+
1270+
.[apititle]#Constructor with device#
1271+
[source,role=synopsis,id=api:context-ctor-device]
1272+
----
1273+
explicit context(const device& dev, const property_list& propList = {})
1274+
----
1275+
1276+
_Effects:_ Constructs a [code]#context# object that contains the device
1277+
[code]#dev#.
1278+
The context's platform is the platform that contains [code]#dev#.
1279+
1280+
'''
1281+
1282+
.[apititle]#Constructor with device and async handler#
1283+
[source,role=synopsis,id=api:context-ctor-device-async-handler]
1284+
----
1285+
explicit context(const device& dev, async_handler asyncHandler,
1286+
const property_list& propList = {})
1287+
----
1288+
1289+
_Effects:_ Constructs a [code]#context# object that contains the device
1290+
[code]#dev#.
1291+
The context's platform is the platform that contains [code]#dev#.
1292+
The context has the asynchronous error handler [code]#asyncHandler#.
12451293

12461294
'''
12471295

1248-
.[apititle]#Construct from device#
1249-
[source,role=synopsis,id=api:context-ctor-dev]
1296+
.[apititle]#Constructor with platform#
1297+
[source,role=synopsis,id=api:context-ctor-platform]
12501298
----
1251-
explicit context(const device& dev, async_handler asyncHandler = {})
1299+
explicit context(const platform &plt, const property_list &propList = {})
12521300
----
12531301

1254-
_Effects:_ Constructs a [code]#context# object using the [code]#dev# parameter
1255-
to determine the associated platform and device.
1256-
The associated platform is the platform that contains [code]#dev#, and the
1257-
associated device is [code]#dev#.
1258-
The constructed context uses the [code]#asyncHandler# parameter to handle
1259-
exceptions.
1302+
_Effects:_ Constructs a [code]#context# object that contains all of the devices
1303+
in the platform [code]#plt#.
1304+
The context's platform is [code]#plt#.
1305+
1306+
_Throws:_ An [code]#exception# with the [code]#errc::invalid# error code if the
1307+
platform [code]#plt# contains no devices.
12601308

12611309
'''
12621310

1263-
.[apititle]#Construct from device list#
1264-
[source,role=synopsis,id=api:context-ctor-dev-list]
1311+
.[apititle]#Constructor with platform and async handler#
1312+
[source,role=synopsis,id=api:context-ctor-platform-async-handler]
12651313
----
1266-
explicit context(const std::vector<device>& deviceList,
1267-
async_handler asyncHandler = {})
1314+
explicit context(const platform &plt, async_handler asyncHandler,
1315+
const property_list &propList = {})
1316+
----
1317+
1318+
_Effects:_ Constructs a [code]#context# object that contains all of the devices
1319+
in the platform [code]#plt#.
1320+
The context's platform is [code]#plt#.
1321+
The context has the asynchronous error handler [code]#asyncHandler#.
1322+
1323+
_Throws:_ An [code]#exception# with the [code]#errc::invalid# error code if the
1324+
platform [code]#plt# contains no devices.
1325+
1326+
'''
1327+
1328+
.[apititle]#Constructor with device list#
1329+
[source,role=synopsis,id=api:context-ctor-device-list]
1330+
----
1331+
explicit context(const std::vector<device>& deviceList, const property_list& propList = {})
12681332
----
12691333

12701334
_Preconditions:_ All devices in [code]#deviceList# must be associated with the
12711335
same platform.
12721336

1273-
_Effects:_ Constructs a [code]#context# object using the [code]#deviceList#
1274-
parameter to determine the associated platform and device.
1275-
The associated platform is the platform that contains all of the devices in
1337+
_Effects:_ Constructs a [code]#context# object that contains all of the devices
1338+
in [code]#deviceList#.
1339+
The context's platform is the platform that contains the devices in
12761340
[code]#deviceList#.
1277-
The associated devices are those devices in [code]#deviceList#.
1278-
The constructed context uses the [code]#asyncHandler# parameter to handle
1279-
exceptions.
1341+
1342+
_Throws:_ An [code]#exception# with the [code]#errc::invalid# error code if
1343+
[code]#deviceList# is empty.
1344+
1345+
'''
1346+
1347+
.[apititle]#Constructor with device list and async handler#
1348+
[source,role=synopsis,id=api:context-ctor-device-list-async-handler]
1349+
----
1350+
explicit context(const std::vector<device>& deviceList, async_handler asyncHandler,
1351+
const property_list& propList = {})
1352+
----
1353+
1354+
_Preconditions:_ All devices in [code]#deviceList# must be associated with the
1355+
same platform.
1356+
1357+
_Effects:_ Constructs a [code]#context# object that contains all of the devices
1358+
in [code]#deviceList#.
1359+
The context's platform is the platform that contains the devices in
1360+
[code]#deviceList#.
1361+
The context has the asynchronous error handler [code]#asyncHandler#.
1362+
1363+
_Throws:_ An [code]#exception# with the [code]#errc::invalid# error code if
1364+
[code]#deviceList# is empty.
12801365

12811366
'''
12821367

@@ -1503,6 +1588,7 @@ At a minimum, each context must support [code]#memory_scope::work_item#,
15031588
[[sec:context-properties]]
15041589
==== Properties
15051590

1591+
The <<core-spec>> does not define any properties for the context constructors.
15061592
The [code]#property_list# constructor parameters are present for extensibility.
15071593

15081594

adoc/headers/context.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ class context {
1414
explicit context(const device& dev, async_handler asyncHandler,
1515
const property_list& propList = {});
1616

17+
explicit context(const platform &plt, const property_list &propList = {});
18+
19+
explicit context(const platform &plt, async_handler asyncHandler,
20+
const property_list &propList = {});
21+
1722
explicit context(const std::vector<device>& deviceList,
1823
const property_list& propList = {});
1924

0 commit comments

Comments
 (0)