From 1f7ec12f847d187c86f05b88b5c034c0e71fde2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C5=BDu=C5=BEek?= Date: Tue, 14 Aug 2018 15:18:50 +0100 Subject: [PATCH 01/16] Initial draft for casting `multi_ptr` --- multi_ptr-cast/index.md | 20 +++++++ multi_ptr-cast/sycl-2.2/index.md | 97 ++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 multi_ptr-cast/index.md create mode 100644 multi_ptr-cast/sycl-2.2/index.md diff --git a/multi_ptr-cast/index.md b/multi_ptr-cast/index.md new file mode 100644 index 0000000..474c557 --- /dev/null +++ b/multi_ptr-cast/index.md @@ -0,0 +1,20 @@ +# Casting multi_ptr pointers + +| Proposal ID | CP016 | +|-------------|--------| +| Name | Casting multi_ptr pointers | +| Date of Creation | 14 August 2018 | +| Target | SYCL 1.2.1 | +| Current Status | _Work in Progress_ | +| Reply-to | Peter Žužek | +| Original author | Peter Žužek | +| Contributors | | + +## Overview + +This paper proposes the addition of pointer casting functions to SYCL +in order to simplify casting of the `multi_ptr` class. + +## Versions + +[Version 1](sycl-2.2/index.md) diff --git a/multi_ptr-cast/sycl-2.2/index.md b/multi_ptr-cast/sycl-2.2/index.md new file mode 100644 index 0000000..cb4ca2d --- /dev/null +++ b/multi_ptr-cast/sycl-2.2/index.md @@ -0,0 +1,97 @@ +# Casting multi_ptr pointers + +## Motivation + +The current SYCL 1.2.1 specification contains the `multi_ptr` class +which is designed mostly for OpenCL interoperability +and calling certain functions which rely on OpenCL builtins. +The `multi_ptr` class has two template parameters: +`ElementType` as the type of the underlying data, +and `Space` to designate the address space of the pointer. +It is not allowed to cast pointers to a different address space, +but casting pointers to a different underlying type is completely valid C++, +within the type restrictions for the cast. + +Programmers wanting to cast `multi_ptr` to `multi_ptr` +don't have many options to do so in SYCL 1.2.1. +There are only two specified casts in SYCL 1.2.1: + * Using `static_cast` to cast `multi_ptr` to `multi_ptr` + (defined through an explicit conversion operator) + * Using `static_cast` to cast `multi_ptr` to `multi_ptr` + (defined through an explicit conversion operator) + +Therefore, the only option to perform a cast from +`multi_ptr` to `multi_ptr` +is to use both casts like so: +```cpp +// Using global_ptr here to simplify the code +// decltype(multiPtrA) == global_ptr +auto multiPtrB = static_cast>(static_cast>(multiPtrA)); +``` + +This is problematic on a few levels: + * Verbosity + * Only allows static casts + * Allows casting the underlying `A*` pointer to a `B*` pointer + even if the type system forbids it + * Does not handle `const` cases + +Therefore, there is a clear need to provide more casting options for the `multi_ptr` class +in order to make the casting safer and easier to use. + +## Summary + +This proposal adds a few explicit conversion operators +as member functions of the `multi_ptr` class +and also adds several free functions to the `cl::sycl` namespace +that follow the naming and semantics of the `std::shared_ptr` pointer cast functions +defined by the C++17 standard: https://en.cppreference.com/w/cpp/memory/shared_ptr/pointer_cast. + +## Explicit conversion operators + +The new interface of the `multi_ptr` class would look like this: + +```cpp +namespace cl { +namespace sycl { + +template +class multi_ptr { + public: + /// All existing members here + + ... + + // Explicit conversion to `multi_ptr` + template + explicit operator multi_ptr() const; + + // Explicit conversion to `multi_ptr` + explicit operator multi_ptr() const; +}; + +template +class multi_ptr { + public: + /// All existing members here + + ... + + // Explicit conversion to `multi_ptr` + explicit operator multi_ptr() const; +}; + +} // namespace sycl +} // namespace cl +``` + +The conversion operator to `multi_ptr` replaces +the existing explicit conversion to `multi_ptr`. + +TODO(Peter): Table + +TODO(Peter): Handle multi_ptr + +## Conversion functions + +TODO(Peter) From 1e0dd51803deaadd59838ab5eb7bcc777349b643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C5=BDu=C5=BEek?= Date: Tue, 14 Aug 2018 16:12:48 +0100 Subject: [PATCH 02/16] Basic conversion functions --- multi_ptr-cast/sycl-2.2/index.md | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/multi_ptr-cast/sycl-2.2/index.md b/multi_ptr-cast/sycl-2.2/index.md index cb4ca2d..82fc742 100644 --- a/multi_ptr-cast/sycl-2.2/index.md +++ b/multi_ptr-cast/sycl-2.2/index.md @@ -94,4 +94,33 @@ TODO(Peter): Handle multi_ptr ## Conversion functions -TODO(Peter) +In addition to the conversion operators, +we propose adding the following free functions to the `cl::sycl` namespace: + +```cpp +namespace cl { +namespace sycl { + +template +multi_ptr + static_pointer_cast(const multi_ptr& multiPtr); + +template +multi_ptr + dynamic_pointer_cast(const multi_ptr& multiPtr); + +template +multi_ptr + const_pointer_cast(const multi_ptr& multiPtr); + +template +multi_ptr + reinterpret_pointer_cast(const multi_ptr& multiPtr); + +} // namespace sycl +} // namespace cl +``` + +TODO(Peter): Description + +TODO(Peter): Table From c77402392a18f062bd7c795c9a4f107810264773 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C5=BDu=C5=BEek?= Date: Wed, 15 Aug 2018 11:30:20 +0100 Subject: [PATCH 03/16] Minor formatting changes --- multi_ptr-cast/sycl-2.2/index.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/multi_ptr-cast/sycl-2.2/index.md b/multi_ptr-cast/sycl-2.2/index.md index 82fc742..72ad994 100644 --- a/multi_ptr-cast/sycl-2.2/index.md +++ b/multi_ptr-cast/sycl-2.2/index.md @@ -26,7 +26,8 @@ is to use both casts like so: ```cpp // Using global_ptr here to simplify the code // decltype(multiPtrA) == global_ptr -auto multiPtrB = static_cast>(static_cast>(multiPtrA)); +auto multiPtrB = static_cast>( + static_cast>(multiPtrA)); ``` This is problematic on a few levels: @@ -62,9 +63,9 @@ class multi_ptr { ... - // Explicit conversion to `multi_ptr` - template - explicit operator multi_ptr() const; + // Explicit conversion to `multi_ptr` + template + explicit operator multi_ptr() const; // Explicit conversion to `multi_ptr` explicit operator multi_ptr() const; @@ -85,7 +86,7 @@ class multi_ptr { } // namespace cl ``` -The conversion operator to `multi_ptr` replaces +The conversion operator to `multi_ptr` replaces the existing explicit conversion to `multi_ptr`. TODO(Peter): Table From 3734c028e055e9e3110e1e6ad68230d700097e75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C5=BDu=C5=BEek?= Date: Wed, 15 Aug 2018 11:45:31 +0100 Subject: [PATCH 04/16] Specializations for `void` and `const void` --- multi_ptr-cast/sycl-2.2/index.md | 36 ++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/multi_ptr-cast/sycl-2.2/index.md b/multi_ptr-cast/sycl-2.2/index.md index 72ad994..9156236 100644 --- a/multi_ptr-cast/sycl-2.2/index.md +++ b/multi_ptr-cast/sycl-2.2/index.md @@ -42,12 +42,33 @@ in order to make the casting safer and easier to use. ## Summary -This proposal adds a few explicit conversion operators -as member functions of the `multi_ptr` class +This proposal folds the `void` specialization of the `multi_ptr` class +into the main definition of `multi_ptr`, +handles the cases where `ElementType` is a `const`-qualified type, +adds a few explicit conversion operators +as member functions of the `multi_ptr` class, and also adds several free functions to the `cl::sycl` namespace that follow the naming and semantics of the `std::shared_ptr` pointer cast functions defined by the C++17 standard: https://en.cppreference.com/w/cpp/memory/shared_ptr/pointer_cast. +## Specializations for void and const void + +In SYCL 1.2.1, the `void` specialization of the `multi_ptr` class +is separate from the main definition +because it cannot contain any reference types. +For the purpose of the specification, +we propose folding the two definitions +into a single definition of the `multi_ptr` class, +with comments denoting which types are available +only if `ElementType` is not `void` or `const void`. +The main reason for this simplification +is the introduction of the specialization for `const void`, +which would require the specification to define another specialization +that would be mostly the same as the specialization for `void`. +Simplifying the definiton like this +also covers the case where `ElementType` is not `void` or `const void`, +but some other `const`-qualified type. + ## Explicit conversion operators The new interface of the `multi_ptr` class would look like this: @@ -71,17 +92,6 @@ class multi_ptr { explicit operator multi_ptr() const; }; -template -class multi_ptr { - public: - /// All existing members here - - ... - - // Explicit conversion to `multi_ptr` - explicit operator multi_ptr() const; -}; - } // namespace sycl } // namespace cl ``` From d0aa1ee8fa57445feba4a1b68cf20e4b6aed0bf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C5=BDu=C5=BEek?= Date: Wed, 15 Aug 2018 11:56:40 +0100 Subject: [PATCH 05/16] Tables and descriptions --- multi_ptr-cast/sycl-2.2/index.md | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/multi_ptr-cast/sycl-2.2/index.md b/multi_ptr-cast/sycl-2.2/index.md index 9156236..8774502 100644 --- a/multi_ptr-cast/sycl-2.2/index.md +++ b/multi_ptr-cast/sycl-2.2/index.md @@ -99,9 +99,10 @@ class multi_ptr { The conversion operator to `multi_ptr` replaces the existing explicit conversion to `multi_ptr`. -TODO(Peter): Table - -TODO(Peter): Handle multi_ptr +| Member function | Description | +|-----------------|-------------| +| *`template explicit operator multi_ptr() const`* | Performs a static cast of the underlying pointer `ElementType*` to `ElementTypeU*` and returns a new `multi_ptr` instance containing the cast pointer. The address space stays the same. This conversion is only valid if the static cast from `ElementType*` to `ElementTypeU*` is valid. | +| *`explicit operator multi_ptr() const`* | Performs a static cast of the underlying pointer `ElementType*` to `const ElementType*` and returns a new `multi_ptr` instance containing the cast pointer. The address space stays the same. | ## Conversion functions @@ -112,18 +113,22 @@ we propose adding the following free functions to the `cl::sycl` namespace: namespace cl { namespace sycl { +// Performs a static_cast of the contained pointer template multi_ptr static_pointer_cast(const multi_ptr& multiPtr); +// Performs a dynamic_cast of the contained pointer template multi_ptr dynamic_pointer_cast(const multi_ptr& multiPtr); +// Performs a const_cast of the contained pointer template multi_ptr const_pointer_cast(const multi_ptr& multiPtr); +// Performs a reinterpret_cast of the contained pointer template multi_ptr reinterpret_pointer_cast(const multi_ptr& multiPtr); @@ -132,6 +137,15 @@ multi_ptr } // namespace cl ``` -TODO(Peter): Description +In the table below, each function has the following template parameters: +```cpp +template +``` + +| Member function | Description | +|-----------------|-------------| +| *`multi_ptr static_pointer_cast(const multi_ptr& multiPtr)`* | Performs a `static_cast` of the underlying pointer `ElementTypeT*` contained within `multiPtr` to `ElementTypeU*` and returns a new `multi_ptr` instance containing the cast pointer. The address space stays the same. This conversion is only valid if the `static_cast` from `ElementType*` to `ElementTypeU*` is valid. | +| *`multi_ptr dynamic_pointer_cast(const multi_ptr& multiPtr)`* | Performs a `dynamic_cast` of the underlying pointer `ElementTypeT*` contained within `multiPtr` to `ElementTypeU*` and returns a new `multi_ptr` instance containing the cast pointer. The address space stays the same. This conversion is only valid if the `dynamic_cast` from `ElementType*` to `ElementTypeU*` is valid. | +| *`multi_ptr const_pointer_cast(const multi_ptr& multiPtr)`* | Performs a `const_cast` of the underlying pointer `ElementTypeT*` contained within `multiPtr` to `ElementTypeU*` and returns a new `multi_ptr` instance containing the cast pointer. The address space stays the same. This conversion is only valid if the `const_cast` from `ElementType*` to `ElementTypeU*` is valid. | +| *`multi_ptr reinterpret_pointer_cast(const multi_ptr& multiPtr)`* | Performs a `reinterpret_cast` of the underlying pointer `ElementTypeT*` contained within `multiPtr` to `ElementTypeU*` and returns a new `multi_ptr` instance containing the cast pointer. The address space stays the same. This conversion is only valid if the `reinterpret_cast` from `ElementType*` to `ElementTypeU*` is valid. | -TODO(Peter): Table From d2072d9f83dd7c1910cb95c94fc48770cc4733b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C5=BDu=C5=BEek?= Date: Wed, 15 Aug 2018 12:15:53 +0100 Subject: [PATCH 06/16] Made adding `const` conversion implicit --- multi_ptr-cast/sycl-2.2/index.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/multi_ptr-cast/sycl-2.2/index.md b/multi_ptr-cast/sycl-2.2/index.md index 8774502..9142b1d 100644 --- a/multi_ptr-cast/sycl-2.2/index.md +++ b/multi_ptr-cast/sycl-2.2/index.md @@ -35,7 +35,7 @@ This is problematic on a few levels: * Only allows static casts * Allows casting the underlying `A*` pointer to a `B*` pointer even if the type system forbids it - * Does not handle `const` cases + * Does not handle `const` qualifiers Therefore, there is a clear need to provide more casting options for the `multi_ptr` class in order to make the casting safer and easier to use. @@ -88,8 +88,8 @@ class multi_ptr { template explicit operator multi_ptr() const; - // Explicit conversion to `multi_ptr` - explicit operator multi_ptr() const; + // Implicit conversion to `multi_ptr` + operator multi_ptr() const; }; } // namespace sycl @@ -101,8 +101,8 @@ the existing explicit conversion to `multi_ptr`. | Member function | Description | |-----------------|-------------| -| *`template explicit operator multi_ptr() const`* | Performs a static cast of the underlying pointer `ElementType*` to `ElementTypeU*` and returns a new `multi_ptr` instance containing the cast pointer. The address space stays the same. This conversion is only valid if the static cast from `ElementType*` to `ElementTypeU*` is valid. | -| *`explicit operator multi_ptr() const`* | Performs a static cast of the underlying pointer `ElementType*` to `const ElementType*` and returns a new `multi_ptr` instance containing the cast pointer. The address space stays the same. | +| *`template explicit operator multi_ptr() const`* | Performs a static cast of the underlying pointer `ElementType*` to `ElementTypeU*` and returns a new `multi_ptr` instance containing the cast pointer. The address space stays the same. This conversion is only valid if the `static_cast` from `ElementType*` to `ElementTypeU*` is valid. | +| *`operator multi_ptr() const`* | Performs a static cast of the underlying pointer `ElementType*` to `const ElementType*` and returns a new `multi_ptr` instance containing the cast pointer. The address space stays the same. This conversion is implicit because it is always valid to add a `const` qualifier. | ## Conversion functions From 19e9d2c2161152e240cc3a5294f493633431dd8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C5=BDu=C5=BEek?= Date: Wed, 15 Aug 2018 12:18:53 +0100 Subject: [PATCH 07/16] Simple cast examples --- multi_ptr-cast/sycl-2.2/index.md | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/multi_ptr-cast/sycl-2.2/index.md b/multi_ptr-cast/sycl-2.2/index.md index 9142b1d..7d66a3e 100644 --- a/multi_ptr-cast/sycl-2.2/index.md +++ b/multi_ptr-cast/sycl-2.2/index.md @@ -149,3 +149,42 @@ template const_pointer_cast(const multi_ptr& multiPtr)`* | Performs a `const_cast` of the underlying pointer `ElementTypeT*` contained within `multiPtr` to `ElementTypeU*` and returns a new `multi_ptr` instance containing the cast pointer. The address space stays the same. This conversion is only valid if the `const_cast` from `ElementType*` to `ElementTypeU*` is valid. | | *`multi_ptr reinterpret_pointer_cast(const multi_ptr& multiPtr)`* | Performs a `reinterpret_cast` of the underlying pointer `ElementTypeT*` contained within `multiPtr` to `ElementTypeU*` and returns a new `multi_ptr` instance containing the cast pointer. The address space stays the same. This conversion is only valid if the `reinterpret_cast` from `ElementType*` to `ElementTypeU*` is valid. | +## Examples + +### Simple casts + +These examples focus on `global_ptr` for brevity, +but it works the same for all `multi_ptr` types. + +```cpp +using namespace cl::sycl; +const global_ptr ptrInt = get_some_global_ptr(); + +// Conversion operator +auto ptrFloat1 = static_cast>(ptrInt); +auto ptrVoid1 = static_cast>(ptrInt); +auto ptrConstInt1 = static_cast>(ptrInt); + +// static_pointer_cast +auto ptrFloat2 = static_pointer_cast(ptrInt); +auto ptrVoid2 = static_pointer_cast(ptrInt); +auto ptrConstInt2 = static_pointer_cast(ptrInt); + +// const_pointer_cast +auto ptrConstInt3 = const_pointer_cast(ptrInt); +// auto ptrIntStripConst = static_cast>(ptrConstInt1); // illegal +auto ptrIntStripConst = const_pointer_cast(ptrConstInt1); + +// reinterpret_pointer_cast +auto ptrFloat4 = reinterpret_pointer_cast(ptrInt); +auto ptrVoid4 = reinterpret_pointer_cast(ptrInt); +auto ptrConstInt4 = reinterpret_pointer_cast(ptrInt); +``` + +### `dynamic_pointer_cast` + +TODO(Peter) + +### Passing `multi_ptr` to functions + +TODO(Peter) From 58c313ccf60b19ace629d46e5be29904e5a21512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C5=BDu=C5=BEek?= Date: Tue, 6 Nov 2018 17:49:31 +0000 Subject: [PATCH 08/16] More examples --- multi_ptr-cast/sycl-2.2/index.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/multi_ptr-cast/sycl-2.2/index.md b/multi_ptr-cast/sycl-2.2/index.md index 7d66a3e..0c9ab10 100644 --- a/multi_ptr-cast/sycl-2.2/index.md +++ b/multi_ptr-cast/sycl-2.2/index.md @@ -149,6 +149,10 @@ template const_pointer_cast(const multi_ptr& multiPtr)`* | Performs a `const_cast` of the underlying pointer `ElementTypeT*` contained within `multiPtr` to `ElementTypeU*` and returns a new `multi_ptr` instance containing the cast pointer. The address space stays the same. This conversion is only valid if the `const_cast` from `ElementType*` to `ElementTypeU*` is valid. | | *`multi_ptr reinterpret_pointer_cast(const multi_ptr& multiPtr)`* | Performs a `reinterpret_cast` of the underlying pointer `ElementTypeT*` contained within `multiPtr` to `ElementTypeU*` and returns a new `multi_ptr` instance containing the cast pointer. The address space stays the same. This conversion is only valid if the `reinterpret_cast` from `ElementType*` to `ElementTypeU*` is valid. | +## Add `const` to existing functions taking a `multi_ptr` + +TODO(Peter) + ## Examples ### Simple casts @@ -188,3 +192,19 @@ TODO(Peter) ### Passing `multi_ptr` to functions TODO(Peter) + +Implicit conversion to `multi_ptr`: + +```cpp + +using namespace cl::sycl; + +template +void function_taking_const_ptr(const multi_ptr& ptr); + +const global_ptr ptrInt = get_some_global_ptr(); + +// function_taking_const_ptr(static_cast(static_cast(ptrInt))); +function_taking_const_ptr(ptrInt); + +``` From 593a7a9288c282ac756def3f01943d448f456d58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C5=BDu=C5=BEek?= Date: Wed, 19 Dec 2018 13:47:11 +0000 Subject: [PATCH 09/16] Updated dates and main table entry --- README.md | 1 + multi_ptr-cast/index.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 748d045..5cb861e 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ from this registry in the future. | CP013 | [P1436 & P1437: Papers for affinity-based execution](affinity/index.md) | ISO C++ SG1, SG14, LEWG | 15 November 2017 | 17 June 2019 | _Published_ | | CP014 | [Shared Virtual Memory](svm/index.md) | SYCL 2.2 | 22 January 2018 | 22 January 2018 | _Work in Progress_ | | CP015 | [Specialization Constant](spec-constant/index.md) | SYCL 1.2.1 extension | 24 April 2018 | 24 April 2018 | _Work in Progress_ | +| CP016 | [Casting multi_ptr pointers](multi_ptr-cast/index.md) | SYCL 1.2.1 extension / SYCL 2.2 | 19 December 2018 | 19 December 2018 | _Work in Progress_ | | CP017 | [Host Access](host_access/index.md) | SYCL 1.2.1 vendor extension | 17 September 2018 | 13 December 2018 | _Available since CE 1.0.3_ | | CP018 | [Built-in kernels](builtin_kernels/index.md) | SYCL 1.2.1 vendor extension | 12 October 2018 | 12 October 2018 | _Available since CE 1.0.3_ | | CP019 | [On-chip Memory Allocation](onchip-memory/index.md) | SYCL 1.2.1 vendor extension | 03 December 2018 | 03 December 2018 | _Available since CE 1.0.3_ | diff --git a/multi_ptr-cast/index.md b/multi_ptr-cast/index.md index 474c557..de05bcf 100644 --- a/multi_ptr-cast/index.md +++ b/multi_ptr-cast/index.md @@ -3,7 +3,7 @@ | Proposal ID | CP016 | |-------------|--------| | Name | Casting multi_ptr pointers | -| Date of Creation | 14 August 2018 | +| Date of Creation | 19 December 2018 | | Target | SYCL 1.2.1 | | Current Status | _Work in Progress_ | | Reply-to | Peter Žužek | From 3f7f07de79c0499b19854715c693ec0bbd3cc053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C5=BDu=C5=BEek?= Date: Tue, 8 Jan 2019 14:17:23 +0000 Subject: [PATCH 10/16] Use `multi_ptr` for `vec::load` --- multi_ptr-cast/sycl-2.2/index.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/multi_ptr-cast/sycl-2.2/index.md b/multi_ptr-cast/sycl-2.2/index.md index 0c9ab10..584ce08 100644 --- a/multi_ptr-cast/sycl-2.2/index.md +++ b/multi_ptr-cast/sycl-2.2/index.md @@ -151,7 +151,19 @@ template +class vec { + public: + /// Existing members + + template + void load(size_t offset, multi_ptr ptr); +}; +``` ## Examples From aea310eed33733ccb6fff2d1b1da5ce750e98624 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C5=BDu=C5=BEek?= Date: Tue, 8 Jan 2019 14:17:37 +0000 Subject: [PATCH 11/16] More examples --- multi_ptr-cast/sycl-2.2/index.md | 36 +++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/multi_ptr-cast/sycl-2.2/index.md b/multi_ptr-cast/sycl-2.2/index.md index 584ce08..ae90819 100644 --- a/multi_ptr-cast/sycl-2.2/index.md +++ b/multi_ptr-cast/sycl-2.2/index.md @@ -174,7 +174,7 @@ but it works the same for all `multi_ptr` types. ```cpp using namespace cl::sycl; -const global_ptr ptrInt = get_some_global_ptr(); +const global_ptr ptrInt = get_some_global_ptr(); // Conversion operator auto ptrFloat1 = static_cast>(ptrInt); @@ -199,24 +199,44 @@ auto ptrConstInt4 = reinterpret_pointer_cast(ptrInt); ### `dynamic_pointer_cast` -TODO(Peter) +```cpp +struct Base { + virtual void foo() const {} + virtual ~Base(){} +}; +struct Derived : public Base { + void foo() const override {} +}; -### Passing `multi_ptr` to functions +using namespace cl::sycl; +const global_ptr ptrBase = get_some_global_ptr(); -TODO(Peter) +auto ptrDerived = dynamic_pointer_cast(ptrBase); +auto ptrBase1 = dynamic_pointer_cast(ptrDerived); +``` -Implicit conversion to `multi_ptr`: +### Passing `multi_ptr` to functions ```cpp - using namespace cl::sycl; +template +void function_taking_ptr(const multi_ptr& ptr); template void function_taking_const_ptr(const multi_ptr& ptr); -const global_ptr ptrInt = get_some_global_ptr(); +const global_ptr ptrInt = get_some_global_ptr(); -// function_taking_const_ptr(static_cast(static_cast(ptrInt))); +function_taking_ptr(ptrInt); +// Implicit conversion to global_ptr: function_taking_const_ptr(ptrInt); +const global_ptr ptrFloat = get_some_global_ptr(); + +// Convert float to int pointer +function_taking_ptr(reinterpret_ptr_cast(ptrFloat)); +// First explicit conversion to global_ptr +// and then implicit conversion to global_ptr: +function_taking_const_ptr(reinterpret_ptr_cast(ptrFloat)); + ``` From 53a7e20e2d93aec5df7077864a6f81e725966203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C5=BDu=C5=BEek?= Date: Tue, 26 Mar 2019 11:27:52 +0000 Subject: [PATCH 12/16] Addressed most comments --- multi_ptr-cast/index.md | 4 ++-- multi_ptr-cast/sycl-2.2/index.md | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/multi_ptr-cast/index.md b/multi_ptr-cast/index.md index de05bcf..9348671 100644 --- a/multi_ptr-cast/index.md +++ b/multi_ptr-cast/index.md @@ -4,11 +4,11 @@ |-------------|--------| | Name | Casting multi_ptr pointers | | Date of Creation | 19 December 2018 | -| Target | SYCL 1.2.1 | +| Target | SYCL 1.2.1 vendor extension | | Current Status | _Work in Progress_ | | Reply-to | Peter Žužek | | Original author | Peter Žužek | -| Contributors | | +| Contributors | Ruyman Reyes | ## Overview diff --git a/multi_ptr-cast/sycl-2.2/index.md b/multi_ptr-cast/sycl-2.2/index.md index ae90819..460ba7a 100644 --- a/multi_ptr-cast/sycl-2.2/index.md +++ b/multi_ptr-cast/sycl-2.2/index.md @@ -112,6 +112,7 @@ we propose adding the following free functions to the `cl::sycl` namespace: ```cpp namespace cl { namespace sycl { +namespace codeplay { // Performs a static_cast of the contained pointer template @@ -133,6 +134,7 @@ template reinterpret_pointer_cast(const multi_ptr& multiPtr); +} // namespace codeplay } // namespace sycl } // namespace cl ``` @@ -142,7 +144,7 @@ In the table below, each function has the following template parameters: template ``` -| Member function | Description | +| Function | Description | |-----------------|-------------| | *`multi_ptr static_pointer_cast(const multi_ptr& multiPtr)`* | Performs a `static_cast` of the underlying pointer `ElementTypeT*` contained within `multiPtr` to `ElementTypeU*` and returns a new `multi_ptr` instance containing the cast pointer. The address space stays the same. This conversion is only valid if the `static_cast` from `ElementType*` to `ElementTypeU*` is valid. | | *`multi_ptr dynamic_pointer_cast(const multi_ptr& multiPtr)`* | Performs a `dynamic_cast` of the underlying pointer `ElementTypeT*` contained within `multiPtr` to `ElementTypeU*` and returns a new `multi_ptr` instance containing the cast pointer. The address space stays the same. This conversion is only valid if the `dynamic_cast` from `ElementType*` to `ElementTypeU*` is valid. | @@ -170,10 +172,11 @@ class vec { ### Simple casts These examples focus on `global_ptr` for brevity, -but it works the same for all `multi_ptr` types. +but the same operation is valid on any other `multi_ptr` type. ```cpp using namespace cl::sycl; +using namespace codeplay; const global_ptr ptrInt = get_some_global_ptr(); // Conversion operator @@ -209,6 +212,7 @@ struct Derived : public Base { }; using namespace cl::sycl; +using namespace codeplay; const global_ptr ptrBase = get_some_global_ptr(); auto ptrDerived = dynamic_pointer_cast(ptrBase); @@ -219,6 +223,7 @@ auto ptrBase1 = dynamic_pointer_cast(ptrDerived); ```cpp using namespace cl::sycl; +using namespace codeplay; template void function_taking_ptr(const multi_ptr& ptr); From 76e795bc136c1fb6d05e53517b5f7463655ab1eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C5=BDu=C5=BEek?= Date: Sat, 21 Sep 2019 09:18:13 +0100 Subject: [PATCH 13/16] Removed parts that were merged as SYCL 1.2.1 errata --- multi_ptr-cast/sycl-2.2/index.md | 39 +------------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) diff --git a/multi_ptr-cast/sycl-2.2/index.md b/multi_ptr-cast/sycl-2.2/index.md index 460ba7a..f255047 100644 --- a/multi_ptr-cast/sycl-2.2/index.md +++ b/multi_ptr-cast/sycl-2.2/index.md @@ -42,33 +42,12 @@ in order to make the casting safer and easier to use. ## Summary -This proposal folds the `void` specialization of the `multi_ptr` class -into the main definition of `multi_ptr`, -handles the cases where `ElementType` is a `const`-qualified type, -adds a few explicit conversion operators +This proposal adds a few explicit conversion operators as member functions of the `multi_ptr` class, and also adds several free functions to the `cl::sycl` namespace that follow the naming and semantics of the `std::shared_ptr` pointer cast functions defined by the C++17 standard: https://en.cppreference.com/w/cpp/memory/shared_ptr/pointer_cast. -## Specializations for void and const void - -In SYCL 1.2.1, the `void` specialization of the `multi_ptr` class -is separate from the main definition -because it cannot contain any reference types. -For the purpose of the specification, -we propose folding the two definitions -into a single definition of the `multi_ptr` class, -with comments denoting which types are available -only if `ElementType` is not `void` or `const void`. -The main reason for this simplification -is the introduction of the specialization for `const void`, -which would require the specification to define another specialization -that would be mostly the same as the specialization for `void`. -Simplifying the definiton like this -also covers the case where `ElementType` is not `void` or `const void`, -but some other `const`-qualified type. - ## Explicit conversion operators The new interface of the `multi_ptr` class would look like this: @@ -151,22 +130,6 @@ template const_pointer_cast(const multi_ptr& multiPtr)`* | Performs a `const_cast` of the underlying pointer `ElementTypeT*` contained within `multiPtr` to `ElementTypeU*` and returns a new `multi_ptr` instance containing the cast pointer. The address space stays the same. This conversion is only valid if the `const_cast` from `ElementType*` to `ElementTypeU*` is valid. | | *`multi_ptr reinterpret_pointer_cast(const multi_ptr& multiPtr)`* | Performs a `reinterpret_cast` of the underlying pointer `ElementTypeT*` contained within `multiPtr` to `ElementTypeU*` and returns a new `multi_ptr` instance containing the cast pointer. The address space stays the same. This conversion is only valid if the `reinterpret_cast` from `ElementType*` to `ElementTypeU*` is valid. | -## Add `const` to existing functions taking a `multi_ptr` - -For the class `vec`, -use a const-qualified `multi_ptr` for the `load` member function: - -```cpp -template -class vec { - public: - /// Existing members - - template - void load(size_t offset, multi_ptr ptr); -}; -``` - ## Examples ### Simple casts From f0602ae21f984dc2df7066911bf4599a9c010eb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C5=BDu=C5=BEek?= Date: Sat, 21 Sep 2019 09:55:47 +0100 Subject: [PATCH 14/16] Updated date --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5cb861e..6b6eed3 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ from this registry in the future. | CP013 | [P1436 & P1437: Papers for affinity-based execution](affinity/index.md) | ISO C++ SG1, SG14, LEWG | 15 November 2017 | 17 June 2019 | _Published_ | | CP014 | [Shared Virtual Memory](svm/index.md) | SYCL 2.2 | 22 January 2018 | 22 January 2018 | _Work in Progress_ | | CP015 | [Specialization Constant](spec-constant/index.md) | SYCL 1.2.1 extension | 24 April 2018 | 24 April 2018 | _Work in Progress_ | -| CP016 | [Casting multi_ptr pointers](multi_ptr-cast/index.md) | SYCL 1.2.1 extension / SYCL 2.2 | 19 December 2018 | 19 December 2018 | _Work in Progress_ | +| CP016 | [Casting multi_ptr pointers](multi_ptr-cast/index.md) | SYCL 1.2.1 extension / SYCL 2.2 | 19 December 2018 | 21 September 2019 | _Work in Progress_ | | CP017 | [Host Access](host_access/index.md) | SYCL 1.2.1 vendor extension | 17 September 2018 | 13 December 2018 | _Available since CE 1.0.3_ | | CP018 | [Built-in kernels](builtin_kernels/index.md) | SYCL 1.2.1 vendor extension | 12 October 2018 | 12 October 2018 | _Available since CE 1.0.3_ | | CP019 | [On-chip Memory Allocation](onchip-memory/index.md) | SYCL 1.2.1 vendor extension | 03 December 2018 | 03 December 2018 | _Available since CE 1.0.3_ | From 8a4975dbbb55edee7a1b867a4b77d0d53c3ad196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C5=BDu=C5=BEek?= Date: Sun, 22 Sep 2019 14:17:07 +0100 Subject: [PATCH 15/16] Removed vendor namespace --- multi_ptr-cast/sycl-2.2/index.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/multi_ptr-cast/sycl-2.2/index.md b/multi_ptr-cast/sycl-2.2/index.md index f255047..dfdb2cf 100644 --- a/multi_ptr-cast/sycl-2.2/index.md +++ b/multi_ptr-cast/sycl-2.2/index.md @@ -91,7 +91,6 @@ we propose adding the following free functions to the `cl::sycl` namespace: ```cpp namespace cl { namespace sycl { -namespace codeplay { // Performs a static_cast of the contained pointer template @@ -113,7 +112,6 @@ template reinterpret_pointer_cast(const multi_ptr& multiPtr); -} // namespace codeplay } // namespace sycl } // namespace cl ``` @@ -139,7 +137,7 @@ but the same operation is valid on any other `multi_ptr` type. ```cpp using namespace cl::sycl; -using namespace codeplay; + const global_ptr ptrInt = get_some_global_ptr(); // Conversion operator @@ -175,7 +173,6 @@ struct Derived : public Base { }; using namespace cl::sycl; -using namespace codeplay; const global_ptr ptrBase = get_some_global_ptr(); auto ptrDerived = dynamic_pointer_cast(ptrBase); @@ -186,7 +183,6 @@ auto ptrBase1 = dynamic_pointer_cast(ptrDerived); ```cpp using namespace cl::sycl; -using namespace codeplay; template void function_taking_ptr(const multi_ptr& ptr); From bdf61595a1da442e0d4353652124f042d80b44e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C5=BDu=C5=BEek?= Date: Sun, 22 Sep 2019 14:17:30 +0100 Subject: [PATCH 16/16] Some fixes to examples --- multi_ptr-cast/sycl-2.2/index.md | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/multi_ptr-cast/sycl-2.2/index.md b/multi_ptr-cast/sycl-2.2/index.md index dfdb2cf..91b31f0 100644 --- a/multi_ptr-cast/sycl-2.2/index.md +++ b/multi_ptr-cast/sycl-2.2/index.md @@ -141,24 +141,30 @@ using namespace cl::sycl; const global_ptr ptrInt = get_some_global_ptr(); // Conversion operator -auto ptrFloat1 = static_cast>(ptrInt); auto ptrVoid1 = static_cast>(ptrInt); auto ptrConstInt1 = static_cast>(ptrInt); // static_pointer_cast -auto ptrFloat2 = static_pointer_cast(ptrInt); -auto ptrVoid2 = static_pointer_cast(ptrInt); -auto ptrConstInt2 = static_pointer_cast(ptrInt); +global_ptr ptrVoid2 = + static_pointer_cast(ptrInt); +global_ptr ptrConstInt2 = + static_pointer_cast(ptrInt); // const_pointer_cast -auto ptrConstInt3 = const_pointer_cast(ptrInt); -// auto ptrIntStripConst = static_cast>(ptrConstInt1); // illegal -auto ptrIntStripConst = const_pointer_cast(ptrConstInt1); +global_ptr ptrConstInt3 = + const_pointer_cast(ptrInt); +// global_ptr ptrIntStripConst = +// static_cast>(ptrConstInt1); // illegal +global_ptr ptrIntStripConst = + const_pointer_cast(ptrConstInt1); // reinterpret_pointer_cast -auto ptrFloat4 = reinterpret_pointer_cast(ptrInt); -auto ptrVoid4 = reinterpret_pointer_cast(ptrInt); -auto ptrConstInt4 = reinterpret_pointer_cast(ptrInt); +global_ptr ptrFloat4 = + reinterpret_pointer_cast(ptrInt); +global_ptr ptrVoid4 = + reinterpret_pointer_cast(ptrInt); +global_ptr ptrConstInt4 = + reinterpret_pointer_cast(ptrInt); ``` ### `dynamic_pointer_cast` @@ -173,7 +179,7 @@ struct Derived : public Base { }; using namespace cl::sycl; -const global_ptr ptrBase = get_some_global_ptr(); +const global_ptr ptrBase = get_some_global_ptr(); auto ptrDerived = dynamic_pointer_cast(ptrBase); auto ptrBase1 = dynamic_pointer_cast(ptrDerived);