Page MenuHomePhabricator

[Docs][OpenCL] Documentation of C++ for OpenCL mode
AcceptedPublic

Authored by Anastasia on Jul 9 2019, 7:24 AM.

Diff Detail

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes
Anastasia marked 5 inline comments as done.Jul 16 2019, 4:53 AM

Addressed some review comments. Refs are still to be fixed!

Anastasia added inline comments.Jul 16 2019, 4:55 AM
docs/LanguageExtensions.rst
1673

Ok, specific here is as opposite to generic.

1753–1761

In v2.0 drivers this is a manual step. In v2.2 drivers it is expected to be done automatically.

1758

I think IR linker makes them unique i.e. adds a suffix. Although I think the files (including the path) linked are supposed to be unique. Anyway, good point to look into.

No idea about obj linker. We currently don't support this feature.

1768

This is the example I am explaining just below.

docs/UsersManual.rst
2797

Manual is good for examples. Some new developers might find it useful to have the full line even though it's quite simple.

Anastasia updated this revision to Diff 210101.Jul 16 2019, 8:11 AM
mantognini accepted this revision.Jul 17 2019, 2:26 AM

Beside my two comments, I think this looks good.

docs/LanguageExtensions.rst
1614

( -> , (there's no matching closing parenthesis.)

1652–1657

foo() isn't actually called here. You probably meant to write this:

__local C c1;
C c2;
__constant C c3;

c1.foo(); // will resolve to the first foo
c2.foo(); // will resolve to the second foo
c3.foo(); // error due to mismatching address spaces - can't convert to __local or __generic
This revision is now accepted and ready to land.Jul 17 2019, 2:26 AM
kpet requested changes to this revision.Jul 17 2019, 6:52 AM

Very useful to have all of this documented! Thanks!

docs/LanguageExtensions.rst
1527

I'm tempted to suggest you merge the first two sentences and tone down the claim in the second. "This functionality [...] and C++17, enabling _some_ regular C++ features [...].

1527

s/All/Most/? Stating that all functionality from OpenCL C is available right before stating that the differences will be described feels like a contradiction.

1535

Probably worth adding exceptions to the list.

1541

I would remove this last sentence. Only a very small portion of the libray can be supported anyway.

1553

I would remove the "yet", unless we can refer to an on-going and visible effort.

1553

"Clang extends existing concept" feels like it should be re-worded.

1555

"using sets and overlapping" feels incomplete. Pretending I can't guess: sets of what? What is overlapping what? :)

1557

Why use __generic when generic is equally valid and easier on the eyes? The same comment applies to other mentions of address space keywords.

1558

This is ambiguous. One could read that conversions from __generic to __constant are allowed.

1564

Isn't a conversion explicit if a cast operator is used?

1565

At the time of writing addrspace_cast doesn't seem to exist in trunk and C-style casts seem to work.

1565

Didn't you mean "from __generic to named address spaces"?

1577

Makes me wonder whether const members couldn't be in the constant address space.

1626

the address space?

1631

I would remove the "for example to take advantage of memory bank accesses" or make the example clear.

1641

the overload

1652–1657

+1, I was about to make the same comment.

1668

Shouldn't this be C() __generic? Similar comments can be made for the other members.

1684

template parameterS

1702

"such a program" or "such programs"

1760

I would say "must be constructed before the first kernel begins execution" and "may be destroyed once the last kernel has completed its execution". These are requirements for a runtime environment, not functionality provided by Clang. The documentation should only describe the interface with the runtime and the requirements on the runtime.

1761

OpenCL doesn't have an API for this per-se, regardless of the version. The only mechanism currently specified is the SPIR-V Initializer and Finalizer execution modes for entrypoints, either of which currently require an OpenCL 2.2 implementation.

1762

I would say that "applications are required to run all of these initialization kernels before any others if they exist".

1779

This could be managed by the application with a scheme similar to the one you're proposing for constructor functions.

docs/UsersManual.rst
2400

Shouldn't "Clang9" be "Clang 9"? You may even want to spell it out "version 9 of Clang".

2401

"A C++ mode" or "A non-standard C++ language extension" to be more precise?

2769

No plans that we're aware of ;). For all we know, there could be a company/individual working on this. I think conjectures on people's plans don't belong in the documentation.

2771

Everything is relative. I would keep this 100% factual: "there are restrictions". This is not a sales pitch :).

2779

I find -std=c++ confusing/misleading. Maybe we should change the way -cl-std works so we can have -std=clc++ and -cl-std=c++?

This revision now requires changes to proceed.Jul 17 2019, 6:52 AM

Very useful to have all of this documented! Thanks!

Would it be ok if I fix those in a separate commit? I would really like to commit the core part before the release branch is taken.

kpet accepted this revision.Jul 17 2019, 8:36 AM

Would it be ok if I fix those in a separate commit? I would really like to commit the core part before the release branch is taken.

I'm fine with this as long as we can continue the discussion for open comments in this review. Accepting the revision as I don't seem to be able to go back on my request for another patch.

This revision is now accepted and ready to land.Jul 17 2019, 8:36 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJul 17 2019, 10:21 AM
Anastasia reopened this revision.Jul 17 2019, 11:27 AM

Reopening to continue reviews.

This revision is now accepted and ready to land.Jul 17 2019, 11:27 AM
Anastasia updated this revision to Diff 215106.Wed, Aug 14, 6:35 AM
Anastasia marked 26 inline comments as done.

Addressed various comments from Kevin.

Anastasia marked 12 inline comments as done and 2 inline comments as done.Wed, Aug 14, 6:48 AM
Anastasia added inline comments.
docs/LanguageExtensions.rst
327

FYI, this is not part of my change. It was just hard to produce combined diff.

1541

I think it's valuable especially for metaprogramming. I was being asked about it.

1553

I need to understand what needs re-wording

1557

I prefer to use __ for two reasons (1) it's more official in OpenCL docs and tutorials (2) I sometimes omit the noun and just use it as a short term in the text.

1564

It's complicated to explain but basically some cast operators perform implicit conversions of what they are not expected to do because implicit conversions are allowed everywhere even if the operator isn't intended to do the conversion explicitly.

Similar example in C++, most of operators accept converting to const objects.

1565

At the time of writing addrspace_cast doesn't seem to exist in trunk and C-style casts seem to work.

I think it's ok to document full extension even if it's WIP.

1577

No constant specify memory region but const indicates that object is not changed during lifetime. You can cast away const but you can't convert constant object to any other address space.

1761

Not sure whether you imply any action here.

1779

The Itanium C++ ABIs for destructors are different and we haven't got it working yet for OpenCL. I would leave the description as is for now.

docs/UsersManual.rst
2771

I think it's fair to say few restrictions because the majority of C++ just works in OpenCL.

svenvh added inline comments.Thu, Aug 15, 5:21 AM
docs/LanguageExtensions.rst
1561

"For OpenCL it means that implicit conversions are allowed from a ​named address space except for conversion from the `__constant to the __generic` address space."

I would omit "that is a superset of all others except for `__constant`" as that is already documented in the OpenCL spec and it might confuse readers here. If you want to keep it, I suggest rephrasing it as a separate sentence.

1563

+The+ `__constant` address space

1570

"C-style casts follow"

1630

+the+ `__generic` address space

(also in the next few lines)

1647

+an+ address space qualifier

1650

ithe -> the

1651

Duplicate "to" (to to)

1652

Add comma:
... overloads, compilation ...

1715

Add comma:
... instantiation, compilation ...

1730

Once a template has been instantiated, regular restrictions for address spaces will apply.

1746

the `__private` address space

1747

some other -> another

1748

it's -> it is

add comma:
... valid, otherwise ...

1776

enqueue *a* constructor

1782

Add comma:
... libraries, multiple ...

1793

Add comma:
... initialized, the ...

1794

contain +the+

docs/UsersManual.rst
2765

Clang9 -> Clang 9 (with space).

2769

I think conjectures on people's plans don't belong in the documentation.

Agreed.

2771

I agree with @kpet and also prefer "There are restrictions" instead of an unquantified statement.

2776

I wouldn't say "new" mode as this is part of a persistent user manual.

2778

Again I would avoid "new mode".

"To enable the C++ for OpenCL mode,"

Also: pass *one of* the following command line options when compiling a `.cl`

So in total:
To enable the C++ for OpenCL mode, pass one of the following command line options when compiling a `.cl` file:

Anastasia updated this revision to Diff 215562.Fri, Aug 16, 4:44 AM
Anastasia marked an inline comment as done and 2 inline comments as not done.
  • Addressed comments from Sven.
Anastasia added inline comments.Fri, Aug 16, 4:45 AM
docs/UsersManual.rst
2771

Ok, I don't understand what value does it bring to make information less specific but potentially it's not important enough to continue the argument. The idea of this sentence was indeed to point out that the mode is just very close to C++ with very few restrictions. This isn't a program so it can't have a formal definition for every statement. :P

Anastasia updated this revision to Diff 215922.Mon, Aug 19, 9:17 AM

Added small corrections in various parts.

svenvh accepted this revision.Mon, Aug 19, 9:33 AM

LGTM!