<div dir="ltr">+ some more people who care about CUDA support but might not be subscribed to this list.<br></div><br><div class="gmail_quote"><div dir="ltr">On Tue, 11 Dec 2018 at 09:39, JF Bastien via libcxx-dev <<a href="mailto:libcxx-dev@lists.llvm.org">libcxx-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space">I’m very excited to have NVIDIA collaborate on libc++. It’s worth supporting your weirdo macro hack as a transitional tool.<div><br></div><div>I’m especially interested in working on freestanding in clang / libc++, bringing the good parts of it from the current C++ standard, and working with you and other on the Committee to make C++23 freestanding actually nice (Ben Craig has been working on <a href="http://wg21.link/P0829R3" target="_blank">wg21.link/P0829R3</a>). I hope that we can experiment on what’s “nice” in clang / libc++ in the next few months.</div><div><div>One design constraint around freestanding: I want to make sure that clang can keep supporting other STL implementations.</div><div><br></div><div>I’d like to understand if we can have a different ABI for freestanding, given that it’s not supported in libc++ today. This might be an opportunity to fix some mistakes.</div><div><br></div></div><div>On “freestanding” macro, clang does the following today:</div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font face="Courier">  if (LangOpts.Freestanding)</font></div><div><font face="Courier">    Builder.defineMacro("__STDC_HOSTED__", "0");</font></div><div><font face="Courier">  else</font></div><div><font face="Courier">    Builder.defineMacro("__STDC_HOSTED__</font><span style="font-family:Courier">"</span><span style="font-family:Courier">);</span></div></blockquote><div>Otherwise, clang’s lib/Headers do some stuff with HOSTED as well, which might interfere with freestanding.</div><div><br>Good header hygiene indeed seems necessary, especially for <algorithm>. Louis mentioned that he was interested in looking into this.</div><div>Louis did a survey and found the following:</div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div><div>Freestanding in the current C++20 draft requires the following headers:</div></div></div><div><div><div><font face="Courier"><br></font></div></div></div><div><div><div><font face="Courier">    <ciso646></font></div></div></div><div><div><div><font face="Courier">    <cstddef></font></div></div></div><div><div><div><font face="Courier">    <cfloat> </font></div></div></div><div><div><div><font face="Courier">    <limits> </font></div></div></div><div><div><div><font face="Courier">    <climits></font></div></div></div><div><div><div><font face="Courier">    <cstdint></font></div></div></div><div><div><div><font face="Courier">    <cstdlib></font></div></div></div><div><div><div><font face="Courier">    <new></font></div></div></div><div><div><div><font face="Courier">    <typeinfo></font></div></div></div><div><div><div><font face="Courier">    <exception></font></div></div></div><div><div><div><font face="Courier">    <initializer_list></font></div></div></div><div><div><div><font face="Courier">    <cstdarg></font></div></div></div><div><div><div><font face="Courier">    <type_traits></font></div></div></div><div><div><div><font face="Courier">    <atomic></font></div></div></div><div><div><div><br></div></div></div><div><div><div>Of those headers, I think the following are easy to provide with minimal changes to libc++ and without having to ship a libc++ shared object (or compiler-rt), and they use the following parts of the C Standard Library:</div></div></div><div><div><div><font face="Courier"><br></font></div></div></div><div><div><div><font face="Courier">    <ciso646>: nothing</font></div></div></div><div><div><div><font face="Courier">    <cstddef>: stddef.h</font></div></div></div><div><div><div><font face="Courier">    <cfloat> : float.h</font></div></div></div><div><div><div><font face="Courier">    <limits> : stddef.h</font></div></div></div><div><div><div><font face="Courier">    <climits>: limits.h</font></div></div></div><div><div><div><font face="Courier">    <cstdint>: stdint.h</font></div></div></div><div><div><div><font face="Courier">    <cstdlib>: stdlib.h</font></div></div></div><div><div><div><font face="Courier">    <initializer_list>: stddef.h</font></div></div></div><div><div><div><font face="Courier">    <cstdarg>: stdarg.h</font></div></div></div><div><div><div><font face="Courier">    <type_traits>: stddef.h</font></div></div></div><div><div><div><br></div></div></div><div><div><div>As a result, I think the following are low-hanging fruit that do not require any runtime support AFAICT:</div></div></div><div><div><div><font face="Courier"><br></font></div></div></div><div><div><div><font face="Courier">    <ciso646></font></div></div></div><div><div><div><font face="Courier">    <cstddef></font></div></div></div><div><div><div><font face="Courier">    <cfloat></font></div></div></div><div><div><div><font face="Courier">    <limits></font></div></div></div><div><div><div><font face="Courier">    <climits></font></div></div></div><div><div><div><font face="Courier">    <cstdint></font></div></div></div><div><div><div><font face="Courier">    <initializer_list></font></div></div></div><div><div><div><font face="Courier">    <type_traits></font></div></div></div><div><div><div><br></div></div></div><div><div><div>Other things we might be able to throw in with minimal effort:</div></div></div><div><div><div><font face="Courier"><br></font></div></div></div><div><div><div><font face="Courier">    <bit></font></div></div></div><div><div><div><font face="Courier">    <ratio></font></div></div></div><div><div><div><br></div></div></div><div><div><div>Other things that we SHOULD be able to have, but that would require refactoring in libc++ (and most of them are not part of the current freestanding):</div></div></div><div><div><div><font face="Courier"><br></font></div></div></div><div><div><div><font face="Courier">    <tuple></font></div></div></div><div><div><div><font face="Courier">    <pair></font></div></div></div><div><div><div><font face="Courier">    most if not all of <functional></font></div></div></div><div><div><div><font face="Courier">    most of <algorithm></font></div></div></div><div><div><div><font face="Courier">    <span></font></div></div></div><div><div><div><font face="Courier">    <array></font></div></div></div><div><div><div><font face="Courier">    <string_view></font></div></div></div><div><div><div><font face="Courier">    lock-free parts of <atomic></font></div></div></div></blockquote><div><div><div><br></div></div></div><div><br><div><br><blockquote type="cite"><div>On Dec 10, 2018, at 9:23 PM, Olivier Giroux via libcxx-dev <<a href="mailto:libcxx-dev@lists.llvm.org" target="_blank">libcxx-dev@lists.llvm.org</a>> wrote:</div><br class="m_6343777391069328247Apple-interchange-newline"><div><div class="m_6343777391069328247WordSection1" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt">Hello libc++-dev,<u></u><u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt"><u></u> <u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt">In the discussion of<span class="m_6343777391069328247Apple-converted-space"> </span><a href="https://reviews.llvm.org/D55517" style="color:rgb(149,79,114);text-decoration:underline" target="_blank">https://reviews.llvm.org/D55517</a>, I mentioned that we are attempting a vendor variant of libcxx that uses _VSTD differently. Eric pointed out that I should have started here, so we could talk about design goals. He’s right, I’m sorry.<u></u><u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt"><u></u> <u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt">Not one to bury the lede, I’d like to talk about a CUDA C++ standard library.<u></u><u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt"><u></u> <u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt">The ultimate goal of something like that should be that most things in C++, if not bolted too-tightly onto the operating system, should be able to be passed and used between CPU and GPU. There’s no fundamental reason why we don’t have a big chunk of C++ working like this,<span class="m_6343777391069328247Apple-converted-space"> </span><i>today</i>, if we’re talking about contemporary HPC-friendly GPUs. The reason we don’t have much is that it’s a huge pile of work and everyone has managed to avoid doing it so far.<u></u><u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt"><u></u> <u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt">One exploration vehicle was shown at CppCon in September (by me, see: YouTube, and<span class="m_6343777391069328247Apple-converted-space"> </span><a href="https://github.com/ogiroux/freestanding" style="color:rgb(149,79,114);text-decoration:underline" target="_blank">https://github.com/ogiroux/freestanding</a>) and then we made but failed to present a more detailed poster at the LLVM dev meeting in October. And now we’re here.<span class="m_6343777391069328247Apple-converted-space"> </span></span><span style="font-size:11pt;font-family:"Apple Color Emoji"">😊</span><span style="font-size:11pt"><u></u><u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt"><u></u> <u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt">After making a few exploration vehicles (2 overall, 4 for <atomic>), we now think we’ll create version 1 this way:<u></u><u></u></span></div><ol start="1" type="1" style="margin-bottom:0in;margin-top:0in"><li class="m_6343777391069328247MsoListParagraph" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt">Wrap select libcxx <*> headers with <cuda/*> to introduce symbols in cuda::* instead of std::*, and…<u></u><u></u></span><ol start="1" type="a" style="margin-bottom:0in;margin-top:0in"><li class="m_6343777391069328247MsoListParagraph" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt">These facilities are always heterogeneous, NORTTI, and NOEXCEPTIONS.<u></u><u></u></span></li><li class="m_6343777391069328247MsoListParagraph" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt">Enable users to include them<span class="m_6343777391069328247Apple-converted-space"> </span><i>on top of</i><span class="m_6343777391069328247Apple-converted-space"> </span>their host library (that being CPU only).<u></u><u></u></span></li></ol></li><li class="m_6343777391069328247MsoListParagraph" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt">“Select” here means prioritizing headers in Freestanding now, or soon, basically the header-only facilities.<u></u><u></u></span></li><li class="m_6343777391069328247MsoListParagraph" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt">Subsequently help maintain the intersection of libcxx and Freestanding.<u></u><u></u></span></li></ol><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt"><u></u> <u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt">In terms of libcxx design, we think that we could layer on this surface:<u></u><u></u></span></div><ul type="disc" style="margin-bottom:0in;margin-top:0in"><li class="m_6343777391069328247MsoListParagraph" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt">A freestanding mode, say LIBCXX_FREESTANDING, with a design goal of placing low-OS-coupling variants of code for facilities under this mode, and some agreement that Freestanding libraries have different ABI goals than their closest Hosted relative.<u></u><u></u></span><ul type="circle" style="margin-bottom:0in;margin-top:0in"><li class="m_6343777391069328247MsoListParagraph" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt">For example, in <atomic>, it would be preferable for Freestanding implementations (and users) if the<span class="m_6343777391069328247Apple-converted-space"> </span><i>lock-in-atomic</i><span class="m_6343777391069328247Apple-converted-space"> </span>strategy was used for non-lock-free atomics (instead of the<span class="m_6343777391069328247Apple-converted-space"> </span><i>sharded-lock-table</i><span class="m_6343777391069328247Apple-converted-space"> </span>strategy tucked inside __cxa_atomic_*) because that then frees the program from dependencies on libatomic.<u></u><u></u></span></li><li class="m_6343777391069328247MsoListParagraph" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt">It is my intention to contribute the code for this 3<sup>rd</sup><span class="m_6343777391069328247Apple-converted-space"> </span>strategy, and other maintenance to <atomic>, some of which I’ve already made in my branch.<u></u><u></u></span></li></ul></li><li class="m_6343777391069328247MsoListParagraph" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt">An extension point that allows std::* symbols to be put into another namespace, both for ABI and to co-exist.<u></u><u></u></span><ul type="circle" style="margin-bottom:0in;margin-top:0in"><li class="m_6343777391069328247MsoListParagraph" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt">This is in tension with Eric’s proposed change.<u></u><u></u></span></li></ul></li><li class="m_6343777391069328247MsoListParagraph" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt">An extension point that allows us to tune visibility control, e.g. add __device__ linkage to local-linkage symbols in those headers included in the subset (Freestanding minimum, or the implementation-defined choice).<u></u><u></u></span><ul type="circle" style="margin-bottom:0in;margin-top:0in"><li class="m_6343777391069328247MsoListParagraph" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt">This was at one point in tension with changes Louis was making, but I think we’re Ok right now.<u></u><u></u></span></li></ul></li><li class="m_6343777391069328247MsoListParagraph" style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt">And, generally speaking, good header inclusion hygiene that tries to minimize what’s pulled into a facility’s header.<u></u><u></u></span></li></ul><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt"><u></u> <u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt">That should isolate most of the ugly stuff in our code; version 1 will indeed be fairly ugly, no doubt about that. But then, hopefully, this all ends with libcxx gaining a new implementer!<u></u><u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt"><u></u> <u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt">Thanks for reading, I’ll try to answer your questions as best I can.<u></u><u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt"><u></u> <u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt">Sincerely,<u></u><u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt"><u></u> <u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:11pt">Olivier<br><br><u></u><u></u></span></div></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><hr></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">This email message is for the sole use of the intended recipient(s) and may contain confidential information.  Any unauthorized review, use, disclosure or distribution is prohibited.  If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><hr></div><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;float:none;display:inline!important">_______________________________________________</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;float:none;display:inline!important">libcxx-dev mailing list</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><a href="mailto:libcxx-dev@lists.llvm.org" style="color:rgb(149,79,114);text-decoration:underline;font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">libcxx-dev@lists.llvm.org</a><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-dev" style="color:rgb(149,79,114);text-decoration:underline;font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-dev</a></div></blockquote></div><br></div></div>_______________________________________________<br>
libcxx-dev mailing list<br>
<a href="mailto:libcxx-dev@lists.llvm.org" target="_blank">libcxx-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-dev</a><br>
</blockquote></div>